fixed indexing API issues
This commit is contained in:
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
|
||||
distributionUrl=http://services.gradle.org/distributions/gradle-4.4-all.zip
|
||||
|
||||
@@ -23,7 +23,7 @@ import java.util.List;
|
||||
public class WebAPICallbacks {
|
||||
|
||||
public interface SignInCallback {
|
||||
void onSignInSuccess(UserApp admin);
|
||||
void onSignInSuccess(UserApp userApp);
|
||||
void onSignInFailed();
|
||||
void onSignInError();
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package net.irext.webapi;
|
||||
import android.content.Context;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.util.Log;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import net.irext.webapi.model.*;
|
||||
@@ -38,6 +39,11 @@ public class WebAPIs {
|
||||
private static final String DEFAULT_APP = "/irext-server";
|
||||
private static String URL_PREFIX = DEFAULT_ADDRESS + DEFAULT_APP;
|
||||
|
||||
// download bin from OSS
|
||||
private static final String IR_BIN_FILE_PREFIX = "irda_";
|
||||
private static final String IR_BIN_FILE_SUFFIX = ".bin";
|
||||
private static final String IR_BIN_DOWNLOAD_PREFIX = "http://irext-debug.oss-cn-hangzhou.aliyuncs.com/";
|
||||
|
||||
private static final String SERVICE_SIGN_IN = "/app/app_login";
|
||||
private static final String SERVICE_LIST_CATEGORIES = "/indexing/list_categories";
|
||||
private static final String SERVICE_LIST_BRANDS = "/indexing/list_brands";
|
||||
@@ -48,7 +54,7 @@ public class WebAPIs {
|
||||
private static final String SERVICE_DOWNLOAD_BIN = "/operation/download_bin";
|
||||
private static final String SERVICE_ONLINE_DECODE = "/operation/decode";
|
||||
|
||||
private int adminId;
|
||||
private int id;
|
||||
private String token;
|
||||
|
||||
private OkHttpClient mHttpClient;
|
||||
@@ -72,6 +78,16 @@ public class WebAPIs {
|
||||
return mInstance;
|
||||
}
|
||||
|
||||
private InputStream getFileByteStreamByURL(String url) throws IOException {
|
||||
Request request = new Request.Builder()
|
||||
.url(url)
|
||||
.get()
|
||||
.build();
|
||||
|
||||
Response response = new OkHttpClient().newCall(request).execute();
|
||||
return response.body().byteStream();
|
||||
}
|
||||
|
||||
private String postToServer(String url, String json) throws IOException {
|
||||
MediaType JSON
|
||||
= MediaType.parse("application/json; charset=utf-8");
|
||||
@@ -123,14 +139,17 @@ public class WebAPIs {
|
||||
appSignInRequest.setAndroidSignature(signature);
|
||||
String bodyJson = appSignInRequest.toJson();
|
||||
|
||||
Log.d(TAG, "Android APP example sign-in request data : " + bodyJson);
|
||||
String response = postToServer(signInURL, bodyJson);
|
||||
|
||||
Log.d(TAG, "Android APP example sign-in response data : " + response);
|
||||
LoginResponse loginResponse = new Gson().fromJson(response, LoginResponse.class);
|
||||
if (loginResponse.getStatus().getCode() == Constants.ERROR_CODE_SUCCESS) {
|
||||
UserApp admin = loginResponse.getEntity();
|
||||
if (0 != admin.getId() && null != admin.getToken()) {
|
||||
adminId = admin.getId();
|
||||
token = admin.getToken();
|
||||
signInCallback.onSignInSuccess(admin);
|
||||
UserApp userApp = loginResponse.getEntity();
|
||||
if (0 != userApp.getId() && null != userApp.getToken()) {
|
||||
id = userApp.getId();
|
||||
token = userApp.getToken();
|
||||
signInCallback.onSignInSuccess(userApp);
|
||||
} else {
|
||||
signInCallback.onSignInFailed();
|
||||
}
|
||||
@@ -145,7 +164,7 @@ public class WebAPIs {
|
||||
public void listCategories(int from, int count, ListCategoriesCallback listCategoriesCallback) {
|
||||
String listCategoriesURL = URL_PREFIX + SERVICE_LIST_CATEGORIES;
|
||||
ListCategoriesRequest listCategoriesRequest = new ListCategoriesRequest();
|
||||
listCategoriesRequest.setAdminId(adminId);
|
||||
listCategoriesRequest.setId(id);
|
||||
listCategoriesRequest.setToken(token);
|
||||
listCategoriesRequest.setFrom(from);
|
||||
listCategoriesRequest.setCount(count);
|
||||
@@ -171,7 +190,7 @@ public class WebAPIs {
|
||||
ListBrandsCallback listBrandsCallback) {
|
||||
String listBrandsURL = URL_PREFIX + SERVICE_LIST_BRANDS;
|
||||
ListBrandsRequest listBrandsRequest = new ListBrandsRequest();
|
||||
listBrandsRequest.setAdminId(adminId);
|
||||
listBrandsRequest.setId(id);
|
||||
listBrandsRequest.setToken(token);
|
||||
listBrandsRequest.setCategoryId(categoryId);
|
||||
listBrandsRequest.setFrom(from);
|
||||
@@ -197,7 +216,7 @@ public class WebAPIs {
|
||||
public void listProvinces(ListProvincesCallback listProvincesCallback) {
|
||||
String listProvincesURL = URL_PREFIX + SERVICE_LIST_PROVINCES;
|
||||
ListCitiesRequest listCitiesRequest = new ListCitiesRequest();
|
||||
listCitiesRequest.setAdminId(adminId);
|
||||
listCitiesRequest.setId(id);
|
||||
listCitiesRequest.setToken(token);
|
||||
String bodyJson = listCitiesRequest.toJson();
|
||||
|
||||
@@ -220,7 +239,7 @@ public class WebAPIs {
|
||||
public void listCities(String prefix, ListCitiesCallback listCitiesCallback) {
|
||||
String listCitiesURL = URL_PREFIX + SERVICE_LIST_CITIES;
|
||||
ListCitiesRequest listCitiesRequest = new ListCitiesRequest();
|
||||
listCitiesRequest.setAdminId(adminId);
|
||||
listCitiesRequest.setId(id);
|
||||
listCitiesRequest.setToken(token);
|
||||
listCitiesRequest.setProvincePrefix(prefix);
|
||||
String bodyJson = listCitiesRequest.toJson();
|
||||
@@ -245,7 +264,7 @@ public class WebAPIs {
|
||||
ListOperatersCallback listOperatersCallback) {
|
||||
String listOperatorsURL = URL_PREFIX + SERVICE_LIST_OPERATORS;
|
||||
ListOperatorsRequest listOperatorsRequest = new ListOperatorsRequest();
|
||||
listOperatorsRequest.setAdminId(adminId);
|
||||
listOperatorsRequest.setId(id);
|
||||
listOperatorsRequest.setToken(token);
|
||||
listOperatorsRequest.setCityCode(cityCode);
|
||||
listOperatorsRequest.setFrom(0);
|
||||
@@ -275,7 +294,7 @@ public class WebAPIs {
|
||||
ListIndexesCallback onListIndexCallback) {
|
||||
String listIndexesURL = URL_PREFIX + SERVICE_LIST_INDEXES;
|
||||
ListIndexesRequest listIndexesRequest = new ListIndexesRequest();
|
||||
listIndexesRequest.setAdminId(adminId);
|
||||
listIndexesRequest.setId(id);
|
||||
listIndexesRequest.setToken(token);
|
||||
listIndexesRequest.setCategoryId(categoryId);
|
||||
listIndexesRequest.setBrandId(brandId);
|
||||
@@ -304,9 +323,10 @@ public class WebAPIs {
|
||||
@SuppressWarnings("unused")
|
||||
public void downloadBin(String remoteMap, int indexId,
|
||||
DownloadBinCallback downloadBinCallback) {
|
||||
String downloadURL = URL_PREFIX + SERVICE_DOWNLOAD_BIN;
|
||||
String fileName = IR_BIN_FILE_PREFIX + remoteMap + IR_BIN_FILE_SUFFIX;
|
||||
String downloadURL = IR_BIN_DOWNLOAD_PREFIX + fileName;
|
||||
DownloadBinaryRequest downloadBinaryRequest = new DownloadBinaryRequest();
|
||||
downloadBinaryRequest.setAdminId(adminId);
|
||||
downloadBinaryRequest.setId(id);
|
||||
downloadBinaryRequest.setToken(token);
|
||||
downloadBinaryRequest.setIndexId(indexId);
|
||||
|
||||
@@ -314,7 +334,7 @@ public class WebAPIs {
|
||||
|
||||
if (null != bodyJson) {
|
||||
try {
|
||||
InputStream binStream = postToServerForOctets(downloadURL, bodyJson);
|
||||
InputStream binStream = getFileByteStreamByURL(downloadURL);
|
||||
|
||||
if (null != binStream) {
|
||||
downloadBinCallback.onDownloadBinSuccess(binStream);
|
||||
@@ -333,7 +353,7 @@ public class WebAPIs {
|
||||
public int[] decodeIR(int indexId) {
|
||||
String decodeURL = URL_PREFIX + SERVICE_ONLINE_DECODE;
|
||||
DecodeRequest decodeRequest = new DecodeRequest();
|
||||
decodeRequest.setAdminId(adminId);
|
||||
decodeRequest.setId(id);
|
||||
decodeRequest.setToken(token);
|
||||
decodeRequest.setIndexId(indexId);
|
||||
|
||||
|
||||
@@ -14,11 +14,11 @@ import com.google.gson.Gson;
|
||||
*/
|
||||
public class BaseRequest {
|
||||
|
||||
private int adminId;
|
||||
private int id;
|
||||
private String token;
|
||||
|
||||
public BaseRequest(int adminId, String token) {
|
||||
this.adminId = adminId;
|
||||
public BaseRequest(int id, String token) {
|
||||
this.id = id;
|
||||
this.token = token;
|
||||
}
|
||||
|
||||
@@ -26,12 +26,12 @@ public class BaseRequest {
|
||||
|
||||
}
|
||||
|
||||
public int getAdminId() {
|
||||
return adminId;
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setAdminId(int adminId) {
|
||||
this.adminId = adminId;
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getToken() {
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package net.irext.webapi.response;
|
||||
|
||||
import net.irext.webapi.model.UserApp;
|
||||
|
||||
/**
|
||||
* Filename: LoginResponse.java
|
||||
* Revised: Date: 2017-03-31
|
||||
|
||||
1
web-sdk/.gitignore
vendored
1
web-sdk/.gitignore
vendored
@@ -1,5 +1,6 @@
|
||||
.idea/
|
||||
out/
|
||||
output/
|
||||
|
||||
*.class
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ import java.util.List;
|
||||
public class WebAPICallbacks {
|
||||
|
||||
public interface SignInCallback {
|
||||
void onSignInSuccess(UserApp admin);
|
||||
void onSignInSuccess(UserApp userApp);
|
||||
void onSignInFailed();
|
||||
void onSignInError();
|
||||
}
|
||||
|
||||
@@ -32,6 +32,11 @@ public class WebAPIs {
|
||||
private static final String DEFAULT_APP = "/irext-server";
|
||||
private static String URL_PREFIX = DEFAULT_ADDRESS + DEFAULT_APP;
|
||||
|
||||
// download bin from OSS
|
||||
private static final String IR_BIN_FILE_PREFIX = "irda_";
|
||||
private static final String IR_BIN_FILE_SUFFIX = ".bin";
|
||||
private static final String IR_BIN_DOWNLOAD_PREFIX = "http://irext-debug.oss-cn-hangzhou.aliyuncs.com/";
|
||||
|
||||
private static final String SERVICE_SIGN_IN = "/app/app_login";
|
||||
private static final String SERVICE_LIST_CATEGORIES = "/indexing/list_categories";
|
||||
private static final String SERVICE_LIST_BRANDS = "/indexing/list_brands";
|
||||
@@ -42,7 +47,7 @@ public class WebAPIs {
|
||||
private static final String SERVICE_DOWNLOAD_BIN = "/operation/download_bin";
|
||||
private static final String SERVICE_ONLINE_DECODE = "/operation/decode";
|
||||
|
||||
private int adminId;
|
||||
private int id;
|
||||
private String token;
|
||||
|
||||
private OkHttpClient mHttpClient;
|
||||
@@ -66,6 +71,16 @@ public class WebAPIs {
|
||||
return mInstance;
|
||||
}
|
||||
|
||||
private InputStream getFileByteStreamByURL(String url) throws IOException {
|
||||
Request request = new Request.Builder()
|
||||
.url(url)
|
||||
.get()
|
||||
.build();
|
||||
|
||||
Response response = new OkHttpClient().newCall(request).execute();
|
||||
return response.body().byteStream();
|
||||
}
|
||||
|
||||
private String postToServer(String url, String json) throws IOException {
|
||||
MediaType JSON
|
||||
= MediaType.parse("application/json; charset=utf-8");
|
||||
@@ -105,12 +120,12 @@ public class WebAPIs {
|
||||
try {
|
||||
String response = postToServer(signInURL, bodyJson);
|
||||
LoginResponse loginResponse = new Gson().fromJson(response, LoginResponse.class);
|
||||
if(loginResponse.getStatus().getCode() == Constants.ERROR_CODE_SUCCESS) {
|
||||
UserApp admin = loginResponse.getEntity();
|
||||
if (0 != admin.getId() && null != admin.getToken()) {
|
||||
adminId = admin.getId();
|
||||
token = admin.getToken();
|
||||
signInCallback.onSignInSuccess(admin);
|
||||
if (loginResponse.getStatus().getCode() == Constants.ERROR_CODE_SUCCESS) {
|
||||
UserApp userApp = loginResponse.getEntity();
|
||||
if (0 != userApp.getId() && null != userApp.getToken()) {
|
||||
id = userApp.getId();
|
||||
token = userApp.getToken();
|
||||
signInCallback.onSignInSuccess(userApp);
|
||||
} else {
|
||||
signInCallback.onSignInFailed();
|
||||
}
|
||||
@@ -125,7 +140,7 @@ public class WebAPIs {
|
||||
public void listCategories(int from, int count, ListCategoriesCallback listCategoriesCallback) {
|
||||
String listCategoriesURL = URL_PREFIX + SERVICE_LIST_CATEGORIES;
|
||||
ListCategoriesRequest listCategoriesRequest = new ListCategoriesRequest();
|
||||
listCategoriesRequest.setAdminId(adminId);
|
||||
listCategoriesRequest.setId(id);
|
||||
listCategoriesRequest.setToken(token);
|
||||
listCategoriesRequest.setFrom(from);
|
||||
listCategoriesRequest.setCount(count);
|
||||
@@ -151,7 +166,7 @@ public class WebAPIs {
|
||||
ListBrandsCallback listBrandsCallback) {
|
||||
String listBrandsURL = URL_PREFIX + SERVICE_LIST_BRANDS;
|
||||
ListBrandsRequest listBrandsRequest = new ListBrandsRequest();
|
||||
listBrandsRequest.setAdminId(adminId);
|
||||
listBrandsRequest.setId(id);
|
||||
listBrandsRequest.setToken(token);
|
||||
listBrandsRequest.setCategoryId(categoryId);
|
||||
listBrandsRequest.setFrom(from);
|
||||
@@ -177,7 +192,7 @@ public class WebAPIs {
|
||||
public void listProvinces(ListProvincesCallback listProvincesCallback) {
|
||||
String listProvincesURL = URL_PREFIX + SERVICE_LIST_PROVINCES;
|
||||
ListCitiesRequest listCitiesRequest = new ListCitiesRequest();
|
||||
listCitiesRequest.setAdminId(adminId);
|
||||
listCitiesRequest.setId(id);
|
||||
listCitiesRequest.setToken(token);
|
||||
String bodyJson = listCitiesRequest.toJson();
|
||||
|
||||
@@ -200,7 +215,7 @@ public class WebAPIs {
|
||||
public void listCities(String prefix, ListCitiesCallback listCitiesCallback) {
|
||||
String listCitiesURL = URL_PREFIX + SERVICE_LIST_CITIES;
|
||||
ListCitiesRequest listCitiesRequest = new ListCitiesRequest();
|
||||
listCitiesRequest.setAdminId(adminId);
|
||||
listCitiesRequest.setId(id);
|
||||
listCitiesRequest.setToken(token);
|
||||
listCitiesRequest.setProvincePrefix(prefix);
|
||||
String bodyJson = listCitiesRequest.toJson();
|
||||
@@ -225,7 +240,7 @@ public class WebAPIs {
|
||||
ListOperatersCallback listOperatersCallback) {
|
||||
String listOperatorsURL = URL_PREFIX + SERVICE_LIST_OPERATORS;
|
||||
ListOperatorsRequest listOperatorsRequest = new ListOperatorsRequest();
|
||||
listOperatorsRequest.setAdminId(adminId);
|
||||
listOperatorsRequest.setId(id);
|
||||
listOperatorsRequest.setToken(token);
|
||||
listOperatorsRequest.setCityCode(cityCode);
|
||||
listOperatorsRequest.setFrom(0);
|
||||
@@ -255,7 +270,7 @@ public class WebAPIs {
|
||||
ListIndexesCallback onListIndexCallback) {
|
||||
String listIndexesURL = URL_PREFIX + SERVICE_LIST_INDEXES;
|
||||
ListIndexesRequest listIndexesRequest = new ListIndexesRequest();
|
||||
listIndexesRequest.setAdminId(adminId);
|
||||
listIndexesRequest.setId(id);
|
||||
listIndexesRequest.setToken(token);
|
||||
listIndexesRequest.setCategoryId(categoryId);
|
||||
listIndexesRequest.setBrandId(brandId);
|
||||
@@ -284,9 +299,10 @@ public class WebAPIs {
|
||||
@SuppressWarnings("unused")
|
||||
public void downloadBin(String remoteMap, int indexId,
|
||||
DownloadBinCallback downloadBinCallback) {
|
||||
String downloadURL = URL_PREFIX + SERVICE_DOWNLOAD_BIN;
|
||||
String fileName = IR_BIN_FILE_PREFIX + remoteMap + IR_BIN_FILE_SUFFIX;
|
||||
String downloadURL = IR_BIN_DOWNLOAD_PREFIX + fileName;
|
||||
DownloadBinaryRequest downloadBinaryRequest = new DownloadBinaryRequest();
|
||||
downloadBinaryRequest.setAdminId(adminId);
|
||||
downloadBinaryRequest.setId(id);
|
||||
downloadBinaryRequest.setToken(token);
|
||||
downloadBinaryRequest.setIndexId(indexId);
|
||||
|
||||
@@ -294,7 +310,7 @@ public class WebAPIs {
|
||||
|
||||
if (null != bodyJson) {
|
||||
try {
|
||||
InputStream binStream = postToServerForOctets(downloadURL, bodyJson);
|
||||
InputStream binStream = getFileByteStreamByURL(downloadURL);
|
||||
|
||||
if (null != binStream) {
|
||||
downloadBinCallback.onDownloadBinSuccess(binStream);
|
||||
@@ -313,7 +329,7 @@ public class WebAPIs {
|
||||
public int[] decodeIR(int indexId) {
|
||||
String decodeURL = URL_PREFIX + SERVICE_ONLINE_DECODE;
|
||||
DecodeRequest decodeRequest = new DecodeRequest();
|
||||
decodeRequest.setAdminId(adminId);
|
||||
decodeRequest.setId(id);
|
||||
decodeRequest.setToken(token);
|
||||
decodeRequest.setIndexId(indexId);
|
||||
|
||||
|
||||
@@ -14,11 +14,11 @@ import com.google.gson.Gson;
|
||||
*/
|
||||
public class BaseRequest {
|
||||
|
||||
private int adminId;
|
||||
private int id;
|
||||
private String token;
|
||||
|
||||
public BaseRequest(int adminId, String token) {
|
||||
this.adminId = adminId;
|
||||
public BaseRequest(int id, String token) {
|
||||
this.id = id;
|
||||
this.token = token;
|
||||
}
|
||||
|
||||
@@ -26,12 +26,12 @@ public class BaseRequest {
|
||||
|
||||
}
|
||||
|
||||
public int getAdminId() {
|
||||
return adminId;
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setAdminId(int adminId) {
|
||||
this.adminId = adminId;
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getToken() {
|
||||
|
||||
@@ -15,9 +15,9 @@ public class LoginResponse extends ServiceResponse {
|
||||
|
||||
private UserApp entity;
|
||||
|
||||
public LoginResponse(Status status, UserApp admin) {
|
||||
public LoginResponse(Status status, UserApp userApp) {
|
||||
super(status);
|
||||
this.entity = admin;
|
||||
this.entity = userApp;
|
||||
}
|
||||
|
||||
public LoginResponse() {
|
||||
|
||||
Reference in New Issue
Block a user