This repository was archived by the owner on Oct 2, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Language library refactor #37
Open
graceyim
wants to merge
256
commits into
develop
Choose a base branch
from
lang-library-refactor
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
256 commits
Select commit
Hold shift + click to select a range
236ea0b
Refactor get_auth_url
a2e09a6
Refactor get_oauth_signed_url
3c679a4
Check kwargs and set default values for get_auth_url
d6799d9
Check kwargs for ttl or set default value
f76a6e8
Rename _get_oauth_signed_url
1230438
Rename authenticate params
aa3cc13
Rename AuthenticationStatus to AuthenticationRequest
ad1da3e
Rename PairingStatus to Pairing
4ba88b0
remove get_pair_url test
0635cc3
Refactor authenticate_with_otp
5d7ae27
Add Pairing.refresh_from_server
276008b
Add AuthenticationRequest.refresh_from_server
de24260
Rename uri to url
2d27608
Add UserTerminal class and test
453c0ea
Add get_user_terminal_by_id
9da5024
Add UserTerminal.refresh_from_server
f32ec21
Remove comment since test is passing
205a1cb
"Refactor" AuthenticationRequest.refresh_from_server
eb80a8b
"Refactor" Pairing.refresh_from_server
0616c0b
Return UserTerminal instance from create_user_terminal
aad114e
Refactor enable_user and disable_user
a047dda
Add get_pairing_reset_link
ea710e8
Add email_pairing_reset_link_to_user
15aa251
Add post and get
be1639a
Add User and create_user
3ac3e53
Add get_user_by_id
e0e8167
Add User.refresh_from_server
62fc11a
Add User.enable and User.disable
a5bafd2
Rename user_name to username
2411879
Add reset_user and User.reset
05ff6d7
Update README.md
e4daab1
Remove commented out code
9cf10a4
Update README-Iframe.md
8cefa84
Update version to 2.0.0
3ab7e37
Update demo.py
ecaa370
Update demo_bells_and_whistles.py
5f850fb
nevermind the country code for demo_bells_and_whistles.py
bcfbfd8
Use fresh_from_server to update pairing and authorization request
0b45f77
Add pending field to Pairing class
8460a07
Merge branch 'lang-library-refactor' of github.com:toopher/toopher-py…
e6a03dc
Fix order of checking if pairing is pending or complete
31826c8
Rename auth_request_status to auth_request
c90ed54
Make sure there are two blank lines between classes
f44460d
Try to make text pretty for Seth
a0ec572
Merge branch 'lang-library-refactor' of github.com:toopher/toopher-py…
e29fb83
Make it even prettier
0dc53e3
Make printing prettier
b7eb00d
Create get_qr_code_image
934b363
Fix QR image tests
87bcc27
Add pair by QR code to demo_bells_and_whistles.py
a8d1bb7
Use refresh_from_server() instead of get_authentication_request_by_id()
dfd2433
Create API documentation
21e7f30
Move api-docs.md
f188926
Rename get_auth_url() to get_auth_iframe_url()
5166251
Rename get_user_management_url() to get_user_management_iframe_url()
df7beb4
Fix spacing for ToopherIframeTests
a57b3ee
Add setUp() and clean up ToopherTests
b9a84e6
Add setUp() and cleanup ZeroStorageTests
e39358c
Update ToopherTests.setUp()
416d7ad
Add setUp() and cleanup AuthenticationRequestTests
9b1e7e8
Make sure we save self._raw_data appropriately with instance methods
0822d14
have AuthenticationRequest.authenticate_with_otp update self instance…
f4afb3f
Add setUp() and cleanup PairingTests
3d7d2d2
Add setUp() and cleanup UserTerminalTests
cc662e9
Add setUp() and cleanup UserTests
837ef2a
Merge branch 'lang-library-refactor' of github.com:toopher/toopher-py…
b019990
Remove repetitive code and use ToopherApi.post and ToopherApi.get ins…
fbbef1a
Merge branch 'lang-library-refactor' of github.com:toopher/toopher-py…
751e261
Don't call _set_toopher_disabled_for_user within User.enable and User…
dd135eb
Make Pairing.user store a User instance
7816771
Add attributes and arguments to ToopherIframe documentation
8596125
Add UserTerminal.update
6a704f7
Have AuthenticationRequest.terminal be a UserTerminal instance and up…
f704f06
Fix table
882068b
Fix remaining tables
62cc4b7
Create User.update
2356092
Update get_auth_url and get_user_management_url names
9dee6f4
Add Pairing.update
022fc98
Add AuthenticationRequest.user => User
dd9559b
Merge branch 'lang-library-refactor' of github.com:toopher/toopher-py…
6de4799
Don't return anything on User.reset
c36a9a0
Have UserTerminal.user return a User instance
85d1f92
Move get_reset_link and email_reset_link under Pairing class
4e1f44b
Switch order of params in authenticate_with_otp
f2cc5f6
Clean up demo
1ff6176
Update api-docs
aa7acb7
Add AdvancedApiUsageFactory and ApiRawRequester with get and post met…
5a380eb
Remove old get_pairing_reset_link and email_pairing_reset_link_to_user
603ae22
Add PairingFinder and get_by_id
bd95088
Add AuthenticationRequestFinder and get_by_id
a7fe786
Update ToopherIFrame docs
e3fa38a
Merge branch 'lang-library-refactor' of github.com:toopher/toopher-py…
2014811
Add UserFinder and get_by_id
61872d0
Add UserFinder.get_by_name
8dd013c
Add UserTerminalFinder and get_by_id
4a9a4b5
Update args tables
79486f9
Update headers and defaults
42fc2aa
Remove deprecated methods from ToopherApi that are now instance metho…
701789c
Remove deprecated methods from ToopherApi that are now in ApiRawReque…
6a25488
Update api-docs
276db7e
Merge branch 'lang-library-refactor' of github.com:toopher/toopher-py…
24c312f
Update api-docs
0045490
Rename X_Finder to Xs plural namespace
55e7651
Move create_user and create_user_terminal to Users.create and UserTer…
dbe3ffc
Rename get_auth_iframe_url() to get_authentication_url()
14fe88b
Rename get_user_management_iframe_url() to get_user_management_url()
821f9c9
Cleanup test names
7fc0114
Update formatting in api-docs
ebfff60
Update formatting for list
b6ab3d2
Correct args for validate_postback
657acc6
Fix formatting for Users
bffe89d
Remove args from validate_postback
5ace2e3
Update args table for ToopherIframe
19d2a59
Dont make another API call in Users.get_by_name when it is unnecessary
896f28d
Merge branch 'lang-library-refactor' of github.com:toopher/toopher-py…
0213038
Rename tests to be more descriptive
288f1b6
Make self.assertTrue(False) self.fail() with explanatory message
ac17c32
Have SignatureValidationError inherit from ToopherApiError
7adf87b
Merge branch 'lang-library-refactor' of github.com:toopher/toopher-py…
f72d768
Merge ZeroStorageTests with ToopherTests
6634943
Make update() for User, UserTerminal, Pairing, and AuthenticationRequ…
3d308de
Add Action class and AuthenticationRequest.action
116c51b
Change DEFAULT_IFRAME_TTL to 300
1ac3815
Check for disable_toopher_auth
a4444ac
Rename authenticate_with_otp to grant_with_otp
34b7067
Merge branch 'lang-library-refactor' of github.com:toopher/toopher-py…
64348c4
Remove default values for allow_inline_pairing, automation_allowed an…
7573002
Merge branch 'lang-library-refactor' of github.com:toopher/toopher-py…
3b40521
Add reason_code to AuthenticationRequest class
b68af09
Rename terminal.name_extra to terminal.requester_specified_id
8ecfd29
Rename enable/disable to enable_toopher_authentication/disable_toophe…
b15845b
Rename user.disable_toopher_auth to user.toopher_authentication_enabled
972884d
Create ToopherBase class for __getattr__()
5e1702b
Add Pairing.api and Pairings.api
2ac7371
Add AuthenticationRequest.api and AuthenticationRequests.api
a121413
Add User.api, Users.api, UserTerminal.api and UserTerminals.api
077caab
Don't need to store self.raw in Pairings, Users, AuthenticationReques…
0b102f9
Refactor PairingTests.test_get_reset_link()
4a72283
Merge branch 'lang-library-refactor' of github.com:toopher/toopher-py…
aea5be6
Add ToopherBaseTests.test_pickling_and_unpickling()
52f23fa
Remove old comment
41145da
Remove unncessary return statement
5990fac
Rename _raw_data to raw_response
b489469
Update UserTerminal.__init__ to use api
5396b60
Remove unused variable from ToopherApiDemo
f950359
Update auth.refresh_from_server() in README
43c3c57
Refactor __init__ method of factory objects into base class
bdd540f
Cleanup test_get_qr_code_image to only check last_called_method and l…
239a5fc
Fix errors in tests
e7cab37
Also test 2.7
58670ec
Merge pull request #39 from toopher/feature/refactor-factory-base-class
dshafer c1ec60d
Add User.toopher_authentication_enabled and cleanup __init__
cde61e5
Add UserTerminal.requester_specified_id and cleanup __init__
fb12f42
Cleanup Action.__init__ and _update
cad48f7
Cleanup AuthenticationRequest.__init__ and _update
877a015
Cleanup Pairing.__init__ and _update
cf3114b
Rename terminal_name_extra to requester_specified_terminal_id
03ca33b
Use named parameters for ToopherApi.authenticate
40b90d9
Refactor ToopherApi.authenticate
85a1514
Use authenticate by username (zero requester storage) in demo
2454f84
Use pythonic syntax in variable assignment
4d5e7f8
Update demo and cleanup prints
4aa7d0c
Update ToopherIframe README with new validate postback options
2bf0609
Remove separate python API doc
330cc12
Urlencode Toopher form data for ToopherIframe
c3f6113
Use single quotes
b3209c5
Improve ToopherApiError messages
1c51cbf
Add info to ToopherApiError messages
8b437e9
Replace ToopherApi.validate_postback with #process_postback and #is_p…
d4a7210
Add default reset_email for ToopherIframe.get_authentication_url
3e4567f
Add tests for #update
b3e843c
Update ToopherIframe tests to match postback values from API
df99d15
Update CONTRIBUTING.md to use nosetests to run tests
d67885f
Log errors in ToopherIframe.is_authentication_granted instead of rais…
0886691
Rename ToopherIframe._urldecode_data to _urldecode_iframe_data
470c0c7
Split tests into separate files
9f5c7a4
Use 'api.toopher.test' URL for tests
b1c00cb
Split ToopherIframe into own file
471c0dc
Config log messages for ToopherIframe.is_authentication_granted
61349c5
Refactor ToopherIframe._validate_postback
c4353b8
Update travis.yml with new test script
e5ee6c6
Clean up ToopherIframe tests and improve coverage
497d0c9
Merge kwargs with params in ToopherIframe.get_user_management_url
88202a4
Rename ToopherIframe._signature to _calculate_signature
0a04334
Refactor error message for signature calculation error
b1b23b5
Update readme with new import
15086a9
Removed Werkzeug from requirements
026b115
Remove pillow from requirements
bb028aa
Update Iframe README with new process_postback
95bdcde
Refactor ToopherApi._request to return raw response or json
3f61a91
Test ToopherApiError in Action.__init__ and update
15f2917
Add tests for ToopherIframe.get_authentication_url
20a4c3c
Fix code snippets in Iframe readme
b5625e7
Fix Iframe README
99e13c5
Return True if UserDisabledError
dd8cb26
Simplify return for #is_authentication_granted
764e6cd
Simplify assignment for boolean values
64af51d
Reorder methods
9c19e33
Set default reset_email for #get_user_management_url and test
d8c1cb2
Log UserDisabledError as info not error
da9202e
Remove demo bells and whistles
6e9ad94
Update readme with named, optional args for #authenticate
b7ce02b
Add CONTRIBUTING.md info to README
0e5c5f5
Reorder sections in README
4188e6e
Combine README and README-Iframe
f4571b2
Refactor README
6502c86
Clean up IFRAME text
c410e78
Reformat text and subheaders
f2f75fc
Remove dupe test
f9dc71d
Use self.request_token instead of ToopherIframeTest.request_token
e39865d
Add tests for ToopherIframe.is_authentication_granted
501153b
Add test for process_postback with extras
862c0c6
Add test for ToopherIframe.process_postback without request token
cf664ed
Simplify README
a74935d
Use dict for postback_data tests
ddd526e
Rename get_authentication_url tests
f109152
Remove process_postback from README
0817299
Cleanup tests for is_authentication_granted and make sure to pass kwa…
71d2490
Fix error tests for is_authentication_granted
b0b0ede
Set default reset_email, request_token and requester_metadata to empt…
1ef2b9a
Add Iframe version to params in get_oauth_signed_url
fe94dc0
Cleanup Iframe tests
0371537
Expand test for get_user_management_url
abce789
Add test for is_authentication_granted with auth request is granted a…
48314a2
Improve test failure messages for is_authentication_granted
05a4f1b
Cleanup text in demo
b5ed48b
Include base_uri when creating new instance of ToopherApi
fbf85e0
Refactor Pairing.get_qr_code_image to use new get_raw method
45d7931
Add license section to README
4f77063
Add coverage to nosetests script
30c81d9
Improve tests for User
f20c6cb
Use cover-inclusive for nosetests
c32f47b
Improve tests for Pairing
eb71816
Move HttpClientMock to new testutils file
ff0eac9
Cleanup pickle test
23fc9aa
Cleanup ToopherApi test
d3d0534
Update coveragerc to exclude test files
6de42f0
Simplify test script for travis
6712470
Authenticate by username in README
9b7878f
Add more info about postback_data
29a1fad
Expect iframe postback data to be a string from POST parameter toophe…
ddf9271
Keep blank values when parsing postback data
8ca207b
Add process_postback test for keys with empty values
8f341c3
Cleanup text in the README
9a8cae2
fix parameter error for Users.get_by_name
dshafer 8bf5770
fix another incorrect parameter
dshafer 5539c41
fix tests too
dshafer 2c1323e
python 3 updates
natemoser 5083c36
update to reflect Python 3.6
natemoser 6b1a43a
Merge pull request #40 from natemoser/lang-library-refactor
dshafer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,4 @@ | |
omit = | ||
*/python?.?/* | ||
*/site-packages/nose/* | ||
tests.py | ||
test/* |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,3 +54,7 @@ Icon | |
|
||
### Added by etg | ||
setenv | ||
|
||
### Added by ndm | ||
venv | ||
.idea |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
language: python | ||
python: | ||
- 2.6 | ||
- 2.7 | ||
install: | ||
- pip install -r requirements.txt --use-mirrors | ||
script: | ||
nosetests tests.py --with-coverage --cover-package=toopher | ||
nosetests --with-coverage test | ||
after_success: | ||
coveralls |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,85 +1,104 @@ | ||
#ToopherPython | ||
#ToopherPython [](https://travis-ci.org/toopher/toopher-python) | ||
|
||
[](https://travis-ci.org/toopher/toopher-python) | ||
ToopherPython is a Toopher API library that simplifies the task of interfacing with the Toopher API from Python code. | ||
This project wrangles all the dependency libraries and handles the required OAuth and JSON functionality so you can | ||
focus on just using the API. | ||
|
||
#### Introduction | ||
ToopherPython is a Toopher API library that simplifies the task of interfacing with the Toopher API from Python code. This project wrangles all the required OAuth and JSON functionality so you can focus on just using the API. | ||
### Python Version | ||
* 3.6 | ||
|
||
#### Learn the Toopher API | ||
### Documentation | ||
Make sure you visit [https://dev.toopher.com](https://dev.toopher.com) to get acquainted with the Toopher API fundamentals. The documentation there will tell you the details about the operations this API wrapper library provides. | ||
|
||
#### OAuth Authentication | ||
First off, to access the Toopher API you'll need to sign up for an account at the [Toopher developers portal](https://dev.toopher.com) and create a "requester". When that process is complete, your requester is issued OAuth 1.0a credentials in the form of a consumer key and secret. Your key is used to identify your requester when Toopher interacts with your customers, and the secret is used to sign each request so that we know it is generated by you. This library properly formats each request with your credentials automatically. | ||
## ToopherApi Workflow | ||
|
||
#### The Toopher Two-Step | ||
Interacting with the Toopher web service involves two steps: pairing, and authenticating. | ||
|
||
##### Pair | ||
Before you can enhance your website's actions with Toopher, your customers will need to pair their phone's Toopher app with your website. To do this, they generate a unique, nonsensical "pairing phrase" from within the app on their phone. You will need to prompt them for a pairing phrase as part of the Toopher enrollment process. Once you have a pairing phrase, just send it to the Toopher web service and we'll return a pairing ID that you can use whenever you want to authenticate an action for that user. | ||
|
||
##### Authenticate | ||
You have complete control over what actions you want to authenticate using Toopher (for example: logging in, changing account information, making a purchase, etc.). Just send us the user's pairing ID, a name for the terminal they're using, and a description of the action they're trying to perform and we'll make sure they actually want it to happen. | ||
|
||
#### Librarified | ||
This library makes it super simple to do the Toopher two-step. Check it out: | ||
### Step 1: Pair | ||
Before you can enhance your website's actions with Toopher, your customers will need to pair their mobile device's Toopher app with your website. To do this, they generate a unique pairing phrase from within the app on their mobile device. You will need to prompt them for a pairing phrase as part of the Toopher enrollment process. Once you have a pairing phrase, just send it to the Toopher web service along with your requester credentials and we'll return a pairing ID that you can use whenever you want to authenticate an action for that user. | ||
|
||
```python | ||
import toopher | ||
|
||
# Create an API object using your credentials | ||
api = toopher.ToopherApi("<your consumer key>", "<your consumer secret>") | ||
|
||
# Step 1 - Pair with their phone's Toopher app | ||
pairing_status = api.pair("pairing phrase", "username@yourservice.com") | ||
# Step 1 - Pair with their mobile device's Toopher app | ||
pairing = api.pair("username@yourservice.com", "pairing phrase") | ||
``` | ||
|
||
### Step 2: Authenticate | ||
You have complete control over what actions you want to authenticate using Toopher (logging in, changing account | ||
information, making a purchase, etc.). Just send us the username or pairing ID and we'll make sure they actually want it to happen | ||
. You can also choose to provide the following optional parameters: terminal name, requester specified ID and | ||
action name (*default: "Log in"*). | ||
|
||
```python | ||
# Step 2 - Authenticate a log in | ||
auth = api.authenticate(pairing_status.id, "my computer") | ||
authentication_request = api.authenticate("username@yourservice.com", "terminal name") | ||
|
||
# Once they've responded you can then check the status | ||
auth_status = api.get_authentication_status(auth.id) | ||
if (auth_status.pending == False and auth_status.granted == True): | ||
authentication_request.refresh_from_server() | ||
if not authentication_request.pending and authentication_request.granted: | ||
# Success! | ||
``` | ||
|
||
#### Handling Errors | ||
If any request runs into an error a `ToopherApiError` will be thrown with more details on what went wrong. | ||
## ToopherIframe Workflow | ||
|
||
#### Zero-Storage usage option | ||
Requesters can choose to integrate the Toopher API in a way does not require storing any per-user data such as Pairing ID and Terminal ID - all of the storage | ||
is handled by the Toopher API Web Service, allowing your local database to remain unchanged. If the Toopher API needs more data, it will `raise()` a specific | ||
error that allows your code to respond appropriately. | ||
### Step 1: Embed a request in an IFRAME | ||
1. Generate an authentication URL by providing a username. | ||
2. Display a webpage to your user that embeds this URL within an `<iframe>` element. | ||
|
||
```python | ||
try: | ||
# optimistically try to authenticate against Toopher API with username and a Terminal Identifier | ||
# Terminal Identifer is typically a randomly generated secure browser cookie. It does not | ||
# need to be human-readable | ||
auth = api.authenticate_by_user_name(user_name, requester_terminal_id) | ||
|
||
# if you got here, everything is good! poll the auth request status as described above | ||
# there are four distinct errors ToopherAPI can return if it needs more data | ||
except UserDisabledError: | ||
# you have marked this user as disabled in the Toopher API. | ||
except UserUnknownError: | ||
# This user has not yet paired a mobile device with their account. Pair them | ||
# using api.pair() as described above, then re-try authentication | ||
except TerminalUnknownError: | ||
# This user has not assigned a "Friendly Name" to this terminal identifier. | ||
# Prompt them to enter a terminal name, then submit that "friendly name" to | ||
# the Toopher API: | ||
# api.create_user_terminal(user_name, terminal_name, requester_terminal_id) | ||
# Afterwards, re-try authentication | ||
except PairingDeactivatedError: | ||
# this user does not have an active pairing, | ||
# typically because they deleted the pairing. You can prompt | ||
# the user to re-pair with a new mobile device. | ||
import toopher | ||
|
||
# Create an API object using your credentials | ||
iframe_api = toopher.ToopherIframe("<your consumer key>", "<your consumer secret>") | ||
|
||
|
||
auth_iframe_url = iframe_api.get_authentication_url("username@yourservice.com"); | ||
|
||
# Add an <iframe> element to your HTML: | ||
# <iframe id="toopher_iframe" src=auth_iframe_url /> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should add some information about how to style the iframe - they should make it 300px tall. Width should be at least 400px, with 720px or wider being preferred There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The plan was to have the original HTML markup info moved to the dev site. Do you think it needs to be included here as well? |
||
``` | ||
|
||
#### Dependencies | ||
This library uses the [Requests](http://docs.python-requests.org/en/latest/) library to handle OAuth signing and to make the web requests. If you install using pip (or easy_install) they'll be installed automatically for you. | ||
### Step 2: Validate the postback data | ||
|
||
The simplest way to validate the postback data is to call `is_authentication_granted` to check if the authentication request was granted. | ||
|
||
#### Try it out | ||
Check out `demo.py` for an example program that walks you through the whole process! Just download the contents of this repo, make sure you have the dependencies listed above installed, and then run it like-a-this: | ||
```python | ||
# Retrieve the postback data as a string from POST parameter 'iframe_postback_data' | ||
postback_data = request.args['iframe_postback_data'] | ||
|
||
# Returns boolean indicating if authentication request was granted by user | ||
authentication_request_granted = iframe_api.is_authentication_granted(postback_data) | ||
|
||
if authentication_request_granted: | ||
# Success! | ||
``` | ||
|
||
### Handling Errors | ||
If any request runs into an error a `ToopherApiError` will be thrown with more details on what went wrong. | ||
|
||
### Demo | ||
Check out `demo.py` for an example program that walks you through the whole process! Just download the contents of | ||
this repo, make sure you have the dependencies installed, and run the command below: | ||
```shell | ||
$ python demo.py | ||
``` | ||
|
||
## Contributing | ||
### Dependencies | ||
This library uses the [Requests](http://docs.python-requests.org/en/latest/) library and [OAuthLib](https://oauthlib.readthedocs.org/en/latest/index.html) to handle OAuth signing and make the web requests. | ||
|
||
Toopher uses [pip](https://pypi.python.org/pypi/pip) to install Python packages. To ensure all dependencies are up-to-date run: | ||
```shell | ||
$ python ./demo.py | ||
$ pip install -r requirements.txt | ||
``` | ||
|
||
### Tests | ||
To run the tests using [nose](http://nose.readthedocs.org/en/latest/) enter: | ||
```shell | ||
$ nosetests test | ||
``` | ||
|
||
## License | ||
ToopherPython is licensed under the MIT License. See LICENSE.txt for the full text. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
(function(window, $){ | ||
var postToUrl = function (path, params, method){ | ||
method = method || 'POST'; | ||
var form = $('<form />').attr('method', method).attr('action', path); | ||
for (var key in params){ | ||
if (params.hasOwnProperty(key)){ | ||
var hiddenField = $('<input />').attr('type', 'hidden').attr('name', key).attr('value', params[key]); | ||
form.append(hiddenField); | ||
} | ||
} | ||
$('body').append(form); | ||
form.submit(); | ||
} | ||
|
||
var handleMessage = function(e){ | ||
var msgData = JSON.parse(e.data); | ||
if (msgData.status === 'toopher-api-complete'){ | ||
var iframe = $('#toopher_iframe'); | ||
var frameworkPostArgsJSON = iframe.attr('framework_post_args'); | ||
var frameworkPostArgs = {}; | ||
if(frameworkPostArgsJSON){ | ||
frameworkPostArgs = $.parseJSON(frameworkPostArgsJSON); | ||
} | ||
var postData = $.extend({}, msgData.payload, frameworkPostArgs); | ||
var toopherData = {'toopher_iframe_data': $.param(postData)}; | ||
|
||
if(iframe.attr('use_ajax_postback')){ | ||
$.post(iframe.attr('toopher_postback'), toopherData) | ||
.done(function(data){ | ||
data = $.parseJSON(data); | ||
}); | ||
} else { | ||
postToUrl(iframe.attr('toopher_postback'), toopherData, 'POST'); | ||
} | ||
} | ||
} | ||
|
||
if (window.addEventListener) { | ||
window.addEventListener('message', handleMessage, false); | ||
} else { | ||
window.attachEvent('onmessage', handleMessage); | ||
} | ||
})(window, jQuery); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to check that the user has responded affirmatively like we do after the
authenticate
call below--can you please add a similar check here? Note that pairings areenabled
rather thangranted
.