https://github.com/sethwebster/our-groceries-client
https://github.com/sethwebster/our-groceries-client
Last synced: about 1 year ago
JSON representation
- Host: GitHub
- URL: https://github.com/sethwebster/our-groceries-client
- Owner: sethwebster
- Created: 2016-03-29T02:43:47.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2021-05-09T16:05:21.000Z (about 5 years ago)
- Last Synced: 2025-03-09T14:02:49.016Z (over 1 year ago)
- Language: JavaScript
- Size: 12.7 KB
- Stars: 11
- Watchers: 9
- Forks: 7
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Our Groceries Client
Current Features
* Provides Authentication
* Allows Retrieval of User's grocery lists
* Allows addition of items to lists
### Installation
```
npm install our-groceries-client
```
### Usage
```javascript
var OurGroceriesClient = require('our-groceries-client');
// or import OurGroceriesClient from 'our-groceries-client'
var username = ""
, password = ""
, listName = ""
, itemName = "Apples"
, quantity = 1;
var client = new OurGroceriesClient();
var handlers = {
// Called when authentication completes, either success or failure
authComplete: function(result) {
if (result.success) {
client.getLists(handlers.getListsComplete);
} else {
console.log("Authentication Failed: "+result.error);
}
},
// Called when fetching the list of lists completes, either success or failure
getListsComplete: function(result) {
if (result.success) {
var list = client.findList(result.response.shoppingLists, listName);
if (list) {
client.getList(list.id, handlers.getListComplete);
} else {
console.log("Unable to find list: "+listName);
}
} else {
console.log("Unable to get lists: "+result.error);
}
},
// Called when fetching a single list completes, either success or failure
getListComplete: function(result) {
var list = result.response.list;
client.addToList(list.id, itemName, quantity, handlers.addToListComplete);
},
// Called after adding the item completes
addToListComplete: function(result) {
if (result.success) {
console.log("Successfully added to list.");
} else {
console.log("Unable to add to list: "+result.error);
}
}
}
// Authenticate
client.authenticate(username, password, handlers.authComplete);
```