use of com.google.gson.stream.JsonReader in project weixin-java-tools by chanjarster.
the class WxCpServiceImpl method departCreate.
public Integer departCreate(WxCpDepart depart) throws WxErrorException {
String url = "https://qyapi.weixin.qq.com/cgi-bin/department/create";
String responseContent = execute(new SimplePostRequestExecutor(), url, depart.toJson());
JsonElement tmpJsonElement = Streams.parse(new JsonReader(new StringReader(responseContent)));
return GsonHelper.getAsInteger(tmpJsonElement.getAsJsonObject().get("id"));
}
use of com.google.gson.stream.JsonReader in project weixin-java-tools by chanjarster.
the class WxCpServiceImpl method oauth2getUserInfo.
@Override
public String[] oauth2getUserInfo(String agentId, String code) throws WxErrorException {
String url = "https://qyapi.weixin.qq.com/cgi-bin/user/getuserinfo?" + "code=" + code + "&agendid=" + agentId;
String responseText = get(url, null);
JsonElement je = Streams.parse(new JsonReader(new StringReader(responseText)));
JsonObject jo = je.getAsJsonObject();
return new String[] { GsonHelper.getString(jo, "UserId"), GsonHelper.getString(jo, "DeviceId") };
}
use of com.google.gson.stream.JsonReader in project weixin-java-tools by chanjarster.
the class WxMpServiceImpl method getCallbackIP.
@Override
public String[] getCallbackIP() throws WxErrorException {
String url = "https://api.weixin.qq.com/cgi-bin/getcallbackip";
String responseContent = get(url, null);
JsonElement tmpJsonElement = Streams.parse(new JsonReader(new StringReader(responseContent)));
JsonArray ipList = tmpJsonElement.getAsJsonObject().get("ip_list").getAsJsonArray();
String[] ipArray = new String[ipList.size()];
for (int i = 0; i < ipList.size(); i++) {
ipArray[i] = ipList.get(i).getAsString();
}
return ipArray;
}
use of com.google.gson.stream.JsonReader in project cryptomator by cryptomator.
the class VaultSettingsJsonAdapterTest method testDeserialize.
@Test
public void testDeserialize() throws IOException {
String json = "{\"id\": \"foo\", \"path\": \"/foo/bar\", \"mountName\": \"test\", \"winDriveLetter\": \"X\", \"shouldBeIgnored\": true}";
JsonReader jsonReader = new JsonReader(new StringReader(json));
Settings settings = Mockito.mock(Settings.class);
VaultSettings vaultSettings = adapter.read(jsonReader, settings);
Assert.assertEquals("foo", vaultSettings.getId());
Assert.assertEquals(Paths.get("/foo/bar"), vaultSettings.path().get());
Assert.assertEquals("test", vaultSettings.mountName().get());
Assert.assertEquals("X", vaultSettings.winDriveLetter().get());
}
use of com.google.gson.stream.JsonReader in project buck by facebook.
the class WorkerProcessProtocolZeroTest method testReceiveCommandWithIncorrectMessageID.
@Test
public void testReceiveCommandWithIncorrectMessageID() throws IOException {
int messageID = 123;
int differentMessageID = 456;
JsonReader jsonReader = createMockJsonReaderForReceiveCommand(differentMessageID, "command", "/path/to/args", "/path/to/stdout", "/path/to/stderr");
WorkerProcessProtocol protocol = new WorkerProcessProtocolZero(fakeProcessExecutor, fakeLaunchedProcess, dummyJsonWriter, jsonReader, newTempFile());
try {
protocol.receiveCommand(messageID);
} catch (HumanReadableException e) {
assertThat(e.getMessage(), Matchers.containsString(String.format("Expected command's \"id\" value to be \"%d\"", messageID)));
}
}
Aggregations