public class IRHTTPClient
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
APIENDPOINT_BASE
Internet HTTP APIのエンドポイントです。
Endpoint for Internet HTTP API.
|
static java.lang.String |
DEVICE_API_ENDPOINT_IRKITWIFI
IRKit Wi-Fiに接続しているときのDevice HTTP APIのエンドポイントです。
Endpoint for Device HTTP API when IRKit Wi-Fi is active.
|
static java.lang.String |
DEVICE_API_X_REQUESTED_WITH
Device HTTP APIのリクエストに付けるX-Requested-Withヘッダの値。
Value of X-Requested-With header which is added to every request to Device HTTP API.
|
static java.lang.String |
TAG |
Constructor and Description |
---|
IRHTTPClient()
コンストラクタです。インスタンスを取得するときはsharedInstance()メソッドを使ってください。
Constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
addClientKey(java.util.Map<java.lang.String,java.lang.String> params)
引数のparamsにclientkeyを追加します。
Add clientkey to the given params.
|
void |
cancelPostDoor()
waitForDoor()をキャンセルします。
Cancel previously called waitForDoor().
|
void |
cancelRequests()
waitForSignal()をキャンセルします。現在進行中のwaitForSignal()については コールバックは呼ばれません。 |
void |
clearDeviceKeyCache()
Internet HTTP APIのPOST /1/devicesのレスポンスはキャッシュされますが、 そのキャッシュを削除します。IRHTTPClientインスタンスを作成するたびに キャッシュは空になります。 |
void |
connectDeviceToWifi(IRWifiInfo irWifiInfo,
IRAPICallback<IRDeviceAPIService.PostWifiResponse> callback)
IRKitをWi-Fiに接続させます。Device HTTP APIが使える場合のみ動作します。
Connect an IRKit to Wi-Fi.
|
void |
ensureRegisteredAndCall(java.lang.String apiKey,
IRAPICallback<IRInternetAPIService.PostClientsResponse> callback)
clientkeyを取得していない場合は取得します。
Fetch clientkey if it is not fetched yet.
|
java.lang.String |
getClientKey()
clientkeyを返します。
Return the clientkey.
|
IRDeviceAPIService |
getDeviceAPIService()
Device HTTP APIを直接利用するためのインスタンスを返します。
Return the instance which provides direct access to Device HTTP API.
|
IRInternetAPIService |
getInternetAPIService()
Internet HTTP APIを直接利用するためのインスタンスを返します。
Return the instance which provides direct access to Internet HTTP API.
|
IRDeviceAPIService |
getThrottledDeviceAPIService()
スロットル制御を行いながらDevice HTTP APIにアクセスするためのオブジェクトを返します。
Returns an object which accesses Device HTTP API with request throttling.
|
IRDeviceAPIService |
getThrottledDeviceAPIService(IRPeripheral peripheral)
特定のIRKitに対してスロットル制御を行いながらDevice HTTP APIにアクセスするためのオブジェクトを返します。
Returns an object which accesses Device HTTP API with request throttling.
|
IRDeviceAPIService |
getThrottledDeviceAPIService(java.lang.String deviceId)
特定のIRKitに対してスロットル制御を行いながらDevice HTTP APIにアクセスするためのオブジェクトを返します。
Returns an object which accesses Device HTTP API with request throttling.
|
IRInternetAPIService |
getThrottledInternetAPIService()
スロットル制御を行いながらInternet HTTP APIにアクセスするためのオブジェクトを返します。
Returns an object which accesses Internet HTTP API with request throttling.
|
IRInternetAPIService |
getThrottledInternetAPIService(IRPeripheral peripheral)
特定のIRKitに対してスロットル制御を行いながらInternet HTTP APIにアクセスするためのオブジェクトを返します。
Returns an object which accesses Internet HTTP API with request throttling.
|
IRInternetAPIService |
getThrottledInternetAPIService(java.lang.String deviceId)
特定のIRKitに対してスロットル制御を行いながらInternet HTTP APIにアクセスするためのオブジェクトを返します。
Returns an object which accesses Internet HTTP API with request throttling.
|
boolean |
hasClientKey()
clientkeyがセット済みかどうかを返します。
Return whether clientkey has been set.
|
void |
obtainDeviceKey(IRAPICallback<IRInternetAPIService.PostDevicesResponse> callback)
devicekeyを取得します。
Fetch a devicekey.
|
void |
registerClient(java.lang.String apiKey,
IRAPICallback<IRInternetAPIService.PostClientsResponse> callback)
apikeyを元にclientkeyを取得します。
Fetch clientkey using apikey.
|
void |
sendSignalOverInternet(IRSignal signal,
IRAPICallback<IRInternetAPIService.PostMessagesResponse> callback)
Internet HTTP APIで赤外線信号を送信します。
Send signal over Internet HTTP API.
|
void |
sendSignalOverLocalNetwork(IRSignal signal,
IRAPIResult result)
Device HTTP APIで赤外線信号を送信します。
Send IRSignal over Device HTTP API.
|
void |
setClientKey(java.lang.String key)
clientkeyをセットします。
Set a clientkey.
|
void |
setDeviceAPIEndpoint(java.lang.String endpoint)
Device HTTP APIのエンドポイントをセットします。
Set an endpoint for Device HTTP API.
|
static IRHTTPClient |
sharedInstance() |
void |
testIfIRKitWifiConnected(IRAPIResult result)
192.168.1.1にリクエストを発行してレスポンスヘッダに"IRKit"が含まれていることを確認します。
Sends a request to 192.168.1.1 and checks if the response header contains "IRKit".
|
void |
waitForDoor(java.lang.String deviceId,
IRAPICallback<IRInternetAPIService.PostDoorResponse> callback)
POST /1/doorを呼んで結果を待機します。サーバ側でタイムアウトして408が返ってきた場合は再度リクエストして待機します。 |
void |
waitForSignal(IRAPICallback<IRInternetAPIService.GetMessagesResponse> callback)
IRKitサーバに保存されている最新の赤外線信号を削除して、新しく赤外線信号を待機します。
Clear the IR signal saved in IRKit server, then wait for a new IR signal.
|
void |
waitForSignal(IRAPICallback<IRInternetAPIService.GetMessagesResponse> callback,
boolean clear)
赤外線信号を受信します。
Receive an IR signal.
|
public static final java.lang.String TAG
public static final java.lang.String APIENDPOINT_BASE
public static final java.lang.String DEVICE_API_ENDPOINT_IRKITWIFI
public static final java.lang.String DEVICE_API_X_REQUESTED_WITH
public IRHTTPClient()
sharedInstance()
public static IRHTTPClient sharedInstance()
public void setClientKey(java.lang.String key)
key
- clientkeypublic void setDeviceAPIEndpoint(java.lang.String endpoint)
endpoint
- A string like "http://127.0.0.1"public void registerClient(java.lang.String apiKey, IRAPICallback<IRInternetAPIService.PostClientsResponse> callback)
apiKey
- apikeycallback
- 結果を受け取るコールバック。 Callback to be notified a result.public void ensureRegisteredAndCall(java.lang.String apiKey, IRAPICallback<IRInternetAPIService.PostClientsResponse> callback)
apiKey
- apikeycallback
- 結果を受け取るコールバック。 Callback to be notified a result.public void sendSignalOverInternet(IRSignal signal, IRAPICallback<IRInternetAPIService.PostMessagesResponse> callback)
signal
- IRSignalcallback
- 結果を受け取るコールバック。 Callback to be notified a result.public void sendSignalOverLocalNetwork(IRSignal signal, IRAPIResult result)
signal
- IRSignalresult
- 結果を受け取るコールバック。 Callback to be notified a result.public void waitForSignal(IRAPICallback<IRInternetAPIService.GetMessagesResponse> callback)
callback
- 結果を受け取るコールバック。 Callback to be notified a result.public void waitForSignal(IRAPICallback<IRInternetAPIService.GetMessagesResponse> callback, boolean clear)
callback
- 結果を受け取るコールバック。 Callback to be notified a result.clear
- trueの場合、IRKitサーバに保存されている信号を削除して、新しい信号を待機します。
If true, delete the IR signal saved in IRKit server, then wait for a new IR signal.public void cancelRequests()
waitForSignal()をキャンセルします。現在進行中のwaitForSignal()については コールバックは呼ばれません。
Cancel waitForSignal(). The callback passed to ongoing waitForSignal() will never be called.
public void addClientKey(java.util.Map<java.lang.String,java.lang.String> params)
params
- Map objectpublic void clearDeviceKeyCache()
Internet HTTP APIのPOST /1/devicesのレスポンスはキャッシュされますが、 そのキャッシュを削除します。IRHTTPClientインスタンスを作成するたびに キャッシュは空になります。
Delete the cached response of POST /1/devices. A newly-created IRHTTPClient instance does not have a cached response. When it receives the response of POST /1/devices of Internet HTTP API, it will be cached.
public void obtainDeviceKey(IRAPICallback<IRInternetAPIService.PostDevicesResponse> callback)
callback
- devicekey取得結果を受け取るコールバック。
Callback to be notified a result which contains devicekey.public void connectDeviceToWifi(IRWifiInfo irWifiInfo, IRAPICallback<IRDeviceAPIService.PostWifiResponse> callback)
irWifiInfo
- 接続先のWi-Fi情報。 Target Wi-Fi.callback
- 結果を受け取るコールバック。 Callback to be notified a result.public void cancelPostDoor()
public void waitForDoor(java.lang.String deviceId, IRAPICallback<IRInternetAPIService.PostDoorResponse> callback)
POST /1/doorを呼んで結果を待機します。サーバ側でタイムアウトして408が返ってきた場合は再度リクエストして待機します。
Call POST/1/door and wait for a result. When server returns 408 (server-side timeout), another request will be sent and this method will keep waiting.
deviceId
- deviceidcallback
- 結果を受け取るコールバック。 Callback to be notified a result.public void testIfIRKitWifiConnected(IRAPIResult result)
result
- レスポンスヘッダにIRKitが含まれていればonSuccess()、含まれていなければonError()が呼ばれる。
If the response header contains "IRKit", onSuccess() will be called.
Otherwise onError() will be called.public IRInternetAPIService getInternetAPIService()
public IRDeviceAPIService getDeviceAPIService()
public IRDeviceAPIService getThrottledDeviceAPIService(IRPeripheral peripheral)
peripheral
- 対象となるIRKitデバイス。 Target IRKit device.public IRDeviceAPIService getThrottledDeviceAPIService(java.lang.String deviceId)
deviceId
- 対象となるIRKitデバイスのdeviceid。 Deviceid of the target IRKit device.public IRDeviceAPIService getThrottledDeviceAPIService()
public IRInternetAPIService getThrottledInternetAPIService(IRPeripheral peripheral)
peripheral
- 対象となるIRKitデバイス。 Target IRKit device.public IRInternetAPIService getThrottledInternetAPIService(java.lang.String deviceId)
deviceId
- 対象となるIRKitデバイスのdeviceid。 Deviceid of the target IRKit device.public IRInternetAPIService getThrottledInternetAPIService()
public java.lang.String getClientKey()
public boolean hasClientKey()