Skip to content

Commit

Permalink
Update get events example code in README.mustache
Browse files Browse the repository at this point in the history
  • Loading branch information
jv-asana committed Dec 13, 2023
1 parent f366ca9 commit ffaeaf8
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 14 deletions.
19 changes: 12 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -721,29 +721,34 @@ let opts = {
};
const timeouts = 5000

// Used to fetch for initial sync token
const setSyncToken = async () => {
await eventsApiInstance.getEvents(resource, opts).then((result) => {
console.log('API called successfully. Returned data: ' + JSON.stringify(result.data, null, 2));
console.log(JSON.stringify(result.data, null, 2));
}, (error) => {
let syncToken = error.response.body.sync;
opts['sync'] = syncToken;
console.log(syncToken);
});
}

const getEvents = async () => {
console.log("Setting Sync Token");
console.log("Setting sync token");
await setSyncToken();
// Fetch for new events every 5 seconds -> NOTE: the sync token has expired or reached 100 events you will need to implement logic to get the next set of events
console.log(`Fetching events every ${timeouts/1000} second(s) since sync ${opts['sync']}:`);
// Fetch for new events every 5 seconds
console.log(`Fetching events every ${timeouts/1000} second(s)`);
while(true) {
await eventsApiInstance.getEvents(resource, opts).then((result) => {
console.log('API called successfully. Returned data: ' + JSON.stringify(result.data, null, 2));
// Print response
console.log(`Fetching events since sync: ${opts['sync']}`);
console.log(JSON.stringify(result.data, null, 2));

// Update the sync token with the new sync token provided in the response
opts['sync'] = result._response.sync;
}, (error) => {
if (error.status === 412) {
let syncToken = error.response.body.sync;
opts['sync'] = syncToken;
console.log(syncToken);
console.log(`412 error new sync token: ${syncToken}`);
} else{
console.error(error.response.text);
}
Expand Down
19 changes: 12 additions & 7 deletions codegen/templates/README.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -516,29 +516,34 @@ let opts = {
};
const timeouts = 5000

// Used to fetch for initial sync token
const setSyncToken = async () => {
await eventsApiInstance.getEvents(resource, opts).then((result) => {
console.log('API called successfully. Returned data: ' + JSON.stringify(result.data, null, 2));
console.log(JSON.stringify(result.data, null, 2));
}, (error) => {
let syncToken = error.response.body.sync;
opts['sync'] = syncToken;
console.log(syncToken);
});
}

const getEvents = async () => {
console.log("Setting Sync Token");
console.log("Setting sync token");
await setSyncToken();
// Fetch for new events every 5 seconds -> NOTE: the sync token has expired or reached 100 events you will need to implement logic to get the next set of events
console.log(`Fetching events every ${timeouts/1000} second(s) since sync ${opts['sync']}:`);
// Fetch for new events every 5 seconds
console.log(`Fetching events every ${timeouts/1000} second(s)`);
while(true) {
await eventsApiInstance.getEvents(resource, opts).then((result) => {
console.log('API called successfully. Returned data: ' + JSON.stringify(result.data, null, 2));
// Print response
console.log(`Fetching events since sync: ${opts['sync']}`);
console.log(JSON.stringify(result.data, null, 2));

// Update the sync token with the new sync token provided in the response
opts['sync'] = result._response.sync;
}, (error) => {
if (error.status === 412) {
let syncToken = error.response.body.sync;
opts['sync'] = syncToken;
console.log(syncToken);
console.log(`412 error new sync token: ${syncToken}`);
} else{
console.error(error.response.text);
}
Expand Down

0 comments on commit ffaeaf8

Please sign in to comment.