For Developers
Design Patterns
The use() function
This function will either initialize an instance of the User or Graph API based on the token set you pass it. All the requests you make with that instance with now be scoped to that TokenSet.
// Graph API
edlink.use({
access_token: '[...]',
type: TokenSetType.Integration
});
// User API
edlink.use({
access_token: '[...]',
refresh_token: '[...]',
expiration_date: Date.now();
type: TokenSetType.Person
});
Using async generators {sdk-async-generators}
This SDK makes use of generators to simplify pagination. Here is an example of how to use one:
const schools: Map<string, School> = new Map();
for await (const school of edlink.use(token_set).schools.list({ limit: 20 })) {
schools.set(school.id, school);
}
console.log(schools.size); // 20
Error handling for generators is a little different. You can see more about this here.
Paging Arguments {sdk-paging-options}
Some functions paginate requests and accept a configuration object allowing you to customize this behavior. For example:
edlink.use(token_set).schools.list({
// Pass parameters here
});
Parameter | Type | Description |
---|---|---|
limit | number | The max number of items to recieve. |
Filtering {sdk-filtering}
Some functions accept a filter object allowing you to filter the results the API returns. For example:
for await (const person of edlink.use(token_set).people.list({
filter: {
first_name: [{ operator: 'starts with', value: 'Lil' }]
}
})) {
console.log(person.first_name); // Lilly, Lillian, etc.
}
Read more about filtering here.