2017-05-29 07:14:41 +08:00
## Usage
### 1. Register your APP
2023-04-19 13:36:02 +08:00
Register your APP on irext SDK console [irext SDK console ](http://site.irext.net ), (You need to register an irext account first
2017-05-29 07:14:41 +08:00
While your APP is registered, you can see the APP key and APP secret in your APP list
### 2. Import the SDK
You can either import this project or download the web-api .jar file from [Java SDK ](http://irext-lib-releaese.oss-cn-hangzhou.aliyuncs.com/decode/0.1.2/web-api-java-0.1.2.jar ) and import to your project
### 3. Use the SDK
Import classes:
```java
import net.irext.webapi.model.*;
import net.irext.webapi.WebAPIs;
2017-07-04 21:15:25 +08:00
import net.irext.webapi.WebAPICallbacks.*;
2017-05-29 07:14:41 +08:00
```
Get web API instance:
```java
WebAPIs webApis = WebAPIs.getInstance();
```
Sign in for access id and token:
```java
// App key and secret are fetched in step 1.
2017-07-04 21:15:25 +08:00
SignInCallback signInCallback = new SignInCallback() {
@Override
public void onSignInSuccess(UserApp userApp) {
int id = userApp.getId();
int token = userApp.getToken();
}
@Override
public void onSignInFailed() {
}
@Override
public void onSignInError() {
}
};
webApis.signIn(context, signInCallback);
2017-05-29 07:14:41 +08:00
```
Fetch household appliances categories:
```java
2017-07-04 21:15:25 +08:00
ListCategoriesCallback listCategoriesCallback = new ListCategoriesCallback() {
@Override
public void onListCategoriesSuccess(List<Category> categories) {
}
@Override
public void onListCategoriesFailed() {
}
@Override
public void onListCategoriesError() {
}
};
webApis.listCategories(listCategoriesCallback);
2017-05-29 07:14:41 +08:00
```
Fetch brands of a certain category other than STB:
```java
2017-07-04 21:15:25 +08:00
ListBrandsCallback listBrandsCallback = new ListBrandsCallback() {
@Override
public void onListBrandsSuccess(List<Brand> brands) {
}
@Override
public void onListBrandsFailed() {
}
@Override
public void onListBrandsError() {
}
};
webApis.listBrands(category.getId(), listBrandsCallback);
2017-05-29 07:14:41 +08:00
```
Fetch cities (in China) for STB:
```java
2017-07-04 21:15:25 +08:00
ListProvincesCallback listProvincesCallback = new ListProvincesCallback() {
@Override
public void onListProvincesSuccess(List<City> provinces) {
}
@Override
public void onListProvincesFailed() {
}
@Override
public void onListProvincesError() {
}
};
ListCitiesCallback listCitiesCallback = new ListCitiesCallback() {
@Override
public void onListCitiesSuccess(List<City> cities) {
}
@Override
public void onListCitiesFailed() {
}
@Override
public void onListCitiesError() {
}
};
webApis.listProvinces(listProvincesCallback);
webApis.listCities(provincePrefix, listCitiesCallback);
2017-05-29 07:14:41 +08:00
```
Fetch STB operators of a certain city:
```java
2017-07-04 21:15:25 +08:00
ListOperatersCallback listOperatorCallback = new ListOperatersCallback() {
@Override
public void onListOperatorsSuccess(List<StbOperator> operators) {
}
@Override
public void onListOperatorsFailed() {
}
@Override
public void onListOperatorsError() {
}
};
webApis.listOperators(cityCode, listOperatorCallback);
2017-05-29 07:14:41 +08:00
```
Fetch remote indexes of a certain brand or STB operator:
```java
2017-07-04 21:15:25 +08:00
ListIndexesCallback listIndexesCallback = new ListIndexesCallback() {
@Override
public void onListIndexesSuccess(List<RemoteIndex> indexes) {
}
@Override
public void onListIndexesFailed() {
}
@Override
public void onListIndexesError() {
}
};
webApis.listRemoteIndexes(category.getId(), brand.getId(), city.getCode(), operator.getOperator_id(), listIndexesCallback);
2017-05-29 07:14:41 +08:00
```
Download IR binary for certain remote index:
```java
2017-07-04 21:15:25 +08:00
DownloadBinCallback downloadBinCallback = new DownloadBinCallback() {
@Override
public void onDownloadBinSuccess(InputStream inputStream) {
}
@Override
public void onDownloadBinFailed() {
}
@Override
public void onDownloadBinError() {
}
};
webApis.downloadBin(remoteIndex.getRemote_map(), remoteIndex.getId(), downloadBinCallback);
2017-05-29 07:14:41 +08:00
```