Skip to content

Commit

Permalink
chore: update examples, add file posting to index.cjs
Browse files Browse the repository at this point in the history
  • Loading branch information
dtfiedler committed Sep 1, 2023
1 parent 538f2f8 commit 61c6b5f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
17 changes: 16 additions & 1 deletion examples/node/index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
const { TurboFactory, TurboUnauthenticatedPaymentService } = await import(
'../../lib/index.js'
);
const path = require('path');
const fs = require('fs');
/**
* Fetching rates using an unauthenticated Turbo client.
*/
Expand Down Expand Up @@ -51,11 +53,24 @@
);

/**
* Fetch the estimated amount of winc returned for $1 USD
* Fetch the estimated amount of winc returned for 10 USD (1000 cents).
*/
const estimatedWinc = await turboAuthClient.getWincForFiat({
amount: 1000,
currency: 'usd',
});
console.log('10 USD to winc:', estimatedWinc);

/**
* Post local files to the Turbo service.
*/
console.log('Posting raw files to Turbo service...');
const filePaths = [path.join(__dirname, './files/0_kb.txt')];
const fileStreamGenerators = filePaths.map(
(filePath) => () => fs.createReadStream(filePath),
);
const uploadResult = await turboAuthClient.uploadFiles({
fileStreamGenerators: fileStreamGenerators,
});
console.log(JSON.stringify(uploadResult, null, 2));
})();
10 changes: 5 additions & 5 deletions examples/node/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ import {
);

/**
* Fetch the estimated amount of winc returned for 10 USD (1000 cents)
* Fetch the estimated amount of winc returned for 10 USD (1000 cents).
*/
const estimatedWinc = await turboAuthClient.getWincForFiat({
amount: 1000,
Expand All @@ -56,12 +56,12 @@ import {
console.log('10 USD to winc:', estimatedWinc);

/**
* Post some local raw files to the Turbo service.
* Post local files to the Turbo service.
*/
console.log('Posting raw files to Turbo service...');
const files = [new URL('files/0_kb.txt', import.meta.url).pathname];
const fileStreamGenerators = files.map(
(file) => () => fs.createReadStream(file),
const filePaths = [new URL('files/0_kb.txt', import.meta.url).pathname];
const fileStreamGenerators = filePaths.map(
(filePath) => () => fs.createReadStream(filePath),
);
const uploadResult = await turboAuthClient.uploadFiles({
fileStreamGenerators: fileStreamGenerators,
Expand Down

0 comments on commit 61c6b5f

Please sign in to comment.