@Override public String tagCreate(String tagName) throws WxErrorException { String url = "https://qyapi.weixin.qq.com/cgi-bin/tag/create"; JsonObject o = new JsonObject(); o.addProperty("tagname", tagName); String responseContent = post(url, o.toString()); JsonElement tmpJsonElement = Streams.parse(new JsonReader(new StringReader(responseContent))); return tmpJsonElement.getAsJsonObject().get("tagid").getAsString(); }
private void logInfoMessage(JsonObject json) { String value; if (json.has("stream")) { value = json.get("stream").getAsString().replaceFirst("\n$", ""); } else if (json.has("status")) { value = json.get("status").getAsString(); } else { value = json.toString(); } log.info("%s", value); }
@Override public List<WxMpUserSummary> getUserSummary(Date beginDate, Date endDate) throws WxErrorException { String url = "https://api.weixin.qq.com/datacube/getusersummary"; JsonObject param = new JsonObject(); param.addProperty("begin_date", SIMPLE_DATE_FORMAT.format(beginDate)); param.addProperty("end_date", SIMPLE_DATE_FORMAT.format(endDate)); String responseContent = post(url, param.toString()); JsonElement tmpJsonElement = Streams.parse(new JsonReader(new StringReader(responseContent))); return WxMpGsonBuilder.INSTANCE.create().fromJson(tmpJsonElement.getAsJsonObject().get("list"), new TypeToken<List<WxMpUserSummary>>() { }.getType()); }
private Object readFieldValue(JsonObject fields, CustomField customField) { String fieldId = customField.getId(); String fieldValue = ""; if(fieldIsDefined(fields, fieldId)) { if(fields.get(fieldId).isJsonPrimitive()) { fieldValue = fields.getAsJsonPrimitive(fieldId).getAsString(); } else if(fields.get(fieldId).isJsonObject()) { fieldValue = fields.getAsJsonObject(fieldId).toString(); } } if (isJSON(fieldValue)) { JsonObject field = new JsonParser().parse(fieldValue).getAsJsonObject(); if (customField.getType().equals("string") || customField.getType().equals("option")) { return field.equals(JsonNull.INSTANCE) ? "" : field.getAsJsonPrimitive("value").getAsString(); } else if (customField.getType().equals("array") || customField.getType().equals("option-with-child")) { return readListFrom(field); } } return fieldValue; }
private void publish(JsonObject jsonPubMsg) throws MqttException, UnsupportedEncodingException { final String METHOD = "publish1"; String topic = jsonPubMsg.get("topic").getAsString(); int qos = jsonPubMsg.get("qos").getAsInt(); JsonObject payload = jsonPubMsg.getAsJsonObject("payload"); LoggerUtility.log(Level.FINE, CLASS_NAME, METHOD, ": Topic(" + topic + ") qos=" + qos + " payload (" + payload.toString() + ")"); MqttMessage message = new MqttMessage(); message.setPayload(payload.toString().getBytes("UTF-8")); message.setQos(qos); publish(topic, message); }
@Override public String jsonObjectFromJsonMap(Map<String, String> map) { JsonObject object = new JsonObject(); JsonParser parser = new JsonParser(); for (String key : map.keySet()) { String jsonString = map.get(key); JsonElement element = parser.parse(jsonString); object.add(key, element); } return object.toString(); } }
post.setRequestBody(queryJson.toString()); JsonObject jsonResponse = ViewRequester.executeRequestWithResponseAsJson (viewQueryParameters, post); int index = 0; for (ViewQueryParameters<K, V> params : requestParameters) { JsonObject response = jsonResponses.get(index).getAsJsonObject(); responses.add(new ViewResponseImpl<K, V>(params, response, null)); index++;
public static int updateSlotItemData(JsonObject api_data) { if (helper == null) return -1; JsonObject item = null; if (api_data.has("api_create_flag") && api_data.get("api_create_flag").getAsInt() == 1) { item = (JsonObject) api_data.get("api_slot_item"); } else if (api_data.has("api_slotitem_id")) { item = api_data; } if (item != null) { int item_id = item.get("api_id").getAsInt(); int kc_item_id = item.get("api_slotitem_id").getAsInt(); int itemType = getKcItemStatusById(kc_item_id, "type").get("type").getAsJsonArray().get(2).getAsInt(); item.addProperty("api_locked", 0); item.addProperty("api_level", 0); if (isItemAircraft(itemType)) { item.addProperty("api_alv", 0); } helper.putItemValue(item_id, item.toString()); Log.e("KCA", KcaUtils.format("add item %d", item_id)); return kc_item_id; } return 0; }
public String shortUrl(String long_url) throws WxErrorException { String url = "https://api.weixin.qq.com/cgi-bin/shorturl"; JsonObject o = new JsonObject(); o.addProperty("action", "long2short"); o.addProperty("long_url", long_url); String responseContent = execute(new SimplePostRequestExecutor(), url, o.toString()); JsonElement tmpJsonElement = Streams.parse(new JsonReader(new StringReader(responseContent))); return tmpJsonElement.getAsJsonObject().get("short_url").getAsString(); }
protected void parseAuthenticationResponse(JsonObject jsonRet) throws RestApiConnectionException { if (!hasId(jsonRet)) { throw new RestApiConnectionException("Failed on authentication with the following HTTP response received:" + jsonRet.toString()); } this.instanceUrl = jsonRet.get("instance_url").getAsString(); this.accessToken = jsonRet.get("access_token").getAsString(); this.createdAt = System.currentTimeMillis(); } }
@Override public List<WxMpUserCumulate> getUserCumulate(Date beginDate, Date endDate) throws WxErrorException { String url = "https://api.weixin.qq.com/datacube/getusercumulate"; JsonObject param = new JsonObject(); param.addProperty("begin_date", SIMPLE_DATE_FORMAT.format(beginDate)); param.addProperty("end_date", SIMPLE_DATE_FORMAT.format(endDate)); String responseContent = post(url, param.toString()); JsonElement tmpJsonElement = Streams.parse(new JsonReader(new StringReader(responseContent))); return WxMpGsonBuilder.INSTANCE.create().fromJson(tmpJsonElement.getAsJsonObject().get("list"), new TypeToken<List<WxMpUserCumulate>>() { }.getType()); }
private void publish(JsonObject jsonPubMsg) throws MqttException, UnsupportedEncodingException { final String METHOD = "publish1"; String topic = jsonPubMsg.get("topic").getAsString(); int qos = jsonPubMsg.get("qos").getAsInt(); JsonObject payload = jsonPubMsg.getAsJsonObject("payload"); LoggerUtility.log(Level.FINE, CLASS_NAME, METHOD, ": Topic(" + topic + ") qos=" + qos + " payload (" + payload.toString() + ")"); MqttMessage message = new MqttMessage(); message.setPayload(payload.toString().getBytes("UTF-8")); message.setQos(qos); publish(topic, message); }
@Override public String jsonObjectFromJsonMap(Map<String, String> map) { JsonObject object = new JsonObject(); JsonParser parser = new JsonParser(); for (String key : map.keySet()) { String jsonString = map.get(key); JsonElement element = parser.parse(jsonString); object.add(key, element); } return object.toString(); } }
public List<RollupTask> parseRollupTasks(String json) throws BeanValidationException, QueryException { List<RollupTask> tasks = new ArrayList<>(); JsonParser parser = new JsonParser(); JsonArray rollupTasks = parser.parse(json).getAsJsonArray(); for (int i = 0; i < rollupTasks.size(); i++) { JsonObject taskObject = rollupTasks.get(i).getAsJsonObject(); RollupTask task = parseRollupTask(taskObject, "tasks[" + i + "]"); task.addJson(taskObject.toString().replaceAll("\\n", "")); tasks.add(task); } return tasks; }
@Override public String createExecContainer(String containerId, Arguments arguments) throws DockerAccessException { String url = urlBuilder.createExecContainer(containerId); JsonObject request = new JsonObject(); request.addProperty("Tty", true); request.addProperty("AttachStdin", false); request.addProperty("AttachStdout", true); request.addProperty("AttachStderr", true); request.add("Cmd", JsonFactory.newJsonArray(arguments.getExec())); String execJsonRequest = request.toString(); try { String response = delegate.post(url, execJsonRequest, new ApacheHttpClientDelegate.BodyResponseHandler(), HTTP_CREATED); JsonObject json = JsonFactory.newJsonObject(response); if (json.has("Warnings")) { logWarnings(json); } return json.get("Id").getAsString(); } catch (IOException e) { throw new DockerAccessException(e, "Unable to exec [%s] on container [%s]", request.toString(), containerId); } }
@Override public int invite(String userId, String inviteTips) throws WxErrorException { String url = "https://qyapi.weixin.qq.com/cgi-bin/invite/send"; JsonObject jsonObject = new JsonObject(); jsonObject.addProperty("userid", userId); if (StringUtils.isNotEmpty(inviteTips)) { jsonObject.addProperty("invite_tips", inviteTips); } String responseContent = post(url, jsonObject.toString()); JsonElement tmpJsonElement = Streams.parse(new JsonReader(new StringReader(responseContent))); return tmpJsonElement.getAsJsonObject().get("type").getAsInt(); }
private void publish(JsonObject jsonPubMsg) throws MqttException, UnsupportedEncodingException { final String METHOD = "publish1"; String topic = jsonPubMsg.get("topic").getAsString(); int qos = jsonPubMsg.get("qos").getAsInt(); JsonObject payload = jsonPubMsg.getAsJsonObject("payload"); LoggerUtility.log(Level.FINE, CLASS_NAME, METHOD, ": Topic(" + topic + ") qos=" + qos + " payload (" + payload.toString() + ")"); MqttMessage message = new MqttMessage(); message.setPayload(payload.toString().getBytes("UTF-8")); message.setQos(qos); publish(topic, message); }
public String bodyParametersToJson(List<NameValuePair> bodyParameters) { JsonObject jsonObject = new JsonObject(); JsonElement jsonElement; for (NameValuePair nameValuePair : bodyParameters) { try { jsonElement = new JsonParser().parse(nameValuePair.getValue()); } catch (JsonSyntaxException e) { jsonElement = new JsonPrimitive(nameValuePair.getValue()); } jsonObject.add(nameValuePair.getName(), jsonElement); } return jsonObject.toString(); }
public RollupTask parseRollupTask(String json, String id) throws BeanValidationException, QueryException { JsonParser parser = new JsonParser(); JsonObject taskObject = parser.parse(json).getAsJsonObject(); RollupTask task = parseRollupTask(taskObject, ""); String newJson = taskObject.toString(); if (id != null) { // If updating the task, replace the new Id with the old Id newJson = newJson.replace(task.getId(), id); } task.addJson(newJson.replaceAll("\\n", "")); return task; }
kunderaMetadata); String _id = object.get("_id").getAsString(); Reader reader = new InputStreamReader(content); JsonObject jsonObject = gson.fromJson(reader, JsonObject.class); JsonElement rev = jsonObject.get("_rev"); object.add("_rev", rev); stringEntity = new StringEntity(object.toString(), Constants.CHARSET_UTF8); stringEntity.setContentType("application/json"); put.setEntity(stringEntity);