Java Code Examples for org.brickred.socialauth.Profile#setLocation()
The following examples show how to use
org.brickred.socialauth.Profile#setLocation() .
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: GitHubImpl.java From socialauth with MIT License | 5 votes |
private Profile getProfile() throws Exception { String presp; try { Response response = authenticationStrategy.executeFeed(ENDPOINTS.get(Constants.API_URL) + "/user"); presp = response.getResponseBodyAsString(Constants.ENCODING); } catch (Exception e) { throw new SocialAuthException("Error while getting profile from " + ENDPOINTS.get(Constants.API_URL) + "/user", e); } try { LOG.debug("User Profile : " + presp); JSONObject resp = new JSONObject(presp); Profile p = new Profile(); p.setValidatedId(resp.optString("id", null)); p.setFullName(resp.optString("name", null)); p.setEmail(resp.optString("email", null)); p.setLocation(resp.optString("location", null)); p.setProfileImageURL(resp.optString("avatar_url", null)); p.setDisplayName(resp.optString("login", null)); p.setProviderId(getProviderId()); if (config.isSaveRawResponse()) { p.setRawResponse(presp); } userProfile = p; return p; } catch (Exception ex) { throw new ServerDataException( "Failed to parse the user profile json : " + presp, ex); } }
Example 2
Source File: AmazonImpl.java From socialauth with MIT License | 5 votes |
private Profile getProfile() throws Exception { String presp; try { Response response = authenticationStrategy.executeFeed(PROFILE_URL); presp = response.getResponseBodyAsString(Constants.ENCODING); } catch (Exception e) { throw new SocialAuthException("Error while getting profile from " + PROFILE_URL, e); } try { LOG.debug("User Profile : " + presp); JSONObject resp = new JSONObject(presp); Profile p = new Profile(); p.setFullName(resp.optString("name", null)); p.setEmail(resp.optString("email", null)); p.setValidatedId(resp.optString("user_id", null)); p.setLocation(resp.optString("postal_code", null)); if (config.isSaveRawResponse()) { p.setRawResponse(presp); } p.setProviderId(getProviderId()); if (config.isSaveRawResponse()) { p.setRawResponse(presp); } userProfile = p; return p; } catch (Exception ex) { throw new ServerDataException( "Failed to parse the user profile json : " + presp, ex); } }
Example 3
Source File: RunkeeperImpl.java From socialauth with MIT License | 4 votes |
private Profile getProfile() throws Exception { String presp; try { Map<String, String> hmap = new HashMap<String, String>(); hmap.put("Accept", "application/vnd.com.runkeeper.Profile+json"); Response response = authenticationStrategy.executeFeed(PROFILE_URL, MethodType.GET.toString(), null, hmap, null); presp = response.getResponseBodyAsString(Constants.ENCODING); } catch (Exception e) { throw new SocialAuthException("Error while getting profile from " + PROFILE_URL, e); } try { LOG.debug("User Profile : " + presp); JSONObject resp = new JSONObject(presp); Profile p = new Profile(); if (resp.has("profile")) { String purl = resp.getString("profile"); String parr[] = purl.split("/"); p.setValidatedId(parr[parr.length - 1]); } if (resp.has("name")) { p.setFirstName(resp.getString("name")); p.setFullName(resp.getString("name")); } if (resp.has("location")) { p.setLocation(resp.getString("location")); } if (resp.has("birthday")) { String bstr = resp.getString("birthday"); if (bstr != null) { if (bstr.matches("[A-Za-z]{3}, \\d{1,2} [A-Za-z]{3} \\d{4} \\d{2}:\\d{2}:\\d{2}")) { DateFormat df = new SimpleDateFormat( "EEE, dd MMM yyyy hh:mm:ss"); Date d = df.parse(bstr); Calendar c = Calendar.getInstance(); c.setTime(d); BirthDate bd = new BirthDate(); bd.setDay(c.get(Calendar.DAY_OF_MONTH)); bd.setYear(c.get(Calendar.YEAR)); bd.setMonth(c.get(Calendar.MONTH) + 1); p.setDob(bd); } } } if (resp.has("gender")) { p.setGender(resp.getString("gender")); } if (resp.has("normal_picture")) { p.setProfileImageURL(resp.getString("normal_picture")); } p.setProviderId(getProviderId()); userProfile = p; return p; } catch (Exception ex) { throw new ServerDataException( "Failed to parse the user profile json : " + presp, ex); } }
Example 4
Source File: FourSquareImpl.java From socialauth with MIT License | 4 votes |
private Profile getProfile() throws Exception { LOG.debug("Obtaining user profile"); Profile profile = new Profile(); Response serviceResponse; try { serviceResponse = authenticationStrategy.executeFeed(PROFILE_URL); } catch (Exception e) { throw new SocialAuthException( "Failed to retrieve the user profile from " + PROFILE_URL, e); } String res; try { res = serviceResponse.getResponseBodyAsString(Constants.ENCODING); } catch (Exception exc) { throw new SocialAuthException("Failed to read response from " + PROFILE_URL, exc); } JSONObject jobj = new JSONObject(res); JSONObject rObj; JSONObject uObj; if (jobj.has("response")) { rObj = jobj.getJSONObject("response"); } else { throw new SocialAuthException( "Failed to parse the user profile json : " + res); } if (rObj.has("user")) { uObj = rObj.getJSONObject("user"); } else { throw new SocialAuthException( "Failed to parse the user profile json : " + res); } profile.setValidatedId(uObj.optString("id", null)); profile.setFirstName(uObj.optString("firstName", null)); profile.setLastName(uObj.optString("lastName", null)); profile.setProfileImageURL(uObj.optString("photo", null)); profile.setGender(uObj.optString("gender", null)); profile.setLocation(uObj.optString("homeCity", null)); if (uObj.has("contact")) { JSONObject cobj = uObj.getJSONObject("contact"); if (cobj.has("email")) { profile.setEmail(cobj.optString("email", null)); } } profile.setProviderId(getProviderId()); if (config.isSaveRawResponse()) { profile.setRawResponse(res); } userProfile = profile; return profile; }
Example 5
Source File: MySpaceImpl.java From socialauth with MIT License | 4 votes |
private Profile getProfile() throws Exception { LOG.debug("Obtaining user profile"); Profile profile = new Profile(); Response serviceResponse = null; try { serviceResponse = authenticationStrategy.executeFeed(PROFILE_URL); } catch (Exception e) { throw new SocialAuthException( "Failed to retrieve the user profile from " + PROFILE_URL, e); } if (serviceResponse.getStatus() != 200) { throw new SocialAuthException( "Failed to retrieve the user profile from " + PROFILE_URL + ". Staus :" + serviceResponse.getStatus()); } String result; try { result = serviceResponse .getResponseBodyAsString(Constants.ENCODING); LOG.debug("User Profile :" + result); } catch (Exception exc) { throw new SocialAuthException("Failed to read response from " + PROFILE_URL, exc); } JSONObject pObj = new JSONObject(); JSONObject jobj = new JSONObject(result); if (jobj.has("person")) { pObj = jobj.getJSONObject("person"); } else { throw new ServerDataException( "Failed to parse the user profile json : " + result); } profile.setDisplayName(pObj.optString("displayName", null)); profile.setValidatedId(pObj.optString("id", null)); if (pObj.has("name")) { JSONObject nobj = pObj.getJSONObject("name"); profile.setLastName(nobj.optString("familyName", null)); profile.setFirstName(nobj.optString("givenName", null)); } profile.setLocation(pObj.optString("location", null)); profile.setDisplayName(pObj.optString("nickname", null)); profile.setLanguage(pObj.optString("lang", null)); profile.setProfileImageURL(pObj.optString("thumbnailUrl", null)); profile.setProviderId(getProviderId()); if (config.isSaveRawResponse()) { profile.setRawResponse(result); } userProfile = profile; return profile; }
Example 6
Source File: StackExchangeImpl.java From socialauth with MIT License | 4 votes |
private Profile getProfile() throws Exception { String presp; String profileURL = PROFILE_URL; String site = "stackoverflow"; if (config.getCustomProperties() != null) { if (config.getCustomProperties().get("site") != null) { site = config.getCustomProperties().get("site"); } profileURL += "?key=" + config.getCustomProperties().get("key") + "&site=" + site; } else { throw new SocialAuthException( "Please set 'stackapps.com.custom.key' property in oauth_consumer.properties "); } try { Response response = authenticationStrategy.executeFeed(profileURL); presp = response.getResponseBodyAsString(Constants.ENCODING); } catch (Exception e) { throw new SocialAuthException("Error while getting profile from " + profileURL, e); } try { LOG.debug("User Profile : " + presp); JSONObject jsonResp = new JSONObject(presp); Profile p = new Profile(); if (jsonResp.has("items")) { JSONArray items = jsonResp.getJSONArray("items"); if (items.length() > 0) { JSONObject resp = items.getJSONObject(0); p.setDisplayName(resp.optString("display_name", null)); p.setFullName(resp.optString("display_name", null)); p.setProfileImageURL(resp.optString("profile_image", null)); p.setValidatedId(resp.optString("user_id", null)); p.setLocation(resp.optString("location", null)); if (config.isSaveRawResponse()) { p.setRawResponse(presp); } p.setProviderId(getProviderId()); if (config.isSaveRawResponse()) { p.setRawResponse(presp); } } } userProfile = p; return p; } catch (Exception ex) { throw new ServerDataException( "Failed to parse the user profile json : " + presp, ex); } }
Example 7
Source File: FacebookImpl.java From socialauth with MIT License | 4 votes |
private Profile authFacebookLogin() throws Exception { String presp; try { Response response = authenticationStrategy.executeFeed(PROFILE_URL); presp = response.getResponseBodyAsString(Constants.ENCODING); } catch (Exception e) { throw new SocialAuthException("Error while getting profile from " + PROFILE_URL, e); } try { LOG.debug("User Profile : " + presp); JSONObject resp = new JSONObject(presp); Profile p = new Profile(); p.setValidatedId(resp.optString("id", null)); p.setFullName(resp.optString("name", null)); p.setFirstName(resp.optString("first_name", null)); p.setLastName(resp.optString("last_name", null)); p.setEmail(resp.optString("email", null)); if (resp.has("location")) { p.setLocation(resp.getJSONObject("location").optString("name", null)); } if (resp.has("birthday")) { String bstr = resp.optString("birthday"); String[] arr = bstr.split("/"); BirthDate bd = new BirthDate(); if (arr.length > 0) { bd.setMonth(Integer.parseInt(arr[0])); } if (arr.length > 1) { bd.setDay(Integer.parseInt(arr[1])); } if (arr.length > 2) { bd.setYear(Integer.parseInt(arr[2])); } p.setDob(bd); } p.setGender(resp.optString("gender", null)); p.setProfileImageURL(String.format(PROFILE_IMAGE_URL, resp.getString("id"))); String locale = resp.optString("locale", null); if (locale != null) { String a[] = locale.split("_"); p.setLanguage(a[0]); p.setCountry(a[1]); } p.setProviderId(getProviderId()); if (config.isSaveRawResponse()) { p.setRawResponse(presp); } userProfile = p; return p; } catch (Exception ex) { throw new ServerDataException( "Failed to parse the user profile json : " + presp, ex); } }