Skip to content

Commit

Permalink
Updating models
Browse files Browse the repository at this point in the history
  • Loading branch information
ranesr committed Aug 14, 2018
1 parent beed827 commit 5b4bac2
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ public class AutoCompleteParameters implements Parameters {
private Double longitude;
private Locale locale;

public String getParameters() throws Exception {
StringBuilder builder = new StringBuilder();
public String getParameters() throws NullParameterException {
StringBuilder builder = new StringBuilder("?");
if (text == null) {
throw new NullParameterException("text cannot be null for /autocomplete endpoint.");
}
builder.append("&text=").append(text);
builder.append("text=").append(text);

if (latitude != null) {
builder.append("&latitude=").append(String.valueOf(latitude));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

package com.yelp.model.parameters;

import com.yelp.services.YelpApi;
import lombok.Data;

import com.yelp.exception.InvalidParameterException;
Expand All @@ -48,7 +49,7 @@ public class BusinessMatchesParameters implements Parameters {
private Integer limit;
private String matchThreshold;

public String getParameters() throws Exception {
public String getParameters() throws NullParameterException, InvalidParameterException {
StringBuilder builder = new StringBuilder("?");

if (StringUtils.isBlank(name)) {
Expand Down Expand Up @@ -86,15 +87,15 @@ public String getParameters() throws Exception {
if (latitude != null) {
if (latitude < -90 || latitude > 90) {
throw new InvalidParameterException("Please input the correct parameter value for latitude in " +
"/businesses/matches endpoint.");
YelpApi.BUSINESSES_MATCHES_ENDPOINT + " endpoint.");
}
builder.append("&latitude=").append(latitude);
}

if (longitude != null) {
if (longitude < -180 || longitude > 180) {
throw new InvalidParameterException("Please input the correct parameter value for longitude in " +
"/businesses/matches endpoint.");
YelpApi.BUSINESSES_MATCHES_ENDPOINT + " endpoint.");
}
builder.append("&longitude=").append(longitude);
}
Expand All @@ -114,7 +115,7 @@ public String getParameters() throws Exception {
if (limit != null) {
if (limit > 10) {
throw new InvalidParameterException("Please input the correct parameter value for limit in " +
"/businesses/matches endpoint.");
YelpApi.BUSINESSES_MATCHES_ENDPOINT + " endpoint.");
}
builder.append("&limit=").append(limit);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public class BusinessSearchParameters implements Parameters {
private Integer openAt;
private List<Attribute> attributes;

public String getParameters() throws Exception {
public String getParameters() throws NullParameterException, InvalidParameterException {
StringBuilder builder = new StringBuilder("?");

if (!StringUtils.isBlank(term)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

import com.yelp.exception.NullParameterException;

import com.yelp.services.YelpApi;
import lombok.Data;

import org.apache.commons.lang3.StringUtils;
Expand All @@ -33,11 +34,12 @@ public class BusinessSearchPhoneParameters implements Parameters {
private String phone;

@Override
public String getParameters() throws Exception {
public String getParameters() throws NullParameterException {
StringBuilder builder = new StringBuilder("?");

if (StringUtils.isBlank(phone)) {
throw new NullParameterException("Phone cannot be null for /businesses/search/phone endpoint.");
throw new NullParameterException("Phone cannot be null for " + YelpApi.BUSINESSES_SEARCH_PHONE_ENDPOINT
+ " endpoint.");
}
builder.append("phone=").append(phone);

Expand Down
5 changes: 4 additions & 1 deletion src/main/java/com/yelp/model/parameters/Parameters.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,13 @@

package com.yelp.model.parameters;

import com.yelp.exception.InvalidParameterException;
import com.yelp.exception.NullParameterException;

import java.util.List;

public interface Parameters {
String getParameters() throws Exception;
String getParameters() throws NullParameterException, InvalidParameterException;

default <E> String getParameterValues(List<E> list) {
StringBuilder builder = new StringBuilder();
Expand Down

0 comments on commit 5b4bac2

Please sign in to comment.