Skip to content

Commit

Permalink
First commit of the Moves App python library
Browse files Browse the repository at this point in the history
  • Loading branch information
Joost Plattel authored and Joost Plattel committed Jul 9, 2013
0 parents commit e539557
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
@@ -0,0 +1,2 @@
*.pyc
*.git
62 changes: 62 additions & 0 deletions moves.py
@@ -0,0 +1,62 @@
# A python class for easy access to the Moves App data. Created by Joost Plattel [http://github.com/jplattel]

import requests

class Moves():

CLIENT_ID = '' # Client ID, get this by creating an app
CLIENT_SECRET = '' # Client Secret, get this by creating an app
REDIRECT_URL = '' # Callback URL for getting an access token
API_URL = 'https://api.moves-app.com/oauth/v1/'

# Generate an request URL
def request_url(self):
u = 'https://api.moves-app.com/oauth/v1/authorize?response_type=code'
c = '&client_id=' + CLIENT_ID
s = '&scope=' + 'activity location' # Assuming we want both activity and locations
url = u + c + s
return url # Open this URL for the PIN, then authenticate with it and it will redirect you to the callback URL with a request-code, specified in the API access.

# Get access_token
def auth(self, request_token):
c = '&client_id=' + CLIENT_ID
r = '&redirect_uri=' + REDIRECT_URL
s = '&client_secret=' + CLIENT_SECRET
j = requests.post('access_token?grant_type=authorization_code&code=' + request_token + c + s + r)
token = j.json()['access_token']
return token

# Standard GET and profile requests

# Base request
def get(self, token, endpoint):
token = '?access_token=' + token
return requests.get(API_URL + endpoint + token).json()

# /user/profile
def get_profile(self, token):
token = '?access_token=' + token
root = '/user/profile'
return requests.get(API_URL + root + token).json()

# Summary requests

# /user/summary/daily/<date>
# /user/summary/daily/<week>
# /user/summary/daily/<month>
def get_summary(self, token, date):
token = '?access_token=' + token
return requests.get(API_URL + '/user/summary' + date + token).json()


# Range requests, max range of 7 days!

# /user/summary/daily?from=<start>&to=<end>
# /user/activities/daily?from=<start>&to=<end>
# /user/places/daily?from=<start>&to=<end>
# /user/storyline/daily?from=<start>&to=<end>
def get_range(access_token, endpoint, start, end):
export = get(access_token, endpoint + '?from=' + start + '&to=' + end)
return export


24 changes: 24 additions & 0 deletions readme.md
@@ -0,0 +1,24 @@
# PyMoves, a python library for the Moves App API

## Dependencies

The only dependency of this library is [Requests](http://docs.python-requests.org/en/latest/).

## Example Usage

from pymoves import Moves
m = Moves()

Get a request token URL:

request_url = m.request_url()

Open the Moves app and enter the PIN, then you will be redirected the url specified in for the app. The next step is to use the code to get and access token:

access_token = m.auth()

If you have an access token you can make requests like:

m.get_profile(access_token)

This will fetch all user info. Other requests are also build in, but beware of the range requests as they have a limit of 7 days.

0 comments on commit e539557

Please sign in to comment.