Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
198 commits
Select commit Hold shift + click to select a range
48ea471
Remove pairUri()
Jan 20, 2015
7ac476e
Refactor authUri() and update tests
Jan 21, 2015
aa7e347
Update javadocs comment for allowInlinePairing
Jan 21, 2015
1e44fc2
Create getUserManagementUrl() with test
Jan 21, 2015
e73ee87
Rename uri to url
Jan 22, 2015
095ada0
Refactor getAuthenticationUrl() so that it treats extras as a black box
Jan 22, 2015
3950292
Rename PairingStatus to Pairing
Jan 22, 2015
4ec06eb
Update javadocs for extras
Jan 22, 2015
0b21d02
Rename validate to validatePostback
Jan 22, 2015
9e39d2e
Create User class and update Pairing and tests
Jan 22, 2015
aa92de3
Add comment for old test
Jan 22, 2015
c8f0375
Rename getPairingStatus to getPairing
Jan 22, 2015
09a6844
Use JSONObject for HttpClientMock
Jan 22, 2015
3cdf869
Replace ToopherAPI.getPairing() with ToopherAPI.advanced.pairings.get…
Jan 22, 2015
550e518
Correct javadocs for setToopherEnabledForUser()
Jan 22, 2015
5537363
Rename AuthenticationStatus to AuthenticationRequest
Jan 22, 2015
c62a8ef
Create UserTerminal class
Jan 22, 2015
f03db07
Add variables to setUp() and DEFAULT_BASE_URL for tests
Jan 22, 2015
60bc22b
Create ToopherAPI.advanced.authenticationRequests.getById()
Jan 22, 2015
eb23d15
Create ToopherAPI.advanced.users.getById()
Jan 22, 2015
27edf24
Cleanup ToopherAPI, TestToopherAPI and User
Jan 22, 2015
472fc33
Create ToopherAPI.advanced.users.getByName()
Jan 23, 2015
244f105
Create ToopherAPI.advanced.users.create()
Jan 23, 2015
7a98127
Fix endpoint in Users.getByName()
Jan 23, 2015
b5ed216
Create ToopherAPI.advanced.userTerminals.getById()
Jan 23, 2015
2cb4de7
Create Action object
Jan 26, 2015
995612c
Add Action and User to AuthenticationRequest object
Jan 26, 2015
308bc31
Remove raw from UserTerminal
Jan 26, 2015
34d72a1
Create ApiRawRequester class for get() and post()
Jan 26, 2015
c7b2798
Refactor pair() to handle regular, QR and SMS pairings
Jan 26, 2015
582d7d9
Add terminalNameExtra to tests
Jan 26, 2015
c555c1a
Remove old getAuthenticationStatus()
Jan 26, 2015
ad38f26
Refactor authenticate() to handle authentication with username or pai…
Jan 26, 2015
ab268af
Add AuthenticationRequest.authenticate_with_otp()
Jan 26, 2015
98068e3
Add update() to Action
Jan 26, 2015
0d1073d
Add update() and remove raw from User
Jan 26, 2015
10b9fac
Add update() to UserTerminal
Jan 26, 2015
db58896
Update AuthenticationRequest with update methods
Jan 26, 2015
8a56fe0
Add AuthenticationRequest.refreshFromServer()
Jan 26, 2015
d98b233
Add toString() for UserTerminal
Jan 26, 2015
d5b943e
Update User when updating UserTerminal
Jan 26, 2015
37b4045
Add UserTerminal.refreshFromServer()
Jan 26, 2015
1e5a666
Remove raw from Pairing
Jan 26, 2015
b8a82dc
Add Pairing.refresh_from_server() and update()
Jan 26, 2015
810075d
Make update() private in AuthenticationRequest and Pairing
Jan 27, 2015
0f2832e
Change DEFAULT_TTL to 300
Jan 27, 2015
75d01cd
Add Pairing.getResetLink()
Jan 27, 2015
d914a07
Add Pairing object to test setUp()
Jan 27, 2015
24a1c17
Add Pairing.emailResetLink()
Jan 27, 2015
8d5be41
Add extras to params in Pairing.getResetLink()
Jan 29, 2015
8fb9adc
Use ApiRawRequester.post(endpoint, params) when extras are null
Jan 29, 2015
5849894
Add ApiRawRequester.get(endpoint, params) for when extras are null
Jan 29, 2015
7f42379
Update HttpClientMock and add ResponseMock to mock 2 responses to tes…
Jan 29, 2015
a5b13df
Rename endpoint for UserTerminal.getById to be consistent with other …
Jan 29, 2015
1dc677c
Rename DEFAULT_BASE_URL endpoint in tests to be consistent with Tooph…
Jan 29, 2015
c75cacb
Add reason_code to AuthenticationRequest
Feb 3, 2015
3acc683
Use camelCase, not snake_case
Feb 3, 2015
8797998
Add api to User(s), UserTerminal(s), AuthenticationRequest(s) and Pai…
Feb 3, 2015
914f390
Rename authenticateWithOtp to grantWithOtp
Feb 4, 2015
2f97790
Fix testAdvancedUsersCreateWithExtras()
Feb 4, 2015
6208a4a
Rename User.enabled to User.toopherAuthenticationEnabled
Feb 4, 2015
44e80f7
Update setter for User.toopherAuthenticationEnabled
Feb 4, 2015
5886e7e
Use camelCase, not snake_case
Feb 4, 2015
ce03544
Add User.refreshFromServer()
Feb 4, 2015
3245a80
Add User.enableToopherAuthentication()
Feb 4, 2015
dafc853
Add User.disableToopherAuthentication()
Feb 4, 2015
edf2bf4
Add User.reset()
Feb 4, 2015
68a10f5
Rename raw to rawResponse in ApiResponseObject
Feb 4, 2015
125abd7
Clean up javadocs
Feb 4, 2015
82d24b0
Add Pairing.getQrCodeImage()
Feb 5, 2015
2e3fd06
Use String.format for strings
Feb 5, 2015
97fbb04
Use DEFAULT_BASE_URL in ToopherAPI tests
Feb 5, 2015
cb6e296
Clean up tests for Pairing
Feb 5, 2015
90ed945
Clean up tests for AuthenticationRequest
Feb 5, 2015
13d560f
Update HttpClientMock.getLastCalledEndpoint() to return endpoint with…
Feb 6, 2015
ac2ef13
Clean up tests for AuthenticationRequest
Feb 5, 2015
1a288fe
Update HttpClientMock.getLastCalledEndpoint() to return endpoint with…
Feb 6, 2015
9976b68
Remove methods from ToopherAPI that have been moved to Authentication…
Feb 6, 2015
c4d9bfd
Add UserTerminals.create to replace assignUserFriendlyNameToTerminal
Feb 6, 2015
09f4dcd
Clean up ApiRawRequester.get() and post()
Feb 6, 2015
efcfec1
Update HttpClientMock.getExpectedResponse to return expectedResponseB…
Feb 6, 2015
43d28a3
Clean up and add tests for ToopherAPI
Feb 6, 2015
4eded8f
Merge branch 'lang-library-refactor' of github.com:toopher/toopher-ja…
Feb 6, 2015
c2787bf
Clean up tests for ToopherIframe
Feb 6, 2015
1136bb4
Remove leading / from User.reset endpoint
Feb 6, 2015
463276b
Initialize json responses in @BeforeClass
Feb 6, 2015
93998ee
Clean up and add tests for User
Feb 6, 2015
53b6310
Clean up and add tests for User
Feb 6, 2015
401a531
Clean up and add tests for UserTerminal
Feb 6, 2015
49fc0ba
Use @BeforeClass instead of @Before for TestAuthenticationRequest
Feb 6, 2015
6d4fcb3
Add javadocs and clean up UserTerminal
Feb 6, 2015
383d5be
Add ApiResponseObject.updateRawResponse for updates
Feb 6, 2015
4d70f06
Add javadocs and clean up User
Feb 6, 2015
4596371
Add javadocs and clean up Pairing
Feb 6, 2015
c0733fc
Update javadocs and clean up Pairing
Feb 6, 2015
d8e15e2
Update javadocs and clean up ToopherAPI
Feb 6, 2015
70a894b
Update javadocs and clean up AuthenticationRequest
Feb 6, 2015
84b6948
Update ToopherAPIDemo
Feb 9, 2015
c74c5e9
Update ApiResponseObject.updateRawResponse to throw JSONException
Feb 9, 2015
ea0334f
Update Action.update to throw JSONException
Feb 9, 2015
3941910
Update AuthenticationRequest to throw JSONException
Feb 9, 2015
9620d5a
Update Pairing to throw JSONException
Feb 9, 2015
c306d73
Update ToopherAPI to throw JSONException
Feb 9, 2015
ff5f479
Update ToopherAPIDemo to catch JSONException
Feb 9, 2015
7537370
Update User to throw JSONException
Feb 9, 2015
0a75c6b
Update UserTerminal to throw JSONException
Feb 9, 2015
9ae00c4
Update README with new pair() and authenticate()
Feb 9, 2015
908b880
Update Iframe README
Feb 9, 2015
7692512
Rename validate to validatePostback
Feb 9, 2015
793733e
Rename ToopherAPI to ToopherApi
Feb 10, 2015
88af71b
Use 'this' in AdvancedApiUsageFactory
Feb 10, 2015
0657c5c
Use 'this' in AdvancedApiUsageFactory
Feb 10, 2015
d6e8794
Merge branch 'lang-library-refactor' of github.com:toopher/toopher-ja…
Feb 10, 2015
8713b8d
Fix spacing in AuthenticationRequest
Feb 10, 2015
6d6e486
Rename ToopherAPI/TestToopherAPI to ToopherApi/TestToopherApi
Feb 10, 2015
253e225
Update rawResponse for Action
Feb 10, 2015
ea2ec6c
Use old style of testing authenticationUrl by assertEquals oauth_sign…
Feb 10, 2015
e41e635
Reformat all com.toopher files
Feb 10, 2015
d6d4312
Use URI instead of java.net.URI
Feb 10, 2015
a200088
Add links to objects in javadocs
Feb 10, 2015
9657937
Add User.toopher_authentication_enabled and remove disable_toopher_auth
Feb 13, 2015
355e0e5
Rename terminal_name_extra to requester_specified_terminal_id
Feb 13, 2015
33e2e38
Rename UserTerminal.name_extra to requester_specified_id
Feb 13, 2015
3eeba27
Update javadocs for ToopherIframe.getUserManagementUrl
Feb 18, 2015
e5f8f1d
Update ToopherAPIDemo
Feb 18, 2015
bbdadbb
Combine declaration and initialization of result
Feb 18, 2015
03307d6
No need to remove before put on JSONObject
Feb 18, 2015
0771e7a
Add ToopherPairingDeactivatedError to parseRequestError
Feb 19, 2015
7fef957
Update testCreateSmsPairing to use number formatted as phone number
Feb 19, 2015
f2e3f4f
Use getToopherApi() to create new ToopherApi
Feb 19, 2015
16d9168
Return new User from Users.getByName instead of getById
Feb 19, 2015
6934eed
Remove expectedUriResponses since Users.getByName only needs one resp…
Feb 19, 2015
0e3f02d
Fix ant build errors
Feb 24, 2015
576abfd
Check if resetEmail is null before adding to params
Feb 25, 2015
1843190
Update README
Feb 25, 2015
abc168b
Cleanup DEMO text
Feb 25, 2015
5116514
Replace deprecated DefaultHttpClient
Feb 25, 2015
90b34e0
Add demo command for mvn
Feb 25, 2015
f0e518a
Remove unnecessary printlns
Feb 25, 2015
4e3d5b6
Refactor ToopherApi.authenticate to accept terminalName and requester…
Feb 26, 2015
14ab3cf
Test ToopherIframe.dateOverride and nonceOverride
Feb 26, 2015
4868b83
Add CONTRIBUTING.md for dependency and test info
Mar 3, 2015
74c15f2
Add ToopherIframe test for validatePostback without TTL
Mar 4, 2015
b4babee
Add method overrides for getAuthenticationUrl and add tests
Mar 5, 2015
4a7a1f1
Add test for ToopherIframe creation and getDate
Mar 5, 2015
a71fd0a
Add default resetEmail for getUserManagementUrl and test
Mar 5, 2015
ba80c76
Add javadocs for getAuthenticationUrl
Mar 5, 2015
79be413
Add tests for parseRequestError
Mar 5, 2015
71d09b4
Test oauth_signature when extras are passed to getAuthenticationUrl
Mar 5, 2015
61480b1
Add tests for Users.getByName
Mar 5, 2015
449b59e
Remove unused method overrides
Mar 5, 2015
4c8ff2b
Add test for AuthenticationRequest.toString
Mar 5, 2015
dacc7a5
Add test for User.toString
Mar 5, 2015
c35ea4a
Add test for UserTerminal.toString
Mar 5, 2015
928ddfb
Add test for Pairing.toString
Mar 5, 2015
d41163c
Update pom to exclude ToopherAPIDemo from jacoco reports
Mar 5, 2015
2579295
Add tests for ToopherApi create
Mar 5, 2015
3a6c32c
Expand tests for ToopherApi.authenticate
Mar 5, 2015
9a3c837
Cleanup ToopherApi.authenticate
Mar 5, 2015
7b50e68
Add tests for parseRequestError
Mar 5, 2015
3d16992
Add test for empty QR response body
Mar 5, 2015
af65c63
Make sure tests fail when expected error is not thrown
Mar 5, 2015
da83107
Test ResponseHandler when response body is empty
Mar 5, 2015
2baa847
Add another test for getAuthenticationUrl
Mar 5, 2015
fccbad2
Assert error codes are correct for ToopherClientErrors
Mar 5, 2015
ebbc7c5
Add method override for ToopherIframe.getUserManagementUrl
Mar 6, 2015
f4fcdb9
Add override for ToopherIframe.validatePostback and test
Mar 6, 2015
b376468
Rename validatePostback to processPostback
Mar 6, 2015
bcfebb0
Add getExtrasForUrl helper method for tests
Mar 6, 2015
f2cee13
Add getPostbackData helper method for tests
Mar 6, 2015
23d80de
Move ToopherIframe.setDateOverride to test setUp
Mar 6, 2015
33451c0
Update tests to throw SignatureValidationError instead of try/catch b…
Mar 6, 2015
83d3e91
Update ToopherApi tests
Mar 9, 2015
e5d9b58
Refactor getAuthenticationUrl and tests
Mar 10, 2015
00f9c64
Use processPostback to verify authenticity of ToopherIframe postback …
Mar 10, 2015
25c13aa
Use Iframe instead of iframe
Mar 10, 2015
a7279dc
Add isAuthenticationGranted and tests
Mar 10, 2015
df1a990
Add ttl and expires to params in getOAuthUrl
Mar 11, 2015
fdb2891
Set defaults for resetEmail, sessionToken and requesterMetadata as em…
Mar 11, 2015
ea0422e
Add resetEmail to extras for getUserManagementUrl
Mar 11, 2015
5ecf996
Use a map for Toopher iframe postback data
Mar 20, 2015
ec1513c
Increase test coverage for ToopherIframe
Mar 20, 2015
2572a4a
Merge branch 'develop' of github.com:toopher/toopher-java into lang-l…
Mar 23, 2015
8a247e2
Update js for ToopherIframe postback data
Mar 23, 2015
4343e29
Update demo to match toopher-python
Mar 24, 2015
9a8e733
Include baseUri when creating new instance of ToopherApi
Mar 24, 2015
8b8ca34
Add MIT license
Mar 25, 2015
42f2d2a
Update ToopherIframe tests to throw URISyntaxException for processPos…
Mar 25, 2015
71bf1b7
Cleanup javadocs
Mar 25, 2015
972fff5
Refactor ToopherApi.authenticate
Mar 25, 2015
6846030
Reorder methods in ToopherIframe
Mar 25, 2015
037f956
Remove unused exception
Mar 25, 2015
b16dcb8
Remove unused imports
Mar 25, 2015
8775465
Add license to README
Mar 26, 2015
fe388e9
Add processPostback test for keys with empty values
Mar 30, 2015
376d07f
Simplify README and add iframe info
Mar 31, 2015
31b2ebd
Bump pom.xml version to 2.0.0-PREVIEW
dshafer Apr 3, 2015
ca0a89b
Add jar-with-dependencies goal
dshafer Apr 3, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Refactor pair() to handle regular, QR and SMS pairings
  • Loading branch information
Grace Yim committed Jan 26, 2015
commit c7b27984fd75f967809e6a14da5aa2b31d951ed2
85 changes: 39 additions & 46 deletions src/main/java/com/toopher/ToopherAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -157,64 +157,39 @@ public ToopherAPI(String consumerKey, String consumerSecret, URI uri, HttpClient


/**
* Create a pairing
*
* @param pairingPhrase
* The pairing phrase supplied by the user
* @param userName
* A user-facing descriptive name for the user (displayed in requests)
* @return A Pairing object
* @throws RequestError
* Thrown when an exceptional condition is encountered
*/
public Pairing pair(String pairingPhrase, String userName) throws RequestError {
return this.pair(pairingPhrase, userName, null);
}

/**
* Create a pairing
*
* @param pairingPhrase
* The pairing phrase supplied by the user
* Create a QR pairing
Copy link
Member

Choose a reason for hiding this comment

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

This is a big vague. I think we'll want to add some additional information, like "This return a PNG that should be scanned by the user to complete the pairing process."

* @param userName
* A user-facing descriptive name for the user (displayed in requests)
* @param extras
* An optional Map of extra parameters to provide to the API
* @return A Pairing object
* A user-facing descriptive name for the user (displayed in requests)
* @return A Pairing object
* @throws RequestError
* Thrown when an exceptional condition is encountered
* Thrown when an exceptional condition is encountered
*/
public Pairing pair(String pairingPhrase, String userName, Map<String, String> extras) throws RequestError {
final String endpoint = "pairings/create";

List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("pairing_phrase", pairingPhrase));
params.add(new BasicNameValuePair("user_name", userName));

JSONObject json = advanced.raw.post(endpoint, params, extras);
try {
return new Pairing(json);
} catch (Exception e) {
throw new RequestError(e);
}
public Pairing pair(String userName) throws RequestError {
Map<String, String> extras = new HashMap<String, String>();
return this.pair(userName, "", extras);
}

/**
* Create a pairing that is presented as a QR code
* Create an SMS pairing or regular pairing
*
* @param pairingPhraseOrNum
* The pairing phrase or phone number supplied by the user
* @param userName
* A user-facing descriptive name for the user (displayed in requests)
* @return A Pairing object
* @throws RequestError
* Thrown when an exceptional condition is encountered
*/
public Pairing pairWithQrCode(String userName) throws RequestError {
return this.pairWithQrCode(userName, null);
public Pairing pair(String userName, String pairingPhraseOrNum) throws RequestError {
Map<String, String> extras = new HashMap<String, String>();
return this.pair(userName, pairingPhraseOrNum, extras);
}

/**
* Create a pairing that is presented as a QR code
* Create an SMS pairing or regular pairing
*
* @param pairingPhraseOrNum
* The pairing phrase or phone number supplied by the user
* @param userName
* A user-facing descriptive name for the user (displayed in requests)
* @param extras
Expand All @@ -223,15 +198,33 @@ public Pairing pairWithQrCode(String userName) throws RequestError {
* @throws RequestError
* Thrown when an exceptional condition is encountered
*/
public Pairing pairWithQrCode(String userName, Map<String, String> extras) throws RequestError {
final String endpoint = "pairings/create/qr";
public Pairing pair( String userName, String pairingPhraseOrNum, Map<String, String> extras) throws RequestError {
String endpoint;
JSONObject result;

List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("user_name", userName));

JSONObject json = advanced.raw.post(endpoint, params, extras);
for (Map.Entry<String, String> entry : extras.entrySet()) {
params.add(new BasicNameValuePair(entry.getKey(), entry.getValue()));
}

if (!pairingPhraseOrNum.isEmpty()) {
if (pairingPhraseOrNum.matches("\\d+")) {
params.add(new BasicNameValuePair("phone_number", pairingPhraseOrNum));
endpoint = "pairings/create/sms";
} else {
params.add(new BasicNameValuePair("pairing_phrase", pairingPhraseOrNum));
endpoint = "pairings/create";
}
} else {
endpoint = "pairings/create/qr";
}

result = advanced.raw.post(endpoint, params, null);

try {
return new Pairing(json);
return new Pairing(result);
} catch (Exception e) {
throw new RequestError(e);
}
Expand Down
27 changes: 25 additions & 2 deletions src/test/java/com/toopher/TestToopherAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public void testCreatePairing() throws InterruptedException, RequestError {

ToopherAPI toopherApi = new ToopherAPI("key", "secret",
createURI("https://api.toopher.test/v1"), httpClient);
Pairing pairing = toopherApi.pair("awkward turtle", "some user");
Pairing pairing = toopherApi.pair("some user", "awkward turtle");

assertEquals(httpClient.getLastCalledMethod(), "POST");
assertEquals(httpClient.getLastCalledData("pairing_phrase"), "awkward turtle");
Expand All @@ -88,7 +88,7 @@ public void testCreateQrPairing() throws InterruptedException, RequestError {

ToopherAPI toopherApi = new ToopherAPI("key", "secret",
createURI("https://api.toopher.test/v1"), httpClient);
Pairing pairing = toopherApi.pairWithQrCode(userName);
Pairing pairing = toopherApi.pair(userName);

assertEquals(httpClient.getLastCalledMethod(), "POST");
assertEquals(pairing.user.id, userId);
Expand All @@ -97,6 +97,29 @@ public void testCreateQrPairing() throws InterruptedException, RequestError {
assertTrue(pairing.enabled);
}

@Test
public void testCreateSmsPairing() throws InterruptedException, RequestError {
JSONObject jsonResponse = new JSONObject();
jsonResponse.put("id", id);
jsonResponse.put("enabled", true);
jsonResponse.put("pending", true);
jsonResponse.put("user", user);

HttpClientMock httpClient = new HttpClientMock(200, jsonResponse.toString());

ToopherAPI toopherApi = new ToopherAPI("key", "secret",
createURI(DEFAULT_BASE_URL), httpClient);
Pairing pairing = toopherApi.pair(userName, "123456");

assertEquals(httpClient.getLastCalledMethod(), "POST");
assertEquals(httpClient.getLastCalledData("phone_number"), "123456");

assertEquals(pairing.user.id, userId);
assertEquals(pairing.user.name, userName);
assertTrue(pairing.pending);
assertTrue(pairing.enabled);
}

@Test
public void testAdvancedPairingsGetById() throws InterruptedException, RequestError {
JSONObject jsonResponse = new JSONObject();
Expand Down