List of usage examples for com.google.gson JsonObject getAsJsonPrimitive
public JsonPrimitive getAsJsonPrimitive(String memberName)
From source file:com.hkm.datamodel.StandJsonResponse.java
License:Open Source License
public void run() throws Exception { final JsonObject jsob = parser.parse(returned_data).getAsJsonObject(); if (jsob.has(RESULT)) { final String result = jsob.getAsJsonPrimitive(STATUS).getAsString(); if (result.equalsIgnoreCase(FAILURE)) { transaction_result = false;/*from ww w .j ava2 s. c om*/ if (jsob.has(MESSAGE)) { message = jsob.getAsJsonPrimitive(MESSAGE).getAsString(); } else { message = "line 76: " + returned_data; } if (json_success_action_d != null) { json_success_action_d.onfailure(message); } else { throw new Exception(message); } } else if (result.equalsIgnoreCase(SUCCESS)) { transaction_result = true; if (jsob.has(TIME)) { return_time_stamp = jsob.getAsJsonPrimitive(TIME).getAsLong(); if (json_success_action != null) { json_success_action.onsuccess(return_time_stamp); } if (json_success_action_d != null) { json_success_action_d.onsuccess(return_time_stamp); } } } } }
From source file:com.hkm.root.Tasks.upload_data.java
License:Open Source License
@Override protected String doInBackground(Void... strings) { //todo continue to develop the rest to of the data checking String all_done = ""; try {//from www .ja va 2 s. co m sb = new StringBuilder(); if (!ac.isNetworkOnline()) throw new Exception("no network"); ArrayList<SketchMapData> dmap = current_job_task.getSketchMapList(); ArrayList<PhotoViewData> hmap = current_job_task.getPhotoList(); job_id = ac.getRefInt(appWork.TASK_ID); if (job_id == -1) { throw new Exception("Technical issue: job ID is not found"); } final String t = ac.getRef(appWork.TASK_JSON + job_id); final String response = OCokHttpPostData(WP_DATA_ENDPOINT, t); if (response.equalsIgnoreCase("")) { throw new Exception(response); } else { success_events_achieved++; //final Type listType = new TypeToken<List<String>>() {}.getType(); //List<String> v = json.fromJson(response, listType); final JsonObject jsob = parser.parse(response).getAsJsonObject(); if (jsob.has(STATUS)) { final String status = jsob.getAsJsonPrimitive(STATUS).getAsString(); final String message = jsob.getAsJsonPrimitive(MESSAGE).getAsString(); if (status.equalsIgnoreCase(FAILURE)) { throw new Exception(message); } else if (status.equalsIgnoreCase(SUCCESS)) { if (jsob.has(RESULT)) { post_target = jsob.getAsJsonPrimitive(RESULT).getAsInt(); /** * IMAGES UPLOAD HERE SKETCHMAPS */ files.clear(); if (dmap.size() > 0) { for (SketchMapData d : dmap) { if (d.hasUri()) { files.add(d.get_draw_map_uri()); } } OCokHttpUpload(files, WP_BASE_MAP_ENDPOINT, MEDIA_TYPE_PNG); } /** * IMAGES UPLOAD HERE PHOTOS */ files.clear(); if (hmap.size() > 0) { for (PhotoViewData d : hmap) { files.add(d.uri); } OCokHttpUpload(files, WP_WORK_PHOTO_ENDPOINT, MEDIA_TYPE_JPG); } files.clear(); current_job_task.getLRSignatures(files); current_job_task.getCSSignatures(files); if (files.size() > 0) { OCokHttpUpload(files, WP_SIGNATURES_ENDPOINT, MEDIA_TYPE_JPG); } } else throw new Exception( "return success but the json format is not correct. Please check on the php source of the output method for this error."); } else { throw new Exception(message); } } } all_done = "done"; } catch (JsonIOException e) { all_done = e.getMessage(); } catch (JsonSyntaxException e) { all_done = e.getMessage(); } catch (JsonParseException e) { all_done = e.getMessage(); } catch (UnknownError e) { all_done = e.getMessage(); } catch (UnknownFormatFlagsException e) { all_done = e.getMessage(); } catch (ClassCastException e) { all_done = e.getMessage(); } catch (UnsupportedOperationException e) { all_done = e.getMessage(); } catch (NullPointerException e) { all_done = e.getMessage(); } catch (RuntimeException e) { all_done = e.getMessage(); } catch (Exception e) { all_done = e.getMessage(); } return all_done; }
From source file:com.ibasco.agql.protocols.valve.dota2.webapi.interfaces.Dota2Econ.java
License:Open Source License
public CompletableFuture<String> getItemIconPath(String iconName, Dota2IconType iconType) { CompletableFuture<JsonObject> json = sendRequest( new GetItemIconPath(VERSION_1, iconName, iconType.getType())); return json.thenApply(r -> { JsonObject result = r.getAsJsonObject("result"); if (result.has("path")) return result.getAsJsonPrimitive("path").getAsString(); return null; });//from w w w . j a va2 s . co m }
From source file:com.ibasco.agql.protocols.valve.steam.webapi.adapters.SteamAssetDescDeserializer.java
License:Open Source License
@Override public SteamAssetDescription deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { SteamAssetDescription desc = new SteamAssetDescription(); JsonObject jsonObj = json.getAsJsonObject(); String type = jsonObj.getAsJsonPrimitive("type").getAsString(); String value = jsonObj.getAsJsonPrimitive("value").getAsString(); Map<String, String> mAppData = new HashMap<>(); JsonElement appData = jsonObj.get("app_data"); if (appData.isJsonObject()) { desc.setAppData(context.deserialize(appData, HashMap.class)); } else {/* w w w . j a va 2 s . c o m*/ desc.setAppData(mAppData); } desc.setType(type); desc.setValue(value); return desc; }
From source file:com.ibasco.agql.protocols.valve.steam.webapi.interfaces.SteamApps.java
License:Open Source License
public CompletableFuture<List<SteamGameServer>> getServersAtAddress(InetAddress address) { final CompletableFuture<JsonObject> json = sendRequest( new GetServersAtAddress(1, address.getHostAddress())); return json.thenApply(root -> { JsonObject response = root.getAsJsonObject("response"); Boolean success = response.getAsJsonPrimitive("success").getAsBoolean(); JsonArray serverList = response.getAsJsonArray("servers"); if (success) { Type serverListType = new TypeToken<List<SteamGameServer>>() { }.getType();/*w w w .j a v a 2 s . c o m*/ return builder().fromJson(serverList, serverListType); } throw new AsyncGameLibUncheckedException("Server returned an invalid response"); }); }
From source file:com.ibasco.agql.protocols.valve.steam.webapi.interfaces.SteamEconItems.java
License:Open Source License
public CompletableFuture<List<SteamEconPlayerItem>> getPlayerItems(int appId, long steamId, int apiVersion) { CompletableFuture<JsonObject> json = sendRequest(new GetPlayerItems(appId, steamId, apiVersion)); return json.thenApply(root -> { JsonObject result = root.getAsJsonObject("result"); int status = result.getAsJsonPrimitive("status").getAsInt(); JsonArray items = result.getAsJsonArray("items"); Type type = new TypeToken<List<SteamEconPlayerItem>>() { }.getType();//from w w w . ja v a2 s. c o m return fromJson(items, type); }); }
From source file:com.ibasco.agql.protocols.valve.steam.webapi.interfaces.SteamEconItems.java
License:Open Source License
public CompletableFuture<SteamEconSchema> getSchema(int appId, int version) { CompletableFuture<JsonObject> json = sendRequest(new GetSchema(appId, version)); return json.thenApply(root -> { JsonObject result = root.getAsJsonObject("result"); int status = result.getAsJsonPrimitive("status").getAsInt(); return fromJson(result, SteamEconSchema.class); });//from ww w . j a v a 2 s . c om }
From source file:com.ibasco.agql.protocols.valve.steam.webapi.interfaces.SteamEconItems.java
License:Open Source License
public CompletableFuture<String> getSchemaUrl(int appId, int version) { CompletableFuture<JsonObject> json = sendRequest(new GetSchemaUrl(appId, version)); return json.thenApply(root -> { JsonObject result = root.getAsJsonObject("result"); int status = result.getAsJsonPrimitive("status").getAsInt(); return result.getAsJsonPrimitive("items_game_url").getAsString(); });//from w w w .j a va 2 s.c o m }
From source file:com.ibasco.agql.protocols.valve.steam.webapi.interfaces.SteamEconItems.java
License:Open Source License
public CompletableFuture<Integer> getStoreStatus(int appId, int version) { CompletableFuture<JsonObject> json = sendRequest(new GetStoreStatus(appId, version)); return json.thenApply(root -> { JsonObject result = root.getAsJsonObject("result"); return result.getAsJsonPrimitive("store_status").getAsInt(); });//w w w . j av a 2 s . c o m }
From source file:com.ibasco.agql.protocols.valve.steam.webapi.interfaces.SteamEconomy.java
License:Open Source License
public CompletableFuture<List<SteamAssetPriceInfo>> getAssetPrices(int appId, String currency, String language) {//from ww w. j a v a 2 s .c o m CompletableFuture<JsonObject> json = sendRequest(new GetAssetPrices(VERSION_1, appId, currency, language)); return json.thenApply(root -> { JsonObject result = root.getAsJsonObject("result"); boolean success = result.getAsJsonPrimitive("success").getAsBoolean(); if (success) { JsonArray assets = result.getAsJsonArray("assets"); Type type = new TypeToken<List<SteamAssetPriceInfo>>() { }.getType(); return builder().fromJson(assets, type); } return new ArrayList<SteamAssetPriceInfo>(); }); }