diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4548ebd --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*.pyc +*.git diff --git a/moves.py b/moves.py new file mode 100644 index 0000000..4dd1b97 --- /dev/null +++ b/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/ + # /user/summary/daily/ + # /user/summary/daily/ + 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=&to= + # /user/activities/daily?from=&to= + # /user/places/daily?from=&to= + # /user/storyline/daily?from=&to= + def get_range(access_token, endpoint, start, end): + export = get(access_token, endpoint + '?from=' + start + '&to=' + end) + return export + + diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..1a0de61 --- /dev/null +++ b/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.