1.0.0 • Published 2 years ago

tgtg-js v1.0.0

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

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: 'your_email@example.com',
});

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:

1.0.0

2 years ago