1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 package org.mozilla.gecko.background.fxa.profile; 6 7 import java.net.URI; 8 import java.net.URISyntaxException; 9 import java.util.concurrent.Executor; 10 11 import org.mozilla.gecko.background.fxa.oauth.FxAccountAbstractClient; 12 import org.mozilla.gecko.sync.ExtendedJSONObject; 13 import org.mozilla.gecko.sync.net.AuthHeaderProvider; 14 import org.mozilla.gecko.sync.net.BaseResource; 15 import org.mozilla.gecko.sync.net.BearerAuthHeaderProvider; 16 17 import ch.boye.httpclientandroidlib.HttpResponse; 18 19 20 /** 21 * Talk to an fxa-profile-server to get profile information like name, age, gender, and avatar image. 22 * <p> 23 * This client was written against the API documented at <a href="https://github.com/mozilla/fxa-profile-server/blob/0c065619f5a2e867f813a343b4c67da3fe2c82a4/docs/API.md">https://github.com/mozilla/fxa-profile-server/blob/0c065619f5a2e867f813a343b4c67da3fe2c82a4/docs/API.md</a>. 24 */ 25 public class FxAccountProfileClient10 extends FxAccountAbstractClient { FxAccountProfileClient10(String serverURI, Executor executor)26 public FxAccountProfileClient10(String serverURI, Executor executor) { 27 super(serverURI, executor); 28 } 29 profile(final String token, RequestDelegate<ExtendedJSONObject> delegate)30 public void profile(final String token, RequestDelegate<ExtendedJSONObject> delegate) { 31 BaseResource resource; 32 try { 33 resource = new BaseResource(new URI(serverURI + "profile")); 34 } catch (URISyntaxException e) { 35 invokeHandleError(delegate, e); 36 return; 37 } 38 39 resource.delegate = new ResourceDelegate<ExtendedJSONObject>(resource, delegate) { 40 @Override 41 public AuthHeaderProvider getAuthHeaderProvider() { 42 return new BearerAuthHeaderProvider(token); 43 } 44 45 @Override 46 public void handleSuccess(int status, HttpResponse response, ExtendedJSONObject body) { 47 try { 48 delegate.handleSuccess(body); 49 return; 50 } catch (Exception e) { 51 delegate.handleError(e); 52 return; 53 } 54 } 55 }; 56 57 resource.get(); 58 } 59 } 60