tgtg-js
v1.0.0
Published
The TGTG-JS (Too Good To Go JavaScript) package is a set of functions that provides a simple and easy-to-use way to integrate the features of Too Good To Go's API into your JavaScript projects.
Downloads
1
Readme
TGTG-JS
This package is an unofficial client for the TooGoodToGo API. It allows you to interact with the API to fetch information about available products, manage orders, and more.
Installation
npm install --save <package_name>
Usage
Here is an example of using this client to log in and fetch available items near a given geographical position:
const TgtgClient = require('<package_name>');
const client = new TgtgClient({
email: '[email protected]',
});
client.login()
.then(() => {
return client.get_items(48.8566, 2.3522, 10);
})
.then(items => {
console.log(items);
})
.catch(error => {
console.error('Error:', error.message);
});
Available Methods
login()
Authenticates the client with the API using the email address provided during initialization. This method must be called before using other methods of the class. If an access_token and refresh_token are provided during initialization, this method will attempt to refresh the access_token if needed.
refresh_access_token()
Refreshes the access_token using the current refresh_token. This method is automatically called by the login() method if needed.
get_items(latitude, longitude, radius)
Fetches available items near a given geographical position.
Returns a promise that resolves an array of objects representing the available items.
Configuration Options
During the initialization of the client, you can provide an options object to configure the behavior of the client. The available options are as follows: