com.linecorp.linesdk.LineProfile Java Examples
The following examples show how to use
com.linecorp.linesdk.LineProfile.
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: TalkApiClientTest.java From line-sdk-android with Apache License 2.0 | 6 votes |
@Test public void testGetProfile() { doReturn(EXPECTED_RESULT).when(httpClient).get( any(Uri.class), anyMapOf(String.class, String.class), anyMapOf(String.class, String.class), any(ResponseDataParser.class)); LineApiResponse<LineProfile> actualResult = target.getProfile(ACCESS_TOKEN); assertSame(EXPECTED_RESULT, actualResult); verify(httpClient, times(1)).get( eq(Uri.parse(API_BASE_URL + "/v2/profile")), eq(Collections.singletonMap("Authorization", "Bearer " + ACCESS_TOKEN.getAccessToken())), eq(Collections.emptyMap()), responseParserCaptor.capture()); assertTrue(responseParserCaptor.getValue() instanceof TalkApiClient.ProfileParser); }
Example #2
Source File: AutoRefreshLineApiClientProxyTest.java From line-sdk-android with Apache License 2.0 | 5 votes |
@Test public void testRefreshErrorByServerError() throws Exception { when(lineApiClientImpl.getProfile()).thenReturn( Results.unauthorized()); when(lineApiClientImpl.refreshAccessToken()).thenReturn( Results.unauthorized()); LineApiResponse<LineProfile> response = target.getProfile(); assertEquals(LineApiResponseCode.SERVER_ERROR, response.getResponseCode()); assertEquals(HttpURLConnection.HTTP_UNAUTHORIZED, response.getErrorData().getHttpResponseCode()); verify(lineApiClientImpl, times(1)).refreshAccessToken(); verify(lineApiClientImpl, times(1)).getProfile(); }
Example #3
Source File: PostLoginActivity.java From line-sdk-starter-android-v2 with MIT License | 5 votes |
protected void onPostExecute(LineApiResponse<LineProfile> apiResponse) { if(apiResponse.isSuccess()) { ProfileDialogFragment newFragment = new ProfileDialogFragment(); newFragment.setProfileInfo(apiResponse.getResponseData()); newFragment.show(getFragmentManager(), null); unlockScreenOrientation(); } else { Toast.makeText(getApplicationContext(), "Failed to get profile.", Toast.LENGTH_SHORT).show(); Log.e(TAG, "Failed to get Profile: " + apiResponse.getErrorData().toString()); } }
Example #4
Source File: LineLogin.java From cordova-line-login-plugin with Apache License 2.0 | 5 votes |
public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode != REQUEST_CODE) { return; } LineLoginResult result = LineLoginApi.getLoginResultFromIntent(data); if (result.getResponseCode() == LineApiResponseCode.SUCCESS) { JSONObject json = new JSONObject(); try { LineProfile profile = result.getLineProfile(); json.put("userID", profile.getUserId()); json.put("displayName", profile.getDisplayName()); if (profile.getPictureUrl() != null) { json.put("pictureURL", profile.getPictureUrl().toString()); } LineIdToken lineIdToken = result.getLineIdToken(); json.put("email", lineIdToken.getEmail()); callbackContext.success(json); } catch (JSONException e) { this.UnknownError(e.toString()); } } else if (result.getResponseCode() == LineApiResponseCode.CANCEL) { this.SDKError(result.getResponseCode().toString(), "user cancel"); } else { this.SDKError(result.getResponseCode().toString(), result.toString()); } }
Example #5
Source File: LineApiClientImplTest.java From line-sdk-android with Apache License 2.0 | 5 votes |
@Test public void testGetProfileWithApiCallError() { LineApiResponse<LineProfile> expectedResponse = LineApiResponse.createAsError( LineApiResponseCode.INTERNAL_ERROR, LineApiError.DEFAULT); doReturn(expectedResponse) .when(internalTalkApiClient) .getProfile(any(InternalAccessToken.class)); accessTokenCache.saveAccessToken(ACCESS_TOKEN); LineApiResponse<LineProfile> actualResponse = target.getProfile(); assertSame(expectedResponse, actualResponse); verify(internalTalkApiClient, times(1)).getProfile(ACCESS_TOKEN); }
Example #6
Source File: LineApiClientImplTest.java From line-sdk-android with Apache License 2.0 | 5 votes |
@Test public void testGetProfile() { LineApiResponse<LineProfile> expectedResponse = LineApiResponse.createAsSuccess(PROFILE); doReturn(expectedResponse) .when(internalTalkApiClient) .getProfile(any(InternalAccessToken.class)); accessTokenCache.saveAccessToken(ACCESS_TOKEN); LineApiResponse<LineProfile> actualResponse = target.getProfile(); assertSame(expectedResponse, actualResponse); verify(internalTalkApiClient, times(1)).getProfile(ACCESS_TOKEN); }
Example #7
Source File: AutoRefreshLineApiClientProxyTest.java From line-sdk-android with Apache License 2.0 | 5 votes |
@Test public void testRefreshErrorByNetworkError() throws Exception { when(lineApiClientImpl.getProfile()).thenReturn( Results.unauthorized()); when(lineApiClientImpl.refreshAccessToken()).thenReturn( Results.networkError()); LineApiResponse<LineProfile> response = target.getProfile(); assertTrue(response.isNetworkError()); verify(lineApiClientImpl, times(1)).refreshAccessToken(); verify(lineApiClientImpl, times(1)).getProfile(); }
Example #8
Source File: AutoRefreshLineApiClientProxyTest.java From line-sdk-android with Apache License 2.0 | 5 votes |
@Test public void testNoRefreshWithApiSuccess() throws Exception { when(lineApiClientImpl.getProfile()).thenReturn( Results.success()); LineApiResponse<LineProfile> response = target.getProfile(); assertTrue(response.isSuccess()); verify(lineApiClientImpl, never()).refreshAccessToken(); verify(lineApiClientImpl, times(1)).getProfile(); }
Example #9
Source File: AutoRefreshLineApiClientProxyTest.java From line-sdk-android with Apache License 2.0 | 5 votes |
@Test public void testAutoRefreshWithUnauthorizedError() throws Exception { when(lineApiClientImpl.getProfile()).thenReturn( Results.unauthorized(), Results.success()); when(lineApiClientImpl.refreshAccessToken()).thenReturn( Results.success()); LineApiResponse<LineProfile> response = target.getProfile(); assertTrue(response.isSuccess()); verify(lineApiClientImpl, times(1)).refreshAccessToken(); verify(lineApiClientImpl, times(2)).getProfile(); }
Example #10
Source File: TalkApiClient.java From line-sdk-android with Apache License 2.0 | 5 votes |
private static LineFriendProfile parseLineFriendProfile(@NonNull JSONObject jsonObject) throws JSONException { LineProfile lineProfile = ProfileParser.parseLineProfile(jsonObject); String overriddenDisplayName = jsonObject.optString("displayNameOverridden", null); return new LineFriendProfile(lineProfile.getUserId(), lineProfile.getDisplayName(), lineProfile.getPictureUrl(), lineProfile.getStatusMessage(), overriddenDisplayName); }
Example #11
Source File: TalkApiClient.java From line-sdk-android with Apache License 2.0 | 5 votes |
private static LineProfile parseLineProfile(@NonNull JSONObject jsonObject) throws JSONException { String pictureUrlStr = jsonObject.optString("pictureUrl", null /* fallback */); return new LineProfile( jsonObject.getString("userId"), jsonObject.getString("displayName"), pictureUrlStr == null ? null : Uri.parse(pictureUrlStr), jsonObject.optString("statusMessage", null /* fallback */)); }
Example #12
Source File: TalkApiClient.java From line-sdk-android with Apache License 2.0 | 5 votes |
@NonNull public LineApiResponse<LineProfile> getProfile(@NonNull InternalAccessToken accessToken) { final Uri uri = buildUri(apiBaseUrl, BASE_PATH_COMMON_API, "profile"); return httpClient.get( uri, buildRequestHeaders(accessToken), Collections.emptyMap() /* queryParameters */, PROFILE_PARSER); }
Example #13
Source File: LineLoginResult.java From line-sdk-android with Apache License 2.0 | 5 votes |
private LineLoginResult(@NonNull final Parcel in) { responseCode = readEnum(in, LineApiResponseCode.class); nonce = in.readString(); lineProfile = in.readParcelable(LineProfile.class.getClassLoader()); lineIdToken = in.readParcelable(LineIdToken.class.getClassLoader()); friendshipStatusChanged = (Boolean) in.readValue(Boolean.class.getClassLoader()); lineCredential = in.readParcelable(LineCredential.class.getClassLoader()); errorData = in.readParcelable(LineApiError.class.getClassLoader()); }
Example #14
Source File: TalkApiClient.java From line-sdk-android with Apache License 2.0 | 4 votes |
@NonNull @Override protected LineProfile parseJsonToObject(@NonNull JSONObject jsonObject) throws JSONException { return parseLineProfile(jsonObject); }
Example #15
Source File: LineLoginResultTest.java From line-sdk-android with Apache License 2.0 | 4 votes |
@NonNull private static LineProfile createLineProfile() { return new LineProfile("id", "displayName", Uri.parse("http://line.me"), "statusMessage"); }
Example #16
Source File: LineLoginResultTest.java From line-sdk-android with Apache License 2.0 | 4 votes |
@Test public void testEquals() { final LineLoginResult expected = loginResultBuilder().build(); // equals assertEquals(expected, loginResultBuilder().build()); // not equals: responseCode assertNotEquals(expected, loginResultBuilder() .responseCode(LineApiResponseCode.CANCEL) .build()); // not equals: nonce assertNotEquals(expected, loginResultBuilder() .nonce(null) .build()); assertNotEquals(expected, loginResultBuilder() .nonce("differentNonce") .build()); // not equals: lineProfile assertNotEquals(expected, loginResultBuilder() .lineProfile(null) .build()); assertNotEquals(expected, loginResultBuilder() .lineProfile( new LineProfile("id2", "displayName", Uri.parse("http://line.me"), "statusMessage") ) .build()); // not equals: lineIdToken assertNotEquals(expected, loginResultBuilder() .lineIdToken(null) .build()); assertNotEquals(expected, loginResultBuilder() .lineIdToken( new Builder() .issuer("https://access.line.me") .subject("abcdef") .audience("123456") .issuedAt(now) .expiresAt(oneHourLater) .nonce("qwerty") .name("displayName") .picture("http://line.me") .email("[email protected]") .build() ) .build()); // not equals: friendshipStatusChanged assertNotEquals(expected, loginResultBuilder() .friendshipStatusChanged(null) .build()); assertNotEquals(expected, loginResultBuilder() .friendshipStatusChanged(false) .build()); // not equals: friendshipStatusChanged assertNotEquals(expected, loginResultBuilder() .lineCredential(null) .build()); assertNotEquals(expected, loginResultBuilder() .lineCredential( new LineCredential( new LineAccessToken("accessToken-xxx", 1000, 2000), Arrays.asList(Scope.FRIEND, Scope.GROUP, Scope.OPENID_CONNECT, Scope.OC_EMAIL)) ) .build()); // not equals: errorData assertNotEquals(expected, loginResultBuilder() .errorData(null) .build()); assertNotEquals(expected, loginResultBuilder() .errorData(new LineApiError("testErrorMessage2")) .build()); }
Example #17
Source File: LineAuthenticationControllerTest.java From line-sdk-android with Apache License 2.0 | 4 votes |
@Test public void testSuccess() throws Exception { Intent newIntentData = new Intent(); doReturn(BrowserAuthenticationApi.Result.createAsSuccess(REQUEST_TOKEN_STR, null)) .when(browserAuthenticationApi) .getAuthenticationResultFrom(newIntentData); doReturn(LineApiResponse.createAsSuccess(ISSUE_ACCESS_TOKEN_RESULT)) .when(authApiClient) .issueAccessToken(CHANNEL_ID, REQUEST_TOKEN_STR, PKCE_CODE, REDIRECT_URI); doReturn(LineApiResponse.createAsSuccess(ACCOUNT_INFO)) .when(talkApiClient) .getProfile(ACCESS_TOKEN); doReturn(LineApiResponse.createAsSuccess(OPEN_ID_DISCOVERY_DOCUMENT)) .when(authApiClient) .getOpenIdDiscoveryDocument(); target.startLineAuthentication(); Robolectric.getBackgroundThreadScheduler().runOneTask(); Robolectric.getForegroundThreadScheduler().runOneTask(); verify(browserAuthenticationApi, times(1)) .getRequest(activity, config, PKCE_CODE, LINE_AUTH_PARAMS); target.onActivityResult(3 /* requestCode */, 0 /* resultCode */, null /* data */); target.handleIntentFromLineApp(newIntentData); Robolectric.getBackgroundThreadScheduler().runOneTask(); Robolectric.getForegroundThreadScheduler().runOneTask(); verify(activity, times(1)).onAuthenticationFinished( new LineLoginResult.Builder() .responseCode(LineApiResponseCode.SUCCESS) .nonce(NONCE) .lineProfile(new LineProfile(USER_ID, DISPLAY_NAME, PICTURE_URL, STATUS_MESSAGE)) .lineIdToken(ID_TOKEN) .friendshipStatusChanged(null) .lineCredential(new LineCredential( new LineAccessToken(ACCESS_TOKEN_STR, EXPIRES_IN, ISSUED_CLIENT_TIME), SCOPE_LIST)) .errorData(LineApiError.DEFAULT) .build() ); assertEquals(ACCESS_TOKEN, accessTokenCache.getAccessToken()); }
Example #18
Source File: TalkApiClientTest.java From line-sdk-android with Apache License 2.0 | 4 votes |
@Test public void testProfileParser() throws IOException { TalkApiClient.ProfileParser target = new TalkApiClient.ProfileParser(); verifyResponseDataParser( target, new LineProfile( "testMid", "testDisplayName", Uri.parse("testPictureUrl"), "testStatusMessage"), new TestJsonDataBuilder() .put("userId", "testMid") .put("displayName", "testDisplayName") .put("pictureUrl", "testPictureUrl") .put("statusMessage", "testStatusMessage") .buildAsString() ); verifyResponseDataParser( target, new LineProfile( "testMid", "testDisplayName", null /* pictureUrl */, null /* statucMessage */), new TestJsonDataBuilder() .put("userId", "testMid") .put("displayName", "testDisplayName") .buildAsString() ); verifyToThrowException( target, new TestJsonDataBuilder() .put("displayName", "testDisplayName") .buildAsString() ); verifyToThrowException( target, new TestJsonDataBuilder() .put("userId", "testMid") .buildAsString() ); }
Example #19
Source File: LineAuthenticationController.java From line-sdk-android with Apache License 2.0 | 4 votes |
@Override protected LineLoginResult doInBackground(@Nullable BrowserAuthenticationApi.Result... params) { BrowserAuthenticationApi.Result authResult = params[0]; String requestToken = authResult.getRequestToken(); PKCECode pkceCode = authenticationStatus.getPKCECode(); String sentRedirectUri = authenticationStatus.getSentRedirectUri(); if (TextUtils.isEmpty(requestToken) || pkceCode == null || TextUtils.isEmpty(sentRedirectUri)) { return LineLoginResult.internalError("Requested data is missing."); } // Acquire access token LineApiResponse<IssueAccessTokenResult> accessTokenResponse = authApiClient.issueAccessToken( config.getChannelId(), requestToken, pkceCode, sentRedirectUri); if (!accessTokenResponse.isSuccess()) { return LineLoginResult.error(accessTokenResponse); } IssueAccessTokenResult issueAccessTokenResult = accessTokenResponse.getResponseData(); InternalAccessToken accessToken = issueAccessTokenResult.getAccessToken(); List<Scope> scopes = issueAccessTokenResult.getScopes(); LineProfile lineProfile = null; String userId = null; if (scopes.contains(Scope.PROFILE)) { // Acquire account information LineApiResponse<LineProfile> profileResponse = talkApiClient.getProfile(accessToken); if (!profileResponse.isSuccess()) { return LineLoginResult.error(profileResponse); } lineProfile = profileResponse.getResponseData(); userId = lineProfile.getUserId(); } // Cache the acquired access token accessTokenCache.saveAccessToken(accessToken); final LineIdToken idToken = issueAccessTokenResult.getIdToken(); if (idToken != null) { try { validateIdToken(idToken, userId); } catch (final Exception e) { return LineLoginResult.internalError(e.getMessage()); } } return new LineLoginResult.Builder() .nonce(authenticationStatus.getOpenIdNonce()) .lineProfile(lineProfile) .lineIdToken(idToken) .friendshipStatusChanged(authResult.getFriendshipStatusChanged()) .lineCredential(new LineCredential( new LineAccessToken( accessToken.getAccessToken(), accessToken.getExpiresInMillis(), accessToken.getIssuedClientTimeMillis()), scopes )) .build(); }
Example #20
Source File: PostLoginActivity.java From line-sdk-starter-android-v2 with MIT License | 4 votes |
public LineProfile getProfileInfo() { return profileInfo; }
Example #21
Source File: PostLoginActivity.java From line-sdk-starter-android-v2 with MIT License | 4 votes |
public void setProfileInfo(LineProfile profileInfo) { this.profileInfo = profileInfo; }
Example #22
Source File: PostLoginActivity.java From line-sdk-starter-android-v2 with MIT License | 4 votes |
protected LineApiResponse<LineProfile> doInBackground(Void... params) { return lineApiClient.getProfile(); }
Example #23
Source File: LineApiClientImpl.java From line-sdk-android with Apache License 2.0 | 4 votes |
@Override @TokenAutoRefresh @NonNull public LineApiResponse<LineProfile> getProfile() { return callWithAccessToken(talkApiClient::getProfile); }
Example #24
Source File: LineApiClient.java From line-sdk-android with Apache License 2.0 | 2 votes |
/** * Gets the user profile information. * * @return A {@link LineApiResponse} object. If the API call is successful, the * {@link LineApiResponse} object contains a {@link LineProfile} object that contains the * user's profile. If the API call fails, the payload of the {@link LineApiResponse} object is * <code>null</code>. */ @NonNull LineApiResponse<LineProfile> getProfile();
Example #25
Source File: LineLoginResult.java From line-sdk-android with Apache License 2.0 | 2 votes |
/** * Gets the user's profile information. * * @return A {@link LineProfile} object with the user's LINE profile. */ @Nullable public LineProfile getLineProfile() { return lineProfile; }