use of com.github.openjson.JSONObject in project triplea by triplea-game.
the class TripleAForumPoster method login.
private JSONObject login(final CloseableHttpClient client) throws IOException {
final HttpPost post = new HttpPost(tripleAForumURL + "/api/ns/login");
post.setEntity(new UrlEncodedFormEntity(Arrays.asList(newUsernameParameter(), newPasswordParameter()), StandardCharsets.UTF_8));
HttpProxy.addProxy(post);
try (CloseableHttpResponse response = client.execute(post)) {
final String rawJson = EntityUtils.toString(response.getEntity());
return new JSONObject(rawJson);
}
}
use of com.github.openjson.JSONObject in project triplea by triplea-game.
the class TripleAForumPoster method getUserId.
private int getUserId(final CloseableHttpClient client) throws IOException {
final JSONObject jsonObject = login(client);
checkUser(jsonObject);
return jsonObject.getInt("uid");
}
use of com.github.openjson.JSONObject in project triplea by triplea-game.
the class OpenJsonUtilsTest method toList_ShouldConvertJsonObjectValueToMap.
@Test
public void toList_ShouldConvertJsonObjectValueToMap() {
final JSONArray jsonArray = new JSONArray(Arrays.asList(new JSONObject(ImmutableMap.of("name", 42))));
final List<Object> elements = OpenJsonUtils.toList(jsonArray);
assertThat(elements, is(Arrays.asList(ImmutableMap.of("name", 42))));
}
use of com.github.openjson.JSONObject in project triplea by triplea-game.
the class OpenJsonUtilsTest method toMap_ShouldReturnMapContainingJsonObjectProperties.
@Test
public void toMap_ShouldReturnMapContainingJsonObjectProperties() {
final JSONObject jsonObject = new JSONObject(ImmutableMap.of("name1", "value1", "name2", 2, "name3", 3.0));
final Map<String, Object> properties = OpenJsonUtils.toMap(jsonObject);
assertThat(properties, is(ImmutableMap.of("name1", "value1", "name2", 2, "name3", 3.0)));
}
use of com.github.openjson.JSONObject in project triplea by triplea-game.
the class OpenJsonUtilsTest method toMap_ShouldConvertJsonObjectValueToMap.
@Test
public void toMap_ShouldConvertJsonObjectValueToMap() {
final JSONObject jsonObject = new JSONObject(ImmutableMap.of("name", new JSONObject(ImmutableMap.of("childName", 42))));
final Map<String, Object> properties = OpenJsonUtils.toMap(jsonObject);
assertThat(properties, is(ImmutableMap.of("name", ImmutableMap.of("childName", 42))));
}
Aggregations