@Test
  public void testSearchByCoordinateOptions() throws IOException {
    CoordinateOptions coordinate =
        CoordinateOptions.builder().latitude(37.7867703362929).longitude(-122.399958372115).build();

    Map<String, String> params = new HashMap<>();
    params.put("term", "yelp");

    Call<SearchResponse> call = yelpAPI.search(coordinate, params);
    Response<SearchResponse> response = call.execute();
    Assert.assertEquals(200, response.code());

    SearchResponse searchResponse = response.body();
    Assert.assertNotNull(searchResponse);
  }
示例#2
0
  public void search() {
    Map<String, String> params = new HashMap<>();

    // general params
    params.put("term", query);
    params.put("limit", "3");

    Log.d(
        TAG,
        "Searching "
            + query
            + " in location "
            + location.getLatitude()
            + ","
            + location.getLongitude());
    // coordinates
    CoordinateOptions coordinate =
        CoordinateOptions.builder()
            .latitude(location.getLatitude())
            .longitude(location.getLongitude())
            .build();
    Call<SearchResponse> call = yelpAPI.search(coordinate, params);
    // Response<SearchResponse> response = call.execute();

    // Call<SearchResponse> call = yelpAPI.search("Chicago", params);

    Callback<SearchResponse> searchResponseCallback =
        new Callback<SearchResponse>() {
          @Override
          public void onResponse(Response<SearchResponse> response, Retrofit retrofit) {
            SearchResponse searchResponse = response.body();
            Log.d(TAG, "Yelp has returned " + searchResponse.total() + " results");

            YelpDataObject yelpDataObject = new YelpDataObject();
            List<YelpPoint> yelpPoints = new ArrayList<YelpPoint>();
            yelpPoints.addAll(yelpDataObject.populate(response.body()));
            yelpHelperListener.updateYelpPoints(yelpPoints);
          }

          @Override
          public void onFailure(Throwable t) {
            Log.d(TAG, "Error on Yelp Search: " + t.toString());
            yelpHelperListener.errorOnYelp();
          }
        };
    call.enqueue(searchResponseCallback);
  }