Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/flochtililoch/automate
Automatic API wrapper
https://github.com/flochtililoch/automate
Last synced: about 5 hours ago
JSON representation
Automatic API wrapper
- Host: GitHub
- URL: https://github.com/flochtililoch/automate
- Owner: flochtililoch
- Created: 2014-06-13T03:06:32.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2014-08-14T15:45:16.000Z (over 10 years ago)
- Last Synced: 2024-10-08T15:14:22.603Z (about 1 month ago)
- Language: CoffeeScript
- Size: 2.53 MB
- Stars: 0
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Automatic API Wrapper
See [Automatic API](https://www.automatic.com/developer/) for more details.
## Installation
```bash
npm install automate --save
```## Usage
```coffescript
express = require 'express'
cookieParser = require 'cookie-parser'
{AutomaticAPIClient} = require 'automate'automaticAccessToken = 'automaticAccessToken'
api = new AutomaticAPIClient
appId: '1234567890' # replace with your app id
appSecret: '1234567890' # replace with your app secredapp = express()
app.use cookieParser()
app.get '/', (req, res) ->
accessToken = req.cookies[automaticAccessToken]
res.redirect api.getAuthorizeUrl() unless accessToken# optionally define request parameters
qs =
page: req.query.page or 1
max_per_page: 100api.setAccessToken accessToken
api.getTrips {qs}, (err, response) ->
res.end response.bodyapp.get '/redirect', (req, res) ->
{state, code} = req.query
api.accessGranted {state, code}, (err, token) ->
return err if err?
res.cookie automaticAccessToken, JSON.stringify(token), maxAge: new Date(token.expiresAt) - new Date()
res.redirect '/'app.listen 3070
```