static IterableService newInstance(String apiKey) {
   // all of this intercepter/chain stuff is just so callers don't
   // have to pass the API key into every single method/api call
   OkHttpClient client = new OkHttpClient();
   client
       .interceptors()
       .add(
           chain ->
               chain.proceed(
                   chain
                       .request()
                       .newBuilder()
                       .url(
                           chain
                               .request()
                               .httpUrl()
                               .newBuilder()
                               .addQueryParameter(IterableService.PARAM_API_KEY, apiKey)
                               .build())
                       .build()));
   HttpUrl url =
       new HttpUrl.Builder()
           .scheme("https")
           .host(IterableService.HOST)
           .addQueryParameter(IterableService.PARAM_API_KEY, apiKey)
           .build();
   Retrofit retrofit =
       new Retrofit.Builder()
           .baseUrl(url)
           .client(client)
           .addConverterFactory(GsonConverterFactory.create())
           .build();
   return retrofit.create(IterableService.class);
 }
 @Before
 public void setUp() {
   Retrofit retrofit =
       new Retrofit.Builder()
           .endpoint(server.getUrl("/").toString())
           .converterFactory(new StringConverterFactory())
           .callAdapterFactory(ObservableCallAdapterFactory.create())
           .build();
   service = retrofit.create(Service.class);
 }
  private DataManager() {

    Retrofit retrofit =
        new Retrofit.Builder()
            .baseUrl(BASE_URL)
            .addConverterFactory(GsonConverterFactory.create())
            .build();

    mApiInterface = retrofit.create(ApiInterface.class);
  }
Beispiel #4
0
    public static InstagramService create() {
      Retrofit retrofit =
          new Retrofit.Builder()
              .baseUrl(API_BASE_URL)
              .addConverterFactory(GsonConverterFactory.create())
              .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
              .build();

      return retrofit.create(InstagramService.class);
    }
Beispiel #5
0
 public static APIService getInstance() {
   Retrofit retrofit =
       new Retrofit.Builder()
           .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
           .addConverterFactory(JacksonConverterFactory.create())
           .baseUrl("http://api.map.baidu.com/")
           .build();
   apiService = retrofit.create(APIService.class);
   return apiService;
 }
  public static <S> S createService(Class<S> serviceClass, int api_type) {

    OkHttpClient client = new OkHttpClient();
    Retrofit retrofit =
        new Retrofit.Builder()
            .baseUrl(RestConfig.getBaseUrl(api_type))
            .addConverterFactory(GsonConverterFactory.create(GsonFactory.createGson(api_type)))
            .client(client)
            .build();

    return retrofit.create(serviceClass);
  }
 public static WeatherAPI createWeatherService(boolean isLoggerOn) {
   ObjectMapper mapper = new ObjectMapper();
   Retrofit.Builder builder =
       new Retrofit.Builder()
           .baseUrl(Constants.BASE_WEATHER_API_URL)
           .addConverterFactory(JacksonConverterFactory.create(mapper));
   if (isLoggerOn) {
     builder.client(createOkHttpClient());
   }
   Retrofit retrofit = builder.build();
   return retrofit.create(WeatherAPI.class);
 }
  @Provides
  PostsAPI providePostsApi() {
    OkHttpClient okHttpClient = new OkHttpClient();

    okHttpClient.setConnectTimeout(5, TimeUnit.SECONDS); // connect timeout
    okHttpClient.setReadTimeout(5, TimeUnit.SECONDS);

    okHttpClient
        .interceptors()
        .add(
            new Interceptor() {
              @Override
              public Response intercept(Chain chain) throws IOException {

                Request originalRequest = chain.request(); // Current Request
                Log.i("Body", bodyToString(originalRequest));
                Response response = chain.proceed(originalRequest); // Get response of the request

                // I am logging the response body in debug mode. When I do this I consume the
                // response (OKHttp only lets you do this once) so i have re-build a new one using
                // the cached body
                String bodyString = response.body().string();
                Log.i("Response Body", bodyString);

                Log.i(
                    "NetworkModule",
                    String.format(
                        "Sending request %s with headers %s ",
                        originalRequest.url(), originalRequest.headers()));
                Log.i(
                    "",
                    (String.format(
                        "Got response HTTP %s %s \n\n with body %s \n\n with headers %s ",
                        response.code(), response.message(), bodyString, response.headers())));
                response =
                    response
                        .newBuilder()
                        .body(ResponseBody.create(response.body().contentType(), bodyString))
                        .build();

                return response;
              }
            });

    Retrofit retrofit =
        new Retrofit.Builder()
            .baseUrl("http://jsonplaceholder.typicode.com")
            .client(okHttpClient)
            .addConverterFactory(GsonConverterFactory.create())
            .build();

    return retrofit.create(PostsAPI.class);
  }
Beispiel #9
0
 public ApisRetrofit() {
   OkHttpClient client = new OkHttpClient();
   client.setReadTimeout(30, TimeUnit.SECONDS);
   Retrofit retrofit =
       new Retrofit.Builder()
           .client(client)
           .baseUrl("http://apistore.baidu.com")
           .addConverterFactory(GsonConverterFactory.create())
           .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
           .build();
   service = retrofit.create(ApisService.class);
 }
 public TwitterFriendsService(NamesService namesService) {
   this.namesService = namesService;
   this.authToken = System.getProperty(AUTH_TOKEN_PROPERTY);
   this.random = new Random(System.currentTimeMillis());
   Retrofit retrofit =
       new Retrofit.Builder()
           .baseUrl(TWITTER_BASE_URL)
           .client(createOkHttpClient())
           .addConverterFactory(JacksonConverterFactory.create())
           .build();
   this.twitterService = retrofit.create(TwitterService.class);
   LOG.info("Twitter service initialized");
 }
public class EventRESTClient {

  private Retrofit retrofit =
      new Retrofit.Builder()
          .baseUrl("http://eskimo-cmpe277.rhcloud.com")
          .addConverterFactory(GsonConverterFactory.create())
          .build();

  private EventAPI service = retrofit.create(EventAPI.class);

  public Call<Event> createEvent(Event e) {
    return service.createEvent(
        e.getUser_id(),
        e.getEvent_details(),
        e.getEvent_name(),
        e.getLocation(),
        e.getStart_time(),
        e.getEnd_time());
  }

  public Call<List<Event>> getAttendingEvents(String userId) {
    return service.getAttendingEvents(userId);
  }

  public Call<Event> getEventById(String id) {
    return service.getEventById(id);
  }
}
  @Override
  protected String doInBackground(String... params) {

    String sent = params[0];

    final Retrofit retrofit =
        new Retrofit.Builder().baseUrl("http://" + Connection.HOST + ":" + Connection.PORT).build();
    Service service = retrofit.create(Service.class);

    try {
      return service.searchMyCreatAd(sent).execute().body().string();

    } catch (IOException e) {
      e.printStackTrace();
    }
    return null;
  }
  @Override
  public void onCreate() {
    super.onCreate();
    Gson gson = new GsonBuilder().create();

    Retrofit retrofit =
        new Retrofit.Builder()
            .baseUrl(service_url)
            .addConverterFactory(GsonConverterFactory.create(gson))
            .build();
    donationService = retrofit.create(DonationServiceProxy.class);

    timer = new Timer();

    // this.refreshDonationList();

    Log.v("Donation", "Donation App Started");
  }
Beispiel #14
0
  public static FreshmanApiInterface getClient() {
    if (feApiInterface == null) {

      OkHttpClient okClient = new OkHttpClient();
      HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
      interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
      okClient.interceptors().add(interceptor);

      Retrofit client =
          new Retrofit.Builder()
              .baseUrl(baseUrl)
              .addConverter(String.class, new ToStringConverter())
              .client(okClient)
              .addConverterFactory(GsonConverterFactory.create())
              .build();
      feApiInterface = client.create(FreshmanApiInterface.class);
    }
    return feApiInterface;
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    Retrofit retrofit =
        new Retrofit.Builder()
            .baseUrl("https://api.stackexchange.com/2.2/")
            .addConverterFactory(GsonConverterFactory.create())
            .build();

    stackExchangeService = retrofit.create(StackExchangeService.class);

    questionsAdapter =
        new QuestionsAdapter(MainActivity.this, R.layout.questions_list_row, new ArrayList<Item>());

    initRefreshButton();
    initQuestionsList();
  }
 /** Initializes the Retrofit network adapter and creates the API interface. */
 private void initNetworking() {
   OkHttpClient client = new OkHttpClient();
   if (BuildConfig.DEBUG) {
     HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
     interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
     client.interceptors().add(interceptor);
   }
   Gson gson =
       new GsonBuilder()
           .setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES)
           .create();
   Retrofit retrofit =
       new Retrofit.Builder()
           .baseUrl(String.format("https://%s.auth0.com/", mAuthDomain))
           .client(client)
           .addConverterFactory(GsonConverterFactory.create(gson))
           .build();
   mLoginApi = retrofit.create(LoginAPI.class);
 }
  @Override
  public void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    retrofit =
        new Retrofit.Builder()
            .baseUrl("http://api.themoviedb.org/")
            .addConverterFactory(GsonConverterFactory.create())
            .build();

    service = retrofit.create(MovieService.class);
  }
Beispiel #18
0
  public boolean cancelOrder(int id) {

    Retrofit retrofit =
        new Retrofit.Builder()
            .baseUrl("https://app.bb-evacuator.ru/api/")
            .addConverterFactory(GsonConverterFactory.create())
            .build();

    Api api = retrofit.create(Api.class);
    Log.d("SD11", "OK");
    Call<CancelResponse> call = api.cancelOrder(id);
    call.enqueue(
        new Callback<CancelResponse>() {

          @Override
          public void onResponse(Response<CancelResponse> response, Retrofit retrofit) {
            CancelResponse re = response.body();
            Log.d("SD11", response.message());
            if ((response.code() != 404 && response.code() != 401)) {
              isOk = re.getError() == 0;
              Log.d("SD11", String.valueOf(response.code()));
              Log.d("SD11", re.getErrorMessage());
              Log.d("SD11", String.valueOf(re.getError()));
              re.getErrorMessage();
              re.getError();
            } else {
              isOk = false;
            }
            Log.d("SD11", String.valueOf(isOk));
          }

          @Override
          public void onFailure(Throwable t) {
            Log.d("SD11", "eror" + t.toString());
          }
        });

    return isOk;
  }
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    /*
            setListAdapter(new RecetaAdapter(
                    getActivity(),
                    RepoRecetas.getInstance().getRecetas(null,10)));

    */
    final String BASE_URL = "http://192.168.247.112:8080/";

    Retrofit retrofit =
        new Retrofit.Builder()
            .baseUrl(BASE_URL)
            .addConverterFactory(GsonConverterFactory.create())
            .build();

    recetaService = retrofit.create(RecetasService.class);

    Call<List<Receta>> recetasCall = recetaService.getRecetas();

    recetasCall.enqueue(
        new Callback<List<Receta>>() {
          @Override
          public void onResponse(Response<List<Receta>> response, Retrofit retrofit) {
            List<Receta> recetasList = response.body();

            setListAdapter(new RecetaAdapter(getActivity(), recetasList));
          }

          @Override
          public void onFailure(Throwable t) {
            t.printStackTrace();
            Log.e("RecetasApp", t.getMessage());
          }
        });
  }
Beispiel #20
0
  public void sendIDsAWS(String uberCode, String gcmID) {
    Retrofit retrofit =
        new Retrofit.Builder()
            .baseUrl(Constants.AWS_URL)
            .addConverterFactory(GsonConverterFactory.create())
            .build();
    UberAuthRequest service = retrofit.create(UberAuthRequest.class);
    Call<OAuthResponse> oauthCall = service.getToken(uberCode, gcmID);
    oauthCall.enqueue(
        new Callback<OAuthResponse>() {
          @Override
          public void onResponse(Response<OAuthResponse> response) {
            // Intent intent = new Intent(getApplicationContext(), StartGameActivity.class);
            // startActivity(intent);
            finish();
          }

          @Override
          public void onFailure(Throwable t) {
            finish();
          }
        });
  }
  public void testEpisodes() throws Exception {

    Retrofit retrofit =
        new Retrofit.Builder()
            .baseUrl(BuildConfig.HOST)
            .addConverterFactory(GsonConverterFactory.create())
            .build();

    TraktApi traktApi = retrofit.create(TraktApi.class);

    Call<List<Episode>> call = traktApi.episodes("game-of-thrones", 1);

    Response<List<Episode>> response = call.execute();

    if (response.isSuccess()) {
      List<Episode> episodes = response.body();

      boolean hasEpisodes = episodes.size() > 0;

      assertTrue(hasEpisodes);
    } else {
      assertFalse(true);
    }
  }
  public MovieVideosResponse fetchMovieVideos(long movieId) {
    try {
      MovieAPI mApi = mRetrofit.create(MovieAPI.class);
      Call<MovieVideosResponse> callApi = mApi.listMovieVideos(movieId, MovieAPIService.API_KEY);
      Response<MovieVideosResponse> movieResponse = callApi.execute();
      if (movieResponse != null && movieResponse.isSuccess()) {
        return movieResponse.body();
      } else {
        if (movieResponse != null && movieResponse.errorBody() != null) {
          Log.e(LOG_TAG, movieResponse.errorBody().string());
        }
      }

    } catch (Exception e) {
      Log.e(LOG_TAG, e.getMessage());
    }
    return null;
  }
  public DiscoverMovieResponse fetchMoviesWithOrder(String orderQuery) {
    try {
      MovieAPI mApi = mRetrofit.create(MovieAPI.class);
      Call<DiscoverMovieResponse> callApi =
          mApi.listMoviesWithOrder(MovieAPIService.API_KEY, orderQuery);
      Response<DiscoverMovieResponse> movieResponse = callApi.execute();
      if (movieResponse != null && movieResponse.isSuccess()) {
        return movieResponse.body();
      } else {
        if (movieResponse != null && movieResponse.errorBody() != null) {
          Log.e(LOG_TAG, movieResponse.errorBody().string());
        }
      }

    } catch (Exception e) {
      Log.e(LOG_TAG, e.getMessage());
    }
    return null;
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.create_trip_screen);
    ButterKnife.bind(this);

    // Get tracker.
    t = ((Ntrip) getApplication()).getTracker(Ntrip.TrackerName.APP_TRACKER);

    retrofit =
        new Retrofit.Builder()
            .baseUrl(Utilitys.baseUrl)
            .addConverterFactory(GsonConverterFactory.create())
            .build();
    reqCall = retrofit.create(RequestCallBack.class);

    AdView mAdView = (AdView) findViewById(R.id.adView);
    AdRequest adRequest =
        new AdRequest.Builder().addTestDevice(AdRequest.DEVICE_ID_EMULATOR).build();

    mAdView.loadAd(adRequest);
  }
 /**
  * Initializes an instance of DatetimeOperations.
  *
  * @param retrofit the Retrofit instance built from a Retrofit Builder.
  * @param client the instance of the service client containing this operation class.
  */
 public DatetimeOperationsImpl(Retrofit retrofit, AutoRestDateTimeTestService client) {
   this.service = retrofit.create(DatetimeService.class);
   this.client = client;
 }
 /**
  * Initializes an instance of SubscriptionInMethodOperations.
  *
  * @param retrofit the Retrofit instance built from a Retrofit Builder.
  * @param client the instance of the service client containing this operation class.
  */
 public SubscriptionInMethodOperationsImpl(
     Retrofit retrofit, AutoRestAzureSpecialParametersTestClient client) {
   this.service = retrofit.create(SubscriptionInMethodService.class);
   this.client = client;
 }
 public static ApiInterface getApi() {
   Retrofit ra = new Builder().baseUrl("https://www.rescuetime.com").build();
   return ra.create(ApiInterface.class);
 }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    mTextView = (LinearLayout) findViewById(R.id.mTextView);
    mButton = (Button) findViewById(R.id.mButton);
    mProgressDialog = new ProgressDialog(MainActivity.this);
    mIdEdit = (EditText) findViewById(R.id.mIdEdit);
    mPwEdit = (EditText) findViewById(R.id.mPwEdit);

    retrofit =
        new Retrofit.Builder()
            .baseUrl("http://grooshbene.milkgun.kr")
            .addConverterFactory(GsonConverterFactory.create())
            .build();

    final JSONService service = retrofit.create(JSONService.class);

    mTextView.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            Intent intent = new Intent(MainActivity.this, SigninActivity.class);
            startActivity(intent);
          }
        });

    mButton.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            mProgressDialog = new ProgressDialog(MainActivity.this);
            mProgressDialog.setMessage("잠시만 기다려주세요.....");
            mProgressDialog.show();

            final Call<User> call =
                service.login(mIdEdit.getText().toString(), mPwEdit.getText().toString());
            call.enqueue(
                new Callback<User>() {
                  @Override
                  public void onResponse(Response<User> response) {
                    mProgressDialog.dismiss();
                    if (response.code() == 200) {
                      User user = response.body();
                      Log.e("asdf", user.user_name);
                      //                            List<User.Article> articles =
                      // response.body().article;
                      //                            for(User.Article article : articles){
                      //                                Log.e("sex", article.title);
                      //                            }
                      if (user != null) {
                        Intent intent = new Intent(MainActivity.this, HomeActivity.class);
                        savePreferences(user.user_name);
                        startActivity(intent);
                        finish();
                      }
                    } else {
                      mProgressDialog.dismiss();
                      Toast.makeText(
                              getApplicationContext(), "아이디나 비밀번호를 확인해 주세요!", Toast.LENGTH_SHORT)
                          .show();

                      Log.e("asdf", "error");
                    }
                  }

                  @Override
                  public void onFailure(Throwable t) {
                    mProgressDialog.dismiss();
                    Toast.makeText(getApplicationContext(), "요청을 전송할 수 없습니다.", Toast.LENGTH_SHORT)
                        .show();
                    Log.e("Error", "Server Error!");
                    Log.e("ErrorMessage", String.valueOf(t));
                  }
                });
          }
        });
  }
 /**
  * Initializes an instance of ImplicitOperations.
  *
  * @param retrofit the Retrofit instance built from a Retrofit Builder.
  * @param client the instance of the service client containing this operation class.
  */
 public ImplicitOperationsImpl(Retrofit retrofit, AutoRestRequiredOptionalTestService client) {
   this.service = retrofit.create(ImplicitService.class);
   this.client = client;
 }
 public ApiVersionDefaultImpl(Retrofit retrofit, AutoRestAzureSpecialParametersTestClient client) {
   this.service = retrofit.create(ApiVersionDefaultService.class);
   this.client = client;
 }