/** * Gets the profile of the authorizing {@linkplain XingUser user} (The user who has granted access to the API * consumer). * <p> * Possible optional <i>query</i> parameters: * <table> * <tr> * <th>Parameter Name</th> * <th><b>Description</b></th> * </tr> * <tr> * <td><strong>fields</strong></td> * <td>List of user attributes to return. If this parameter is not used, the full user profile will be returned * .</td> * </tr> * </table> * * @return A {@linkplain CallSpec callSpec object} ready to execute the request. * * @see <a href="https://dev.xing.com/docs/get/users/:id">'Get user details' resource page</a> */ public CallSpec<XingUser, HttpError> getOwnProfile() { return getUserById(ME); }
/** * Returns the legal information for the authorizing {@linkplain XingUser user}. * * @return A {@linkplain CallSpec callSpec} object ready to execute the request. * * @see <a href="https://dev.xing.com/docs/get/users/:user_id/legal_information">'Get legal information of a user' * resource page</a> */ public CallSpec<String, HttpError> getOwnLegalInformation() { return getUserLegalInformation(ME); } }
/** * Returns the recent profile message for the authorizing {@linkplain XingUser user}. * * @return A {@linkplain CallSpec callSpec} object ready to execute the request. * * @see <a href="https://dev.xing.com/docs/get/users/:user_id/profile_message">'Get user profile message' resource * page</a> */ public CallSpec<ProfileMessage, HttpError> getOwnProfileMessage() { return getUserProfileMessage(ME); }
@Test public void getUserLegalInformation() throws Exception { MockResponse mockResponse = new MockResponse().setBody("{\n" + " \"legal_information\": {\n" + " \"content\": \"Hello there.\"\n" + " }\n" + '}'); // Enqueue twice server.enqueue(mockResponse); server.enqueue(mockResponse); Response<String, HttpError> response1 = resource.getUserLegalInformation("test").execute(); assertThat(response1.body()).isEqualTo("Hello there."); Response<String, HttpError> response2 = resource.getOwnLegalInformation().execute(); assertThat(response2.body()).isEqualTo("Hello there."); } }
@Test public void getUserProfileMessage() throws Exception { MockResponse mockResponse = new MockResponse().setBody("{\n" + " \"profile_message\": {\n" + " \"updated_at\": \"2011-07-18T11:40:19Z\",\n" + " \"message\": \"My new profile message.\"\n" + " }\n" + '}'); // Enqueue twice server.enqueue(mockResponse); server.enqueue(mockResponse); Response<ProfileMessage, HttpError> response1 = resource.getUserProfileMessage("test").execute(); // If no exception was thrown then the spec is build correctly. SafeCalendar safeCalendar = new SafeCalendar(2011, 6, 18, 11, 40, 19); safeCalendar.setTimeZone(TimeZone.getTimeZone("UTC")); assertThat(response1.body().updatedAt()).isEqualTo(safeCalendar); assertThat(response1.body().message()).isEqualTo("My new profile message."); Response<ProfileMessage, HttpError> response2 = resource.getOwnProfileMessage().execute(); // If no exception was thrown then the spec is build correctly. assertThat(response2.body().updatedAt()).isEqualTo(safeCalendar); assertThat(response2.body().message()).isEqualTo("My new profile message."); }
@Override public Resource create(XingApi api) { return new UserProfilesResource(api); } };
/** * Gets a particular {@linkplain XingUser user's} profile. The data returned by this call will be checked and * filtered on the basis of the privacy settings of the requested user. * <p> * Possible optional <i>query</i> parameters: * <table> * <tr> * <th>Parameter Name</th> * <th><b>Description</b></th> * </tr> * <tr> * <td><strong>fields</strong></td> * <td>List of user attributes to return. If this parameter is not used, the full user profile will be returned * .</td> * </tr> * </table> * * @param id Id of the requested {@linkplain XingUser user}. * @return A {@linkplain CallSpec callSpec object} ready to execute the request. * * @see <a href="https://dev.xing.com/docs/get/users/:id">'Get user details' resource page</a> */ public CallSpec<XingUser, HttpError> getUserById(String id) { return Resource.<XingUser, HttpError>newGetSpec(api, "/v1/users/{id}") .pathParam("id", id) .responseAs(first(XingUser.class, "users")) .build(); }
@Test public void findUsersByKeyword() throws Exception { server.enqueue(new MockResponse().setBody("{\n" + " \"users\": {\n" + " \"items\": [\n" + " {\n" + " \"user\": {\n" + " \"id\": \"2_abcdef\"\n" + " }\n" + " },\n" + " {\n" + " \"user\": {\n" + " \"id\": \"3_ad7e12\"\n" + " }\n" + " }\n" + " ],\n" + " \"total\": 2\n" + " }\n" + '}')); Response<List<XingUser>, HttpError> response = resource.findUsersByKeyword("test").execute(); // If no exception was thrown then the spec is build correctly. assertThat(response.body().size()).isEqualTo(2); assertThat(response.body().get(0).id()).isEqualTo("2_abcdef"); assertThat(response.body().get(1).id()).isEqualTo("3_ad7e12"); }
@Test public void getOwnProfile() throws Exception { server.enqueue(new MockResponse().setBody("{\n" + " \"users\": [\n" + " \n" + userJson + " ]\n" + '}')); Response<XingUser, HttpError> response = resource.getOwnProfile().execute(); // If no exception was thrown then the spec is build correctly. assertThat(response.body().id()).isEqualTo("123456_abcdef"); }
@Test public void getOwnIdCard() throws Exception { server.enqueue(new MockResponse().setBody("{\n" + " \"id_card\": {\n" + " \"id\": \"test_id\"\n" + " }\n" + '}')); Response<XingUser, HttpError> response = resource.getOwnIdCard().execute(); // If no exception was thrown then the spec is build correctly. assertThat(response.body().id()).isEqualTo("test_id"); }
@Test public void findUsersByEmail() throws Exception { server.enqueue(new MockResponse().setBody("{\n" + " \"results\": {\n" + " \"items\": [\n" + " {\n" + " \"email\": \"existing_user@xing.com\",\n" + " \"hash\": null,\n" + " \"user\": {\n" + " \"id\": \"10368_ddec16\"\n" + " }\n" + " },\n" + " {\n" + " \"email\": \"unknown_user@xing.com\",\n" + " \"hash\": null,\n" + " \"user\": null\n" + " }\n" + " ],\n" + " \"total\": 2\n" + " }\n" + '}')); Response<List<XingUser>, HttpError> response = resource .findUsersByEmail(Collections.singletonList("mail")).execute(); // If no exception was thrown then the spec is build correctly. assertThat(response.body().size()).isEqualTo(2); assertThat(response.body().get(0).id()).isEqualTo("10368_ddec16"); assertThat(response.body().get(1)).isNull(); }
@Test public void getUserById() throws Exception { server.enqueue(new MockResponse().setBody("{\n" + " \"users\": [\n" + " \n" + userJson + ", " + userJson + " ]\n" + '}')); Response<XingUser, HttpError> response = resource.getUserById("some_id").execute(); // If no exception was thrown then the spec is build correctly. assertThat(response.body().id()).isEqualTo("123456_abcdef"); }