params);
84 |
85 | /**
86 | * Make a request to the search endpoint by bounding box. Specify a southwest latitude/longitude and a northeast
87 | * latitude/longitude in {@link BoundingBoxOptions}.
88 | *
89 | * {@link BoundingBoxOptions} is already encoded in {@link BoundingBoxOptions#toString()} for the special URI
90 | * character it uses, "encoded" is set to true so Retrofit doesn't encode it again.
91 | *
92 | * @param boundingBox Geographical bounding box to search in.
93 | * @param params Key, value pairs as search API params. Keys and values will be URL encoded by {@link QueryMap}.
94 | * @return Object to execute the request.
95 | * @see http://www.yelp.com/developers/documentation/v2/search_api#searchGBB
96 | */
97 | @GET("/v2/search")
98 | Call search(
99 | @Query(value = "bounds", encoded = true) BoundingBoxOptions boundingBox,
100 | @QueryMap Map params
101 | );
102 | }
103 |
104 |
--------------------------------------------------------------------------------
/src/main/java/com/yelp/clientlib/connection/YelpAPIFactory.java:
--------------------------------------------------------------------------------
1 | package com.yelp.clientlib.connection;
2 |
3 | import okhttp3.OkHttpClient;
4 | import com.yelp.clientlib.exception.ErrorHandlingInterceptor;
5 |
6 | import retrofit2.converter.jackson.JacksonConverterFactory;
7 | import retrofit2.Retrofit;
8 | import se.akerfeldt.okhttp.signpost.OkHttpOAuthConsumer;
9 | import se.akerfeldt.okhttp.signpost.SigningInterceptor;
10 |
11 |
12 | /**
13 | * Util class to create YelpAPI as the stub to use Yelp API. This is the entry point to use this clientlib.
14 | *
15 | * Example:
16 | * YelpAPIFactory apiFactory = new YelpAPIFactory(consumerKey, consumerSecret, token, tokenSecret);
17 | * YelpAPI yelpAPI = apiFactory.createAPI();
18 | * Business business = yelpAPI.getBusiness(businessId).execute();
19 | *
20 | */
21 | public class YelpAPIFactory {
22 |
23 | private static final String YELP_API_BASE_URL = "https://api.yelp.com";
24 |
25 | private OkHttpClient httpClient;
26 |
27 | /**
28 | * Construct a new {@code YelpAPIFactory}.
29 | *
30 | * @param consumerKey the consumer key.
31 | * @param consumerSecret the consumer secret.
32 | * @param token the access token.
33 | * @param tokenSecret the token secret.
34 | * @see https://www.yelp.com/developers/manage_api_keys
35 | */
36 | public YelpAPIFactory(String consumerKey, String consumerSecret, String token, String tokenSecret) {
37 | OkHttpOAuthConsumer consumer = new OkHttpOAuthConsumer(consumerKey, consumerSecret);
38 | consumer.setTokenWithSecret(token, tokenSecret);
39 |
40 | this.httpClient = new OkHttpClient.Builder()
41 | .addInterceptor(new SigningInterceptor(consumer))
42 | .addInterceptor(new ErrorHandlingInterceptor())
43 | .build();
44 | }
45 |
46 | /**
47 | * Initiate a {@link YelpAPI} instance.
48 | *
49 | * @return an instance of {@link YelpAPI}.
50 | */
51 | public YelpAPI createAPI() {
52 | Retrofit retrofit = new Retrofit.Builder()
53 | .baseUrl(getAPIBaseUrl())
54 | .addConverterFactory(JacksonConverterFactory.create())
55 | .client(this.httpClient)
56 | .build();
57 |
58 | return retrofit.create(YelpAPI.class);
59 | }
60 |
61 | /**
62 | * Get the base URL of Yelp APIs.
63 | *
64 | * @return the base URL of Yelp APIs.
65 | */
66 | public String getAPIBaseUrl() {
67 | return YELP_API_BASE_URL;
68 | }
69 | }
70 |
71 |
--------------------------------------------------------------------------------
/src/main/java/com/yelp/clientlib/entities/Business.java:
--------------------------------------------------------------------------------
1 | package com.yelp.clientlib.entities;
2 |
3 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
4 | import com.fasterxml.jackson.databind.PropertyNamingStrategy;
5 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
6 | import com.fasterxml.jackson.databind.annotation.JsonNaming;
7 | import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder;
8 | import com.google.auto.value.AutoValue;
9 | import com.yelp.clientlib.annotation.Nullable;
10 |
11 | import java.io.Serializable;
12 | import java.util.ArrayList;
13 |
14 | @AutoValue
15 | @JsonIgnoreProperties(ignoreUnknown = true)
16 | @JsonDeserialize(builder = AutoValue_Business.Builder.class)
17 | public abstract class Business implements Serializable {
18 |
19 | public abstract String id();
20 |
21 | public abstract String name();
22 |
23 | @Nullable
24 | public abstract ArrayList categories();
25 |
26 | @Nullable
27 | public abstract String displayPhone();
28 |
29 | @Nullable
30 | public abstract Double distance();
31 |
32 | @Nullable
33 | public abstract String eat24Url();
34 |
35 | @Nullable
36 | public abstract String imageUrl();
37 |
38 | @Nullable
39 | public abstract Boolean isClaimed();
40 |
41 | @Nullable
42 | public abstract Boolean isClosed();
43 |
44 | @Nullable
45 | public abstract String menuProvider();
46 |
47 | @Nullable
48 | public abstract Long menuDateUpdated();
49 |
50 | @Nullable
51 | public abstract String mobileUrl();
52 |
53 | @Nullable
54 | public abstract String phone();
55 |
56 | @Nullable
57 | public abstract String reservationUrl();
58 |
59 | @Nullable
60 | public abstract Integer reviewCount();
61 |
62 | @Nullable
63 | public abstract String snippetImageUrl();
64 |
65 | @Nullable
66 | public abstract String snippetText();
67 |
68 | @Nullable
69 | public abstract String url();
70 |
71 | @Nullable
72 | public abstract ArrayList deals();
73 |
74 | @Nullable
75 | public abstract ArrayList giftCertificates();
76 |
77 | @Nullable
78 | public abstract Location location();
79 |
80 | @Nullable
81 | public abstract Double rating();
82 |
83 | @Nullable
84 | public abstract String ratingImgUrl();
85 |
86 | @Nullable
87 | public abstract String ratingImgUrlLarge();
88 |
89 | @Nullable
90 | public abstract String ratingImgUrlSmall();
91 |
92 | @Nullable
93 | public abstract ArrayList reviews();
94 |
95 | @AutoValue.Builder
96 | @JsonPOJOBuilder(withPrefix = "")
97 | @JsonNaming(PropertyNamingStrategy.LowerCaseWithUnderscoresStrategy.class)
98 | public abstract static class Builder {
99 |
100 | public abstract Builder categories(ArrayList categories);
101 |
102 | public abstract Builder displayPhone(String displayPhone);
103 |
104 | public abstract Builder distance(Double distance);
105 |
106 | public abstract Builder eat24Url(String eat24Url);
107 |
108 | public abstract Builder id(String id);
109 |
110 | public abstract Builder imageUrl(String imageUrl);
111 |
112 | public abstract Builder isClaimed(Boolean isClaimed);
113 |
114 | public abstract Builder isClosed(Boolean isClosed);
115 |
116 | public abstract Builder menuProvider(String menuProvider);
117 |
118 | public abstract Builder menuDateUpdated(Long menuDateUpdated);
119 |
120 | public abstract Builder mobileUrl(String mobileUrl);
121 |
122 | public abstract Builder name(String name);
123 |
124 | public abstract Builder phone(String phone);
125 |
126 | public abstract Builder reservationUrl(String reservationUrl);
127 |
128 | public abstract Builder reviewCount(Integer reviewCount);
129 |
130 | public abstract Builder snippetImageUrl(String snippetImageUrl);
131 |
132 | public abstract Builder snippetText(String snippetText);
133 |
134 | public abstract Builder url(String url);
135 |
136 | public abstract Builder deals(ArrayList deals);
137 |
138 | public abstract Builder giftCertificates(ArrayList giftCertificates);
139 |
140 | public abstract Builder location(Location location);
141 |
142 | public abstract Builder rating(Double ratingScore);
143 |
144 | public abstract Builder ratingImgUrl(String ratingImgUrl);
145 |
146 | public abstract Builder ratingImgUrlLarge(String ratingImgUrlLarge);
147 |
148 | public abstract Builder ratingImgUrlSmall(String ratingImgUrlSmall);
149 |
150 | public abstract Builder reviews(ArrayList reviews);
151 |
152 | public abstract Business build();
153 | }
154 |
155 | public static Builder builder() {
156 | return new AutoValue_Business.Builder();
157 | }
158 | }
159 |
--------------------------------------------------------------------------------
/src/main/java/com/yelp/clientlib/entities/Category.java:
--------------------------------------------------------------------------------
1 | package com.yelp.clientlib.entities;
2 |
3 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
4 | import com.fasterxml.jackson.core.JsonParser;
5 | import com.fasterxml.jackson.core.JsonProcessingException;
6 | import com.fasterxml.jackson.databind.DeserializationContext;
7 | import com.fasterxml.jackson.databind.JsonDeserializer;
8 | import com.fasterxml.jackson.databind.JsonNode;
9 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
10 | import com.google.auto.value.AutoValue;
11 |
12 | import java.io.IOException;
13 | import java.io.Serializable;
14 |
15 | @AutoValue
16 | @JsonIgnoreProperties(ignoreUnknown = true)
17 | @JsonDeserialize(using = CategoryDeserializer.class)
18 | public abstract class Category implements Serializable{
19 |
20 | public abstract String alias();
21 |
22 | public abstract String name();
23 |
24 | @AutoValue.Builder
25 | public abstract static class Builder {
26 |
27 | public abstract Builder alias(String alias);
28 |
29 | public abstract Builder name(String name);
30 |
31 | public abstract Category build();
32 | }
33 |
34 | public static Builder builder() {
35 | return new AutoValue_Category.Builder();
36 | }
37 | }
38 |
39 | /**
40 | * Custom deserializer for Category. The JSON string returned for Category is formatted as an array like
41 | * "["Bar", "bar"]" which does not fit into the default Jackson object deserializer which expects "{" as the first
42 | * character.
43 | */
44 | class CategoryDeserializer extends JsonDeserializer {
45 | @Override
46 | public Category deserialize(JsonParser jsonParser, DeserializationContext context)
47 | throws IOException, JsonProcessingException {
48 | JsonNode node = jsonParser.getCodec().readTree(jsonParser);
49 | String name = node.get(0).textValue();
50 | String alias = node.get(1).textValue();
51 |
52 | return Category.builder().name(name).alias(alias).build();
53 | }
54 | }
55 |
56 |
--------------------------------------------------------------------------------
/src/main/java/com/yelp/clientlib/entities/Coordinate.java:
--------------------------------------------------------------------------------
1 | package com.yelp.clientlib.entities;
2 |
3 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
4 | import com.fasterxml.jackson.databind.PropertyNamingStrategy;
5 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
6 | import com.fasterxml.jackson.databind.annotation.JsonNaming;
7 | import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder;
8 | import com.google.auto.value.AutoValue;
9 |
10 | import java.io.Serializable;
11 |
12 | @AutoValue
13 | @JsonIgnoreProperties(ignoreUnknown = true)
14 | @JsonDeserialize(builder = AutoValue_Coordinate.Builder.class)
15 | public abstract class Coordinate implements Serializable {
16 |
17 | public abstract Double latitude();
18 |
19 | public abstract Double longitude();
20 |
21 | @AutoValue.Builder
22 | @JsonPOJOBuilder(withPrefix = "")
23 | @JsonNaming(PropertyNamingStrategy.LowerCaseWithUnderscoresStrategy.class)
24 | public abstract static class Builder {
25 |
26 | public abstract Builder latitude(Double latitude);
27 |
28 | public abstract Builder longitude(Double longitude);
29 |
30 | public abstract Coordinate build();
31 | }
32 |
33 | public static Builder builder() {
34 | return new AutoValue_Coordinate.Builder();
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/main/java/com/yelp/clientlib/entities/Deal.java:
--------------------------------------------------------------------------------
1 | package com.yelp.clientlib.entities;
2 |
3 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
4 | import com.fasterxml.jackson.databind.PropertyNamingStrategy;
5 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
6 | import com.fasterxml.jackson.databind.annotation.JsonNaming;
7 | import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder;
8 | import com.google.auto.value.AutoValue;
9 | import com.yelp.clientlib.annotation.Nullable;
10 |
11 | import java.io.Serializable;
12 | import java.util.ArrayList;
13 |
14 | @AutoValue
15 | @JsonIgnoreProperties(ignoreUnknown = true)
16 | @JsonDeserialize(builder = AutoValue_Deal.Builder.class)
17 | public abstract class Deal implements Serializable {
18 |
19 | @Nullable
20 | public abstract String additionalRestrictions();
21 |
22 | @Nullable
23 | public abstract String currencyCode();
24 |
25 | @Nullable
26 | public abstract String id();
27 |
28 | @Nullable
29 | public abstract String imageUrl();
30 |
31 | @Nullable
32 | public abstract String importantRestrictions();
33 |
34 | @Nullable
35 | public abstract Boolean isPopular();
36 |
37 | @Nullable
38 | public abstract ArrayList options();
39 |
40 | @Nullable
41 | public abstract Long timeEnd();
42 |
43 | @Nullable
44 | public abstract Long timeStart();
45 |
46 | @Nullable
47 | public abstract String title();
48 |
49 | @Nullable
50 | public abstract String url();
51 |
52 | @Nullable
53 | public abstract String whatYouGet();
54 |
55 | @AutoValue.Builder
56 | @JsonPOJOBuilder(withPrefix = "")
57 | @JsonNaming(PropertyNamingStrategy.LowerCaseWithUnderscoresStrategy.class)
58 | public abstract static class Builder {
59 | public abstract Builder additionalRestrictions(String additionalRestrictions);
60 |
61 | public abstract Builder currencyCode(String currencyCode);
62 |
63 | public abstract Builder id(String id);
64 |
65 | public abstract Builder imageUrl(String imageUrl);
66 |
67 | public abstract Builder importantRestrictions(String importantRestrictions);
68 |
69 | public abstract Builder isPopular(Boolean isPopular);
70 |
71 | public abstract Builder options(ArrayList options);
72 |
73 | public abstract Builder timeEnd(Long timeEnd);
74 |
75 | public abstract Builder timeStart(Long timeStart);
76 |
77 | public abstract Builder title(String title);
78 |
79 | public abstract Builder url(String url);
80 |
81 | public abstract Builder whatYouGet(String whatYouGet);
82 |
83 | public abstract Deal build();
84 | }
85 |
86 | public static Builder builder() {
87 | return new AutoValue_Deal.Builder();
88 | }
89 | }
90 |
--------------------------------------------------------------------------------
/src/main/java/com/yelp/clientlib/entities/DealOption.java:
--------------------------------------------------------------------------------
1 | package com.yelp.clientlib.entities;
2 |
3 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
4 | import com.fasterxml.jackson.databind.PropertyNamingStrategy;
5 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
6 | import com.fasterxml.jackson.databind.annotation.JsonNaming;
7 | import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder;
8 | import com.google.auto.value.AutoValue;
9 | import com.yelp.clientlib.annotation.Nullable;
10 |
11 | import java.io.Serializable;
12 |
13 | @AutoValue
14 | @JsonIgnoreProperties(ignoreUnknown = true)
15 | @JsonDeserialize(builder = AutoValue_DealOption.Builder.class)
16 | public abstract class DealOption implements Serializable {
17 |
18 | @Nullable
19 | public abstract String formattedOriginalPrice();
20 |
21 | @Nullable
22 | public abstract String formattedPrice();
23 |
24 | @Nullable
25 | public abstract Boolean isQuantityLimited();
26 |
27 | @Nullable
28 | public abstract Integer originalPrice();
29 |
30 | @Nullable
31 | public abstract Integer price();
32 |
33 | @Nullable
34 | public abstract String purchaseUrl();
35 |
36 | @Nullable
37 | public abstract Integer remainingCount();
38 |
39 | @Nullable
40 | public abstract String title();
41 |
42 | @AutoValue.Builder
43 | @JsonPOJOBuilder(withPrefix = "")
44 | @JsonNaming(PropertyNamingStrategy.LowerCaseWithUnderscoresStrategy.class)
45 | public abstract static class Builder {
46 |
47 | public abstract Builder formattedOriginalPrice(String formattedOriginalPrice);
48 |
49 | public abstract Builder formattedPrice(String formattedPrice);
50 |
51 | public abstract Builder isQuantityLimited(Boolean isQuantityLimited);
52 |
53 | public abstract Builder originalPrice(Integer originalPrice);
54 |
55 | public abstract Builder price(Integer price);
56 |
57 | public abstract Builder purchaseUrl(String purchaseUrl);
58 |
59 | public abstract Builder remainingCount(Integer remainingCount);
60 |
61 | public abstract Builder title(String title);
62 |
63 | public abstract DealOption build();
64 | }
65 |
66 | public static Builder builder() {
67 | return new AutoValue_DealOption.Builder();
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/src/main/java/com/yelp/clientlib/entities/GiftCertificate.java:
--------------------------------------------------------------------------------
1 | package com.yelp.clientlib.entities;
2 |
3 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
4 | import com.fasterxml.jackson.databind.PropertyNamingStrategy;
5 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
6 | import com.fasterxml.jackson.databind.annotation.JsonNaming;
7 | import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder;
8 | import com.google.auto.value.AutoValue;
9 | import com.yelp.clientlib.annotation.Nullable;
10 |
11 | import java.io.Serializable;
12 | import java.util.ArrayList;
13 |
14 | @AutoValue
15 | @JsonIgnoreProperties(ignoreUnknown = true)
16 | @JsonDeserialize(builder = AutoValue_GiftCertificate.Builder.class)
17 | public abstract class GiftCertificate implements Serializable {
18 |
19 | public abstract String id();
20 |
21 | @Nullable
22 | public abstract String currencyCode();
23 |
24 | @Nullable
25 | public abstract String imageUrl();
26 |
27 | @Nullable
28 | public abstract String unusedBalances();
29 |
30 | @Nullable
31 | public abstract String url();
32 |
33 | @Nullable
34 | public abstract ArrayList options();
35 |
36 | @AutoValue.Builder
37 | @JsonPOJOBuilder(withPrefix = "")
38 | @JsonNaming(PropertyNamingStrategy.LowerCaseWithUnderscoresStrategy.class)
39 | public abstract static class Builder {
40 |
41 | public abstract Builder currencyCode(String currencyCode);
42 |
43 | public abstract Builder id(String id);
44 |
45 | public abstract Builder imageUrl(String imageUrl);
46 |
47 | public abstract Builder unusedBalances(String unusedBalanced);
48 |
49 | public abstract Builder url(String url);
50 |
51 | public abstract Builder options(ArrayList options);
52 |
53 | public abstract GiftCertificate build();
54 | }
55 |
56 | public static Builder builder() {
57 | return new AutoValue_GiftCertificate.Builder();
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/src/main/java/com/yelp/clientlib/entities/GiftCertificateOption.java:
--------------------------------------------------------------------------------
1 | package com.yelp.clientlib.entities;
2 |
3 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
4 | import com.fasterxml.jackson.databind.PropertyNamingStrategy;
5 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
6 | import com.fasterxml.jackson.databind.annotation.JsonNaming;
7 | import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder;
8 | import com.google.auto.value.AutoValue;
9 | import com.yelp.clientlib.annotation.Nullable;
10 |
11 | import java.io.Serializable;
12 |
13 | @AutoValue
14 | @JsonIgnoreProperties(ignoreUnknown = true)
15 | @JsonDeserialize(builder = AutoValue_GiftCertificateOption.Builder.class)
16 | public abstract class GiftCertificateOption implements Serializable {
17 |
18 | @Nullable
19 | public abstract String formattedPrice();
20 |
21 | @Nullable
22 | public abstract Integer price();
23 |
24 | @AutoValue.Builder
25 | @JsonPOJOBuilder(withPrefix = "")
26 | @JsonNaming(PropertyNamingStrategy.LowerCaseWithUnderscoresStrategy.class)
27 | public abstract static class Builder {
28 |
29 | public abstract Builder formattedPrice(String formattedPrice);
30 |
31 | public abstract Builder price(Integer price);
32 |
33 | public abstract GiftCertificateOption build();
34 | }
35 |
36 | public static Builder builder() {
37 | return new AutoValue_GiftCertificateOption.Builder();
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/src/main/java/com/yelp/clientlib/entities/Location.java:
--------------------------------------------------------------------------------
1 | package com.yelp.clientlib.entities;
2 |
3 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
4 | import com.fasterxml.jackson.databind.PropertyNamingStrategy;
5 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
6 | import com.fasterxml.jackson.databind.annotation.JsonNaming;
7 | import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder;
8 | import com.google.auto.value.AutoValue;
9 | import com.yelp.clientlib.annotation.Nullable;
10 |
11 | import java.io.Serializable;
12 | import java.util.ArrayList;
13 |
14 | @AutoValue
15 | @JsonIgnoreProperties(ignoreUnknown = true)
16 | @JsonDeserialize(builder = AutoValue_Location.Builder.class)
17 | public abstract class Location implements Serializable {
18 |
19 | @Nullable
20 | public abstract ArrayList address();
21 |
22 | @Nullable
23 | public abstract String city();
24 |
25 | @Nullable
26 | public abstract Coordinate coordinate();
27 |
28 | @Nullable
29 | public abstract String countryCode();
30 |
31 | @Nullable
32 | public abstract String crossStreets();
33 |
34 | @Nullable
35 | public abstract ArrayList displayAddress();
36 |
37 | @Nullable
38 | public abstract Double geoAccuracy();
39 |
40 | @Nullable
41 | public abstract ArrayList neighborhoods();
42 |
43 | @Nullable
44 | public abstract String postalCode();
45 |
46 | @Nullable
47 | public abstract String stateCode();
48 |
49 | @AutoValue.Builder
50 | @JsonPOJOBuilder(withPrefix = "")
51 | @JsonNaming(PropertyNamingStrategy.LowerCaseWithUnderscoresStrategy.class)
52 | public abstract static class Builder {
53 |
54 | public abstract Builder address(ArrayList address);
55 |
56 | public abstract Builder city(String city);
57 |
58 | public abstract Builder coordinate(Coordinate coordinate);
59 |
60 | public abstract Builder countryCode(String countryCode);
61 |
62 | public abstract Builder crossStreets(String crossStreets);
63 |
64 | public abstract Builder displayAddress(ArrayList displayAddress);
65 |
66 | public abstract Builder geoAccuracy(Double geoAccuracy);
67 |
68 | public abstract Builder neighborhoods(ArrayList neighborhoods);
69 |
70 | public abstract Builder postalCode(String postalCode);
71 |
72 | public abstract Builder stateCode(String stateCode);
73 |
74 | public abstract Location build();
75 | }
76 |
77 | public static Builder builder() {
78 | return new AutoValue_Location.Builder();
79 | }
80 | }
81 |
--------------------------------------------------------------------------------
/src/main/java/com/yelp/clientlib/entities/Region.java:
--------------------------------------------------------------------------------
1 | package com.yelp.clientlib.entities;
2 |
3 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
4 | import com.fasterxml.jackson.databind.PropertyNamingStrategy;
5 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
6 | import com.fasterxml.jackson.databind.annotation.JsonNaming;
7 | import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder;
8 | import com.google.auto.value.AutoValue;
9 |
10 | import java.io.Serializable;
11 |
12 | @AutoValue
13 | @JsonIgnoreProperties(ignoreUnknown = true)
14 | @JsonDeserialize(builder = AutoValue_Region.Builder.class)
15 | public abstract class Region implements Serializable {
16 |
17 | public abstract Coordinate center();
18 |
19 | public abstract Span span();
20 |
21 | @AutoValue.Builder
22 | @JsonPOJOBuilder(withPrefix = "")
23 | @JsonNaming(PropertyNamingStrategy.LowerCaseWithUnderscoresStrategy.class)
24 | public abstract static class Builder {
25 |
26 | public abstract Builder center(Coordinate center);
27 |
28 | public abstract Builder span(Span span);
29 |
30 | public abstract Region build();
31 | }
32 |
33 | public static Builder builder() {
34 | return new AutoValue_Region.Builder();
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/main/java/com/yelp/clientlib/entities/Review.java:
--------------------------------------------------------------------------------
1 | package com.yelp.clientlib.entities;
2 |
3 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
4 | import com.fasterxml.jackson.databind.PropertyNamingStrategy;
5 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
6 | import com.fasterxml.jackson.databind.annotation.JsonNaming;
7 | import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder;
8 | import com.google.auto.value.AutoValue;
9 | import com.yelp.clientlib.annotation.Nullable;
10 |
11 | import java.io.Serializable;
12 |
13 | @AutoValue
14 | @JsonIgnoreProperties(ignoreUnknown = true)
15 | @JsonDeserialize(builder = AutoValue_Review.Builder.class)
16 | public abstract class Review implements Serializable {
17 |
18 | public abstract String id();
19 |
20 | @Nullable
21 | public abstract String excerpt();
22 |
23 | @Nullable
24 | public abstract Double rating();
25 |
26 | @Nullable
27 | public abstract String ratingImageUrl();
28 |
29 | @Nullable
30 | public abstract String ratingImageLargeUrl();
31 |
32 | @Nullable
33 | public abstract String ratingImageSmallUrl();
34 |
35 | @Nullable
36 | public abstract Long timeCreated();
37 |
38 | @Nullable
39 | public abstract User user();
40 |
41 | @AutoValue.Builder
42 | @JsonPOJOBuilder(withPrefix = "")
43 | @JsonNaming(PropertyNamingStrategy.LowerCaseWithUnderscoresStrategy.class)
44 | public abstract static class Builder {
45 |
46 | public abstract Builder excerpt(String excerpt);
47 |
48 | public abstract Builder id(String id);
49 |
50 | public abstract Builder rating(Double rating);
51 |
52 | public abstract Builder ratingImageUrl(String ratingImageUrl);
53 |
54 | public abstract Builder ratingImageLargeUrl(String ratingImageLargeUrl);
55 |
56 | public abstract Builder ratingImageSmallUrl(String ratingImageSmallUrl);
57 |
58 | public abstract Builder timeCreated(Long timeCreated);
59 |
60 | public abstract Builder user(User user);
61 |
62 | public abstract Review build();
63 | }
64 |
65 | public static Builder builder() {
66 | return new AutoValue_Review.Builder();
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/src/main/java/com/yelp/clientlib/entities/SearchResponse.java:
--------------------------------------------------------------------------------
1 | package com.yelp.clientlib.entities;
2 |
3 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
4 | import com.fasterxml.jackson.databind.PropertyNamingStrategy;
5 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
6 | import com.fasterxml.jackson.databind.annotation.JsonNaming;
7 | import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder;
8 | import com.google.auto.value.AutoValue;
9 | import com.yelp.clientlib.annotation.Nullable;
10 |
11 | import java.io.Serializable;
12 | import java.util.ArrayList;
13 |
14 | @AutoValue
15 | @JsonIgnoreProperties(ignoreUnknown = true)
16 | @JsonDeserialize(builder = AutoValue_SearchResponse.Builder.class)
17 | public abstract class SearchResponse implements Serializable {
18 |
19 | public abstract ArrayList businesses();
20 |
21 | @Nullable
22 | public abstract Region region();
23 |
24 | public abstract Integer total();
25 |
26 | @AutoValue.Builder
27 | @JsonPOJOBuilder(withPrefix = "")
28 | @JsonNaming(PropertyNamingStrategy.LowerCaseWithUnderscoresStrategy.class)
29 | public abstract static class Builder {
30 |
31 | public abstract Builder businesses(ArrayList businesses);
32 |
33 | public abstract Builder region(Region region);
34 |
35 | public abstract Builder total(Integer total);
36 |
37 | public abstract SearchResponse build();
38 | }
39 |
40 | public static Builder builder() {
41 | return new AutoValue_SearchResponse.Builder();
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/src/main/java/com/yelp/clientlib/entities/Span.java:
--------------------------------------------------------------------------------
1 | package com.yelp.clientlib.entities;
2 |
3 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
4 | import com.fasterxml.jackson.databind.PropertyNamingStrategy;
5 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
6 | import com.fasterxml.jackson.databind.annotation.JsonNaming;
7 | import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder;
8 | import com.google.auto.value.AutoValue;
9 |
10 | import java.io.Serializable;
11 |
12 | @AutoValue
13 | @JsonIgnoreProperties(ignoreUnknown = true)
14 | @JsonDeserialize(builder = AutoValue_Span.Builder.class)
15 | public abstract class Span implements Serializable {
16 |
17 | public abstract Double latitudeDelta();
18 |
19 | public abstract Double longitudeDelta();
20 |
21 | @AutoValue.Builder
22 | @JsonPOJOBuilder(withPrefix = "")
23 | @JsonNaming(PropertyNamingStrategy.LowerCaseWithUnderscoresStrategy.class)
24 | public abstract static class Builder {
25 |
26 | public abstract Builder latitudeDelta(Double latitudeDelta);
27 |
28 | public abstract Builder longitudeDelta(Double longitudeDelta);
29 |
30 | public abstract Span build();
31 | }
32 |
33 | public static Builder builder() {
34 | return new AutoValue_Span.Builder();
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/main/java/com/yelp/clientlib/entities/User.java:
--------------------------------------------------------------------------------
1 | package com.yelp.clientlib.entities;
2 |
3 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
4 | import com.fasterxml.jackson.databind.PropertyNamingStrategy;
5 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
6 | import com.fasterxml.jackson.databind.annotation.JsonNaming;
7 | import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder;
8 | import com.google.auto.value.AutoValue;
9 | import com.yelp.clientlib.annotation.Nullable;
10 |
11 | import java.io.Serializable;
12 |
13 | @AutoValue
14 | @JsonIgnoreProperties(ignoreUnknown = true)
15 | @JsonDeserialize(builder = AutoValue_User.Builder.class)
16 | public abstract class User implements Serializable {
17 |
18 | public abstract String id();
19 |
20 | @Nullable
21 | public abstract String imageUrl();
22 |
23 | @Nullable
24 | public abstract String name();
25 |
26 | @AutoValue.Builder
27 | @JsonPOJOBuilder(withPrefix = "")
28 | @JsonNaming(PropertyNamingStrategy.LowerCaseWithUnderscoresStrategy.class)
29 | public abstract static class Builder {
30 |
31 | public abstract Builder id(String id);
32 |
33 | public abstract Builder imageUrl(String imageUrl);
34 |
35 | public abstract Builder name(String name);
36 |
37 | public abstract User build();
38 | }
39 |
40 | public static Builder builder() {
41 | return new AutoValue_User.Builder();
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/src/main/java/com/yelp/clientlib/entities/options/BoundingBoxOptions.java:
--------------------------------------------------------------------------------
1 | package com.yelp.clientlib.entities.options;
2 |
3 | import com.google.auto.value.AutoValue;
4 |
5 | import java.util.Locale;
6 |
7 | @AutoValue
8 | public abstract class BoundingBoxOptions {
9 |
10 | /**
11 | * @return Southwest latitude of bounding box.
12 | */
13 | public abstract Double swLatitude();
14 |
15 | /**
16 | * @return Southwest longitude of bounding box.
17 | */
18 | public abstract Double swLongitude();
19 |
20 | /**
21 | * @return Northeast latitude of bounding box.
22 | */
23 | public abstract Double neLatitude();
24 |
25 | /**
26 | * @return Northeast longitude of bounding box.
27 | */
28 | public abstract Double neLongitude();
29 |
30 | /**
31 | * String presentation for {@link BoundingBoxOptions}. The generated string is encoded as
32 | * "swLatitude,swLongitude%7CneLatitude,neLongitude". This method is used by {@link retrofit2.http.Query} to
33 | * generate the values of query parameters.
34 | *
35 | * BoundingBox query param value contains non-suggested URI character '|' which doesn't fit into most of the
36 | * signature functions, we encode it here into "%7C" so it's not passed through http client.
37 | *
38 | * @return String presentation for {@link BoundingBoxOptions}
39 | * @see https://www.yelp.com/developers/documentation/v2/search_api#searchGBB
40 | */
41 | @Override
42 | public String toString() {
43 | return String.format(
44 | Locale.getDefault(),
45 | "%f,%f%%7C%f,%f", swLatitude(), swLongitude(), neLatitude(), neLongitude()
46 | );
47 | }
48 |
49 | @AutoValue.Builder
50 | public abstract static class Builder {
51 |
52 | /**
53 | * @param latitude Sets southwest latitude.
54 | *
55 | * @return this
56 | */
57 | public abstract Builder swLatitude(Double latitude);
58 |
59 | /**
60 | * @param longitude Sets southwest longitude.
61 | *
62 | * @return this
63 | */
64 | public abstract Builder swLongitude(Double longitude);
65 |
66 | /**
67 | * @param latitude Sets northeast latitude.
68 | *
69 | * @return this
70 | */
71 | public abstract Builder neLatitude(Double latitude);
72 |
73 | /**
74 | * @param longitude Sets northeast longitude.
75 | *
76 | * @return this
77 | */
78 | public abstract Builder neLongitude(Double longitude);
79 |
80 | /**
81 | * Returns a reference to the object of {@link BoundingBoxOptions} being constructed by the builder.
82 | *
83 | * @return the {@link BoundingBoxOptions} constructed by the builder.
84 | */
85 | public abstract BoundingBoxOptions build();
86 | }
87 |
88 | public static Builder builder() {
89 | return new AutoValue_BoundingBoxOptions.Builder();
90 | }
91 | }
92 |
--------------------------------------------------------------------------------
/src/main/java/com/yelp/clientlib/entities/options/CoordinateOptions.java:
--------------------------------------------------------------------------------
1 | package com.yelp.clientlib.entities.options;
2 |
3 | import com.google.auto.value.AutoValue;
4 | import com.yelp.clientlib.annotation.Nullable;
5 |
6 | @AutoValue
7 | public abstract class CoordinateOptions {
8 |
9 | /**
10 | * @return Latitude of geo-point to search near.
11 | */
12 | public abstract Double latitude();
13 |
14 | /**
15 | * @return Longitude of geo-point to search near.
16 | */
17 | public abstract Double longitude();
18 |
19 | /**
20 | * @return Optional accuracy of latitude, longitude.
21 | */
22 | @Nullable
23 | public abstract Double accuracy();
24 |
25 | /**
26 | * @return Optional altitude of geo-point to search near.
27 | */
28 | @Nullable
29 | public abstract Double altitude();
30 |
31 | /**
32 | * @return Optional accuracy of altitude.
33 | */
34 | @Nullable
35 | public abstract Double altitudeAccuracy();
36 |
37 | /**
38 | * String presentation for {@code CoordinateOptions}. The generated string is comma separated. It is encoded in the
39 | * order of latitude, longitude, accuracy, altitude and altitudeAccuracy. This method is used by {@code retrofit
40 | * .http.QueryMap} to generate the values of query parameters.
41 | *
42 | * @return String presentation for {@code CoordinateOptions}
43 | */
44 | @Override
45 | public String toString() {
46 | Double[] optionalFields = new Double[]{accuracy(), altitude(), altitudeAccuracy()};
47 |
48 | String coordinate = latitude() + "," + longitude();
49 | for (Double field : optionalFields) {
50 | coordinate = String.format("%s,%s", coordinate, (field == null) ? "" : field.toString());
51 | }
52 |
53 | return coordinate;
54 | }
55 |
56 | @AutoValue.Builder
57 | public abstract static class Builder {
58 |
59 | /**
60 | * @param latitude Sets latitude.
61 | *
62 | * @return this
63 | */
64 | public abstract Builder latitude(Double latitude);
65 |
66 | /**
67 | * @param longitude Sets longitude.
68 | *
69 | * @return this
70 | */
71 | public abstract Builder longitude(Double longitude);
72 |
73 | /**
74 | * @param accuracy Sets accuracy of latitude, longitude.
75 | *
76 | * @return this
77 | */
78 | public abstract Builder accuracy(Double accuracy);
79 |
80 | /**
81 | * @param altitude Sets altitude.
82 | *
83 | * @return this
84 | */
85 | public abstract Builder altitude(Double altitude);
86 |
87 | /**
88 | * @param altitudeAccuracy Sets accuracy of altitude.
89 | *
90 | * @return this
91 | */
92 | public abstract Builder altitudeAccuracy(Double altitudeAccuracy);
93 |
94 | /**
95 | * Returns a reference to the object of {@code CoordinateOptions} being constructed by the builder.
96 | *
97 | * @return the {@code CoordinateOptions} constructed by the builder.
98 | */
99 | public abstract CoordinateOptions build();
100 | }
101 |
102 | public static Builder builder() {
103 | return new AutoValue_CoordinateOptions.Builder();
104 | }
105 | }
106 |
--------------------------------------------------------------------------------
/src/main/java/com/yelp/clientlib/exception/ErrorHandlingInterceptor.java:
--------------------------------------------------------------------------------
1 | package com.yelp.clientlib.exception;
2 |
3 | import com.fasterxml.jackson.databind.JsonNode;
4 | import com.fasterxml.jackson.databind.ObjectMapper;
5 | import okhttp3.Interceptor;
6 | import okhttp3.Response;
7 | import com.yelp.clientlib.exception.exceptions.AreaTooLarge;
8 | import com.yelp.clientlib.exception.exceptions.BadCategory;
9 | import com.yelp.clientlib.exception.exceptions.BusinessUnavailable;
10 | import com.yelp.clientlib.exception.exceptions.ExceededReqs;
11 | import com.yelp.clientlib.exception.exceptions.InternalError;
12 | import com.yelp.clientlib.exception.exceptions.InvalidOAuthCredentials;
13 | import com.yelp.clientlib.exception.exceptions.InvalidOAuthUser;
14 | import com.yelp.clientlib.exception.exceptions.InvalidParameter;
15 | import com.yelp.clientlib.exception.exceptions.InvalidSignature;
16 | import com.yelp.clientlib.exception.exceptions.MissingParameter;
17 | import com.yelp.clientlib.exception.exceptions.MultipleLocations;
18 | import com.yelp.clientlib.exception.exceptions.SSLRequired;
19 | import com.yelp.clientlib.exception.exceptions.UnavailableForLocation;
20 | import com.yelp.clientlib.exception.exceptions.UnexpectedAPIError;
21 | import com.yelp.clientlib.exception.exceptions.UnspecifiedLocation;
22 | import com.yelp.clientlib.exception.exceptions.YelpAPIError;
23 |
24 | import java.io.IOException;
25 |
26 | /**
27 | * {@link Interceptor} to parse and transform the HTTP errors.
28 | */
29 | public class ErrorHandlingInterceptor implements Interceptor {
30 |
31 | private static final ObjectMapper objectMapper = new ObjectMapper();
32 |
33 | /**
34 | * Intercept HTTP responses and raise a {@link YelpAPIError} if the response code is not 2xx.
35 | *
36 | * @param chain {@link okhttp3.Interceptor.Chain} object for sending the HTTP request.
37 | * @return response
38 | * @throws IOException {@link YelpAPIError} generated depends on the response error id.
39 | */
40 | @Override
41 | public Response intercept(Chain chain) throws IOException {
42 | Response response = chain.proceed(chain.request());
43 |
44 | if (!response.isSuccessful()) {
45 | throw parseError(
46 | response.code(),
47 | response.message(),
48 | response.body() != null ? response.body().string() : null
49 | );
50 | }
51 | return response;
52 | }
53 |
54 | private YelpAPIError parseError(int code, String message, String responseBody) throws IOException {
55 | if (responseBody == null) {
56 | return new UnexpectedAPIError(code, message);
57 | }
58 |
59 | JsonNode errorJsonNode = objectMapper.readTree(responseBody).path("error");
60 | String errorId = errorJsonNode.path("id").asText();
61 | String errorText = errorJsonNode.path("text").asText();
62 |
63 | if (errorJsonNode.has("field")) {
64 | errorText += ": " + errorJsonNode.path("field").asText();
65 | }
66 |
67 | switch (errorId) {
68 | case "AREA_TOO_LARGE":
69 | return new AreaTooLarge(code, message, errorId, errorText);
70 | case "BAD_CATEGORY":
71 | return new BadCategory(code, message, errorId, errorText);
72 | case "BUSINESS_UNAVAILABLE":
73 | return new BusinessUnavailable(code, message, errorId, errorText);
74 | case "EXCEEDED_REQS":
75 | return new ExceededReqs(code, message, errorId, errorText);
76 | case "INTERNAL_ERROR":
77 | return new InternalError(code, message, errorId, errorText);
78 | case "INVALID_OAUTH_CREDENTIALS":
79 | return new InvalidOAuthCredentials(code, message, errorId, errorText);
80 | case "INVALID_OAUTH_USER":
81 | return new InvalidOAuthUser(code, message, errorId, errorText);
82 | case "INVALID_PARAMETER":
83 | return new InvalidParameter(code, message, errorId, errorText);
84 | case "INVALID_SIGNATURE":
85 | return new InvalidSignature(code, message, errorId, errorText);
86 | case "MISSING_PARAMETER":
87 | return new MissingParameter(code, message, errorId, errorText);
88 | case "MULTIPLE_LOCATIONS":
89 | return new MultipleLocations(code, message, errorId, errorText);
90 | case "SSL_REQUIRED":
91 | return new SSLRequired(code, message, errorId, errorText);
92 | case "UNAVAILABLE_FOR_LOCATION":
93 | return new UnavailableForLocation(code, message, errorId, errorText);
94 | case "UNSPECIFIED_LOCATION":
95 | return new UnspecifiedLocation(code, message, errorId, errorText);
96 | default:
97 | return new UnexpectedAPIError(code, message, errorId, errorText);
98 | }
99 | }
100 | }
101 |
--------------------------------------------------------------------------------
/src/main/java/com/yelp/clientlib/exception/exceptions/AreaTooLarge.java:
--------------------------------------------------------------------------------
1 | package com.yelp.clientlib.exception.exceptions;
2 |
3 | public class AreaTooLarge extends YelpAPIError {
4 | public AreaTooLarge(int code, String message, String id, String text) {
5 | super(code, message, id, text);
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/src/main/java/com/yelp/clientlib/exception/exceptions/BadCategory.java:
--------------------------------------------------------------------------------
1 | package com.yelp.clientlib.exception.exceptions;
2 |
3 | public class BadCategory extends YelpAPIError {
4 | public BadCategory(int code, String message, String id, String text) {
5 | super(code, message, id, text);
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/src/main/java/com/yelp/clientlib/exception/exceptions/BusinessUnavailable.java:
--------------------------------------------------------------------------------
1 | package com.yelp.clientlib.exception.exceptions;
2 |
3 | public class BusinessUnavailable extends YelpAPIError {
4 | public BusinessUnavailable(int code, String message, String id, String text) {
5 | super(code, message, id, text);
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/src/main/java/com/yelp/clientlib/exception/exceptions/ExceededReqs.java:
--------------------------------------------------------------------------------
1 | package com.yelp.clientlib.exception.exceptions;
2 |
3 | public class ExceededReqs extends YelpAPIError {
4 | public ExceededReqs(int code, String message, String id, String text) {
5 | super(code, message, id, text);
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/src/main/java/com/yelp/clientlib/exception/exceptions/InternalError.java:
--------------------------------------------------------------------------------
1 | package com.yelp.clientlib.exception.exceptions;
2 |
3 | public class InternalError extends YelpAPIError {
4 | public InternalError(int code, String message, String id, String text) {
5 | super(code, message, id, text);
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/src/main/java/com/yelp/clientlib/exception/exceptions/InvalidOAuthCredentials.java:
--------------------------------------------------------------------------------
1 | package com.yelp.clientlib.exception.exceptions;
2 |
3 | public class InvalidOAuthCredentials extends YelpAPIError {
4 | public InvalidOAuthCredentials(int code, String message, String id, String text) {
5 | super(code, message, id, text);
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/src/main/java/com/yelp/clientlib/exception/exceptions/InvalidOAuthUser.java:
--------------------------------------------------------------------------------
1 | package com.yelp.clientlib.exception.exceptions;
2 |
3 | public class InvalidOAuthUser extends YelpAPIError {
4 | public InvalidOAuthUser(int code, String message, String id, String text) {
5 | super(code, message, id, text);
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/src/main/java/com/yelp/clientlib/exception/exceptions/InvalidParameter.java:
--------------------------------------------------------------------------------
1 | package com.yelp.clientlib.exception.exceptions;
2 |
3 | public class InvalidParameter extends YelpAPIError {
4 | public InvalidParameter(int code, String message, String id, String text) {
5 | super(code, message, id, text);
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/src/main/java/com/yelp/clientlib/exception/exceptions/InvalidSignature.java:
--------------------------------------------------------------------------------
1 | package com.yelp.clientlib.exception.exceptions;
2 |
3 | public class InvalidSignature extends YelpAPIError {
4 | public InvalidSignature(int code, String message, String id, String text) {
5 | super(code, message, id, text);
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/src/main/java/com/yelp/clientlib/exception/exceptions/MissingParameter.java:
--------------------------------------------------------------------------------
1 | package com.yelp.clientlib.exception.exceptions;
2 |
3 | public class MissingParameter extends YelpAPIError {
4 | public MissingParameter(int code, String message, String id, String text) {
5 | super(code, message, id, text);
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/src/main/java/com/yelp/clientlib/exception/exceptions/MultipleLocations.java:
--------------------------------------------------------------------------------
1 | package com.yelp.clientlib.exception.exceptions;
2 |
3 | public class MultipleLocations extends YelpAPIError {
4 | public MultipleLocations(int code, String message, String id, String text) {
5 | super(code, message, id, text);
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/src/main/java/com/yelp/clientlib/exception/exceptions/SSLRequired.java:
--------------------------------------------------------------------------------
1 | package com.yelp.clientlib.exception.exceptions;
2 |
3 | public class SSLRequired extends YelpAPIError {
4 | public SSLRequired(int code, String message, String id, String text) {
5 | super(code, message, id, text);
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/src/main/java/com/yelp/clientlib/exception/exceptions/UnavailableForLocation.java:
--------------------------------------------------------------------------------
1 | package com.yelp.clientlib.exception.exceptions;
2 |
3 | public class UnavailableForLocation extends YelpAPIError {
4 | public UnavailableForLocation(int code, String message, String id, String text) {
5 | super(code, message, id, text);
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/src/main/java/com/yelp/clientlib/exception/exceptions/UnexpectedAPIError.java:
--------------------------------------------------------------------------------
1 | package com.yelp.clientlib.exception.exceptions;
2 |
3 | public class UnexpectedAPIError extends YelpAPIError {
4 | public UnexpectedAPIError(int code, String message) {
5 | this(code, message, null, null);
6 | }
7 |
8 | public UnexpectedAPIError(int code, String message, String id, String text) {
9 | super(code, message, id, text);
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/src/main/java/com/yelp/clientlib/exception/exceptions/UnspecifiedLocation.java:
--------------------------------------------------------------------------------
1 | package com.yelp.clientlib.exception.exceptions;
2 |
3 | public class UnspecifiedLocation extends YelpAPIError {
4 | public UnspecifiedLocation(int code, String message, String id, String text) {
5 | super(code, message, id, text);
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/src/main/java/com/yelp/clientlib/exception/exceptions/YelpAPIError.java:
--------------------------------------------------------------------------------
1 | package com.yelp.clientlib.exception.exceptions;
2 |
3 | import java.io.IOException;
4 |
5 | public abstract class YelpAPIError extends IOException {
6 | private int code;
7 | private String message;
8 | private String text;
9 | private String errorId;
10 |
11 | public int getCode() {
12 | return code;
13 | }
14 |
15 | @Override
16 | public String getMessage() {
17 | return message;
18 | }
19 |
20 | public String getText() {
21 | return text;
22 | }
23 |
24 | public String getErrorId() {
25 | return errorId;
26 | }
27 |
28 | public YelpAPIError(int code, String message, String errorId, String text) {
29 | this.code = code;
30 | this.message = message;
31 | this.errorId = errorId;
32 | this.text = text;
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/src/test/java/com/yelp/clientlib/connection/YelpAPITest.java:
--------------------------------------------------------------------------------
1 | package com.yelp.clientlib.connection;
2 |
3 | import com.fasterxml.jackson.databind.JsonNode;
4 | import okhttp3.mockwebserver.MockResponse;
5 | import okhttp3.mockwebserver.MockWebServer;
6 | import okhttp3.mockwebserver.RecordedRequest;
7 | import com.yelp.clientlib.entities.Business;
8 | import com.yelp.clientlib.utils.JsonTestUtils;
9 | import com.yelp.clientlib.entities.SearchResponse;
10 | import com.yelp.clientlib.entities.options.BoundingBoxOptions;
11 | import com.yelp.clientlib.entities.options.CoordinateOptions;
12 | import com.yelp.clientlib.exception.exceptions.BusinessUnavailable;
13 | import com.yelp.clientlib.utils.AsyncTestUtils;
14 | import com.yelp.clientlib.utils.ErrorTestUtils;
15 |
16 | import org.junit.After;
17 | import org.junit.Assert;
18 | import org.junit.Before;
19 | import org.junit.Test;
20 |
21 | import java.io.IOException;
22 | import java.util.ArrayList;
23 | import java.util.HashMap;
24 | import java.util.Map;
25 |
26 | import retrofit2.Call;
27 | import retrofit2.Callback;
28 | import retrofit2.Response;
29 |
30 | public class YelpAPITest {
31 | private MockWebServer mockServer;
32 | private YelpAPI yelpAPI;
33 | private JsonNode businessJsonNode;
34 | private JsonNode searchResponseJsonNode;
35 |
36 | @Before
37 | public void setup() throws IOException {
38 | mockServer = new MockWebServer();
39 | mockServer.start();
40 |
41 | // Use TestAPIFactory so the requests are sent to the mock web server.
42 | YelpAPIFactory yelpAPIFactory = new TestAPIFactory(
43 | "consumerKey",
44 | "consumerSecret",
45 | "token",
46 | "tokenSecret",
47 | mockServer.url("/").toString()
48 | );
49 |
50 | // Make API requests to be executed in main thread so we can verify it easily.
51 | yelpAPIFactory = AsyncTestUtils.setToRunInMainThread(yelpAPIFactory);
52 |
53 | yelpAPI = yelpAPIFactory.createAPI();
54 |
55 | businessJsonNode = JsonTestUtils.getBusinessResponseJsonNode();
56 | searchResponseJsonNode = JsonTestUtils.getSearchResponseJsonNode();
57 | }
58 |
59 | @After
60 | public void teardown() throws IOException {
61 | mockServer.shutdown();
62 | }
63 |
64 | @Test
65 | public void testGetBusiness() throws IOException, InterruptedException {
66 | String testBusinessId = "test-business-id";
67 | setUpMockServerResponse(200, "OK", businessJsonNode.toString());
68 |
69 | Call call = yelpAPI.getBusiness(testBusinessId);
70 | Business business = call.execute().body();
71 |
72 | verifyRequestForGetBusiness(testBusinessId);
73 | verifyResponseDeserializationForGetBusiness(business);
74 | }
75 |
76 | @Test
77 | public void testGetBusinessAsynchronous() throws InterruptedException {
78 | String testBusinessId = "test-business-id";
79 | setUpMockServerResponse(200, "OK", businessJsonNode.toString());
80 |
81 | final ArrayList returnedBusinessWrapper = new ArrayList<>();
82 | Callback businessCallback = new Callback() {
83 | @Override
84 | public void onResponse(Call call, Response response) {
85 | returnedBusinessWrapper.add(response.body());
86 | }
87 |
88 | @Override
89 | public void onFailure(Call call, Throwable t) {
90 | Assert.fail("Unexpected failure: " + t.toString());
91 | }
92 | };
93 |
94 | Call call = yelpAPI.getBusiness(testBusinessId);
95 | call.enqueue(businessCallback);
96 |
97 | verifyRequestForGetBusiness(testBusinessId);
98 | verifyResponseDeserializationForGetBusiness(returnedBusinessWrapper.get(0));
99 | }
100 |
101 | @Test
102 | public void testGetBusinessWithParams() throws IOException, InterruptedException {
103 | setUpMockServerResponse(200, "OK", businessJsonNode.toString());
104 |
105 | String testBusinessId = "test-business-id";
106 | Map params = new HashMap<>();
107 | params.put("cc", "US");
108 | params.put("lang", "en");
109 | params.put("lang_filter", "true");
110 | params.put("actionlinks", "true");
111 |
112 | Call call = yelpAPI.getBusiness(testBusinessId, params);
113 | Business business = call.execute().body();
114 |
115 | verifyRequestForGetBusiness(testBusinessId, params);
116 | verifyResponseDeserializationForGetBusiness(business);
117 | }
118 |
119 | @Test
120 | public void testGetBusinessParamsBeURLEncoded() throws IOException, InterruptedException {
121 | setUpMockServerResponse(200, "OK", businessJsonNode.toString());
122 |
123 | String testBusinessId = "test-business-id";
124 | Map params = new HashMap<>();
125 | String key = "the key";
126 | String value = "the value";
127 | params.put(key, value);
128 | String expectedEncodedParamString = "the%20key=the%20value";
129 |
130 | Call call = yelpAPI.getBusiness(testBusinessId, params);
131 | call.execute().body();
132 |
133 | RecordedRequest recordedRequest = mockServer.takeRequest();
134 | Assert.assertTrue(recordedRequest.getPath().contains(expectedEncodedParamString));
135 | }
136 |
137 | @Test
138 | public void testGetBusinessWithEmptyParams() throws IOException, InterruptedException {
139 | setUpMockServerResponse(200, "OK", businessJsonNode.toString());
140 |
141 | String testBusinessId = "test-business-id";
142 | Call call = yelpAPI.getBusiness(testBusinessId, new HashMap());
143 | Business business = call.execute().body();
144 |
145 | verifyRequestForGetBusiness(testBusinessId);
146 | verifyResponseDeserializationForGetBusiness(business);
147 | }
148 |
149 | @Test(expected = IllegalArgumentException.class)
150 | public void testGetBusinessWithNullParams() throws IOException, InterruptedException {
151 | Call call = yelpAPI.getBusiness("test-business-id", null);
152 | call.execute().body();
153 | }
154 |
155 | @Test
156 | public void testGetPhoneSearch() throws IOException, InterruptedException {
157 | String testPhone = "1234567899";
158 | setUpMockServerResponse(200, "OK", searchResponseJsonNode.toString());
159 |
160 | Call call = yelpAPI.getPhoneSearch(testPhone);
161 | SearchResponse searchResponse = call.execute().body();
162 |
163 | verifyRequestForGetPhoneSearch(testPhone);
164 | verifyResponseDeserializationForSearchResponse(searchResponse);
165 | }
166 |
167 | @Test
168 | public void testGetPhoneSearchAsynchronous() throws InterruptedException {
169 | String testPhone = "1234567899";
170 | setUpMockServerResponse(200, "OK", searchResponseJsonNode.toString());
171 |
172 | final ArrayList responseWrapper = new ArrayList<>();
173 | Callback businessCallback = new Callback() {
174 |
175 | @Override
176 | public void onResponse(Call call, Response response) {
177 | responseWrapper.add(response.body());
178 | }
179 |
180 | @Override
181 | public void onFailure(Call call, Throwable t) {
182 | Assert.fail("Unexpected failure: " + t.toString());
183 | }
184 | };
185 |
186 | Call call = yelpAPI.getPhoneSearch(testPhone);
187 | call.enqueue(businessCallback);
188 |
189 | verifyRequestForGetPhoneSearch(testPhone);
190 | verifyResponseDeserializationForSearchResponse(responseWrapper.get(0));
191 | }
192 |
193 | @Test
194 | public void testGetPhoneSearchWithParams() throws IOException, InterruptedException {
195 | setUpMockServerResponse(200, "OK", searchResponseJsonNode.toString());
196 |
197 | String testPhone = "1234567899";
198 | Map params = new HashMap<>();
199 | params.put("category", "restaurant");
200 | params.put("cc", "US");
201 |
202 | Call call = yelpAPI.getPhoneSearch(testPhone, params);
203 | SearchResponse searchResponse = call.execute().body();
204 |
205 | verifyRequestForGetPhoneSearch(testPhone, params);
206 | verifyResponseDeserializationForSearchResponse(searchResponse);
207 | }
208 |
209 | @Test
210 | public void testGetPhoneSearchWithEmptyParams() throws IOException, InterruptedException {
211 | setUpMockServerResponse(200, "OK", searchResponseJsonNode.toString());
212 |
213 | String testPhone = "1234567899";
214 | Map params = new HashMap<>();
215 |
216 | Call call = yelpAPI.getPhoneSearch(testPhone, params);
217 | SearchResponse searchResponse = call.execute().body();
218 |
219 | verifyRequestForGetPhoneSearch(testPhone);
220 | verifyResponseDeserializationForSearchResponse(searchResponse);
221 | }
222 |
223 | @Test(expected = IllegalArgumentException.class)
224 | public void testGetPhoneSearchWithNullParams() throws IOException, InterruptedException {
225 | Call call = yelpAPI.getPhoneSearch("1234567899", null);
226 | call.execute().body();
227 | }
228 |
229 | @Test
230 | public void testGetBusiness400Response() throws IOException, InterruptedException {
231 | String testBusinessId = "test-business-id";
232 | String errorResponseBodyString = JsonTestUtils.getJsonNodeFromFile("sampleFailureResponse.json").toString();
233 | setUpMockServerResponse(400, "Bad Request", errorResponseBodyString);
234 |
235 | Call call = yelpAPI.getBusiness(testBusinessId);
236 | try {
237 | call.execute().body();
238 | } catch (BusinessUnavailable e) {
239 | ErrorTestUtils.verifyErrorContent(
240 | e,
241 | 400,
242 | "Bad Request",
243 | "BUSINESS_UNAVAILABLE",
244 | "Business information is unavailable"
245 | );
246 | }
247 | }
248 |
249 | @Test
250 | public void testSearchByLocation() throws IOException, InterruptedException {
251 | setUpMockServerResponse(200, "OK", searchResponseJsonNode.toString());
252 |
253 | Map params = new HashMap<>();
254 | params.put("term", "yelp");
255 |
256 | Call call = yelpAPI.search("Boston", params);
257 | SearchResponse searchResponse = call.execute().body();
258 |
259 | Map expectedCalledParams = new HashMap<>(params);
260 | expectedCalledParams.put("location", "Boston");
261 |
262 | verifyRequestForSearch(expectedCalledParams);
263 | verifyResponseDeserializationForSearchResponse(searchResponse);
264 | }
265 |
266 | @Test
267 | public void testSearchByCoordinateOptions() throws IOException, InterruptedException {
268 | setUpMockServerResponse(200, "OK", searchResponseJsonNode.toString());
269 |
270 | Map params = new HashMap<>();
271 | params.put("term", "yelp");
272 |
273 | CoordinateOptions coordinate = CoordinateOptions.builder()
274 | .latitude(11.111111)
275 | .longitude(22.222222)
276 | .build();
277 |
278 | Call call = yelpAPI.search(coordinate, params);
279 | SearchResponse searchResponse = call.execute().body();
280 |
281 | Map expectedCalledParams = new HashMap<>(params);
282 | expectedCalledParams.put("ll", "11.111111,22.222222");
283 | verifyRequestForSearch(expectedCalledParams);
284 | verifyResponseDeserializationForSearchResponse(searchResponse);
285 | }
286 |
287 | @Test
288 | public void testSearchByBoundingBoxOptions() throws IOException, InterruptedException {
289 | setUpMockServerResponse(200, "OK", searchResponseJsonNode.toString());
290 |
291 | Map params = new HashMap<>();
292 | params.put("term", "yelp");
293 |
294 | BoundingBoxOptions bounds = BoundingBoxOptions.builder()
295 | .swLatitude(11.111111)
296 | .swLongitude(22.222222)
297 | .neLatitude(33.333333)
298 | .neLongitude(44.444444)
299 | .build();
300 |
301 | Call call = yelpAPI.search(bounds, params);
302 | SearchResponse searchResponse = call.execute().body();
303 |
304 | Map expectedCalledParams = new HashMap<>(params);
305 | expectedCalledParams.put("bounds", "11.111111,22.222222%7C33.333333,44.444444");
306 | verifyRequestForSearch(expectedCalledParams);
307 | verifyResponseDeserializationForSearchResponse(searchResponse);
308 | }
309 |
310 | private void setUpMockServerResponse(int responseCode, String responseMessage, String responseBody) {
311 | MockResponse mockResponse = new MockResponse()
312 | .addHeader("Content-Type", "application/json; charset=utf-8")
313 | .setBody(responseBody)
314 | .setStatus(String.format("HTTP/1.1 %s %s", responseCode, responseMessage));
315 | mockServer.enqueue(mockResponse);
316 | }
317 |
318 | private void verifyRequestForGetBusiness(String businessId) throws InterruptedException {
319 | verifyRequestForGetBusiness(businessId, null);
320 | }
321 |
322 | private void verifyRequestForGetBusiness(String businessId, Map params)
323 | throws InterruptedException {
324 | verifyRequest("/v2/business/" + businessId, params);
325 | }
326 |
327 | private void verifyRequestForGetPhoneSearch(String phone) throws InterruptedException {
328 | verifyRequestForGetPhoneSearch(phone, null);
329 | }
330 |
331 | private void verifyRequestForGetPhoneSearch(String phone, Map params) throws InterruptedException {
332 | params = (params == null) ? new HashMap() : new HashMap<>(params);
333 | params.put("phone", phone);
334 |
335 | verifyRequest("/v2/phone_search", params);
336 | }
337 |
338 | private void verifyRequestForSearch(Map params) throws InterruptedException {
339 | verifyRequest("/v2/search", params);
340 | }
341 |
342 | private void verifyRequest(String pathPrefix, Map params) throws InterruptedException {
343 | RecordedRequest recordedRequest = mockServer.takeRequest();
344 | verifyAuthorizationHeader(recordedRequest.getHeaders().get("Authorization"));
345 |
346 | Assert.assertEquals("GET", recordedRequest.getMethod());
347 |
348 | String path = recordedRequest.getPath();
349 | Assert.assertTrue(path.startsWith(pathPrefix));
350 | if (params != null) {
351 | for (Map.Entry param : params.entrySet()) {
352 | Assert.assertTrue(path.contains(param.getKey() + "=" + param.getValue()));
353 | }
354 | }
355 |
356 | Assert.assertEquals(0, recordedRequest.getBodySize());
357 | }
358 |
359 | private void verifyResponseDeserializationForGetBusiness(Business business) {
360 | Assert.assertEquals(businessJsonNode.path("id").textValue(), business.id());
361 | }
362 |
363 | private void verifyResponseDeserializationForSearchResponse(SearchResponse searchResponse) {
364 | Assert.assertEquals(new Integer(searchResponseJsonNode.path("total").asInt()), searchResponse.total());
365 | }
366 |
367 | private void verifyAuthorizationHeader(String authHeader) {
368 | Assert.assertNotNull(authHeader);
369 | Assert.assertTrue(authHeader.contains("oauth_consumer_key"));
370 | Assert.assertTrue(authHeader.contains("oauth_nonce"));
371 | Assert.assertTrue(authHeader.contains("oauth_signature_method"));
372 | Assert.assertTrue(authHeader.contains("oauth_signature"));
373 | Assert.assertTrue(authHeader.contains("oauth_timestamp"));
374 | }
375 |
376 | /**
377 | * APIFactory which API base url can be set. Set apiBaseUrl to a mocked web server so requests are directed to it.
378 | */
379 | class TestAPIFactory extends YelpAPIFactory {
380 | private String apiBaseUrl;
381 |
382 | public TestAPIFactory(
383 | String consumerKey,
384 | String consumerSecret,
385 | String token,
386 | String tokenSecret,
387 | String apiBaseUrl
388 | ) {
389 | super(consumerKey, consumerSecret, token, tokenSecret);
390 | this.apiBaseUrl = apiBaseUrl;
391 | }
392 |
393 | @Override
394 | public String getAPIBaseUrl() {
395 | return apiBaseUrl;
396 | }
397 | }
398 | }
399 |
--------------------------------------------------------------------------------
/src/test/java/com/yelp/clientlib/entities/BusinessTest.java:
--------------------------------------------------------------------------------
1 | package com.yelp.clientlib.entities;
2 |
3 | import com.fasterxml.jackson.databind.JsonMappingException;
4 | import com.fasterxml.jackson.databind.JsonNode;
5 | import com.yelp.clientlib.utils.JsonTestUtils;
6 | import com.yelp.clientlib.utils.SerializationTestUtils;
7 |
8 | import org.junit.Assert;
9 | import org.junit.Test;
10 |
11 | import java.io.IOException;
12 |
13 | public class BusinessTest {
14 |
15 | @Test
16 | public void testDeserializeFromJson() throws IOException {
17 | JsonNode businessNode = JsonTestUtils.getBusinessResponseJsonNode();
18 | Business business = JsonTestUtils.deserializeJson(businessNode.toString(), Business.class);
19 |
20 | Assert.assertEquals(businessNode.path("display_phone").textValue(), business.displayPhone());
21 | Assert.assertEquals(businessNode.path("eat24_url").textValue(), business.eat24Url());
22 | Assert.assertEquals(businessNode.path("id").textValue(), business.id());
23 | Assert.assertEquals(businessNode.path("image_url").textValue(), business.imageUrl());
24 | Assert.assertEquals(businessNode.path("is_claimed").asBoolean(), business.isClaimed());
25 | Assert.assertEquals(businessNode.path("is_closed").asBoolean(), business.isClosed());
26 | Assert.assertEquals(new Long(businessNode.path("menu_date_updated").asLong()), business.menuDateUpdated());
27 | Assert.assertEquals(businessNode.path("menu_provider").textValue(), business.menuProvider());
28 | Assert.assertEquals(businessNode.path("mobile_url").textValue(), business.mobileUrl());
29 | Assert.assertEquals(businessNode.path("name").textValue(), business.name());
30 | Assert.assertEquals(businessNode.path("phone").textValue(), business.phone());
31 | Assert.assertEquals(businessNode.path("reservation_url").textValue(), business.reservationUrl());
32 | Assert.assertEquals(new Double(businessNode.path("rating").asDouble()), business.rating());
33 | Assert.assertEquals(businessNode.path("rating_img_url").textValue(), business.ratingImgUrl());
34 | Assert.assertEquals(businessNode.path("rating_img_url_large").textValue(), business.ratingImgUrlLarge());
35 | Assert.assertEquals(businessNode.path("rating_img_url_small").textValue(), business.ratingImgUrlSmall());
36 | Assert.assertEquals(new Integer(businessNode.path("review_count").asInt()), business.reviewCount());
37 | Assert.assertEquals(businessNode.path("snippet_image_url").textValue(), business.snippetImageUrl());
38 | Assert.assertEquals(businessNode.path("snippet_text").textValue(), business.snippetText());
39 | Assert.assertEquals(businessNode.path("url").textValue(), business.url());
40 |
41 | // The following objects are tested in their own tests.
42 | Assert.assertNotNull(business.categories());
43 | Assert.assertNotNull(business.deals());
44 | Assert.assertNotNull(business.giftCertificates());
45 | Assert.assertNotNull(business.location());
46 | Assert.assertNotNull(business.reviews());
47 |
48 | }
49 |
50 | @Test
51 | public void testDeserializationWithMissingNullableAttribute() throws IOException {
52 | String businessJsonString = "{\"name\":\"Yelp\", \"id\":\"yelp-san-francisco\"}";
53 | Business business = JsonTestUtils.deserializeJson(businessJsonString, Business.class);
54 | Assert.assertEquals("Yelp", business.name());
55 | Assert.assertEquals("yelp-san-francisco", business.id());
56 | Assert.assertNull(business.displayPhone());
57 | }
58 |
59 | @Test
60 | public void testDeserializationWithUTF8Characters() throws IOException {
61 | String businessJsonString = "{\"name\":\"Gööd Füsiön Fööd\", \"id\":\"gööd-füsiön-fööd-san-francisco\"}";
62 | Business business = JsonTestUtils.deserializeJson(businessJsonString, Business.class);
63 | Assert.assertEquals("Gööd Füsiön Fööd", business.name());
64 | Assert.assertEquals("gööd-füsiön-fööd-san-francisco", business.id());
65 | }
66 |
67 | @Test
68 | public void testDeserializationWithNoReviewBusinessHasNullForReview() throws IOException {
69 | JsonNode businessNode = JsonTestUtils.getJsonNodeFromFile("noReviewBusinessResponse.json");
70 | Business business = JsonTestUtils.deserializeJson(businessNode.toString(), Business.class);
71 | Assert.assertNull(business.reviews());
72 | Assert.assertEquals(new Integer(0), business.reviewCount());
73 | Assert.assertEquals(businessNode.path("id").textValue(), business.id());
74 | Assert.assertEquals(businessNode.path("rating_img_url").textValue(), business.ratingImgUrl());
75 | Assert.assertEquals(businessNode.path("rating_img_url_small").textValue(), business.ratingImgUrlSmall());
76 | }
77 |
78 | @Test(expected = JsonMappingException.class)
79 | public void testDeserializationFailedWithMissingAttributes() throws IOException {
80 | String businessJsonString = "{\"name\":\"Yelp\"}";
81 | JsonTestUtils.deserializeJson(businessJsonString, Business.class);
82 | }
83 |
84 | @Test
85 | public void testSerializable() throws IOException, ClassNotFoundException {
86 | JsonNode businessNode = JsonTestUtils.getBusinessResponseJsonNode();
87 | Business business = JsonTestUtils.deserializeJson(businessNode.toString(), Business.class);
88 |
89 | byte[] bytes = SerializationTestUtils.serialize(business);
90 | Assert.assertEquals(business, SerializationTestUtils.deserialize(bytes, Business.class));
91 | }
92 |
93 | @Test
94 | public void testBuildWithNullableAttributesNotSet() throws IOException {
95 | Business.builder().name("Yelp").id("yelp-san-francisco").build();
96 | }
97 |
98 | @Test(expected = IllegalStateException.class)
99 | public void testBuildFailedWithMissingId() throws IOException {
100 | Business.builder().name("Yelp").build();
101 | }
102 |
103 | @Test(expected = IllegalStateException.class)
104 | public void testBuildFailedWithMissingName() throws IOException {
105 | Business.builder().id("yelp-san-francisco").build();
106 | }
107 | }
108 |
--------------------------------------------------------------------------------
/src/test/java/com/yelp/clientlib/entities/CategoryTest.java:
--------------------------------------------------------------------------------
1 | package com.yelp.clientlib.entities;
2 |
3 | import com.fasterxml.jackson.databind.JsonMappingException;
4 | import com.fasterxml.jackson.databind.JsonNode;
5 | import com.yelp.clientlib.utils.JsonTestUtils;
6 | import com.yelp.clientlib.utils.SerializationTestUtils;
7 |
8 | import org.junit.Assert;
9 | import org.junit.Test;
10 |
11 | import java.io.IOException;
12 |
13 | public class CategoryTest {
14 |
15 | @Test
16 | public void testDeserializeFromJson() throws IOException {
17 | JsonNode categoryNode = JsonTestUtils.getBusinessResponseJsonNode().path("categories").get(0);
18 | Category category = JsonTestUtils.deserializeJson(categoryNode.toString(), Category.class);
19 |
20 | Assert.assertEquals(categoryNode.get(0).textValue(), category.name());
21 | Assert.assertEquals(categoryNode.get(1).textValue(), category.alias());
22 | }
23 |
24 | @Test(expected = JsonMappingException.class)
25 | public void testDeserializationFailedWithNonPairedValue() throws IOException {
26 | String categoryJsonString = "[\"Restaurant\"]";
27 | JsonTestUtils.deserializeJson(categoryJsonString, Business.class);
28 | }
29 |
30 | @Test
31 | public void testSerializable() throws IOException, ClassNotFoundException {
32 | JsonNode categoryNode = JsonTestUtils.getBusinessResponseJsonNode().path("categories").get(0);
33 | Category category = JsonTestUtils.deserializeJson(categoryNode.toString(), Category.class);
34 |
35 | byte[] bytes = SerializationTestUtils.serialize(category);
36 | Assert.assertEquals(category, SerializationTestUtils.deserialize(bytes, Category.class));
37 | }
38 |
39 | @Test(expected = IllegalStateException.class)
40 | public void testBuildFailedWithNoAlias() throws IOException {
41 | Category.builder().name("Restaurant").build();
42 | }
43 |
44 | @Test(expected = IllegalStateException.class)
45 | public void testBuildFailedWithNoName() throws IOException {
46 | Category.builder().alias("restaurant").build();
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/src/test/java/com/yelp/clientlib/entities/CoordinateTest.java:
--------------------------------------------------------------------------------
1 | package com.yelp.clientlib.entities;
2 |
3 | import com.fasterxml.jackson.databind.JsonNode;
4 | import com.yelp.clientlib.utils.JsonTestUtils;
5 | import com.yelp.clientlib.utils.SerializationTestUtils;
6 |
7 | import org.junit.Assert;
8 | import org.junit.Test;
9 |
10 | import java.io.IOException;
11 |
12 | public class CoordinateTest {
13 |
14 | @Test
15 | public void testDeserializeFromJson() throws IOException {
16 | JsonNode coordinateNode = JsonTestUtils.getBusinessResponseJsonNode().path("location").path("coordinate");
17 | Coordinate coordinate = JsonTestUtils.deserializeJson(coordinateNode.toString(), Coordinate.class);
18 |
19 | Assert.assertEquals(new Double(coordinateNode.path("latitude").asDouble()), coordinate.latitude());
20 | Assert.assertEquals(new Double(coordinateNode.path("longitude").asDouble()), coordinate.longitude());
21 | }
22 |
23 | @Test
24 | public void testSerializable() throws IOException, ClassNotFoundException {
25 | JsonNode coordinateNode = JsonTestUtils.getBusinessResponseJsonNode().path("location").path("coordinate");
26 | Coordinate coordinate = JsonTestUtils.deserializeJson(coordinateNode.toString(), Coordinate.class);
27 |
28 | byte[] bytes = SerializationTestUtils.serialize(coordinate);
29 | Assert.assertEquals(coordinate, SerializationTestUtils.deserialize(bytes, Coordinate.class));
30 | }
31 |
32 | @Test(expected = IllegalStateException.class)
33 | public void testBuildFailedWithNoLatitude() throws IOException {
34 | Coordinate.builder().longitude(123.123123).build();
35 | }
36 |
37 | @Test(expected = IllegalStateException.class)
38 | public void testBuildFailedWithNoLongitude() throws IOException {
39 | Coordinate.builder().latitude(123.123123).build();
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/src/test/java/com/yelp/clientlib/entities/DealOptionTest.java:
--------------------------------------------------------------------------------
1 | package com.yelp.clientlib.entities;
2 |
3 | import com.fasterxml.jackson.databind.JsonNode;
4 | import com.yelp.clientlib.utils.JsonTestUtils;
5 | import com.yelp.clientlib.utils.SerializationTestUtils;
6 |
7 | import org.junit.Assert;
8 | import org.junit.Test;
9 |
10 | import java.io.IOException;
11 |
12 | public class DealOptionTest {
13 |
14 | @Test
15 | public void testDeserializeFromJson() throws IOException {
16 | JsonNode dealOptionNode = JsonTestUtils.getBusinessResponseJsonNode()
17 | .path("deals").get(0).path("options").get(0);
18 | DealOption dealOption = JsonTestUtils.deserializeJson(dealOptionNode.toString(), DealOption.class);
19 |
20 | Assert.assertEquals(
21 | dealOptionNode.path("formatted_original_price").textValue(),
22 | dealOption.formattedOriginalPrice()
23 | );
24 | Assert.assertEquals(dealOptionNode.path("formatted_price").textValue(), dealOption.formattedPrice());
25 | Assert.assertEquals(dealOptionNode.path("is_quantity_limited").asBoolean(), dealOption.isQuantityLimited());
26 | Assert.assertEquals(new Integer(dealOptionNode.path("original_price").asInt()), dealOption.originalPrice());
27 | Assert.assertEquals(new Integer(dealOptionNode.path("price").asInt()), dealOption.price());
28 | Assert.assertEquals(dealOptionNode.path("purchase_url").textValue(), dealOption.purchaseUrl());
29 | Assert.assertEquals(new Integer(dealOptionNode.path("remaining_count").asInt()), dealOption.remainingCount());
30 | Assert.assertEquals(dealOptionNode.path("title").textValue(), dealOption.title());
31 | }
32 |
33 | @Test
34 | public void testSerializable() throws IOException, ClassNotFoundException {
35 | JsonNode dealOptionNode = JsonTestUtils.getBusinessResponseJsonNode()
36 | .path("deals").get(0).path("options").get(0);
37 | DealOption dealOption = JsonTestUtils.deserializeJson(dealOptionNode.toString(), DealOption.class);
38 |
39 | byte[] bytes = SerializationTestUtils.serialize(dealOption);
40 | Assert.assertEquals(dealOption, SerializationTestUtils.deserialize(bytes, DealOption.class));
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/src/test/java/com/yelp/clientlib/entities/DealTest.java:
--------------------------------------------------------------------------------
1 | package com.yelp.clientlib.entities;
2 |
3 | import com.fasterxml.jackson.databind.JsonNode;
4 | import com.yelp.clientlib.utils.JsonTestUtils;
5 | import com.yelp.clientlib.utils.SerializationTestUtils;
6 |
7 | import org.junit.Assert;
8 | import org.junit.Test;
9 |
10 | import java.io.IOException;
11 |
12 | public class DealTest {
13 |
14 | @Test
15 | public void testDeserializeFromJson() throws IOException {
16 | JsonNode dealNode = JsonTestUtils.getBusinessResponseJsonNode().path("deals").get(0);
17 | Deal deal = JsonTestUtils.deserializeJson(dealNode.toString(), Deal.class);
18 |
19 | Assert.assertNull(deal.additionalRestrictions());
20 | Assert.assertEquals(dealNode.path("currency_code").textValue(), deal.currencyCode());
21 | Assert.assertNull(deal.id());
22 | Assert.assertEquals(dealNode.path("image_url").textValue(), deal.imageUrl());
23 | Assert.assertNull(deal.importantRestrictions());
24 | Assert.assertEquals(dealNode.path("is_popular").asBoolean(), deal.isPopular());
25 | Assert.assertNotNull(deal.options().get(0));
26 | Assert.assertNull(deal.timeEnd());
27 | Assert.assertEquals(new Long(dealNode.path("time_start").asLong()), deal.timeStart());
28 | Assert.assertEquals(dealNode.path("title").textValue(), deal.title());
29 | Assert.assertEquals(dealNode.path("url").textValue(), deal.url());
30 | Assert.assertNull(deal.whatYouGet());
31 | }
32 |
33 | @Test
34 | public void testSerializable() throws IOException, ClassNotFoundException {
35 | JsonNode dealNode = JsonTestUtils.getBusinessResponseJsonNode().path("deals").get(0);
36 | Deal deal = JsonTestUtils.deserializeJson(dealNode.toString(), Deal.class);
37 |
38 | byte[] bytes = SerializationTestUtils.serialize(deal);
39 | Assert.assertEquals(deal, SerializationTestUtils.deserialize(bytes, Deal.class));
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/src/test/java/com/yelp/clientlib/entities/GiftCertificateOptionTest.java:
--------------------------------------------------------------------------------
1 | package com.yelp.clientlib.entities;
2 |
3 | import com.fasterxml.jackson.databind.JsonNode;
4 | import com.yelp.clientlib.utils.JsonTestUtils;
5 | import com.yelp.clientlib.utils.SerializationTestUtils;
6 |
7 | import org.junit.Assert;
8 | import org.junit.Test;
9 |
10 | import java.io.IOException;
11 |
12 | public class GiftCertificateOptionTest {
13 |
14 | @Test
15 | public void testDeserializeFromJson() throws IOException {
16 | JsonNode giftCertificateOptionNode = JsonTestUtils.getBusinessResponseJsonNode()
17 | .path("gift_certificates").get(0).path("options").get(0);
18 |
19 | GiftCertificateOption giftCertificateOption = JsonTestUtils.deserializeJson(
20 | giftCertificateOptionNode.toString(),
21 | GiftCertificateOption.class
22 | );
23 |
24 | Assert.assertEquals(
25 | giftCertificateOptionNode.path("formatted_price").textValue(),
26 | giftCertificateOption.formattedPrice()
27 | );
28 | Assert.assertEquals(
29 | new Integer(giftCertificateOptionNode.path("price").asInt()),
30 | giftCertificateOption.price()
31 | );
32 | }
33 |
34 | @Test
35 | public void testSerializable() throws IOException, ClassNotFoundException {
36 | JsonNode giftCertificateOptionNode = JsonTestUtils.getBusinessResponseJsonNode()
37 | .path("gift_certificates").get(0).path("options").get(0);
38 | GiftCertificateOption giftCertificateOption = JsonTestUtils.deserializeJson(
39 | giftCertificateOptionNode.toString(),
40 | GiftCertificateOption.class
41 | );
42 |
43 | byte[] bytes = SerializationTestUtils.serialize(giftCertificateOption);
44 | Assert.assertEquals(
45 | giftCertificateOption,
46 | SerializationTestUtils.deserialize(bytes, GiftCertificateOption.class)
47 | );
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/src/test/java/com/yelp/clientlib/entities/GiftCertificateTest.java:
--------------------------------------------------------------------------------
1 | package com.yelp.clientlib.entities;
2 |
3 | import com.fasterxml.jackson.databind.JsonNode;
4 | import com.yelp.clientlib.utils.JsonTestUtils;
5 | import com.yelp.clientlib.utils.SerializationTestUtils;
6 |
7 | import org.junit.Assert;
8 | import org.junit.Test;
9 |
10 | import java.io.IOException;
11 |
12 | public class GiftCertificateTest {
13 |
14 | @Test
15 | public void testDeserializeFromJson() throws IOException {
16 | JsonNode giftCertificatesNode = JsonTestUtils.getBusinessResponseJsonNode().path("gift_certificates").get(0);
17 |
18 | GiftCertificate giftCertificate = JsonTestUtils.deserializeJson(
19 | giftCertificatesNode.toString(),
20 | GiftCertificate.class
21 | );
22 |
23 | Assert.assertEquals(giftCertificatesNode.path("id").textValue(), giftCertificate.id());
24 | Assert.assertEquals(giftCertificatesNode.path("url").textValue(), giftCertificate.url());
25 | Assert.assertEquals(giftCertificatesNode.path("image_url").textValue(), giftCertificate.imageUrl());
26 | Assert.assertEquals(giftCertificatesNode.path("currency_code").textValue(), giftCertificate.currencyCode());
27 | Assert.assertEquals(giftCertificatesNode.path("unused_balances").textValue(), giftCertificate.unusedBalances());
28 |
29 | // GiftCertificateOption is tested in it's own test.
30 | Assert.assertNotNull(giftCertificate.options().get(0));
31 | }
32 |
33 | @Test
34 | public void testSerializable() throws IOException, ClassNotFoundException {
35 | JsonNode giftCertificatesNode = JsonTestUtils.getBusinessResponseJsonNode().path("gift_certificates").get(0);
36 | GiftCertificate giftCertificate = JsonTestUtils.deserializeJson(
37 | giftCertificatesNode.toString(),
38 | GiftCertificate.class
39 | );
40 |
41 | byte[] bytes = SerializationTestUtils.serialize(giftCertificate);
42 | Assert.assertEquals(giftCertificate, SerializationTestUtils.deserialize(bytes, GiftCertificate.class));
43 | }
44 |
45 | @Test(expected = IllegalStateException.class)
46 | public void testBuildFailedWithNoId() throws IOException {
47 | GiftCertificate.builder().id(null).build();
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/src/test/java/com/yelp/clientlib/entities/LocationTest.java:
--------------------------------------------------------------------------------
1 | package com.yelp.clientlib.entities;
2 |
3 | import com.fasterxml.jackson.databind.JsonNode;
4 | import com.yelp.clientlib.utils.JsonTestUtils;
5 | import com.yelp.clientlib.utils.SerializationTestUtils;
6 |
7 | import org.junit.Assert;
8 | import org.junit.Test;
9 |
10 | import java.io.IOException;
11 |
12 | public class LocationTest {
13 |
14 | @Test
15 | public void testDeserializeFromJson() throws IOException {
16 | JsonNode locationNode = JsonTestUtils.getBusinessResponseJsonNode().path("location");
17 | Location location = JsonTestUtils.deserializeJson(locationNode.toString(), Location.class);
18 |
19 | Assert.assertEquals(1, location.address().size());
20 | Assert.assertEquals(locationNode.path("city").textValue(), location.city());
21 | Assert.assertNotNull(location.coordinate());
22 | Assert.assertEquals(locationNode.path("country_code").textValue(), location.countryCode());
23 | Assert.assertEquals(locationNode.path("cross_streets").textValue(), location.crossStreets());
24 | Assert.assertEquals(3, location.displayAddress().size());
25 | Assert.assertEquals(new Double(locationNode.path("geo_accuracy").asDouble()), location.geoAccuracy());
26 | Assert.assertEquals(2, location.neighborhoods().size());
27 | Assert.assertEquals(locationNode.path("postal_code").textValue(), location.postalCode());
28 | Assert.assertEquals(locationNode.path("state_code").textValue(), location.stateCode());
29 | }
30 |
31 | @Test
32 | public void testSerializable() throws IOException, ClassNotFoundException {
33 | JsonNode locationNode = JsonTestUtils.getBusinessResponseJsonNode().path("location");
34 | Location location = JsonTestUtils.deserializeJson(locationNode.toString(), Location.class);
35 |
36 | byte[] bytes = SerializationTestUtils.serialize(location);
37 | Assert.assertEquals(location, SerializationTestUtils.deserialize(bytes, Location.class));
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/src/test/java/com/yelp/clientlib/entities/RegionTest.java:
--------------------------------------------------------------------------------
1 | package com.yelp.clientlib.entities;
2 |
3 | import com.fasterxml.jackson.databind.JsonNode;
4 | import com.yelp.clientlib.utils.JsonTestUtils;
5 | import com.yelp.clientlib.utils.SerializationTestUtils;
6 |
7 | import org.junit.Assert;
8 | import org.junit.Test;
9 |
10 | import java.io.IOException;
11 |
12 | public class RegionTest {
13 |
14 | @Test
15 | public void testDeserializeFromJson() throws IOException {
16 | JsonNode regionNode = JsonTestUtils.getSearchResponseJsonNode().path("region");
17 | Region region = JsonTestUtils.deserializeJson(regionNode.toString(), Region.class);
18 |
19 | // Coordinate and Span are tested in their own tests.
20 | Assert.assertNotNull(region.center());
21 | Assert.assertNotNull(region.span());
22 | }
23 |
24 | @Test
25 | public void testSerializable() throws IOException, ClassNotFoundException {
26 | JsonNode regionNode = JsonTestUtils.getSearchResponseJsonNode().path("region");
27 | Region region = JsonTestUtils.deserializeJson(regionNode.toString(), Region.class);
28 |
29 | byte[] bytes = SerializationTestUtils.serialize(region);
30 | Assert.assertEquals(region, SerializationTestUtils.deserialize(bytes, Region.class));
31 | }
32 |
33 | @Test(expected = IllegalStateException.class)
34 | public void testBuildFailedWithNoCenter() throws IOException {
35 | Span span = Span.builder().latitudeDelta(50.123).longitudeDelta(50.123).build();
36 | Region.builder().span(span).build();
37 | }
38 |
39 | @Test(expected = IllegalStateException.class)
40 | public void testBuildFailedWithNoSpan() throws IOException {
41 | Coordinate center = Coordinate.builder().latitude(123.123123).longitude(123.123123).build();
42 | Region.builder().center(center).build();
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/src/test/java/com/yelp/clientlib/entities/ReviewTest.java:
--------------------------------------------------------------------------------
1 | package com.yelp.clientlib.entities;
2 |
3 |
4 | import com.fasterxml.jackson.databind.JsonNode;
5 | import com.yelp.clientlib.utils.JsonTestUtils;
6 | import com.yelp.clientlib.utils.SerializationTestUtils;
7 |
8 | import org.junit.Assert;
9 | import org.junit.Test;
10 |
11 | import java.io.IOException;
12 |
13 | public class ReviewTest {
14 |
15 | @Test
16 | public void testDeserializeFromJson() throws IOException {
17 | JsonNode reviewNode = JsonTestUtils.getBusinessResponseJsonNode().path("reviews").get(0);
18 | Review review = JsonTestUtils.deserializeJson(reviewNode.toString(), Review.class);
19 |
20 | Assert.assertEquals(reviewNode.path("excerpt").textValue(), review.excerpt());
21 | Assert.assertEquals(reviewNode.path("id").textValue(), review.id());
22 | Assert.assertEquals(new Double(reviewNode.path("rating").asDouble()), review.rating());
23 | Assert.assertEquals(reviewNode.path("rating_image_large_url").textValue(), review.ratingImageLargeUrl());
24 | Assert.assertEquals(reviewNode.path("rating_image_small_url").textValue(), review.ratingImageSmallUrl());
25 | Assert.assertEquals(reviewNode.path("rating_image_url").textValue(), review.ratingImageUrl());
26 | Assert.assertEquals(new Long(reviewNode.path("time_created").asLong()), review.timeCreated());
27 |
28 | // User is tested in it's own test.
29 | Assert.assertNotNull(review.user());
30 | }
31 |
32 | @Test
33 | public void testSerializable() throws IOException, ClassNotFoundException {
34 | JsonNode reviewNode = JsonTestUtils.getBusinessResponseJsonNode().path("reviews").get(0);
35 | Review review = JsonTestUtils.deserializeJson(reviewNode.toString(), Review.class);
36 |
37 | byte[] bytes = SerializationTestUtils.serialize(review);
38 | Assert.assertEquals(review, SerializationTestUtils.deserialize(bytes, Review.class));
39 | }
40 |
41 | @Test(expected = IllegalStateException.class)
42 | public void testBuildFailedWithNoId() throws IOException {
43 | Review.builder().id(null).build();
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/src/test/java/com/yelp/clientlib/entities/SearchResponseTest.java:
--------------------------------------------------------------------------------
1 | package com.yelp.clientlib.entities;
2 |
3 | import com.fasterxml.jackson.databind.JsonNode;
4 | import com.yelp.clientlib.utils.JsonTestUtils;
5 | import com.yelp.clientlib.utils.SerializationTestUtils;
6 |
7 | import org.junit.Assert;
8 | import org.junit.Test;
9 |
10 | import java.io.IOException;
11 |
12 | public class SearchResponseTest {
13 | @Test
14 | public void testDeserializeFromJson() throws IOException {
15 | JsonNode searchNode = JsonTestUtils.getSearchResponseJsonNode();
16 | SearchResponse searchResponse = JsonTestUtils.deserializeJson(searchNode.toString(), SearchResponse.class);
17 |
18 | Assert.assertEquals(new Integer(searchNode.path("total").asInt()), searchResponse.total());
19 |
20 | // The following objects are tested in their own tests.
21 | Assert.assertNotNull(searchResponse.region());
22 | Assert.assertNotNull(searchResponse.businesses());
23 | }
24 |
25 | @Test
26 | public void testSerializable() throws IOException, ClassNotFoundException {
27 | JsonNode searchResponseNode = JsonTestUtils.getSearchResponseJsonNode();
28 | SearchResponse searchResponse = JsonTestUtils.deserializeJson(
29 | searchResponseNode.toString(),
30 | SearchResponse.class
31 | );
32 |
33 | byte[] bytes = SerializationTestUtils.serialize(searchResponse);
34 | Assert.assertEquals(searchResponse, SerializationTestUtils.deserialize(bytes, SearchResponse.class));
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/test/java/com/yelp/clientlib/entities/SpanTest.java:
--------------------------------------------------------------------------------
1 | package com.yelp.clientlib.entities;
2 |
3 | import com.fasterxml.jackson.databind.JsonNode;
4 | import com.yelp.clientlib.utils.JsonTestUtils;
5 | import com.yelp.clientlib.utils.SerializationTestUtils;
6 |
7 | import org.junit.Assert;
8 | import org.junit.Test;
9 |
10 | import java.io.IOException;
11 |
12 | public class SpanTest {
13 |
14 | @Test
15 | public void testDeserializeFromJson() throws IOException {
16 | JsonNode spanNode = JsonTestUtils.getSearchResponseJsonNode().path("region").path("span");
17 | Span span = JsonTestUtils.deserializeJson(spanNode.toString(), Span.class);
18 |
19 | Assert.assertEquals(new Double(spanNode.path("latitude_delta").asDouble()), span.latitudeDelta());
20 | Assert.assertEquals(new Double(spanNode.path("longitude_delta").asDouble()), span.longitudeDelta());
21 | }
22 |
23 | @Test
24 | public void testSerializable() throws IOException, ClassNotFoundException {
25 | JsonNode spanNode = JsonTestUtils.getSearchResponseJsonNode().path("region").path("span");
26 | Span span = JsonTestUtils.deserializeJson(spanNode.toString(), Span.class);
27 |
28 | byte[] bytes = SerializationTestUtils.serialize(span);
29 | Assert.assertEquals(span, SerializationTestUtils.deserialize(bytes, Span.class));
30 | }
31 |
32 | @Test(expected = IllegalStateException.class)
33 | public void testBuildFailedWithNoLatitudeDelta() throws IOException {
34 | Span.builder().longitudeDelta(50.123123).build();
35 | }
36 |
37 | @Test(expected = IllegalStateException.class)
38 | public void testBuildFailedWithNoLongitude() throws IOException {
39 | Span.builder().latitudeDelta(50.123123).build();
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/src/test/java/com/yelp/clientlib/entities/UserTest.java:
--------------------------------------------------------------------------------
1 | package com.yelp.clientlib.entities;
2 |
3 | import com.fasterxml.jackson.databind.JsonNode;
4 | import com.yelp.clientlib.utils.JsonTestUtils;
5 | import com.yelp.clientlib.utils.SerializationTestUtils;
6 |
7 | import org.junit.Assert;
8 | import org.junit.Test;
9 |
10 | import java.io.IOException;
11 |
12 | public class UserTest {
13 |
14 | @Test
15 | public void testDeserializeFromJson() throws IOException {
16 | JsonNode userNode = JsonTestUtils.getBusinessResponseJsonNode().path("reviews").get(0).path("user");
17 | User user = JsonTestUtils.deserializeJson(userNode.toString(), User.class);
18 |
19 | Assert.assertEquals(userNode.path("id").textValue(), user.id());
20 | Assert.assertEquals(userNode.path("image_url").textValue(), user.imageUrl());
21 | Assert.assertEquals(userNode.path("name").textValue(), user.name());
22 | }
23 |
24 | @Test
25 | public void testSerializable() throws IOException, ClassNotFoundException {
26 | JsonNode userNode = JsonTestUtils.getBusinessResponseJsonNode().path("reviews").get(0).path("user");
27 | User user = JsonTestUtils.deserializeJson(userNode.toString(), User.class);
28 |
29 | byte[] bytes = SerializationTestUtils.serialize(user);
30 | Assert.assertEquals(user, SerializationTestUtils.deserialize(bytes, User.class));
31 | }
32 |
33 | @Test(expected = IllegalStateException.class)
34 | public void testBuildFailedWithNoId() throws IOException {
35 | User.builder().id(null).build();
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/test/java/com/yelp/clientlib/entities/options/BoundingBoxOptionsTest.java:
--------------------------------------------------------------------------------
1 | package com.yelp.clientlib.entities.options;
2 |
3 | import org.junit.Assert;
4 | import org.junit.Test;
5 |
6 | public class BoundingBoxOptionsTest {
7 | Double swLatitude = 11.11111;
8 | Double swLongitude = 22.11111;
9 | Double neLatitude = 33.11111;
10 | Double neLongitude = 44.11111;
11 |
12 | @Test
13 | public void testBuilder() {
14 | BoundingBoxOptions bounds = BoundingBoxOptions.builder()
15 | .swLatitude(swLatitude)
16 | .swLongitude(swLongitude)
17 | .neLatitude(neLatitude)
18 | .neLongitude(neLongitude).build();
19 |
20 | Assert.assertEquals(swLatitude, bounds.swLatitude());
21 | Assert.assertEquals(swLongitude, bounds.swLongitude());
22 | Assert.assertEquals(neLatitude, bounds.neLatitude());
23 | Assert.assertEquals(neLongitude, bounds.neLongitude());
24 | }
25 |
26 | @Test(expected = IllegalStateException.class)
27 | public void testNonSetSwLatitudeRaiseException() {
28 | BoundingBoxOptions.builder()
29 | .swLongitude(swLongitude)
30 | .neLatitude(neLatitude)
31 | .neLongitude(neLongitude)
32 | .build();
33 | }
34 |
35 | @Test(expected = IllegalStateException.class)
36 | public void testNonSetSwLongitudeRaiseException() {
37 | BoundingBoxOptions.builder()
38 | .swLatitude(swLatitude)
39 | .neLatitude(neLatitude)
40 | .neLongitude(neLongitude)
41 | .build();
42 | }
43 |
44 | @Test(expected = IllegalStateException.class)
45 | public void testNonSetNeLatitudeRaiseException() {
46 | BoundingBoxOptions.builder()
47 | .swLatitude(swLatitude)
48 | .swLongitude(swLongitude)
49 | .neLongitude(neLongitude)
50 | .build();
51 | }
52 |
53 | @Test(expected = IllegalStateException.class)
54 | public void testNonSetNeLongitudeRaiseException() {
55 | BoundingBoxOptions.builder()
56 | .swLatitude(swLatitude)
57 | .swLongitude(swLongitude)
58 | .neLatitude(neLatitude)
59 | .build();
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/src/test/java/com/yelp/clientlib/entities/options/CoordinateOptionsTest.java:
--------------------------------------------------------------------------------
1 | package com.yelp.clientlib.entities.options;
2 |
3 | import org.junit.Assert;
4 | import org.junit.Test;
5 |
6 | public class CoordinateOptionsTest {
7 | Double latitude = 11.11111;
8 | Double longitude = 22.11111;
9 | Double accuracy = 9.5;
10 | Double altitude = 100.11;
11 | Double altitudeAccuracy = 9.5;
12 |
13 | @Test
14 | public void testBuilder() {
15 | CoordinateOptions coordinate = CoordinateOptions.builder()
16 | .latitude(latitude)
17 | .longitude(longitude)
18 | .accuracy(accuracy)
19 | .altitude(altitude)
20 | .altitudeAccuracy(altitudeAccuracy)
21 | .build();
22 |
23 | Assert.assertEquals(latitude, coordinate.latitude());
24 | Assert.assertEquals(longitude, coordinate.longitude());
25 | Assert.assertEquals(accuracy, coordinate.accuracy());
26 | Assert.assertEquals(altitude, coordinate.altitude());
27 | Assert.assertEquals(altitudeAccuracy, coordinate.altitudeAccuracy());
28 | }
29 |
30 | @Test
31 | public void testToStringWithLatLong() {
32 | CoordinateOptions coordinate = CoordinateOptions.builder()
33 | .latitude(latitude)
34 | .longitude(longitude)
35 | .build();
36 |
37 | Assert.assertEquals(latitude + "," + longitude + ",,,", coordinate.toString());
38 | }
39 |
40 | @Test
41 | public void testToStringWithLatLongAccuracy() {
42 | CoordinateOptions coordinate = CoordinateOptions.builder()
43 | .latitude(latitude)
44 | .longitude(longitude)
45 | .accuracy(accuracy)
46 | .build();
47 |
48 | Assert.assertEquals(latitude + "," + longitude + "," + accuracy + ",,", coordinate.toString());
49 | }
50 |
51 | @Test
52 | public void testToStringWithLatLongAltitude() {
53 | CoordinateOptions coordinate = CoordinateOptions.builder()
54 | .latitude(latitude)
55 | .longitude(longitude)
56 | .altitude(altitude)
57 | .build();
58 |
59 | Assert.assertEquals(latitude + "," + longitude + ",," + altitude + ",", coordinate.toString());
60 | }
61 |
62 | @Test
63 | public void testToStringWithLatLongAccuracyAltitude() {
64 | CoordinateOptions coordinate = CoordinateOptions.builder()
65 | .latitude(latitude)
66 | .longitude(longitude)
67 | .accuracy(accuracy)
68 | .altitude(altitude)
69 | .build();
70 |
71 | Assert.assertEquals(
72 | latitude + "," + longitude + "," + accuracy + "," + altitude + ",",
73 | coordinate.toString()
74 | );
75 | }
76 |
77 | @Test
78 | public void testToStringWithAllFields() {
79 | CoordinateOptions coordinate = CoordinateOptions.builder()
80 | .latitude(latitude)
81 | .longitude(longitude)
82 | .accuracy(accuracy)
83 | .altitude(altitude)
84 | .altitudeAccuracy(altitudeAccuracy)
85 | .build();
86 |
87 | Assert.assertEquals(
88 | latitude + "," + longitude + "," + accuracy + "," + altitude + "," + altitudeAccuracy,
89 | coordinate.toString()
90 | );
91 | }
92 |
93 | @Test(expected = IllegalStateException.class)
94 | public void testNonSetLatitudeRaiseException() {
95 | CoordinateOptions.builder()
96 | .longitude(longitude)
97 | .build();
98 | }
99 |
100 | @Test(expected = IllegalStateException.class)
101 | public void testNonSetLongitudeRaiseException() {
102 | CoordinateOptions.builder()
103 | .latitude(latitude)
104 | .build();
105 | }
106 |
107 | @Test
108 | public void testNonSetNullableValueRaiseNoException() {
109 | CoordinateOptions.builder()
110 | .latitude(latitude)
111 | .longitude(longitude)
112 | .build();
113 | }
114 | }
--------------------------------------------------------------------------------
/src/test/java/com/yelp/clientlib/exception/ErrorHandlingInterceptorTest.java:
--------------------------------------------------------------------------------
1 | package com.yelp.clientlib.exception;
2 |
3 | import okhttp3.Interceptor;
4 | import okhttp3.MediaType;
5 | import okhttp3.Protocol;
6 | import okhttp3.Request;
7 | import okhttp3.Response;
8 | import okhttp3.ResponseBody;
9 | import com.yelp.clientlib.exception.exceptions.BusinessUnavailable;
10 | import com.yelp.clientlib.exception.exceptions.InternalError;
11 | import com.yelp.clientlib.exception.exceptions.InvalidParameter;
12 | import com.yelp.clientlib.exception.exceptions.UnexpectedAPIError;
13 | import com.yelp.clientlib.utils.ErrorTestUtils;
14 |
15 | import org.easymock.EasyMock;
16 | import org.junit.Assert;
17 | import org.junit.Before;
18 | import org.junit.Test;
19 | import org.junit.runner.RunWith;
20 | import org.powermock.api.easymock.PowerMock;
21 | import org.powermock.core.classloader.annotations.PrepareForTest;
22 | import org.powermock.modules.junit4.PowerMockRunner;
23 |
24 | import java.io.IOException;
25 |
26 | @RunWith(PowerMockRunner.class)
27 | @PrepareForTest({Request.class, Response.class, Protocol.class})
28 | public class ErrorHandlingInterceptorTest {
29 |
30 | Interceptor errorHandlingInterceptor;
31 |
32 | @Before
33 | public void setUp() {
34 | this.errorHandlingInterceptor = new ErrorHandlingInterceptor();
35 | }
36 |
37 | /**
38 | * Ensure the interceptor does nothing besides proceeding the request if the request is done successfully.
39 | */
40 | @Test
41 | public void testSuccessfulRequestNotDoingAnythingExceptProceedingRequests() throws IOException {
42 | Request mockRequest = PowerMock.createMock(Request.class);
43 | Response mockResponse = PowerMock.createMock(Response.class);
44 | Interceptor.Chain mockChain = PowerMock.createMock(Interceptor.Chain.class);
45 |
46 | EasyMock.expect(mockChain.request()).andReturn(mockRequest);
47 | EasyMock.expect(mockChain.proceed(mockRequest)).andReturn(mockResponse);
48 | EasyMock.expect(mockResponse.isSuccessful()).andReturn(true);
49 |
50 | PowerMock.replay(mockRequest, mockResponse, mockChain);
51 |
52 | Response returnedResponse = errorHandlingInterceptor.intercept(mockChain);
53 |
54 | PowerMock.verify(mockChain);
55 | Assert.assertEquals(mockResponse, returnedResponse);
56 | }
57 |
58 | @Test
59 | public void testParseNullResponseBody() throws IOException {
60 | int errorCode = 500;
61 | String errorMessage = "Internal Server Error";
62 |
63 | Interceptor.Chain mockChain = mockChainWithErrorResponse(errorCode, errorMessage, null);
64 | try {
65 | errorHandlingInterceptor.intercept(mockChain);
66 | } catch (UnexpectedAPIError error) {
67 | ErrorTestUtils.verifyErrorContent(error, errorCode, errorMessage, null, null);
68 | return;
69 | }
70 |
71 | Assert.fail("Expected failure not returned.");
72 | }
73 |
74 | @Test
75 | public void testParseBusinessUnavailable() throws IOException {
76 | int errorCode = 400;
77 | String errorMessage = "Bad Request";
78 | String errorId = "BUSINESS_UNAVAILABLE";
79 | String errorText = "Business information is unavailable";
80 | String errorJsonBody = generateErrorJsonString(errorId, errorText);
81 |
82 | Interceptor.Chain mockChain = mockChainWithErrorResponse(errorCode, errorMessage, errorJsonBody);
83 | try {
84 | errorHandlingInterceptor.intercept(mockChain);
85 | } catch (BusinessUnavailable error) {
86 | ErrorTestUtils.verifyErrorContent(error, errorCode, errorMessage, errorId, errorText);
87 | return;
88 | }
89 |
90 | Assert.fail("Expected failure not returned.");
91 | }
92 |
93 | @Test
94 | public void testParseInternalError() throws IOException {
95 | int errorCode = 500;
96 | String errorMessage = "Internal Server Error";
97 | String errorId = "INTERNAL_ERROR";
98 | String errorText = "Some internal error happened";
99 | String errorJsonBody = generateErrorJsonString(errorId, errorText);
100 |
101 | Interceptor.Chain mockChain = mockChainWithErrorResponse(errorCode, errorMessage, errorJsonBody);
102 | try {
103 | errorHandlingInterceptor.intercept(mockChain);
104 | } catch (InternalError error) {
105 | ErrorTestUtils.verifyErrorContent(error, errorCode, errorMessage, errorId, errorText);
106 | return;
107 | }
108 |
109 | Assert.fail("Expected failure not returned.");
110 | }
111 |
112 | @Test
113 | public void testParseErrorWithField() throws IOException {
114 | int errorCode = 400;
115 | String errorMessage = "Bad Request";
116 | String errorId = "INVALID_PARAMETER";
117 | String errorText = "One or more parameters are invalid in request";
118 | String errorField = "phone";
119 | String expectedErrorText = String.format("%s: %s", errorText, errorField);
120 | String errorJsonBody = generateErrorJsonString(errorId, errorText, errorField);
121 |
122 | Interceptor.Chain mockChain = mockChainWithErrorResponse(errorCode, errorMessage, errorJsonBody);
123 | try {
124 | errorHandlingInterceptor.intercept(mockChain);
125 | } catch (InvalidParameter error) {
126 | ErrorTestUtils.verifyErrorContent(error, errorCode, errorMessage, errorId, expectedErrorText);
127 | return;
128 | }
129 |
130 | Assert.fail("Expected failure not returned.");
131 | }
132 |
133 | @Test
134 | public void testParseUnexpectedAPIError() throws IOException {
135 | int errorCode = 400;
136 | String errorMessage = "Bad Request";
137 | String errorId = "COULD_BE_ANY_THING_NOT_DEFINED";
138 | String errorText = "Woops, there is something unexpected happened";
139 | String errorJsonBody = generateErrorJsonString(errorId, errorText);
140 |
141 | Interceptor.Chain mockChain = mockChainWithErrorResponse(errorCode, errorMessage, errorJsonBody);
142 | try {
143 | errorHandlingInterceptor.intercept(mockChain);
144 | } catch (UnexpectedAPIError error) {
145 | ErrorTestUtils.verifyErrorContent(error, errorCode, errorMessage, errorId, errorText);
146 | return;
147 | }
148 |
149 | Assert.fail("Expected failure not returned.");
150 | }
151 |
152 | @Test(expected = IOException.class)
153 | public void testParseInvalidJsonBody() throws IOException {
154 | int errorCode = 500;
155 | String errorMessage = "Internal Server Error";
156 | String errorHTMLBody = "This is not JSON";
157 |
158 | Interceptor.Chain mockChain = mockChainWithErrorResponse(errorCode, errorMessage, errorHTMLBody);
159 | errorHandlingInterceptor.intercept(mockChain);
160 | }
161 |
162 | private Interceptor.Chain mockChainWithErrorResponse(
163 | int errorCode,
164 | String errorMessage,
165 | String errorBody
166 | ) throws IOException {
167 | Response response = new Response.Builder()
168 | .request(PowerMock.createMock(Request.class))
169 | .protocol(PowerMock.createMock(Protocol.class))
170 | .code(errorCode)
171 | .message(errorMessage)
172 | .body(errorBody != null ? ResponseBody.create(MediaType.parse("UTF-8"), errorBody) : null)
173 | .build();
174 |
175 | Interceptor.Chain mockChain = PowerMock.createMock(Interceptor.Chain.class);
176 | EasyMock.expect(mockChain.request()).andReturn(PowerMock.createMock(Request.class));
177 | EasyMock.expect(mockChain.proceed(EasyMock.anyObject(Request.class))).andReturn(response);
178 | PowerMock.replay(mockChain);
179 |
180 | return mockChain;
181 | }
182 |
183 | private String generateErrorJsonString(String errorId, String text) {
184 | String errorJsonStringFormat = "{\"error\": {\"id\": \"%s\", \"text\": \"%s\"}}";
185 | return String.format(errorJsonStringFormat, errorId, text);
186 | }
187 |
188 | private String generateErrorJsonString(String errorId, String text, String field) {
189 | String errorJsonStringFormat = "{\"error\": {\"id\": \"%s\", \"text\": \"%s\", \"field\": \"%s\"}}";
190 | return String.format(errorJsonStringFormat, errorId, text, field);
191 | }
192 | }
193 |
--------------------------------------------------------------------------------
/src/test/java/com/yelp/clientlib/utils/AsyncTestUtils.java:
--------------------------------------------------------------------------------
1 | package com.yelp.clientlib.utils;
2 |
3 | import okhttp3.Dispatcher;
4 | import okhttp3.OkHttpClient;
5 | import com.yelp.clientlib.connection.YelpAPIFactory;
6 |
7 | import org.junit.Assert;
8 |
9 | import java.util.List;
10 | import java.util.concurrent.AbstractExecutorService;
11 | import java.util.concurrent.ExecutorService;
12 | import java.util.concurrent.TimeUnit;
13 |
14 | import junitx.util.PrivateAccessor;
15 |
16 | public class AsyncTestUtils {
17 |
18 | /**
19 | * Make a {@link YelpAPIFactory} to send HTTP requests in main thread so we can verify the test results easily.
20 | * Retrofit uses {@link OkHttpClient} for the underlying HTTP calls, this method replaces the {@link Dispatcher}
21 | * in {@link OkHttpClient} so an {@link ExecutorService} runs jobs in main thread will be used to send HTTP
22 | * requests.
23 | */
24 | public static YelpAPIFactory setToRunInMainThread(YelpAPIFactory yelpAPIFactory) {
25 | Dispatcher synchronousDispatcher = new Dispatcher(newSynchronousExecutorService());
26 |
27 | try {
28 | OkHttpClient httpClient = (OkHttpClient) PrivateAccessor.getField(yelpAPIFactory, "httpClient");
29 | OkHttpClient synchronousHttpClient = httpClient.newBuilder().dispatcher(synchronousDispatcher).build();
30 | PrivateAccessor.setField(yelpAPIFactory, "httpClient", synchronousHttpClient);
31 | } catch (NoSuchFieldException e) {
32 | Assert.fail(e.toString());
33 | }
34 |
35 | return yelpAPIFactory;
36 | }
37 |
38 | /**
39 | * Create an {@link ExecutorService} which runs jobs in main thread.
40 | */
41 | public static ExecutorService newSynchronousExecutorService() {
42 | return new AbstractExecutorService() {
43 | @Override
44 | public void execute(Runnable command) {
45 | command.run();
46 | }
47 |
48 | @Override
49 | public void shutdown() {
50 | throw new UnsupportedOperationException();
51 | }
52 |
53 | @Override
54 | public List shutdownNow() {
55 | throw new UnsupportedOperationException();
56 | }
57 |
58 | @Override
59 | public boolean isShutdown() {
60 | throw new UnsupportedOperationException();
61 | }
62 |
63 | @Override
64 | public boolean isTerminated() {
65 | throw new UnsupportedOperationException();
66 | }
67 |
68 | @Override
69 | public boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedException {
70 | throw new UnsupportedOperationException();
71 | }
72 | };
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/src/test/java/com/yelp/clientlib/utils/ErrorTestUtils.java:
--------------------------------------------------------------------------------
1 | package com.yelp.clientlib.utils;
2 |
3 | import com.yelp.clientlib.exception.exceptions.YelpAPIError;
4 |
5 | import org.junit.Assert;
6 |
7 | public class ErrorTestUtils {
8 |
9 | /**
10 | * Verify a {@link YelpAPIError} contains correct information.
11 | *
12 | * @param error The YelpAPIError to be verified.
13 | * @param expectCode Expected error code.
14 | * @param expectMessage Expected error message.
15 | * @param expectId Expected error Id.
16 | * @param expectText Expected error text.
17 | */
18 | public static void verifyErrorContent(
19 | YelpAPIError error,
20 | int expectCode,
21 | String expectMessage,
22 | String expectId,
23 | String expectText
24 | ) {
25 | Assert.assertEquals(expectCode, error.getCode());
26 | Assert.assertEquals(expectMessage, error.getMessage());
27 | Assert.assertEquals(expectId, error.getErrorId());
28 | Assert.assertEquals(expectText, error.getText());
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/src/test/java/com/yelp/clientlib/utils/JsonTestUtils.java:
--------------------------------------------------------------------------------
1 | package com.yelp.clientlib.utils;
2 |
3 | import com.fasterxml.jackson.databind.JsonNode;
4 | import com.fasterxml.jackson.databind.ObjectMapper;
5 |
6 | import java.io.File;
7 | import java.io.IOException;
8 |
9 | public class JsonTestUtils {
10 | public static final String BUSINESS_RESPONSE_JSON_FILENAME = "businessResponse.json";
11 |
12 | public static final String SEARCH_RESPONSE_JSON_FILENAME = "searchResponse.json";
13 |
14 | public static JsonNode getBusinessResponseJsonNode() throws IOException {
15 | return getJsonNodeFromFile(BUSINESS_RESPONSE_JSON_FILENAME);
16 | }
17 |
18 | public static JsonNode getSearchResponseJsonNode() throws IOException {
19 | return getJsonNodeFromFile(SEARCH_RESPONSE_JSON_FILENAME);
20 | }
21 |
22 | public static JsonNode getJsonNodeFromFile(String filename) throws IOException {
23 | File jsonFile = new File(JsonTestUtils.class.getClassLoader().getResource(filename).getFile());
24 | return new ObjectMapper().readTree(jsonFile);
25 | }
26 |
27 | public static T deserializeJson(String content, Class valueType) throws IOException {
28 | return new ObjectMapper().readValue(content, valueType);
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/src/test/java/com/yelp/clientlib/utils/SerializationTestUtils.java:
--------------------------------------------------------------------------------
1 | package com.yelp.clientlib.utils;
2 |
3 | import java.io.ByteArrayInputStream;
4 | import java.io.ByteArrayOutputStream;
5 | import java.io.IOException;
6 | import java.io.ObjectInputStream;
7 | import java.io.ObjectOutputStream;
8 | import java.io.Serializable;
9 |
10 | public class SerializationTestUtils {
11 |
12 | /**
13 | * Serialize an object into a byte array. The object has to implement {@link Serializable} interface.
14 | *
15 | * @param object Object to be serialized.
16 | * @return Byte array serialized from the object.
17 | */
18 | public static byte[] serialize(T object) throws IOException {
19 | ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
20 | ObjectOutputStream objectOutputStream = new ObjectOutputStream(byteArrayOutputStream);
21 | objectOutputStream.writeObject(object);
22 | objectOutputStream.close();
23 |
24 | return byteArrayOutputStream.toByteArray();
25 | }
26 |
27 | /**
28 | * Deserialize a byte array into an object. The object has to implement {@link Serializable} interface.
29 | *
30 | * @param bytes Byte array to be deserialized.
31 | * @param clazz Class type the object should be deserialized into.
32 | * @return Object deserialized from the byte array.
33 | */
34 | public static T deserialize(byte[] bytes, Class clazz)
35 | throws IOException, ClassNotFoundException {
36 | ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(bytes);
37 | ObjectInputStream objectInputStream = new ObjectInputStream(byteArrayInputStream);
38 | Object object = objectInputStream.readObject();
39 |
40 | return clazz.cast(object);
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/src/test/resources/businessResponse.json:
--------------------------------------------------------------------------------
1 | {
2 | "categories": [
3 | [
4 | "Indian",
5 | "indpak"
6 | ],
7 | [
8 | "Himalayan/Nepalese",
9 | "himalayan"
10 | ]
11 | ],
12 | "deals": [
13 | {
14 | "currency_code": "USD",
15 | "image_url": "http://s3-media4.ak.yelpcdn.com/dphoto/ShQGf5qi-52HwPiKyZTZ3w/m.jpg",
16 | "options": [
17 | {
18 | "formatted_original_price": "$20",
19 | "formatted_price": "$10",
20 | "is_quantity_limited": true,
21 | "original_price": 2000,
22 | "price": 1000,
23 | "purchase_url": "http://www.yelp.com/deal/cC24ccQGIH8mowfu5Vbe0Q/view",
24 | "remaining_count": 36,
25 | "title": "$10 for $20 voucher"
26 | }
27 | ],
28 | "url": "http://www.yelp.com/biz/urban-curry-san-francisco?deal=1",
29 | "is_popular": true,
30 | "time_start": 1317414369,
31 | "title": "$10 for $20 voucher"
32 | }
33 | ],
34 | "display_phone": "+1-415-677-9743",
35 | "eat24_url": "http://e24.io/r/5769?utm_campaign=public&utm_medium=yelpapi&utm_source=yelpapi",
36 | "gift_certificates": [
37 | {
38 | "currency_code": "USD",
39 | "image_url": "http://s3-media4.ak.yelpcdn.com/bphoto/Hv5vsWpqeaUKepr9nffJnw/m.jpg",
40 | "options": [
41 | {
42 | "formatted_price": "$25",
43 | "price": 2500
44 | },
45 | {
46 | "formatted_price": "$50",
47 | "price": 5000
48 | }
49 | ],
50 | "url": "http://www.yelp.com/gift-certificates/some-donut-place-pasadena",
51 | "id": "ZZy5EwrI3wyHw8y54jZruA",
52 | "unused_balances": "CREDIT"
53 | }
54 | ],
55 | "id": "urban-curry-san-francisco",
56 | "image_url": "http://s3-media1.fl.yelpcdn.com/bphoto/u5b1u7c04C1GkptUg0grdA/ms.jpg",
57 | "is_claimed": true,
58 | "is_closed": false,
59 | "location": {
60 | "address": [
61 | "523 Broadway"
62 | ],
63 | "city": "San Francisco",
64 | "coordinate": {
65 | "latitude": 37.7978994,
66 | "longitude": -122.4059649
67 | },
68 | "country_code": "US",
69 | "cross_streets": "Romolo Pl & Kearny St",
70 | "display_address": [
71 | "523 Broadway",
72 | "North Beach/Telegraph Hill",
73 | "San Francisco, CA 94133"
74 | ],
75 | "geo_accuracy": 9.5,
76 | "neighborhoods": [
77 | "North Beach/Telegraph Hill",
78 | "Chinatown"
79 | ],
80 | "postal_code": "94133",
81 | "state_code": "CA"
82 | },
83 | "menu_date_updated": 1443040751,
84 | "menu_provider": "single_platform",
85 | "mobile_url": "http://m.yelp.com/biz/urban-curry-san-francisco",
86 | "name": "Urban Curry",
87 | "phone": "4156779743",
88 | "rating": 4.0,
89 | "rating_img_url": "http://s3-media4.fl.yelpcdn.com/assets/2/www/img/c2f3dd9799a5/ico/stars/v1/stars_4.png",
90 | "rating_img_url_large": "http://s3-media2.fl.yelpcdn.com/assets/2/www/img/ccf2b76faa2c/ico/stars/v1/stars_large_4.png",
91 | "rating_img_url_small": "http://s3-media4.fl.yelpcdn.com/assets/2/www/img/f62a5be2f902/ico/stars/v1/stars_small_4.png",
92 | "review_count": 455,
93 | "reviews": [
94 | {
95 | "excerpt": "One of the owners is a former Sherpa from Nepal who has summitted Mt. Everest twice. While the restaurant is in a seeder part of the City, it's also on one...",
96 | "id": "flAK8Mu4auUdcFNR7iPa6Q",
97 | "rating": 4,
98 | "rating_image_large_url": "http://s3-media2.fl.yelpcdn.com/assets/2/www/img/ccf2b76faa2c/ico/stars/v1/stars_large_4.png",
99 | "rating_image_small_url": "http://s3-media4.fl.yelpcdn.com/assets/2/www/img/f62a5be2f902/ico/stars/v1/stars_small_4.png",
100 | "rating_image_url": "http://s3-media4.fl.yelpcdn.com/assets/2/www/img/c2f3dd9799a5/ico/stars/v1/stars_4.png",
101 | "time_created": 1440895245,
102 | "user": {
103 | "id": "3KNNxsQa4uooK5FAj7bVaQ",
104 | "image_url": "http://s3-media3.fl.yelpcdn.com/photo/hk31BkJvJ8qcqoUvZ38rmQ/ms.jpg",
105 | "name": "Hilary C."
106 | }
107 | }
108 | ],
109 | "snippet_image_url": "http://s3-media3.fl.yelpcdn.com/photo/hk31BkJvJ8qcqoUvZ38rmQ/ms.jpg",
110 | "snippet_text": "One of the owners is a former Sherpa from Nepal who has summitted Mt. Everest twice. While the restaurant is in a seeder part of the City, it's also on one...",
111 | "url": "http://www.yelp.com/biz/urban-curry-san-francisco"
112 | }
--------------------------------------------------------------------------------
/src/test/resources/noReviewBusinessResponse.json:
--------------------------------------------------------------------------------
1 | {
2 | "is_claimed": true,
3 | "rating": 0.0,
4 | "mobile_url": "http://m.yelp.com/biz/yelp-fantastic-san-francisco",
5 | "rating_img_url": "http://media4.fl.yelpcdn.com/assets/2/www/img/04ae5eda5622/ico/stars/v1/stars_0.png",
6 | "review_count": 0,
7 | "name": "Yelp Fantastic",
8 | "rating_img_url_small": "http://media4.fl.yelpcdn.com/assets/2/www/img/d3cd853a8cb7/ico/stars/v1/stars_small_0.png",
9 | "url": "http://www.yelp.com/biz/yelp-fantastic-san-francisco",
10 | "categories": [
11 | [
12 | "Local Flavor",
13 | "localflavor"
14 | ],
15 | [
16 | "Mass Media",
17 | "massmedia"
18 | ]
19 | ],
20 | "phone": "4156069349",
21 | "location": {
22 | "cross_streets": "Natoma St & Minna St",
23 | "city": "San Francisco",
24 | "display_address": [
25 | "140 New Montgomery St",
26 | "Financial District",
27 | "San Francisco, CA 94105"
28 | ],
29 | "geo_accuracy": 9.5,
30 | "neighborhoods": [
31 | "Financial District",
32 | "SoMa"
33 | ],
34 | "postal_code": "94105",
35 | "country_code": "US",
36 | "address": [
37 | "140 New Montgomery St"
38 | ],
39 | "coordinate": {
40 | "latitude": 37.7867703362929,
41 | "longitude": -122.399958372115
42 | },
43 | "state_code": "CA"
44 | },
45 | "display_phone": "+1-415-908-3801",
46 | "rating_img_url_large": "http://media2.fl.yelpcdn.com/assets/2/www/img/1d04a136ee3e/ico/stars/v1/stars_large_0.png",
47 | "id": "yelp-fantastic-san-francisco",
48 | "is_closed": false
49 | }
50 |
--------------------------------------------------------------------------------
/src/test/resources/sampleFailureResponse.json:
--------------------------------------------------------------------------------
1 | {
2 | "error": {
3 | "id": "BUSINESS_UNAVAILABLE",
4 | "text": "Business information is unavailable"
5 | }
6 | }
--------------------------------------------------------------------------------
/src/test/resources/searchResponse.json:
--------------------------------------------------------------------------------
1 | {
2 | "region": {
3 | "span": {
4 | "latitude_delta": 0.05983615047641422,
5 | "longitude_delta": 0.04888134068070826
6 | },
7 | "center": {
8 | "latitude": 37.77991744978345,
9 | "longitude": -122.4147528087815
10 | }
11 | },
12 | "total": 13807,
13 | "businesses": [
14 | {
15 | "is_claimed": true,
16 | "rating": 4.0,
17 | "mobile_url": "http://m.yelp.com/biz/brendas-french-soul-food-san-francisco",
18 | "rating_img_url": "http://s3-media4.fl.yelpcdn.com/assets/2/www/img/c2f3dd9799a5/ico/stars/v1/stars_4.png",
19 | "review_count": 6644,
20 | "name": "Brenda's French Soul Food",
21 | "rating_img_url_small": "http://s3-media4.fl.yelpcdn.com/assets/2/www/img/f62a5be2f902/ico/stars/v1/stars_small_4.png",
22 | "url": "http://www.yelp.com/biz/brendas-french-soul-food-san-francisco",
23 | "categories": [
24 | [
25 | "Breakfast & Brunch",
26 | "breakfast_brunch"
27 | ],
28 | [
29 | "French",
30 | "french"
31 | ],
32 | [
33 | "Soul Food",
34 | "soulfood"
35 | ]
36 | ],
37 | "menu_date_updated": 1442008852,
38 | "phone": "4153458100",
39 | "snippet_text": "Crawfish beignets and cheesy grits are baaaaaaae. Brenda's food is absolutely delicious and prices are great, and it's only been a few hours since I was in...",
40 | "image_url": "http://s3-media1.fl.yelpcdn.com/bphoto/mEzEYZ1lIM6mYfbKgHwCjw/ms.jpg",
41 | "snippet_image_url": "http://s3-media4.fl.yelpcdn.com/photo/kO5nMfF6VsB-YTQXThdvvA/ms.jpg",
42 | "display_phone": "+1-415-345-8100",
43 | "rating_img_url_large": "http://s3-media2.fl.yelpcdn.com/assets/2/www/img/ccf2b76faa2c/ico/stars/v1/stars_large_4.png",
44 | "menu_provider": "single_platform",
45 | "id": "brendas-french-soul-food-san-francisco",
46 | "is_closed": false,
47 | "location": {
48 | "cross_streets": "Turk St & Eddy St",
49 | "city": "San Francisco",
50 | "display_address": [
51 | "652 Polk St",
52 | "Tenderloin",
53 | "San Francisco, CA 94102"
54 | ],
55 | "geo_accuracy": 9.5,
56 | "neighborhoods": [
57 | "Tenderloin"
58 | ],
59 | "postal_code": "94102",
60 | "country_code": "US",
61 | "address": [
62 | "652 Polk St"
63 | ],
64 | "coordinate": {
65 | "latitude": 37.7828800032306,
66 | "longitude": -122.419018169646
67 | },
68 | "state_code": "CA"
69 | }
70 | },
71 | {
72 | "is_claimed": true,
73 | "rating": 4.5,
74 | "mobile_url": "http://m.yelp.com/biz/the-codmother-fish-and-chips-san-francisco",
75 | "rating_img_url": "http://s3-media2.fl.yelpcdn.com/assets/2/www/img/99493c12711e/ico/stars/v1/stars_4_half.png",
76 | "review_count": 1599,
77 | "name": "The Codmother Fish and Chips",
78 | "rating_img_url_small": "http://s3-media2.fl.yelpcdn.com/assets/2/www/img/a5221e66bc70/ico/stars/v1/stars_small_4_half.png",
79 | "url": "http://www.yelp.com/biz/the-codmother-fish-and-chips-san-francisco",
80 | "categories": [
81 | [
82 | "British",
83 | "british"
84 | ],
85 | [
86 | "Fish & Chips",
87 | "fishnchips"
88 | ],
89 | [
90 | "Seafood",
91 | "seafood"
92 | ]
93 | ],
94 | "phone": "4156069349",
95 | "snippet_text": "Very very good fish and chips and fish tacos !!!\n\nLooks like a shack in the side of the road but the food is excellent. Try it !",
96 | "image_url": "http://s3-media3.fl.yelpcdn.com/bphoto/JhkeEgh-NOn9wSHyvaRNdQ/ms.jpg",
97 | "snippet_image_url": "http://s3-media2.fl.yelpcdn.com/photo/5tM6qnZXuTgOaglIdkUQzQ/ms.jpg",
98 | "display_phone": "+1-415-606-9349",
99 | "rating_img_url_large": "http://s3-media4.fl.yelpcdn.com/assets/2/www/img/9f83790ff7f6/ico/stars/v1/stars_large_4_half.png",
100 | "id": "the-codmother-fish-and-chips-san-francisco",
101 | "is_closed": false,
102 | "location": {
103 | "cross_streets": "Jones St & Taylor St",
104 | "city": "San Francisco",
105 | "display_address": [
106 | "496 Beach St",
107 | "North Beach/Telegraph Hill",
108 | "San Francisco, CA 94133"
109 | ],
110 | "geo_accuracy": 9.5,
111 | "neighborhoods": [
112 | "North Beach/Telegraph Hill",
113 | "Fisherman's Wharf"
114 | ],
115 | "postal_code": "94133",
116 | "country_code": "US",
117 | "address": [
118 | "496 Beach St"
119 | ],
120 | "coordinate": {
121 | "latitude": 37.8071157,
122 | "longitude": -122.4172602
123 | },
124 | "state_code": "CA"
125 | }
126 | },
127 | {
128 | "is_claimed": true,
129 | "rating": 4.5,
130 | "mobile_url": "http://m.yelp.com/biz/ikes-place-san-francisco",
131 | "rating_img_url": "http://s3-media2.fl.yelpcdn.com/assets/2/www/img/99493c12711e/ico/stars/v1/stars_4_half.png",
132 | "review_count": 6797,
133 | "name": "Ike's Place",
134 | "rating_img_url_small": "http://s3-media2.fl.yelpcdn.com/assets/2/www/img/a5221e66bc70/ico/stars/v1/stars_small_4_half.png",
135 | "url": "http://www.yelp.com/biz/ikes-place-san-francisco",
136 | "categories": [
137 | [
138 | "Sandwiches",
139 | "sandwiches"
140 | ]
141 | ],
142 | "menu_date_updated": 1445588108,
143 | "phone": "4155536888",
144 | "snippet_text": "I was in town for a few days and had to stop by here based on the fantastic Yelp reviews! \n\nThe place is a small order and go restaurant. They have a large...",
145 | "image_url": "http://s3-media3.fl.yelpcdn.com/bphoto/9jSqZ0UH03FXarOq80Bpww/ms.jpg",
146 | "snippet_image_url": "http://s3-media4.fl.yelpcdn.com/photo/XsrJub-9x7NTpatnk2E0bw/ms.jpg",
147 | "display_phone": "+1-415-553-6888",
148 | "rating_img_url_large": "http://s3-media4.fl.yelpcdn.com/assets/2/www/img/9f83790ff7f6/ico/stars/v1/stars_large_4_half.png",
149 | "menu_provider": "eat24",
150 | "id": "ikes-place-san-francisco",
151 | "is_closed": false,
152 | "location": {
153 | "cross_streets": "Dehon St & Sanchez St",
154 | "city": "San Francisco",
155 | "display_address": [
156 | "3489 16th St",
157 | "Castro",
158 | "San Francisco, CA 94114"
159 | ],
160 | "geo_accuracy": 9.5,
161 | "neighborhoods": [
162 | "Castro"
163 | ],
164 | "postal_code": "94114",
165 | "country_code": "US",
166 | "address": [
167 | "3489 16th St"
168 | ],
169 | "coordinate": {
170 | "latitude": 37.7642944915352,
171 | "longitude": -122.430696487427
172 | },
173 | "state_code": "CA"
174 | }
175 | },
176 | {
177 | "is_claimed": true,
178 | "rating": 4.5,
179 | "mobile_url": "http://m.yelp.com/biz/hrd-san-francisco-2",
180 | "rating_img_url": "http://s3-media2.fl.yelpcdn.com/assets/2/www/img/99493c12711e/ico/stars/v1/stars_4_half.png",
181 | "review_count": 1667,
182 | "name": "HRD",
183 | "rating_img_url_small": "http://s3-media2.fl.yelpcdn.com/assets/2/www/img/a5221e66bc70/ico/stars/v1/stars_small_4_half.png",
184 | "url": "http://www.yelp.com/biz/hrd-san-francisco-2",
185 | "categories": [
186 | [
187 | "Asian Fusion",
188 | "asianfusion"
189 | ]
190 | ],
191 | "menu_date_updated": 1441920733,
192 | "phone": "4155432355",
193 | "snippet_text": "Found out about this by (don't judge me) looking up Diners Drive-Ins and Dives spot in SF. The wait staff was incredible enthusiastic, and answered a lot of...",
194 | "image_url": "http://s3-media4.fl.yelpcdn.com/bphoto/KEwOE6RPiGRm2H0zVHVAgA/ms.jpg",
195 | "snippet_image_url": "http://s3-media4.fl.yelpcdn.com/photo/jJ3kD6f1yVYIXqxPerTm_w/ms.jpg",
196 | "display_phone": "+1-415-543-2355",
197 | "rating_img_url_large": "http://s3-media4.fl.yelpcdn.com/assets/2/www/img/9f83790ff7f6/ico/stars/v1/stars_large_4_half.png",
198 | "menu_provider": "single_platform",
199 | "id": "hrd-san-francisco-2",
200 | "is_closed": false,
201 | "location": {
202 | "cross_streets": "Taber Aly & Park Ave",
203 | "city": "San Francisco",
204 | "display_address": [
205 | "521A 3rd St",
206 | "SoMa",
207 | "San Francisco, CA 94107"
208 | ],
209 | "geo_accuracy": 9.5,
210 | "neighborhoods": [
211 | "SoMa"
212 | ],
213 | "postal_code": "94107",
214 | "country_code": "US",
215 | "address": [
216 | "521A 3rd St"
217 | ],
218 | "coordinate": {
219 | "latitude": 37.7812019,
220 | "longitude": -122.3952255
221 | },
222 | "state_code": "CA"
223 | }
224 | },
225 | {
226 | "is_claimed": true,
227 | "rating": 4.0,
228 | "mobile_url": "http://m.yelp.com/biz/box-kitchen-san-francisco",
229 | "rating_img_url": "http://s3-media4.fl.yelpcdn.com/assets/2/www/img/c2f3dd9799a5/ico/stars/v1/stars_4.png",
230 | "review_count": 307,
231 | "name": "Box Kitchen",
232 | "rating_img_url_small": "http://s3-media4.fl.yelpcdn.com/assets/2/www/img/f62a5be2f902/ico/stars/v1/stars_small_4.png",
233 | "url": "http://www.yelp.com/biz/box-kitchen-san-francisco",
234 | "categories": [
235 | [
236 | "Food Stands",
237 | "foodstands"
238 | ],
239 | [
240 | "Burgers",
241 | "burgers"
242 | ]
243 | ],
244 | "phone": "4155807170",
245 | "snippet_text": "This is a somewhat hidden gem. The food was outstanding. They are the same owners as Louie Bar that I've been to and they have the same amazing potato skins...",
246 | "image_url": "http://s3-media1.fl.yelpcdn.com/bphoto/nrfAbr4yo57-hK0KsF7gZA/ms.jpg",
247 | "snippet_image_url": "http://s3-media4.fl.yelpcdn.com/photo/fJrH0wlC-Myp6Y4-m_9AyA/ms.jpg",
248 | "display_phone": "+1-415-580-7170",
249 | "rating_img_url_large": "http://s3-media2.fl.yelpcdn.com/assets/2/www/img/ccf2b76faa2c/ico/stars/v1/stars_large_4.png",
250 | "id": "box-kitchen-san-francisco",
251 | "is_closed": false,
252 | "location": {
253 | "cross_streets": "5th St & Mary St",
254 | "city": "San Francisco",
255 | "display_address": [
256 | "431 Natoma St",
257 | "SoMa",
258 | "San Francisco, CA 94103"
259 | ],
260 | "geo_accuracy": 9.5,
261 | "neighborhoods": [
262 | "SoMa"
263 | ],
264 | "postal_code": "94103",
265 | "country_code": "US",
266 | "address": [
267 | "431 Natoma St"
268 | ],
269 | "coordinate": {
270 | "latitude": 37.7811688139033,
271 | "longitude": -122.406377480554
272 | },
273 | "state_code": "CA"
274 | }
275 | },
276 | {
277 | "is_claimed": true,
278 | "rating": 4.5,
279 | "mobile_url": "http://m.yelp.com/biz/the-chairman-san-francisco-2",
280 | "rating_img_url": "http://s3-media2.fl.yelpcdn.com/assets/2/www/img/99493c12711e/ico/stars/v1/stars_4_half.png",
281 | "review_count": 139,
282 | "name": "The Chairman",
283 | "rating_img_url_small": "http://s3-media2.fl.yelpcdn.com/assets/2/www/img/a5221e66bc70/ico/stars/v1/stars_small_4_half.png",
284 | "url": "http://www.yelp.com/biz/the-chairman-san-francisco-2",
285 | "categories": [
286 | [
287 | "Asian Fusion",
288 | "asianfusion"
289 | ],
290 | [
291 | "Chinese",
292 | "chinese"
293 | ]
294 | ],
295 | "menu_date_updated": 1445504029,
296 | "phone": "4158138800",
297 | "snippet_text": "I am normally not a fan of delivery fees of more than a dollar or two but the $4.95 fee that The Chairman charges is probably a good thing- otherwise I...",
298 | "image_url": "http://s3-media4.fl.yelpcdn.com/bphoto/ITHb2WpqRc0zb9MDT3d1Dg/ms.jpg",
299 | "snippet_image_url": "http://s3-media3.fl.yelpcdn.com/photo/9nVSCd8GU68CGuxD0Cshug/ms.jpg",
300 | "display_phone": "+1-415-813-8800",
301 | "rating_img_url_large": "http://s3-media4.fl.yelpcdn.com/assets/2/www/img/9f83790ff7f6/ico/stars/v1/stars_large_4_half.png",
302 | "menu_provider": "eat24",
303 | "id": "the-chairman-san-francisco-2",
304 | "is_closed": false,
305 | "location": {
306 | "cross_streets": "Willow St & Ellis St",
307 | "city": "San Francisco",
308 | "display_address": [
309 | "670 Larkin St",
310 | "Tenderloin",
311 | "San Francisco, CA 94109"
312 | ],
313 | "geo_accuracy": 9.5,
314 | "neighborhoods": [
315 | "Tenderloin"
316 | ],
317 | "postal_code": "94109",
318 | "country_code": "US",
319 | "address": [
320 | "670 Larkin St"
321 | ],
322 | "coordinate": {
323 | "latitude": 37.7840223067038,
324 | "longitude": -122.41758517921
325 | },
326 | "state_code": "CA"
327 | }
328 | }
329 | ]
330 | }
--------------------------------------------------------------------------------