@Override
    protected CommonWeather doInBackground(Void... params) {
      try {
        weathersCall =
            weatherDAO.getOpenWeatherForecast(userLocation, getString(R.string.openweather_key));
        forecastIOCall =
            weatherDAO.getForecastIOForecast(userLocation, getString(R.string.forecastio_key));
        wundergroundCall =
            weatherDAO.getWundergroundForecast(userLocation, getString(R.string.wunderground_key));
        weathersCall.enqueue(openWeatherCallback);
        forecastIOCall.enqueue(forecastIOCallback);
        wundergroundCall.enqueue(wundergroundCallback);
        while (!openWeatherRequested || !forecastIORequested || !wundergroundRequested) {
          Thread.sleep(10);
        }
        if (openWeatherForecasts != null)
          agregator.addNewForecastsSource(openWeatherForecasts.convertToCommonWeather());
        if (forecastIOForecasts != null)
          agregator.addNewForecastsSource(forecastIOForecasts.convertToCommonWeather());
        if (wundergroundForecasts != null)
          agregator.addNewForecastsSource(wundergroundForecasts.convertToCommonWeather());
        return agregator.agregate();
      } catch (Exception e) {
        e.printStackTrace();
      }

      return null;
    }
  @Override
  public void onResume() {
    super.onResume();

    Call<HomeFeedResponse> timelineResponseCall =
        ApiManager.getInstance().getService().getHomeFeed();
    timelineResponseCall.enqueue(
        new Callback<HomeFeedResponse>() {
          @Override
          public void onResponse(Response<HomeFeedResponse> response, Retrofit retrofit) {
            if (response.isSuccess()) {
              if (response.body().getHomeFeedOneModel() != null) {
                populateRecycler(response.body().getHomeFeedOneModel());
              } else {
                NotesHelpers.toastMessage(
                    context, getResources().getString(R.string.error_something_is_wrong));
              }
            }
          }

          @Override
          public void onFailure(Throwable t) {
            NotesHelpers.toastMessage(
                context, getResources().getString(R.string.error_something_is_wrong));
          }
        });
  }
  public static void signin(
      String username,
      String password,
      String authToken,
      final PlexHttpUserHandler responseHandler) {
    PlexHttpService service = getService("https://plex.tv", username, password, false);
    Call<PlexUser> call =
        service.signin("Android", VoiceControlForPlexApplication.getUUID(), authToken);
    call.enqueue(
        new Callback<PlexUser>() {
          @Override
          public void onResponse(Response<PlexUser> response) {
            if (response.code() == 200) responseHandler.onSuccess(response.body());
            else if (response.code() == 401) {
              responseHandler.onFailure(response.code());
            }
          }

          @Override
          public void onFailure(Throwable t) {
            t.printStackTrace();
            responseHandler.onFailure(0);
          }
        });
  }
  public static void subscribe(
      PlexClient client,
      int subscriptionPort,
      int commandId,
      String uuid,
      String deviceName,
      final PlexHttpResponseHandler responseHandler) {
    String url = String.format("http://%s:%s", client.address, client.port);
    Logger.d("Subscribing at url %s", url);
    PlexHttpService service = getService(url, true);

    Call<PlexResponse> call = service.subscribe(uuid, deviceName, subscriptionPort, commandId);
    call.enqueue(
        new Callback<PlexResponse>() {
          @Override
          public void onResponse(Response<PlexResponse> response) {
            Logger.d("Subscribe code: %d", response.code());
            if (responseHandler != null) {
              if (response.code() == 200) responseHandler.onSuccess(response.body());
              else responseHandler.onFailure(new Throwable());
            }
          }

          @Override
          public void onFailure(Throwable t) {
            Logger.d("subscribe onFailure:");
            PlexResponse response = new PlexResponse();
            response.status = "ok";
            if (responseHandler != null) responseHandler.onSuccess(response);
            t.printStackTrace();
            if (responseHandler != null) responseHandler.onFailure(t);
          }
        });
  }
  public static void createArtistPlayQueue(
      Connection connection, PlexDirectory artist, final PlexPlayQueueHandler responseHandler) {
    Map qs = new HashMap<>();
    qs.put("type", "audio");
    qs.put("shuffle", "1");
    String uri =
        String.format(
            "library://%s/item/%%2flibrary%%2fmetadata%%2f%s",
            artist.server.machineIdentifier, artist.ratingKey);
    Logger.d("URI: %s", uri);
    qs.put("uri", uri);
    if (artist.server.accessToken != null)
      qs.put(PlexHeaders.XPlexToken, artist.server.accessToken);
    qs.put("continuous", "0");
    qs.put("includeRelated", "1");
    PlexHttpService service =
        getService(String.format("http://%s:%s", connection.address, connection.port));
    Call<MediaContainer> call =
        service.createPlayQueue(qs, VoiceControlForPlexApplication.getUUID());
    call.enqueue(
        new Callback<MediaContainer>() {
          @Override
          public void onResponse(Response<MediaContainer> response) {
            if (responseHandler != null) responseHandler.onSuccess(response.body());
          }

          @Override
          public void onFailure(Throwable t) {
            Logger.d("createPlayQueue failure.");
            t.printStackTrace();
          }
        });
  }
Example #6
0
 @DebugLog
 public Metadata lookupArtistInfo(final String artistName) {
   Call<Artist> call = mLastFM.getArtist(artistName);
   Response<Artist> response;
   try {
     response = call.execute();
   } catch (IOException e) {
     return null;
   }
   Artist artist = response.body();
   if (artist == null) {
     Timber.w("Failed to retrieve artist %s", artistName);
     return null;
   }
   Metadata.Builder bob = Metadata.builder();
   bob.putString(KEY_ARTIST_NAME, artist.getName());
   bob.putString(KEY_ARTIST_SUMMARY, artist.getWikiSummary());
   bob.putString(KEY_ARTIST_BIO, artist.getWikiText());
   Date lastChanged = artist.getWikiLastChanged();
   if (lastChanged != null) {
     bob.putLong(KEY_LAST_MODIFIED, lastChanged.getTime());
   }
   bob.putUri(KEY_ARTIST_URL_URI, Uri.parse(artist.getUrl()));
   bob.putString(KEY_ARTIST_MBID, artist.getMbid());
   return bob.build();
 }
Example #7
0
 /**
  * Upload file.
  *
  * @param fileContent File to upload.
  * @param fileName File name to upload. Name has to be spelled exactly as written here.
  * @param serviceCallback the async ServiceCallback to handle successful and failed responses.
  * @return the {@link Call} object
  */
 public Call<ResponseBody> uploadFileAsync(
     InputStream fileContent,
     String fileName,
     final ServiceCallback<InputStream> serviceCallback) {
   if (fileContent == null) {
     serviceCallback.failure(
         new IllegalArgumentException("Parameter fileContent is required and cannot be null."));
     return null;
   }
   if (fileName == null) {
     serviceCallback.failure(
         new IllegalArgumentException("Parameter fileName is required and cannot be null."));
     return null;
   }
   Call<ResponseBody> call = service.uploadFile(fileContent, fileName);
   call.enqueue(
       new ServiceResponseCallback<InputStream>(serviceCallback) {
         @Override
         public void onResponse(Response<ResponseBody> response, Retrofit retrofit) {
           try {
             serviceCallback.success(uploadFileDelegate(response, retrofit));
           } catch (ServiceException | IOException exception) {
             serviceCallback.failure(exception);
           }
         }
       });
   return call;
 }
 @Override
 public List<Long> getFriends(long userId) throws Exception {
   LOG.info("Getting friends list of user " + userId);
   String userName = namesService.getName(userId);
   LOG.info("Screen name for " + userId + ": " + userName);
   List<Long> friends = new ArrayList<>();
   boolean hasMoreItems = true;
   long maxPosition = -1;
   while (hasMoreItems) {
     LOG.info(
         String.format("Sending request: {userName: %s, maxPosition: %d}", userName, maxPosition));
     Call<UsersResponse> call = twitterService.listFriends(userName, maxPosition);
     Response<UsersResponse> response = call.execute();
     LOG.info("Response received");
     if (response.isSuccess()) {
       UsersResponse responseBody = response.body();
       List<Long> receivedUsers = parseUsers(responseBody.getItemsHtml());
       assert (receivedUsers.size() == responseBody.getNewLatentCount());
       LOG.info(receivedUsers.size() + " users found");
       friends.addAll(receivedUsers);
       hasMoreItems = responseBody.isHasMoreItems();
       maxPosition = responseBody.getMinPosition();
     } else {
       if (!response.message().equals("Not Found")) {
         Thread.sleep(30000 + random.nextInt(90000));
       }
       throw new IllegalStateException(response.message());
     }
     Thread.sleep(random.nextInt(1000));
   }
   return friends;
 }
  /**
   * ###################################################################################
   * ************************************ On Click **************************************
   * ###################################################################################
   */
  public void onClick(View v) {
    Bundle extra = getIntent().getExtras();

    switch (v.getId()) {
      case R.id.btn_customer_tracking_details_order_received:
        cart.setInvoice_ID(extra.getInt("Invoice_ID"));

        Call<Cart> reg = apiService.customerReceivedOrder(cart);

        reg.enqueue(
            new Callback<Cart>() {
              @Override
              public void onResponse(Response<Cart> response, Retrofit retrofit) {
                if (response.message().equalsIgnoreCase("ok")) {
                  Toast.makeText(
                          getBaseContext(), "Your Order is Delivered To You", Toast.LENGTH_LONG)
                      .show();
                  finish();
                }
              }

              @Override
              public void onFailure(Throwable t) {

                Toast.makeText(
                        getBaseContext(),
                        " Oops! An error occurred  + The Throwable is " + t.getMessage().toString(),
                        Toast.LENGTH_LONG)
                    .show();
              }
            });
        break;
    }
  }
  private View getReviewPageView(ViewGroup container) {

    final View view =
        getActivity().getLayoutInflater().inflate(R.layout.review_page, container, false);

    int movieId = getArguments().getInt(MovieDetailActivity.MOVIE_ID);

    Call<ReviewDatas> call =
        MyMovieDbApi.getInstance().getMoviesReviewsDatas(movieId, Constants.MOVIEDB_API_KEY);
    call.enqueue(
        new Callback<ReviewDatas>() {
          @Override
          public void onResponse(Response<ReviewDatas> response, Retrofit retrofit) {
            ReviewDatas data = response.body();
            List<ReviewData> reviewDatas = data.getReviewDatas();
            if (reviewDatas.size() > 0) {
              ListView reviewListView = (ListView) view.findViewById(R.id.review_list);
              reviewListView.setAdapter(new ReviewAdapter(getActivity(), reviewDatas));
            } else {
              TextView noReviewTextView = (TextView) view.findViewById(R.id.no_review_textview);
              noReviewTextView.setVisibility(View.VISIBLE);
            }
          }

          @Override
          public void onFailure(Throwable t) {}
        });

    return view;
  }
 /**
  * Put min datetime value 0001-01-01T00:00:00-14:00.
  *
  * @param datetimeBody the DateTime value
  * @throws ErrorException exception thrown from REST call
  * @throws IOException exception thrown from serialization/deserialization
  * @throws IllegalArgumentException exception thrown from invalid parameters
  * @return the {@link ServiceResponse} object if successful.
  */
 public ServiceResponse<Void> putLocalNegativeOffsetMinDateTime(DateTime datetimeBody)
     throws ErrorException, IOException, IllegalArgumentException {
   if (datetimeBody == null) {
     throw new IllegalArgumentException("Parameter datetimeBody is required and cannot be null.");
   }
   Call<ResponseBody> call = service.putLocalNegativeOffsetMinDateTime(datetimeBody);
   return putLocalNegativeOffsetMinDateTimeDelegate(call.execute(), null);
 }
 /**
  * Test implicitly required path parameter.
  *
  * @param pathParameter the String value
  * @throws ErrorException exception thrown from REST call
  * @throws IOException exception thrown from serialization/deserialization
  * @throws IllegalArgumentException exception thrown from invalid parameters
  * @return the Error object wrapped in {@link ServiceResponse} if successful.
  */
 public ServiceResponse<Error> getRequiredPath(String pathParameter)
     throws ErrorException, IOException, IllegalArgumentException {
   if (pathParameter == null) {
     throw new IllegalArgumentException("Parameter pathParameter is required and cannot be null.");
   }
   Call<ResponseBody> call = service.getRequiredPath(pathParameter);
   return getRequiredPathDelegate(call.execute(), null);
 }
 /**
  * Test implicitly required query parameter.
  *
  * @throws ErrorException exception thrown from REST call
  * @throws IOException exception thrown from serialization/deserialization
  * @throws IllegalArgumentException exception thrown from invalid parameters
  * @return the Error object wrapped in {@link ServiceResponse} if successful.
  */
 public ServiceResponse<Error> getRequiredGlobalQuery()
     throws ErrorException, IOException, IllegalArgumentException {
   if (this.client.getRequiredGlobalQuery() == null) {
     throw new IllegalArgumentException(
         "Parameter this.client.getRequiredGlobalQuery() is required and cannot be null.");
   }
   Call<ResponseBody> call = service.getRequiredGlobalQuery(this.client.getRequiredGlobalQuery());
   return getRequiredGlobalQueryDelegate(call.execute(), null);
 }
  public static void createPlayQueue(
      Connection connection,
      final PlexMedia media,
      final String key,
      String transientToken,
      final PlexPlayQueueHandler responseHandler) {
    Map qs = new HashMap<>();
    qs.put("type", media.getType());
    qs.put("next", "0");

    boolean hasOffset = media.viewOffset != null && Integer.parseInt(media.viewOffset) > 0;
    if (media.isMovie() && !hasOffset) {
      qs.put(
          "extrasPrefixCount",
          Integer.toString(
              VoiceControlForPlexApplication.getInstance()
                  .prefs
                  .get(Preferences.NUM_CINEMA_TRAILERS, 0)));
    }

    String uri =
        String.format(
            "library://%s/item/%%2flibrary%%2fmetadata%%2f%s", media.server.machineIdentifier, key);
    qs.put("uri", uri);
    qs.put("window", "50"); // no idea what this is for
    if (transientToken != null) qs.put("token", transientToken);
    if (media.server.accessToken != null) qs.put(PlexHeaders.XPlexToken, media.server.accessToken);

    Logger.d("Qs: ", qs);
    PlexHttpService service =
        getService(String.format("http://%s:%s", connection.address, connection.port));
    Call<MediaContainer> call =
        service.createPlayQueue(qs, VoiceControlForPlexApplication.getUUID());
    call.enqueue(
        new Callback<MediaContainer>() {
          @Override
          public void onResponse(Response<MediaContainer> response) {
            if (responseHandler != null) {
              MediaContainer mc = response.body();
              for (int i = 0; i < mc.tracks.size(); i++) {
                mc.tracks.get(i).server = media.server;
              }
              for (int i = 0; i < mc.videos.size(); i++) {
                mc.videos.get(i).server = media.server;
                if (mc.videos.get(i).isClip()) mc.videos.get(i).setClipDuration();
              }
              responseHandler.onSuccess(mc);
            }
          }

          @Override
          public void onFailure(Throwable t) {
            Logger.d("createPlayQueue failure.");
            t.printStackTrace();
          }
        });
  }
 /**
  * Put complex types that are polymorphic and have recursive references.
  *
  * @param complexBody Please put a salmon that looks like this: { "fishtype": "salmon", "species":
  *     "king", "length": 1, "age": 1, "location": "alaska", "iswild": true, "siblings": [ {
  *     "fishtype": "shark", "species": "predator", "length": 20, "age": 6, "siblings": [ {
  *     "fishtype": "salmon", "species": "coho", "length": 2, "age": 2, "location": "atlantic",
  *     "iswild": true, "siblings": [ { "fishtype": "shark", "species": "predator", "length": 20,
  *     "age": 6 }, { "fishtype": "sawshark", "species": "dangerous", "length": 10, "age": 105 } ]
  *     }, { "fishtype": "sawshark", "species": "dangerous", "length": 10, "age": 105 } ] }, {
  *     "fishtype": "sawshark", "species": "dangerous", "length": 10, "age": 105 } ] }
  * @throws ErrorException exception thrown from REST call
  * @throws IOException exception thrown from serialization/deserialization
  * @throws IllegalArgumentException exception thrown from invalid parameters
  * @return the {@link ServiceResponse} object if successful.
  */
 public ServiceResponse<Void> putValid(Fish complexBody)
     throws ErrorException, IOException, IllegalArgumentException {
   if (complexBody == null) {
     throw new IllegalArgumentException("Parameter complexBody is required and cannot be null.");
   }
   Validator.validate(complexBody);
   Call<ResponseBody> call = service.putValid(complexBody);
   return putValidDelegate(call.execute(), null);
 }
 /**
  * POST method with subscriptionId modeled in the method. pass in subscription id =
  * '1234-5678-9012-3456' to succeed.
  *
  * @param subscriptionId This should appear as a method parameter, use value '1234-5678-9012-3456'
  * @throws ErrorException exception thrown from REST call
  * @throws IOException exception thrown from serialization/deserialization
  * @throws IllegalArgumentException exception thrown from invalid parameters
  * @return the {@link ServiceResponse} object if successful.
  */
 public ServiceResponse<Void> postMethodLocalValid(String subscriptionId)
     throws ErrorException, IOException, IllegalArgumentException {
   if (subscriptionId == null) {
     throw new IllegalArgumentException(
         "Parameter subscriptionId is required and cannot be null.");
   }
   Call<ResponseBody> call =
       service.postMethodLocalValid(subscriptionId, this.client.getAcceptLanguage());
   return postMethodLocalValidDelegate(call.execute(), null);
 }
Example #17
0
 /**
  * Upload file.
  *
  * @param fileContent File to upload.
  * @param fileName File name to upload. Name has to be spelled exactly as written here.
  * @throws ServiceException exception thrown from REST call
  * @throws IOException exception thrown from serialization/deserialization
  * @throws IllegalArgumentException exception thrown from invalid parameters
  * @return the InputStream object wrapped in {@link ServiceResponse} if successful.
  */
 public ServiceResponse<InputStream> uploadFile(InputStream fileContent, String fileName)
     throws ServiceException, IOException, IllegalArgumentException {
   if (fileContent == null) {
     throw new IllegalArgumentException("Parameter fileContent is required and cannot be null.");
   }
   if (fileName == null) {
     throw new IllegalArgumentException("Parameter fileName is required and cannot be null.");
   }
   Call<ResponseBody> call = service.uploadFile(fileContent, fileName);
   return uploadFileDelegate(call.execute(), null);
 }
  private RawViaplayModel getSectionFromWeb(String url) throws IOException {

    Log.d(TAG, "Retrieving section data from web api");

    Call<RawViaplayModel> call = mApiInterface.getSectionDetail(getUrlParam(url));
    Response<RawViaplayModel> response = call.execute();

    if (response != null) return response.body();

    return null;
  }
Example #19
0
 /**
  * Test implicitly optional query parameter
  *
  * @param queryParameter the String value
  * @throws ServiceException the exception wrapped in ServiceException if failed.
  */
 public void putOptionalQuery(String queryParameter) throws ServiceException {
   try {
     Call<ResponseBody> call = service.putOptionalQuery(queryParameter);
     ServiceResponse<Void> response = putOptionalQueryDelegate(call.execute(), null);
     response.getBody();
   } catch (ServiceException ex) {
     throw ex;
   } catch (Exception ex) {
     throw new ServiceException(ex);
   }
 }
  public List<People> getArchitectsFromCity(String city) throws IOException {

    Call<PeopleResponse> call = service.getPeopleFromQuery(auth, "Software Architect " + city);
    PeopleResponse res = call.execute().body();
    List<People> pList = new ArrayList<>();

    for (List<String> pData : res.getData()) {
      pList.add(new People(pData));
    }

    return pList;
  }
Example #21
0
 /**
  * Test implicitly optional query parameter
  *
  * @return the Error object if successful.
  * @throws ServiceException the exception wrapped in ServiceException if failed.
  */
 public Error getOptionalGlobalQuery() throws ServiceException {
   try {
     Call<ResponseBody> call =
         service.getOptionalGlobalQuery(this.client.getOptionalGlobalQuery());
     ServiceResponse<Error> response = getOptionalGlobalQueryDelegate(call.execute(), null);
     return response.getBody();
   } catch (ServiceException ex) {
     throw ex;
   } catch (Exception ex) {
     throw new ServiceException(ex);
   }
 }
Example #22
0
  private static void testInstance() {
    // This can be used in any Activity, etc.
    HttpApi api = HttpApi.getInstance();

    // Add headers to be added to every api request
    api.addHeader("Authorization", "MyToken123");

    // Prepare the HTTP request & asynchronously execute HTTP request
    Call<HttpApi.HttpBinResponse> call =
        api.getService().postWithJson(new HttpApi.LoginData("username", "secret"));
    call.enqueue(
        new Callback<HttpApi.HttpBinResponse>() {
          /** onResponse is called when any kind of response has been received. */
          public void onResponse(Response<HttpApi.HttpBinResponse> response, Retrofit retrofit) {
            // http response status code + headers
            System.out.println("Response status code: " + response.code());

            // isSuccess is true if response code => 200 and <= 300
            if (!response.isSuccess()) {
              // print response body if unsuccessful
              try {
                System.out.println(response.errorBody().string());
              } catch (IOException e) {
                // do nothing
              }
              return;
            }

            // if parsing the JSON body failed, `response.body()` returns null
            HttpApi.HttpBinResponse decodedResponse = response.body();
            if (decodedResponse == null) return;

            // at this point the JSON body has been successfully parsed
            System.out.println("Response (contains request infos):");
            System.out.println("- url:         " + decodedResponse.url);
            System.out.println("- ip:          " + decodedResponse.origin);
            System.out.println("- headers:     " + decodedResponse.headers);
            System.out.println("- args:        " + decodedResponse.args);
            System.out.println("- form params: " + decodedResponse.form);
            System.out.println("- json params: " + decodedResponse.json);
          }

          /**
           * onFailure gets called when the HTTP request didn't get through. For instance if the URL
           * is invalid / host not reachable
           */
          public void onFailure(Throwable t) {
            System.out.println("onFailure");
            System.out.println(t.getMessage());
          }
        });
  }
  @Test
  public void cardPayment_003_get() throws IOException {
    final Call<CardPaymentEntity> call =
        service.getCardPayment(TestSettings.testUserAppUserId, orderId);
    final Response<CardPaymentEntity> response = call.execute();
    if (response.code() != 200) {
      System.err.println(response.errorBody().string());
    }
    Assert.assertEquals(response.code(), 200);

    final CardPaymentEntity cardPaymentEntity = response.body();
    Assert.assertEquals(cardPaymentEntity.Message, "Recharge test");
  }
  private void refreshData() {

    if (editMenu) {
      Call<Menu> call = Utils.getApi(this).getMenu(menuId);

      call.enqueue(
          new Callback<Menu>() {
            @Override
            public void onResponse(Response<Menu> response, Retrofit retrofit) {

              Menu menu = response.body();

              if (menu != null) {
                setTitle("Redigera " + menu.getMenuTypeString() + "meny");
                adapter = new MenuAdapter(MenuActivity.this, menu, editMenu, MenuActivity.this);
                rv.setAdapter(adapter);
              }
            }

            @Override
            public void onFailure(Throwable t) {
              Log.i(MenuActivity.class.getName(), "Failed to fetch data: " + t.getMessage());
            }
          });

    } else {

      Call<List<Menu>> call = Utils.getApi(this).getMenus();

      call.enqueue(
          new Callback<List<Menu>>() {
            @Override
            public void onResponse(Response<List<Menu>> response, Retrofit retrofit) {

              List<Menu> menus = response.body();

              if (menus != null) {
                Menu menu = Menu.mergedMenuAtCurrentTime(menus);
                setTitle(menu.getMenuTypeString() + "meny");
                adapter = new MenuAdapter(MenuActivity.this, menu, editMenu, MenuActivity.this);
                rv.setAdapter(adapter);
              }
            }

            @Override
            public void onFailure(Throwable t) {
              Log.i(MenuActivity.class.getName(), "Failed to fetch data: " + t.getMessage());
            }
          });
    }
  }
 /**
  * Get null datetime value.
  *
  * @param serviceCallback the async ServiceCallback to handle successful and failed responses.
  * @return the {@link Call} object
  */
 public Call<ResponseBody> getNullAsync(final ServiceCallback<DateTime> serviceCallback) {
   Call<ResponseBody> call = service.getNull();
   call.enqueue(
       new ServiceResponseCallback<DateTime>(serviceCallback) {
         @Override
         public void onResponse(Response<ResponseBody> response, Retrofit retrofit) {
           try {
             serviceCallback.success(getNullDelegate(response, retrofit));
           } catch (ErrorException | IOException exception) {
             serviceCallback.failure(exception);
           }
         }
       });
   return call;
 }
Example #26
0
  private void loadQuestionsList() {
    Call<Wrapper> call = stackExchangeService.listQuestions();
    call.enqueue(
        new Callback<Wrapper>() {
          @Override
          public void onResponse(Response<Wrapper> response) {
            findViewById(R.id.loadingPanel).setVisibility(View.GONE);
            List<Item> items = response.body().getItems();
            questionsAdapter.addAll(items);
          }

          @Override
          public void onFailure(Throwable t) {}
        });
  }
Example #27
0
 /**
  * Test implicitly required path parameter
  *
  * @param pathParameter the String value
  * @return the Error object if successful.
  * @throws ServiceException the exception wrapped in ServiceException if failed.
  */
 public Error getRequiredPath(String pathParameter) throws ServiceException {
   if (pathParameter == null) {
     throw new ServiceException(
         new IllegalArgumentException("Parameter pathParameter is required and cannot be null."));
   }
   try {
     Call<ResponseBody> call = service.getRequiredPath(pathParameter);
     ServiceResponse<Error> response = getRequiredPathDelegate(call.execute(), null);
     return response.getBody();
   } catch (ServiceException ex) {
     throw ex;
   } catch (Exception ex) {
     throw new ServiceException(ex);
   }
 }
 /**
  * Test implicitly optional body parameter.
  *
  * @param bodyParameter the String value
  * @param serviceCallback the async ServiceCallback to handle successful and failed responses.
  * @return the {@link Call} object
  */
 public Call<ResponseBody> putOptionalBodyAsync(
     String bodyParameter, final ServiceCallback<Void> serviceCallback) {
   Call<ResponseBody> call = service.putOptionalBody(bodyParameter);
   call.enqueue(
       new ServiceResponseCallback<Void>(serviceCallback) {
         @Override
         public void onResponse(Response<ResponseBody> response, Retrofit retrofit) {
           try {
             serviceCallback.success(putOptionalBodyDelegate(response, retrofit));
           } catch (ErrorException | IOException exception) {
             serviceCallback.failure(exception);
           }
         }
       });
   return call;
 }
  @Override
  public void getTopStories(final LoadStoriesCallback callback) {
    Call<Story.StoryResult> call = Net.getApi(StoryApi.class).latestStories();
    call.enqueue(
        new Callback<Story.StoryResult>() {
          @Override
          public void onResponse(Response<Story.StoryResult> response, Retrofit retrofit) {
            if (response.body() != null) callback.onStoriesLoaded(response.body().top_stories);
          }

          @Override
          public void onFailure(Throwable t) {
            callback.onDataNotAvailable();
          }
        });
  }
 /**
  * Test implicitly optional query parameter.
  *
  * @param serviceCallback the async ServiceCallback to handle successful and failed responses.
  * @return the {@link Call} object
  */
 public Call<ResponseBody> getOptionalGlobalQueryAsync(
     final ServiceCallback<Error> serviceCallback) {
   Call<ResponseBody> call = service.getOptionalGlobalQuery(this.client.getOptionalGlobalQuery());
   call.enqueue(
       new ServiceResponseCallback<Error>(serviceCallback) {
         @Override
         public void onResponse(Response<ResponseBody> response, Retrofit retrofit) {
           try {
             serviceCallback.success(getOptionalGlobalQueryDelegate(response, retrofit));
           } catch (ErrorException | IOException exception) {
             serviceCallback.failure(exception);
           }
         }
       });
   return call;
 }