List of usage examples for com.google.gson JsonObject getAsJsonObject
public JsonObject getAsJsonObject(String memberName)
From source file:eu.betaas.service.instancemanager.IMInfo.java
License:Apache License
/** * Build an IMInfo object starting from a GSON representation * @param info the GSON representation to set this object * @throws Exception//from w w w . ja va 2 s . c o m */ public void build(String info) throws Exception { JsonElement jelement = new JsonParser().parse(info); JsonObject jobject = jelement.getAsJsonObject(); JsonObject IMinfo = jobject.getAsJsonObject("IMinfo"); mGWId = IMinfo.get("mGWId").getAsString(); mAdminAddress = IMinfo.get("mAdminAddress").getAsString(); mDescription = IMinfo.get("mDescription").getAsString(); mIsStar = IMinfo.get("mIsStar").getAsBoolean(); mCredentials = IMinfo.get("mCredentials").getAsString(); }
From source file:eu.betaas.service.servicemanager.application.RequestManager.java
License:Apache License
/** * @param serviceID//from w w w .j a va 2 s .c o m * @param combineValues if true SM tries to combine (if possible) the values with the operator * @param token the Base64 encoded token to access the service * @return the data provided by the thing service having the specified ID */ public String getThingServiceData(String serviceID, boolean combineValues, String token) { TaaSResourceManager taasRM = ServiceManager.getInstance().getResourceManagerIF(); if (taasRM == null) { mLogger.error("TaaSRM not available to get data"); return ""; } byte[] decodedToken = null; try { if (token != null) decodedToken = Base64Utility.decode(token); } catch (Exception e) { mLogger.error("Cannot decode token: " + e.getMessage()); } JsonObject data = taasRM.getData(serviceID, decodedToken); if (data == null) { mLogger.error("TaaSRM returned a null data"); return ""; } JsonObject serviceResult = data.getAsJsonObject("ServiceResult"); if (serviceResult == null) { mLogger.error("ServiceResult not found in TaaSRM result"); return ""; } if (!combineValues) { return data.toString(); } JsonElement operator = serviceResult.get("operator"); JsonArray dataList = serviceResult.getAsJsonArray("dataList"); try { String combinedResult = combine(dataList, operator); return combinedResult; } catch (Exception e) { mLogger.warn("Cannot combine received values: " + e.getMessage()); mLogger.warn("Returning uncombined data"); return data.toString(); } }
From source file:eu.over9000.skadi.remote.ChannelDataRetriever.java
License:Open Source License
public static ChannelMetadata getChannelMetadata(final Channel channel) { try {//from w ww . ja v a 2 s . c o m final JsonObject streamResponse = getStreamData(channel.getName()); final ChannelMetadataBuilder builder = new ChannelMetadataBuilder(); final JsonObject streamObject; final JsonObject channelObject; final boolean isOnline = !streamResponse.get("stream").isJsonNull(); builder.setOnline(isOnline); if (isOnline) { streamObject = streamResponse.getAsJsonObject("stream"); channelObject = streamObject.getAsJsonObject("channel"); builder.setUptime(getChannelUptime(streamObject)); builder.setViewer(streamObject.get("viewers").getAsInt()); } else { channelObject = getChannelDataForOfflineStream(channel.getName()); builder.setUptime(0L); builder.setViewer(0); } builder.setTitle(getStringIfPresent("status", channelObject)); builder.setGame(getStringIfPresent("game", channelObject)); builder.setLogoURL(getStringIfPresent("logo", channelObject)); builder.setViews(getIntIfPresent("views", channelObject)); builder.setFollowers(getIntIfPresent("followers", channelObject)); builder.setPartner(getBoolIfPresent("partner", channelObject)); return builder.build(); } catch (final Exception e) { LOGGER.error("Exception getting metadata for channel " + channel + ": " + e.getMessage()); return null; } }
From source file:eu.over9000.skadi.service.ImportFollowedService.java
License:Open Source License
@Override protected Task<Set<String>> createTask() { return new Task<Set<String>>() { @Override/*from w w w.ja v a2 s.com*/ protected Set<String> call() throws Exception { this.updateMessage("importing channels for " + ImportFollowedService.this.user); try { final Set<String> channels = new TreeSet<>(); int limit = 0; int offset = 0; String url = "https://api.twitch.tv/kraken/users/" + ImportFollowedService.this.user + "/follows/channels"; String response = HttpUtil.getAPIResponse(url); JsonObject responseObject = ImportFollowedService.this.parser.parse(response).getAsJsonObject(); String parameters = responseObject.getAsJsonObject("_links").get("self").getAsString() .split("\\?")[1]; String[] split = parameters.split("&"); for (final String string : split) { if (string.startsWith("limit")) { limit = Integer.valueOf(string.split("=")[1]); } else if (string.startsWith("offset")) { offset = Integer.valueOf(string.split("=")[1]); } } final int count = responseObject.get("_total").getAsInt(); LOGGER.debug("total channels followed: " + count); this.updateProgress(count, channels.size()); this.updateMessage("Loaded " + channels.size() + " of " + count + " channels"); while (offset < count) { ImportFollowedService.this.parseAndAddChannelsToSet(channels, responseObject); url = "https://api.twitch.tv/kraken/users/" + ImportFollowedService.this.user + "/follows/channels?limit=" + limit + "&offset=" + (offset + limit); response = HttpUtil.getAPIResponse(url); responseObject = ImportFollowedService.this.parser.parse(response).getAsJsonObject(); parameters = responseObject.getAsJsonObject("_links").get("self").getAsString() .split("\\?")[1]; split = parameters.split("&"); for (final String string : split) { if (string.startsWith("limit")) { limit = Integer.valueOf(string.split("=")[1]); } else if (string.startsWith("offset")) { offset = Integer.valueOf(string.split("=")[1]); } } LOGGER.debug("limit=" + limit + " offset=" + offset + " channelsize=" + channels.size()); this.updateProgress(count, channels.size()); this.updateMessage("Loaded " + channels.size() + " of " + count + " channels"); } return channels; } catch (final HttpResponseException e) { if (e.getStatusCode() == 404) { this.updateMessage("The given user does not exist"); return null; } this.updateMessage("Error: " + e.getMessage()); LOGGER.error("Error", e); return null; } catch (final Exception e) { this.updateMessage("Error: " + e.getMessage()); LOGGER.error("Error", e); return null; } } }; }
From source file:eu.supersede.monitor.reconfiguration.executor.model.MonitorList.java
License:Apache License
public MonitorList(JsonObject json) { this.monitors = new ArrayList<>(); this.configSender = json.getAsJsonObject("").get("configSender").getAsString(); this.timeStamp = json.getAsJsonObject("").get("timeStamp").getAsString(); for (Entry<String, JsonElement> entry : json.entrySet()) { if (!entry.getKey().equals("")) monitors.add(new MonitorInfo(entry.getValue().getAsJsonObject(), entry.getKey())); }/* w ww . j a v a 2 s . c o m*/ }