Skip to content

Commit 376d07f

Browse files
author
Grace Yim
committed
Simplify README and add iframe info
1 parent fe388e9 commit 376d07f

File tree

3 files changed

+82
-184
lines changed

3 files changed

+82
-184
lines changed

CONTRIBUTING.md

Lines changed: 0 additions & 24 deletions
This file was deleted.

README-Iframe.md

Lines changed: 0 additions & 108 deletions
This file was deleted.

README.md

Lines changed: 82 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,104 @@
1-
#ToopherJava
1+
#ToopherJava [![Build Status](https://travis-ci.org/toopher/toopher-java.png?branch=master)](https://travis-ci.org/toopher/toopher-java)
22

3-
[![Build
4-
Status](https://travis-ci.org/toopher/toopher-java.png?branch=master)](https://travis-ci.org/toopher/toopher-java)
3+
ToopherJava is a Toopher API library that simplifies the task of interfacing with the Toopher API from Java 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.
54

6-
#### Introduction
7-
ToopherJava is a Toopher API library that simplifies the task of interfacing with the Toopher API from Java code. This project includes all the dependency libraries and handles the required OAuth and JSON functionality so you can focus on just using the API.
5+
*Note: ToopherJava is not meant for use in Android.*
86

9-
Note: ToopherJava is not meant for use in Android.
7+
### Java Version
8+
\>=5.0
109

11-
#### Learn the Toopher API
12-
Make sure you visit (http://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.
10+
### Documentation
11+
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.
1312

14-
#### OAuth Authentication
13+
## ToopherApi Workflow
1514

16-
The first step to accessing the Toopher API is to sign up for an account at the development portal (http://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.
17-
18-
#### The Toopher Two-Step
19-
Interacting with the Toopher web service involves two steps: pairing and authenticating.
20-
21-
##### Pair
22-
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 API 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.
23-
24-
##### Authenticate
25-
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.
26-
27-
#### Librarified
28-
This library makes it super simple to do the Toopher two-step. Check it out:
15+
### Step 1: Pair
16+
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 API along with their username and we'll return a pairing ID that you can use whenever you want to authenticate an action for that user.
2917

3018
```java
3119
import com.toopher.*;
3220

3321
// Create an API object using your credentials
3422
ToopherAPI api = new ToopherAPI("<your consumer key>", "<your consumer secret>");
3523

36-
// Step 1 - Pair with their phone's Toopher app
37-
// With pairing phrase
24+
// Step 1 - Pair with their mobile device's Toopher app
3825
Pairing pairing = api.pair("username@yourservice.com", "pairing phrase");
39-
// With SMS
40-
Pairing pairing = api.pair("username@yourservice.com", "555-555-5555")
41-
// With QR code
42-
Pairing pairing = api.pair("username@yourservice.com")
26+
```
27+
28+
### Step 2: Authenticate
29+
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"*).
30+
31+
```java
32+
// Create an optional Map of extra parameters to provide to the API
33+
Map<String, String> extras = new HashMap<String, String>();
34+
extras.put("terminalName", "terminal name");
35+
extras.put("requesterSpecifiedId", "requester specified ID");
36+
extras.put("actionName", "action name");
4337

4438
// Step 2 - Authenticate a log in
45-
// With pairingId and terminal name
46-
AuthenticationRequest auth = api.authenticate(pairing.id, "my computer");
47-
// With username and requester specified Id (Returns exception if terminal is not found)
48-
AuthenticationRequest auth = api.authenticate("username", null, "requesterSpecifiedId")
49-
// With username, terminal name and requester specified Id (Returns exception if terminal is not found)
50-
AuthenticationRequest auth = api.authenticate("username", "my computer", "requesterSpecifiedId")
51-
// With username and terminal name (New terminal is created if terminal is not found)
52-
AuthenticationRequest auth = api.authenticate("username", "my computer")
39+
AuthenticationRequest authenticationRequest = api.authenticate("username@yourservice.com", extras);
5340

5441
// Once they've responded you can then check the status
55-
auth.refreshFromServer()
42+
authenticationRequest.refreshFromServer();
5643
if (status.pending == false && status.granted == true) {
5744
// Success!
5845
}
5946
```
6047

61-
#### Handling Errors
48+
## ToopherIframe Workflow
49+
50+
### Step 1: Embed a request in an IFRAME
51+
1. Generate an authentication URL by providing a username.
52+
2. Display a webpage to your user that embeds this URL within an `<iframe>` element.
53+
54+
```java
55+
import com.toopher.*;
56+
57+
// Create an API object using your credentials
58+
ToopherIframe iframeApi = new ToopherIframe("<your consumer key>", "<your consumer secret>");
59+
60+
String authenticationUrl = iframeApi.getAuthenticationUrl("username@yourservice.com");
61+
62+
// Add an <iframe> element to your HTML:
63+
// <iframe id="toopher_iframe" src=authenticationUrl />
64+
```
65+
66+
### Step 2: Validate the postback data
67+
68+
The simplest way to validate the postback data is to call `isAuthenticationGranted` to check if the authentication request was granted.
69+
70+
```java
71+
// Retrieve the postback data as a string from POST parameter 'iframe_postback_data'
72+
73+
// Returns boolean indicating if authentication request was granted by user
74+
boolean authenticationRequestGranted = iframeApi.isAuthenticationGranted(postback_data);
75+
76+
if (authenticationRequestGranted) {
77+
// Success!
78+
}
79+
```
80+
81+
### Handling Errors
6282
If any request runs into an error a `RequestError` will be thrown with more details on what went wrong.
6383

64-
#### Dependencies
84+
### Demo
85+
Check out `com.toopher.ToopherAPIDemo.java` 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:
86+
87+
```shell
88+
$ mvn exec:java -Dexec.mainClass="com.toopher.ToopherAPIDemo"
89+
```
90+
91+
## Contributing
92+
### Dependencies
93+
Toopher uses [Maven](https://maven.apache.org/index.html). To install Maven with Homebrew run:
94+
95+
```shell
96+
$ brew install maven
97+
```
98+
6599
This library uses the Apache Commons HttpClient and OAuth-Signpost libraries, which are included as JARs in the "lib" directory. Please add these JARs to your classpath when using our library.
66100

67-
##### Maven
101+
#### Maven
68102
Alternatively, you can consume this library using Maven:
69103

70104
<dependency>
@@ -73,21 +107,17 @@ Alternatively, you can consume this library using Maven:
73107
<version>1.0.0-SNAPSHOT</version>
74108
</dependency>
75109

76-
#### Try it out
77-
Check out `com.toopher.ToopherAPIDemo.java` for an example program that walks you through the whole process!
78-
79-
#####Ant
80-
A runnable jar for the demo can be built and executed in Ant as follows:
110+
### Tests
111+
To run the tests using Maven enter:
81112
```shell
82-
$ ant
83-
$ java -jar dist/toopher-1.0.0.jar
113+
$ mvn test
84114
```
85115

86-
#####Maven
87-
The demo can be executed in Maven as follows:
116+
To get coverage reports with the JaCoCo Maven Plugin enter:
88117
```shell
89-
$ mvn exec:java -Dexec.mainClass="com.toopher.ToopherAPIDemo"
118+
$ mvn clean verify -P all-tests
119+
$ open target/site/jacoco/index.html
90120
```
91121

92-
#### License
93-
ToopherJava is licensed under the MIT License. See LICENSE.txt for the full license text.
122+
## License
123+
ToopherJava is licensed under the MIT License. See LICENSE.txt for the full text.

0 commit comments

Comments
 (0)