com.linecorp.linesdk.LineApiResponse Java Examples
The following examples show how to use
com.linecorp.linesdk.LineApiResponse.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: InternalApisFragment.java From line-sdk-android with Apache License 2.0 | 6 votes |
private void getFriends(View view, String pageRequestToken) { startApiAsyncTask("getFriends", () -> { LineApiResponse<GetFriendsResponse> response = lineApiClient.getFriends(FriendSortField.NAME, pageRequestToken); if (response != null && response.isSuccess() && response.getResponseData() != null) { GetFriendsResponse getFriendsResponse = response.getResponseData(); receivers.addFriends(getFriendsResponse.getFriends()); // get next page if exists // postpone 2 seconds to make sure the first response data is logged. ONLY FOR TESTING purpose String nextPageRequestToken = getFriendsResponse.getNextPageRequestToken(); if (nextPageRequestToken != null) { view.postDelayed( () -> getFriends(view, nextPageRequestToken), 2000 ); } } return response; }); }
Example #2
Source File: TalkApiClientTest.java From line-sdk-android with Apache License 2.0 | 6 votes |
@Test public void testGetFriendshipStatus() { doReturn(EXPECTED_RESULT).when(httpClient).get( any(Uri.class), anyMapOf(String.class, String.class), anyMapOf(String.class, String.class), any(ResponseDataParser.class)); LineApiResponse<LineFriendshipStatus> actualResult = target.getFriendshipStatus(ACCESS_TOKEN); assertSame(EXPECTED_RESULT, actualResult); verify(httpClient, times(1)).get( eq(Uri.parse(API_BASE_URL + "/friendship/v1/status")), eq(Collections.singletonMap("Authorization", "Bearer " + ACCESS_TOKEN.getAccessToken())), eq(Collections.emptyMap()), responseParserCaptor.capture()); assertTrue(responseParserCaptor.getValue() instanceof TalkApiClient.FriendshipStatusParser); }
Example #3
Source File: TalkApiClientTest.java From line-sdk-android with Apache License 2.0 | 6 votes |
@Test public void testSendMessageToMultipleUsersUsingOtt_getOtt_failed() { final LineApiResponse<?> mockResponse = LineApiResponse.createAsError( LineApiResponseCode.NETWORK_ERROR, new LineApiError("")); givenPostWithJsonApiResponse(mockResponse); LineApiResponse<List<SendMessageResponse>> actualApiResponse = target.sendMessageToMultipleUsers( ACCESS_TOKEN, Collections.emptyList(), Collections.emptyList(), true); assertThat(actualApiResponse.getResponseCode(), sameInstance(mockResponse.getResponseCode())); assertThat(actualApiResponse.getErrorData(), sameInstance(mockResponse.getErrorData())); // Gets ott by target user ids verifyApiCallPostWithJson("/" + BASE_PATH_MESSAGE_API + "/" + PATH_OTT_ISSUE); responseParserInstanceShouldBe(TalkApiClient.StringParser.class); // Should not send message due to failure of getting ott verify(target, never()).sendMessageToMultipleUsersUsingOtt(any(), any(), any()); }
Example #4
Source File: TalkApiClientTest.java From line-sdk-android with Apache License 2.0 | 6 votes |
@Test public void testGetGroups_shareMessageWithOtt() { doReturn(EXPECTED_RESULT).when(httpClient).get( any(Uri.class), anyMapOf(String.class, String.class), anyMapOf(String.class, String.class), any(ResponseDataParser.class)); LineApiResponse<GetGroupsResponse> actualResult = target.getGroups(ACCESS_TOKEN, "pageToken01", true); assertSame(EXPECTED_RESULT, actualResult); Map<String, String> expectedQueryParams = new HashMap<>(); expectedQueryParams.put("pageToken", "pageToken01"); verify(httpClient, times(1)).get( eq(Uri.parse(API_BASE_URL + "/" + BASE_PATH_GRAPH_API + "/" + PATH_OTS_GROUPS)), eq(Collections.singletonMap("Authorization", "Bearer " + ACCESS_TOKEN.getAccessToken())), eq(expectedQueryParams), responseParserCaptor.capture()); assertTrue(responseParserCaptor.getValue() instanceof TalkApiClient.GroupParser); }
Example #5
Source File: LineAuthenticationApiClient.java From line-sdk-android with Apache License 2.0 | 6 votes |
@NonNull public LineApiResponse<IssueAccessTokenResult> issueAccessToken( @NonNull String channelId, @NonNull String requestToken, @NonNull PKCECode pkceCode, @NonNull String redirectUri) { final Uri uri = buildUri(apiBaseUrl, BASE_PATH_OAUTH_V21_API, "token"); final Map<String, String> postData = buildParams( "grant_type", "authorization_code", "code", requestToken, "redirect_uri", redirectUri, "client_id", channelId, "code_verifier", pkceCode.getVerifier(), "id_token_key_type", IdTokenKeyType.JWK.name(), "client_version", "LINE SDK Android v" + BuildConfig.VERSION_NAME ); return httpClient.post( uri, emptyMap() /* requestHeaders */, postData, ISSUE_ACCESS_TOKEN_RESULT_PARSER); }
Example #6
Source File: LineApiClientImplTest.java From line-sdk-android with Apache License 2.0 | 6 votes |
@Test public void testRefreshTokenWithNoRefreshToken() { accessTokenCache.saveAccessToken(ACCESS_TOKEN); LineApiResponse<RefreshTokenResult> refreshTokenResponse = LineApiResponse.createAsSuccess(new RefreshTokenResult( "newAccessToken", 999L, null, Collections.emptyList())); doReturn(refreshTokenResponse) .when(internalOauthApiClient) .refreshToken(anyString(), any(InternalAccessToken.class)); LineApiResponse<LineAccessToken> actualResponse = target.refreshAccessToken(); verify(internalOauthApiClient, times(1)).refreshToken(CHANNEL_ID, ACCESS_TOKEN); assertTrue(actualResponse.isSuccess()); assertNotNull(actualResponse.getResponseData()); assertEquals("newAccessToken", actualResponse.getResponseData().getTokenString()); assertEquals(999L, actualResponse.getResponseData().getExpiresInMillis()); assertTrue(actualResponse.getResponseData().getIssuedClientTimeMillis() > 0); InternalAccessToken newAccessToken = accessTokenCache.getAccessToken(); assertNotNull(newAccessToken); assertEquals("newAccessToken", newAccessToken.getAccessToken()); assertEquals(999L, newAccessToken.getExpiresInMillis()); assertTrue(newAccessToken.getIssuedClientTimeMillis() > 0); assertEquals(ACCESS_TOKEN.getRefreshToken(), newAccessToken.getRefreshToken()); }
Example #7
Source File: TalkApiClientTest.java From line-sdk-android with Apache License 2.0 | 6 votes |
@Test public void testGetFriends_shareMessageWithOtt() { doReturn(EXPECTED_RESULT).when(httpClient).get( any(Uri.class), anyMapOf(String.class, String.class), anyMapOf(String.class, String.class), any(ResponseDataParser.class)); LineApiResponse<GetFriendsResponse> actualResult = target.getFriends(ACCESS_TOKEN, FriendSortField.NAME, "pageToken01", true); assertSame(EXPECTED_RESULT, actualResult); Map<String, String> expectedQueryParams = new HashMap<>(); expectedQueryParams.put("sort", "name"); expectedQueryParams.put("pageToken", "pageToken01"); verify(httpClient, times(1)).get( eq(Uri.parse(API_BASE_URL + "/" + BASE_PATH_GRAPH_API + "/" + PATH_OTS_FRIENDS)), eq(Collections.singletonMap("Authorization", "Bearer " + ACCESS_TOKEN.getAccessToken())), eq(expectedQueryParams), responseParserCaptor.capture()); assertTrue(responseParserCaptor.getValue() instanceof TalkApiClient.FriendsParser); }
Example #8
Source File: LineApiClientImplTest.java From line-sdk-android with Apache License 2.0 | 6 votes |
@Test public void testRefreshTokenWithApiError() { accessTokenCache.saveAccessToken(ACCESS_TOKEN); LineApiResponse<RefreshTokenResult> refreshTokenResponse = LineApiResponse.createAsError( LineApiResponseCode.INTERNAL_ERROR, LineApiError.DEFAULT); doReturn(refreshTokenResponse) .when(internalOauthApiClient) .refreshToken(anyString(), any(InternalAccessToken.class)); LineApiResponse<LineAccessToken> actualResponse = target.refreshAccessToken(); verify(internalOauthApiClient, times(1)).refreshToken(CHANNEL_ID, ACCESS_TOKEN); assertFalse(actualResponse.isSuccess()); assertEquals(ACCESS_TOKEN, accessTokenCache.getAccessToken()); }
Example #9
Source File: TalkApiClientTest.java From line-sdk-android with Apache License 2.0 | 6 votes |
@Test public void testSendMessageToMultipleUsersUsingOtt() { final LineApiResponse<?> mockResponse = LineApiResponse.createAsSuccess(""); givenPostWithJsonApiResponse(mockResponse); LineApiResponse<List<SendMessageResponse>> actualResult = target.sendMessageToMultipleUsers( ACCESS_TOKEN, Collections.emptyList(), Collections.emptyList(), true); assertThat(actualResult, sameInstance(mockResponse)); // Gets ott by target user ids verifyApiCallPostWithJson("/" + BASE_PATH_MESSAGE_API + "/" + PATH_OTT_ISSUE); responseParserInstanceShouldBe(TalkApiClient.StringParser.class); // Send the message using ott verifyApiCallPostWithJson("/" + BASE_PATH_MESSAGE_API + "/" + PATH_OTT_SHARE); responseParserInstanceShouldBe(TalkApiClient.MultiSendResponseParser.class); }
Example #10
Source File: LineAuthenticationControllerTest.java From line-sdk-android with Apache License 2.0 | 6 votes |
@Test public void testNetworkErrorOfGettingAccessToken() throws Exception { Intent newIntentData = new Intent(); doReturn(BrowserAuthenticationApi.Result.createAsSuccess(REQUEST_TOKEN_STR, false)) .when(browserAuthenticationApi) .getAuthenticationResultFrom(newIntentData); doReturn(LineApiResponse.createAsError(LineApiResponseCode.NETWORK_ERROR, LineApiError.DEFAULT)) .when(authApiClient) .issueAccessToken(CHANNEL_ID, REQUEST_TOKEN_STR, PKCE_CODE, REDIRECT_URI); target.startLineAuthentication(); Robolectric.getBackgroundThreadScheduler().runOneTask(); Robolectric.getForegroundThreadScheduler().runOneTask(); verify(browserAuthenticationApi, times(1)) .getRequest(activity, config, PKCE_CODE, LINE_AUTH_PARAMS); target.handleIntentFromLineApp(newIntentData); Robolectric.getBackgroundThreadScheduler().runOneTask(); Robolectric.getForegroundThreadScheduler().runOneTask(); verify(activity, times(1)).onAuthenticationFinished( LineLoginResult.error(LineApiResponseCode.NETWORK_ERROR, LineApiError.DEFAULT)); }
Example #11
Source File: LineApiClientImpl.java From line-sdk-android with Apache License 2.0 | 6 votes |
@Override @NonNull public LineApiResponse<LineAccessToken> getCurrentAccessToken() { InternalAccessToken internalAccessToken; try { internalAccessToken = accessTokenCache.getAccessToken(); } catch (Exception exception) { return LineApiResponse.createAsError( LineApiResponseCode.INTERNAL_ERROR, new LineApiError("get access token fail:" + exception.getMessage()) ); } if (internalAccessToken == null) { return LineApiResponse.createAsError( LineApiResponseCode.INTERNAL_ERROR, new LineApiError("The cached access token does not exist.")); } return LineApiResponse.createAsSuccess(new LineAccessToken( internalAccessToken.getAccessToken(), internalAccessToken.getExpiresInMillis(), internalAccessToken.getIssuedClientTimeMillis())); }
Example #12
Source File: LineAuthenticationApiClientTest.java From line-sdk-android with Apache License 2.0 | 6 votes |
@Test public void testRevokeAccessToken() throws Exception { LineApiResponse<?> expectedResponse = LineApiResponse.createAsSuccess(new Object()); doReturn(expectedResponse).when(httpClient).post( any(Uri.class), anyMapOf(String.class, String.class), anyMapOf(String.class, String.class), any(ResponseDataParser.class)); LineApiResponse<?> actualResponse = target.revokeAccessToken(CHANNEL_ID, ACCESS_TOKEN); assertSame(expectedResponse, actualResponse); Map<String, String> expectedPostData = new HashMap<>(2); expectedPostData.put("access_token", ACCESS_TOKEN.getAccessToken()); expectedPostData.put("client_id", CHANNEL_ID); verify(httpClient, times(1)).post( eq(Uri.parse(API_BASE_URL + "/oauth2/v2.1/revoke")), eq(Collections.<String, String>emptyMap()), eq(expectedPostData), any(ResponseDataParser.class)); }
Example #13
Source File: InternalApisFragment.java From line-sdk-android with Apache License 2.0 | 6 votes |
@OnClick(R.id.revoke_access_token_btn) void revokeToken() { startApiAsyncTask("revokeAccessToken", () -> { LineApiResponse<LineAccessToken> currentAccessTokenResponse = lineApiClient.getCurrentAccessToken(); if (!currentAccessTokenResponse.isSuccess()) { return currentAccessTokenResponse; } try { String accessToken = currentAccessTokenResponse.getResponseData().getTokenString(); String response = internalOauthApiClient.revokeAccessToken(channelId, accessToken); return LineApiResponse.createAsSuccess(response); } catch (IOException e) { return LineApiResponse.createAsError( LineApiResponseCode.SERVER_ERROR, new LineApiError(e)); } }); }
Example #14
Source File: TalkApiClientTest.java From line-sdk-android with Apache License 2.0 | 6 votes |
@Test public void testGetGroups_notShareMessageWithOtt() { doReturn(EXPECTED_RESULT).when(httpClient).get( any(Uri.class), anyMapOf(String.class, String.class), anyMapOf(String.class, String.class), any(ResponseDataParser.class)); LineApiResponse<GetGroupsResponse> actualResult = target.getGroups(ACCESS_TOKEN, "pageToken01", false); assertSame(EXPECTED_RESULT, actualResult); Map<String, String> expectedQueryParams = new HashMap<>(); expectedQueryParams.put("pageToken", "pageToken01"); verify(httpClient, times(1)).get( eq(Uri.parse(API_BASE_URL + "/graph/v2/groups")), eq(Collections.singletonMap("Authorization", "Bearer " + ACCESS_TOKEN.getAccessToken())), eq(expectedQueryParams), responseParserCaptor.capture()); assertTrue(responseParserCaptor.getValue() instanceof TalkApiClient.GroupParser); }
Example #15
Source File: TalkApiClient.java From line-sdk-android with Apache License 2.0 | 6 votes |
@NonNull public LineApiResponse<GetGroupsResponse> getGroups( @NonNull InternalAccessToken accessToken, @Nullable String pageToken, boolean isForOttShareMessage) { final String pathSegment = (isForOttShareMessage) ? PATH_OTS_GROUPS : PATH_GROUPS; final Uri uri = buildUri(apiBaseUrl, BASE_PATH_GRAPH_API, pathSegment); final Map<String, String> queryParams; if (!TextUtils.isEmpty(pageToken)) { queryParams = buildParams("pageToken", pageToken); } else { queryParams = Collections.emptyMap(); } return httpClient.get( uri, buildRequestHeaders(accessToken), queryParams, GROUP_PARSER); }
Example #16
Source File: ChannelServiceHttpClientTest.java From line-sdk-android with Apache License 2.0 | 5 votes |
@Test public void testIllegalResponseDataByGet() throws Exception { setErrorData(400, "testErrorMessage".getBytes(CHARSET)); LineApiResponse<String> responseData = target.get( Uri.parse("https://test"), Collections.<String, String>emptyMap() /* requestHeaders */, Collections.<String, String>emptyMap() /* queryParameters */, new StringResponseParser()); assertFalse(responseData.isSuccess()); assertEquals(LineApiResponseCode.SERVER_ERROR, responseData.getResponseCode()); assertEquals(400, responseData.getErrorData().getHttpResponseCode()); assertEquals("testErrorMessage", responseData.getErrorData().getMessage()); }
Example #17
Source File: ChannelServiceHttpClientTest.java From line-sdk-android with Apache License 2.0 | 5 votes |
@Test public void testNetworkErrorByPost() throws Exception { IOException ioException = new IOException(); doThrow(ioException).when(httpsURLConnection).connect(); LineApiResponse<String> responseData = target.post( Uri.parse("https://test"), Collections.<String, String>emptyMap() /* requestHeaders */, Collections.<String, String>emptyMap() /* postData */, new StringResponseParser()); assertFalse(responseData.isSuccess()); assertEquals(LineApiResponseCode.NETWORK_ERROR, responseData.getResponseCode()); assertEquals(new LineApiError(ioException), responseData.getErrorData()); }
Example #18
Source File: ChannelServiceHttpClient.java From line-sdk-android with Apache License 2.0 | 5 votes |
@WorkerThread @NonNull public <T> LineApiResponse<T> delete( @NonNull Uri uri, @NonNull Map<String, String> requestHeaders, @Nullable ResponseDataParser<T> responseDataParser) { HttpURLConnection conn = null; try { conn = openDeleteConnection(uri); setRequestHeaders(conn, requestHeaders); if (BuildConfig.DEBUG) { logRequestForDebug(conn, null /* requestBody */); } conn.connect(); if (BuildConfig.DEBUG) { logResponseHeadersForDebug(conn); } return getChannelServiceResponse(conn, responseDataParser, errorResponseParser); } catch (IOException e) { LineApiResponse<T> response = LineApiResponse.createAsError( LineApiResponseCode.NETWORK_ERROR, new LineApiError(e)); logExceptionForDebug(response, e); return response; } finally { if (conn != null) { conn.disconnect(); } } }
Example #19
Source File: PostLoginActivity.java From line-sdk-starter-android-v2 with MIT License | 5 votes |
protected void onPostExecute(LineApiResponse apiResponse){ if(apiResponse.isSuccess()){ Toast.makeText(getApplicationContext(), "Logout Successful", Toast.LENGTH_SHORT).show(); } else { Toast.makeText(getApplicationContext(), "Logout Failed", Toast.LENGTH_SHORT).show(); Log.e(TAG, "Logout Failed: " + apiResponse.getErrorData().toString()); } unlockScreenOrientation(); }
Example #20
Source File: ChannelServiceHttpClientTest.java From line-sdk-android with Apache License 2.0 | 5 votes |
@Test public void testAccessTokenExpiredByGet() throws Exception { setErrorData(HttpURLConnection.HTTP_UNAUTHORIZED, "testErrorMessage".getBytes(CHARSET)); LineApiResponse<String> responseData = target.get( Uri.parse("https://test"), Collections.<String, String>emptyMap() /* requestHeaders */, Collections.<String, String>emptyMap() /* queryParameters */, new StringResponseParser()); assertFalse(responseData.isSuccess()); assertEquals(LineApiResponseCode.SERVER_ERROR, responseData.getResponseCode()); assertEquals(401, responseData.getErrorData().getHttpResponseCode()); assertEquals("testErrorMessage", responseData.getErrorData().getMessage()); }
Example #21
Source File: LineApiClientImplTest.java From line-sdk-android with Apache License 2.0 | 5 votes |
@Test public void testGetFriendshipStatusWithApiCallError() { LineApiResponse<LineFriendshipStatus> expectedResponse = LineApiResponse.createAsError( LineApiResponseCode.INTERNAL_ERROR, LineApiError.DEFAULT); doReturn(expectedResponse) .when(internalTalkApiClient) .getFriendshipStatus(any(InternalAccessToken.class)); accessTokenCache.saveAccessToken(ACCESS_TOKEN); LineApiResponse<LineFriendshipStatus> actualResponse = target.getFriendshipStatus(); assertSame(expectedResponse, actualResponse); verify(internalTalkApiClient, times(1)).getFriendshipStatus(ACCESS_TOKEN); }
Example #22
Source File: TalkApiClient.java From line-sdk-android with Apache License 2.0 | 5 votes |
@NonNull public LineApiResponse<List<SendMessageResponse>> sendMessageToMultipleUsers( @NonNull InternalAccessToken accessToken, @NonNull List<String> targetUserIds, @NonNull List<MessageData> messages) { return sendMessageToMultipleUsers(accessToken, targetUserIds, messages, false); }
Example #23
Source File: LineApiClientImpl.java From line-sdk-android with Apache License 2.0 | 5 votes |
@Override @TokenAutoRefresh @NonNull public LineApiResponse<GetFriendsResponse> getGroupApprovers( @NonNull String groupId, @Nullable String nextPageRequestToken) { return callWithAccessToken(accessToken -> talkApiClient.getGroupApprovers(accessToken, groupId, nextPageRequestToken)); }
Example #24
Source File: ChannelServiceHttpClientTest.java From line-sdk-android with Apache License 2.0 | 5 votes |
@Test public void testIllegalResponseDataByDelete() throws Exception { setErrorData(400, "testErrorMessage".getBytes(CHARSET)); LineApiResponse<String> responseData = target.delete( Uri.parse("https://test"), Collections.<String, String>emptyMap() /* requestHeaders */, new StringResponseParser()); assertFalse(responseData.isSuccess()); assertEquals(LineApiResponseCode.SERVER_ERROR, responseData.getResponseCode()); assertEquals(400, responseData.getErrorData().getHttpResponseCode()); assertEquals("testErrorMessage", responseData.getErrorData().getMessage()); }
Example #25
Source File: TalkApiClient.java From line-sdk-android with Apache License 2.0 | 5 votes |
@NonNull public LineApiResponse<Boolean> joinOpenChatRoom( @NonNull InternalAccessToken accessToken, @NonNull String roomId, @NonNull String displayName) { final Uri uri = buildUri(apiBaseUrl, BASE_PATH_OPENCHAT_API, "openchats", roomId, "join"); return httpClient.postWithJson( uri, buildRequestHeaders(accessToken), "{\"displayName\": \"" + displayName + "\" }", null); }
Example #26
Source File: LineApiClientImpl.java From line-sdk-android with Apache License 2.0 | 5 votes |
@Override @TokenAutoRefresh @NonNull public LineApiResponse<List<SendMessageResponse>> sendMessageToMultipleUsers( @NonNull List<String> targetUserIds, @NonNull List<MessageData> messages, boolean isOttUsed) { return callWithAccessToken( accessToken -> talkApiClient.sendMessageToMultipleUsers(accessToken, targetUserIds, messages, isOttUsed) ); }
Example #27
Source File: TalkApiClientTest.java From line-sdk-android with Apache License 2.0 | 5 votes |
private void givenPostWithJsonApiResponse(LineApiResponse<?> apiResponse) { doReturn(apiResponse).when(httpClient).postWithJson( any(Uri.class), anyMapOf(String.class, String.class), any(String.class), any(ResponseDataParser.class)); }
Example #28
Source File: LineApiClientImpl.java From line-sdk-android with Apache License 2.0 | 5 votes |
@Override @TokenAutoRefresh @NonNull public LineApiResponse<GetGroupsResponse> getGroups( @Nullable String nextPageRequestToken, boolean isForOttShareMessage) { return callWithAccessToken( accessToken -> talkApiClient.getGroups(accessToken, nextPageRequestToken, isForOttShareMessage)); }
Example #29
Source File: LineApiClientImpl.java From line-sdk-android with Apache License 2.0 | 5 votes |
@Override @TokenAutoRefresh @NonNull public LineApiResponse<List<SendMessageResponse>> sendMessageToMultipleUsers( @NonNull List<String> targetUserIds, @NonNull List<MessageData> messages) { return sendMessageToMultipleUsers(targetUserIds, messages, false); }
Example #30
Source File: LineApiClientImpl.java From line-sdk-android with Apache License 2.0 | 5 votes |
@Override @TokenAutoRefresh @NonNull public LineApiResponse<String> sendMessage( @NonNull String targetUserId, @NonNull List<MessageData> messages) { return callWithAccessToken(accessToken -> talkApiClient.sendMessage(accessToken, targetUserId, messages)); }