gluu
公開メンバ関数 | 静的公開変数類 | 非公開メンバ関数 | 非公開変数類 | 静的非公開変数類 | 全メンバ一覧
com.toopher.ToopherAPI クラス
com.toopher.ToopherAPI 連携図
Collaboration graph

公開メンバ関数

 ToopherAPI (String consumerKey, String consumerSecret)
 
PairingStatus pair (String pairingPhrase, String userName) throws RequestError
 
PairingStatus getPairingStatus (String pairingRequestId) throws RequestError
 
AuthenticationStatus authenticate (String pairingId, String terminalName) throws RequestError
 
AuthenticationStatus authenticate (String pairingId, String terminalName, String actionName) throws RequestError
 
AuthenticationStatus getAuthenticationStatus (String authenticationRequestId) throws RequestError
 

静的公開変数類

static final String VERSION = "1.0.0"
 

非公開メンバ関数

JSONObject get (String endpoint) throws Exception
 
JSONObject post (String endpoint, List< NameValuePair > params) throws Exception
 

非公開変数類

final HttpClient httpClient
 
final OAuthConsumer consumer
 

静的非公開変数類

static ResponseHandler< JSONObject > jsonHandler
 
static final String URI_SCHEME = "https"
 
static final String URI_HOST = "api.toopher.com"
 
static final String URI_BASE = "/v1/"
 

詳解

A Java binding for the Toopher API

構築子と解体子

◆ ToopherAPI()

com.toopher.ToopherAPI.ToopherAPI ( String  consumerKey,
String  consumerSecret 
)
inline

Create an API object with the supplied credentials

引数
consumerKeyThe consumer key for a requester (obtained from the developer portal)
consumerSecretThe consumer secret for a requester (obtained from the developer portal)
49  {
50  httpClient = new DefaultHttpClient();
51  HttpProtocolParams.setUserAgent(httpClient.getParams(),
52  String.format("ToopherJava/%s", VERSION));
53 
54  consumer = new CommonsHttpOAuthConsumer(consumerKey, consumerSecret);
55  }
final OAuthConsumer consumer
Definition: ToopherAPI.java:219
static final String VERSION
Definition: ToopherAPI.java:39
final HttpClient httpClient
Definition: ToopherAPI.java:218

関数詳解

◆ authenticate() [1/2]

AuthenticationStatus com.toopher.ToopherAPI.authenticate ( String  pairingId,
String  terminalName 
) throws RequestError
inline

Initiate a login authentication request

引数
pairingIdThe pairing id indicating to whom the request should be sent
terminalNameThe user-facing descriptive name for the terminal from which the request originates
戻り値
An AuthenticationStatus object
例外
RequestErrorThrown when an exceptional condition is encountered
114  {
115  return authenticate(pairingId, terminalName, null);
116  }
AuthenticationStatus authenticate(String pairingId, String terminalName)
Definition: ToopherAPI.java:114

◆ authenticate() [2/2]

AuthenticationStatus com.toopher.ToopherAPI.authenticate ( String  pairingId,
String  terminalName,
String  actionName 
) throws RequestError
inline

Initiate an authentication request

引数
pairingIdThe pairing id indicating to whom the request should be sent
terminalNameThe user-facing descriptive name for the terminal from which the request originates
actionNameThe user-facing descriptive name for the action which is being authenticated
戻り値
An AuthenticationStatus object
例外
RequestErrorThrown when an exceptional condition is encountered
132  {
133  final String endpoint = "authentication_requests/initiate";
134 
135  List<NameValuePair> params = new ArrayList<NameValuePair>();
136  params.add(new BasicNameValuePair("pairing_id", pairingId));
137  params.add(new BasicNameValuePair("terminal_name", terminalName));
138  if (actionName != null && actionName.length() > 0) {
139  params.add(new BasicNameValuePair("action_name", actionName));
140  }
141 
142  try {
143  JSONObject json = post(endpoint, params);
144  return AuthenticationStatus.fromJSON(json);
145  } catch (Exception e) {
146  throw new RequestError(e);
147  }
148  }
JSONObject post(String endpoint, List< NameValuePair > params)
Definition: ToopherAPI.java:179

◆ get()

JSONObject com.toopher.ToopherAPI.get ( String  endpoint) throws Exception
inlineprivate
171  {
172  URI uri = new URIBuilder().setScheme(URI_SCHEME).setHost(URI_HOST)
173  .setPath(URI_BASE + endpoint).build();
174  HttpGet get = new HttpGet(uri);
175  consumer.sign(get);
176  return httpClient.execute(get, jsonHandler);
177  }
static ResponseHandler< JSONObject > jsonHandler
Definition: ToopherAPI.java:192
static final String URI_HOST
Definition: ToopherAPI.java:215
final OAuthConsumer consumer
Definition: ToopherAPI.java:219
static final String URI_SCHEME
Definition: ToopherAPI.java:214
static final String URI_BASE
Definition: ToopherAPI.java:216
final HttpClient httpClient
Definition: ToopherAPI.java:218

◆ getAuthenticationStatus()

AuthenticationStatus com.toopher.ToopherAPI.getAuthenticationStatus ( String  authenticationRequestId) throws RequestError
inline

Retrieve status information for an authentication request

引数
authenticationRequestIdThe authentication request ID
戻り値
An AuthenticationStatus object
例外
RequestErrorThrown when an exceptional condition is encountered
160  {
161  final String endpoint = String.format("authentication_requests/%s", authenticationRequestId);
162 
163  try {
164  JSONObject json = get(endpoint);
165  return AuthenticationStatus.fromJSON(json);
166  } catch (Exception e) {
167  throw new RequestError(e);
168  }
169  }

◆ getPairingStatus()

PairingStatus com.toopher.ToopherAPI.getPairingStatus ( String  pairingRequestId) throws RequestError
inline

Retrieve the current status of a pairing request

引数
pairingRequestIdThe unique id for a pairing request
戻り値
A PairingStatus object
例外
RequestErrorThrown when an exceptional condition is encountered
92  {
93  final String endpoint = String.format("pairings/%s", pairingRequestId);
94 
95  try {
96  JSONObject json = get(endpoint);
97  return PairingStatus.fromJSON(json);
98  } catch (Exception e) {
99  throw new RequestError(e);
100  }
101  }

◆ pair()

PairingStatus com.toopher.ToopherAPI.pair ( String  pairingPhrase,
String  userName 
) throws RequestError
inline

Create a pairing

引数
pairingPhraseThe pairing phrase supplied by the user
userNameA user-facing descriptive name for the user (displayed in requests)
戻り値
A PairingStatus object
例外
RequestErrorThrown when an exceptional condition is encountered
68  {
69  final String endpoint = "pairings/create";
70 
71  List<NameValuePair> params = new ArrayList<NameValuePair>();
72  params.add(new BasicNameValuePair("pairing_phrase", pairingPhrase));
73  params.add(new BasicNameValuePair("user_name", userName));
74 
75  try {
76  JSONObject json = post(endpoint, params);
77  return PairingStatus.fromJSON(json);
78  } catch (Exception e) {
79  throw new RequestError(e);
80  }
81  }
JSONObject post(String endpoint, List< NameValuePair > params)
Definition: ToopherAPI.java:179

◆ post()

JSONObject com.toopher.ToopherAPI.post ( String  endpoint,
List< NameValuePair >  params 
) throws Exception
inlineprivate
179  {
180  URI uri = new URIBuilder().setScheme(URI_SCHEME).setHost(URI_HOST)
181  .setPath(URI_BASE + endpoint).build();
182  HttpPost post = new HttpPost(uri);
183  if (params != null && params.size() > 0) {
184  post.setEntity(new UrlEncodedFormEntity(params));
185  }
186 
187  consumer.sign(post);
188 
189  return httpClient.execute(post, jsonHandler);
190  }
static ResponseHandler< JSONObject > jsonHandler
Definition: ToopherAPI.java:192
JSONObject post(String endpoint, List< NameValuePair > params)
Definition: ToopherAPI.java:179
static final String URI_HOST
Definition: ToopherAPI.java:215
final OAuthConsumer consumer
Definition: ToopherAPI.java:219
static final String URI_SCHEME
Definition: ToopherAPI.java:214
static final String URI_BASE
Definition: ToopherAPI.java:216
final HttpClient httpClient
Definition: ToopherAPI.java:218

メンバ詳解

◆ consumer

final OAuthConsumer com.toopher.ToopherAPI.consumer
private

◆ httpClient

final HttpClient com.toopher.ToopherAPI.httpClient
private

◆ jsonHandler

ResponseHandler<JSONObject> com.toopher.ToopherAPI.jsonHandler
staticprivate
初期値:
= new ResponseHandler<JSONObject>() {
@Override
public JSONObject handleResponse(HttpResponse response) throws ClientProtocolException,
IOException {
StatusLine statusLine = response.getStatusLine();
if (statusLine.getStatusCode() >= 300) {
throw new HttpResponseException(statusLine.getStatusCode(),
statusLine.getReasonPhrase());
}
HttpEntity entity = response.getEntity();
String json = EntityUtils.toString(entity);
try {
return (JSONObject) new JSONTokener(json).nextValue();
} catch (JSONException e) {
throw new ClientProtocolException("Could not interpret response as JSON", e);
}
}
}

◆ URI_BASE

final String com.toopher.ToopherAPI.URI_BASE = "/v1/"
staticprivate

◆ URI_HOST

final String com.toopher.ToopherAPI.URI_HOST = "api.toopher.com"
staticprivate

◆ URI_SCHEME

final String com.toopher.ToopherAPI.URI_SCHEME = "https"
staticprivate

◆ VERSION

final String com.toopher.ToopherAPI.VERSION = "1.0.0"
static

The ToopherJava binding library version


このクラス詳解は次のファイルから抽出されました: