diff --git a/.gitignore b/.gitignore index 6ffac1c..7c6c6ce 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ *.pyc *.egg-info .coverage +env/ diff --git a/Makefile b/Makefile index ff94f01..bd698c9 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ .DEFAULT_GOAL := test test: clean lint - @py.test --cov app.py -s test/ + @py.test test/ --cov app.py -s lint: @flake8 . diff --git a/README.md b/README.md index 0749bec..dc09eb6 100644 --- a/README.md +++ b/README.md @@ -16,9 +16,9 @@ How To Use This --------------- 1. Navigate over to https://developer.uber.com/, and sign up for an Uber developer account. -2. Register a new Uber application and make your Redirect URI http://localhost:7000/submit - ensure that both the `profile` and `history` OAuth scopes are checked. +2. Register a new Uber application and make your Redirect URI `http://localhost:7000/submit` - ensure that both the `profile` and `history` OAuth scopes are checked. 3. Fill in the relevant information in the `config.json` file in the root folder and add your client id and secret as the environment variables `UBER_CLIENT_ID` and `UBER_CLIENT_SECRET`. -4. Run `export UBER_CLIENT_ID="YOUR_CLIENT_ID"&&export UBER_CLIENT_SECRET="YOUR_CLIENT_SECRET"` +4. Run `export UBER_CLIENT_ID="`*{your client id}*`"&&export UBER_CLIENT_SECRET="`*{your client secret}*`"` 5. Run `pip install -r requirements.txt` to install dependencies 6. Run `python app.py` 7. Navigate to http://localhost:7000 in your browser @@ -47,7 +47,8 @@ Click the button below to set up this sample app on Heroku: [](https://heroku.com/deploy) -After creating your app on Heroku, you have to configure the redirect URL for your Uber OAuth app. Use a `https://{my-app-name}.herokuapp.com/submit` URL. +After creating your app on Heroku, you have to configure the redirect URL for your Uber OAuth app. Use a `https://`*{your-app-name}*`.herokuapp.com/submit` URL. +You will also want to configure the heroku environment variable FLASK_DEBUG=False in order to properly serve SSL traffic. Making Requests --------------- diff --git a/app.py b/app.py index 76f916c..94b2471 100644 --- a/app.py +++ b/app.py @@ -54,7 +54,7 @@ def signup(): params = { 'response_type': 'code', 'redirect_uri': get_redirect_uri(request), - 'scope': ','.join(config.get('scopes')), + 'scopes': ','.join(config.get('scopes')), } url = generate_oauth_service().get_authorize_url(**params) return redirect(url) @@ -72,7 +72,6 @@ def submit(): 'code': request.args.get('code'), 'grant_type': 'authorization_code' } - response = app.requests_session.post( config.get('access_token_url'), auth=( @@ -82,6 +81,7 @@ def submit(): data=params, ) session['access_token'] = response.json().get('access_token') + return render_template( 'success.html', token=response.json().get('access_token') @@ -180,7 +180,7 @@ def price(): @app.route('/history', methods=['GET']) def history(): """Return the last 5 trips made by the logged in user.""" - url = config.get('base_uber_url') + 'history' + url = config.get('base_uber_url_v1_1') + 'history' params = { 'offset': 0, 'limit': 5, @@ -229,4 +229,5 @@ def get_redirect_uri(request): return 'https://{hostname}/submit'.format(hostname=parsed_url.hostname) if __name__ == '__main__': + app.debug = os.environ.get('FLASK_DEBUG', True) app.run(port=7000) diff --git a/config.json b/config.json index e3b8629..46e7fe6 100644 --- a/config.json +++ b/config.json @@ -2,9 +2,10 @@ "access_token_url": "https://login.uber.com/oauth/token", "authorize_url": "https://login.uber.com/oauth/authorize", "base_url": "https://login.uber.com/", - "scopes": ["profile"], + "scopes": ["profile", "history_lite"], "name": "Sample app", "base_uber_url": "https://api.uber.com/v1/", + "base_uber_url_v1_1" : "https://api.uber.com/v1.1/", "start_latitude": "37.781955", "start_longitude": "-122.402367", "end_latitude": "37.744352", diff --git a/requirements-test.txt b/requirements-test.txt index a22d87f..78e2876 100644 --- a/requirements-test.txt +++ b/requirements-test.txt @@ -1,16 +1,12 @@ # Test harness pytest==2.5.2 - # Coverage pytest-cov==1.6 - # HTTP Fixtures betamax==0.4.0 - # LINT OR DIE flake8==2.1.0 pep8==1.5.6 pyflakes==0.8.1 - # Coveralls coveralls==0.4.2 diff --git a/setup.cfg b/setup.cfg index 7da1f96..7598993 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,2 +1,3 @@ [flake8] max-line-length = 100 +exclude = env diff --git a/templates/results.html b/templates/results.html index 7a37a7b..9d4de3b 100644 --- a/templates/results.html +++ b/templates/results.html @@ -9,6 +9,6 @@
{{ data }} +
{{ data }}