Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed class for PEP and changed constants to class variables #2

Merged
merged 1 commit into from Feb 17, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 14 additions & 13 deletions moves.py
Expand Up @@ -3,25 +3,26 @@
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/'
def __init__(self, client_id, client_secret, redirect_url, \
api_url = 'https://api.moves-app.com/oauth/v1/'):
self.client_id = client_id # Client ID, get this by creating an app

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should these not be indented another level?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, line 8 should be intended. Sorry, haven't time for this project any more now :(

self.client_secret = client_secret # Client Secret, get this by creating an app
self.redirect_url = redirect_url # Callback URL for getting an access token
self.api_url = api_url

# 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
c = '&client_id=' + self.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
c = '&client_id=' + self.client_id
r = '&redirect_uri=' + self.redirect_url
s = '&client_secret=' + self.client_secret
j = requests.post('access_token?grant_type=authorization_code&code=' + request_token + c + s + r)
token = j.json()['access_token']
return token
Expand All @@ -31,13 +32,13 @@ def auth(self, request_token):
# Base request
def get(self, token, endpoint):
token = '?access_token=' + token
return requests.get(API_URL + endpoint + token).json()
return requests.get(self.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()
return requests.get(self.api_url + root + token).json()

# Summary requests

Expand All @@ -46,7 +47,7 @@ def get_profile(self, token):
# /user/summary/daily/<month>
def get_summary(self, token, date):
token = '?access_token=' + token
return requests.get(API_URL + '/user/summary' + date + token).json()
return requests.get(self.api_url + '/user/summary' + date + token).json()


# Range requests, max range of 7 days!
Expand All @@ -55,7 +56,7 @@ def get_summary(self, token, date):
# /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):
def get_range(self, access_token, endpoint, start, end):
export = get(access_token, endpoint + '?from=' + start + '&to=' + end)
return export

Expand Down