Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package com.askfast.askfastapi;
  
  import java.util.List;
  import java.util.Set;
 
 public class AskFastRestClient {
 
     public static final String ASKFAST_REST_API = "http://api.ask-fast.com";
     public static final String ASKFAST_KEYSERVER = "http://live.ask-fast.com/keyserver/token";
 
     private String accountId = null;
     private String refreshToken = null;
     private String accessToken = null;
 
     public AskFastRestClient(String accountId) {
         this(accountIdnull);
     }
 
     public AskFastRestClient(String accountIdString refreshToken) {
         this(accountIdrefreshTokennull);
     }
 
     public AskFastRestClient(String accountIdString refreshTokenString accessToken) {
         this. = accountId;
         this. = refreshToken;
         this. = accessToken;
     }
 
     public String startPhoneDialog(String fromAddressString toAddressString url) {
 
         AskFastRestService service = getRestService();
         return service.startDialog(new DialogRequest(fromAddresstoAddressurl));
     }
 
     public Set<AdaptergetAdapters(String type) {
         
         AskFastRestService service = getRestService();
         return service.getAdapters(type);
     }
     
     public void buyAdapter(String adapterId) {
         
         AskFastRestService service = getRestService();
         service.buyAdapter(adapterId);
     }
     
     public void removeAdapter(String adapterId) {
         
         AskFastRestService service = getRestService();
         service.removeAdapter(adapterId);
     }
     
     public Set<AdaptergetFreeAdapters(String adapterTypeString address) {
         
         AskFastRestService service = getRestService();
         return service.getFreeAdapters(adapterTypeaddress);
     }
     
     public Dialog createDialog(Dialog dialog) {
         AskFastRestService service = getRestService();
         return service.createDialog(dialog);
     }
     
     public Set<DialoggetDialogs() {
         
         AskFastRestService service = getRestService();
         return service.getDialogs();
     }
     
     public Dialog getDialog(String dialogId) {
         AskFastRestService service = getRestService();
         return service.getDialog(dialogId);
     }
     
     public Dialog updateDialog(String dialogIdDialog dialog) {
         AskFastRestService service = getRestService();
         return service.updateDialog(dialogIddialog);
     }
     
     public void removeDialog(String dialogId) {
         AskFastRestService service = getRestService();
         service.removeDialog(dialogId);
     }
     
    public List<DDRRecordgetDDRRecords(String adapterIdString fromAddressString typeIdString status,
        Long startTimeLong endTimeString delimitedSessionKeysInteger offsetInteger limit,
        Boolean shouldGenerateCostsBoolean shouldIncludeServiceCosts) {
        AskFastRestService service = getRestService();
        return service.getDDRRecords(adapterIdfromAddresstypeIdstatusstartTimeendTimedelimitedSessionKeys,
                                     offsetlimitshouldGenerateCostsshouldIncludeServiceCosts);
    }
    private RestAdapter getRestAdapter() {
        return new RestAdapter.Builder().setRequestInterceptor(new RequestInterceptor() {
            @Override
            public void intercept(RequestFacade request) {
                try {
                    String token = getAccessToken();
                    request.addHeader("Authorization""Bearer " + token);
                }
                catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }).setEndpoint()
            .setConverter(new JacksonConverter())
            .setClient(new OkClient(new OkHttpClient())).build();
    }
    
    private AskFastRestService getRestService() {
        RestAdapter adapter = getRestAdapter();
        return adapter.create(AskFastRestService.class);
    }
    public String getAccessToken() throws Exception {
        if ( != null) {
            return ;
        }
        else {
            return refreshAccessToken();
        }
    }
    public String getRefreshToken() {
        return ;
    }
    private String refreshAccessToken() throws Exception {
        if ( == null) {
            throw new Exception("AccountID isn't set.");
        }
        if ( == null) {
            throw new Exception("Refresh Token isn't set.");
        }
        // First resfresh accessToken from Keyserver
        OAuthClientRequest request = OAuthClientRequest.tokenLocation()
        // create OAuth client that uses custom http client under the hood
        OAuthClient oAuthClient = new OAuthClient(new URLConnectionClient());
        OAuthJSONAccessTokenResponse response = oAuthClient.accessToken(request);
        if (response.getAccessToken() != null) {
             = response.getAccessToken();
        }
        return ;
    }
New to GrepCode? Check out our FAQ X