diff --git a/.gitignore b/.gitignore index 2c1cc35..ba08868 100644 --- a/.gitignore +++ b/.gitignore @@ -13,5 +13,5 @@ dist /.project /RUNNING_PID /.settings - +test.db \ No newline at end of file diff --git a/pom.xml b/pom.xml index 01e0494..5ce3e3e 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ BookingBug-SDK BookingBug-SDK - 1.4 + 1.9 @@ -68,10 +68,36 @@ commons-lang3 3.0 + + + io.reactivex + rxjava + 1.1.0 + + + + org.xerial + sqlite-jdbc + 3.8.11.2 + + + + com.j256.ormlite + ormlite-jdbc + 4.43 + + + + com.squareup.okhttp3 + okhttp + 3.2.0 + + - com.googlecode.json-simple - json-simple - 1.1 + com.squareup.okhttp + mockwebserver + 2.7.0 + test diff --git a/src/main/bookingbugAPI/api/API.java b/src/main/bookingbugAPI/api/API.java new file mode 100644 index 0000000..358e675 --- /dev/null +++ b/src/main/bookingbugAPI/api/API.java @@ -0,0 +1,22 @@ +package bookingbugAPI.api; + +/** + * Created by sebi on 19.05.2016. + */ +public class API extends AbstractAPI { + + public API(ApiConfig config) { + super(config); + } + + public AdminAPI admin() { + return new AdminAPI(newConfig()); + } + + public static class APIBuilder extends AbstractAPI.ApiConfig { + + public API build() { + return new API(this); + } + } +} diff --git a/src/main/bookingbugAPI/api/AbstractAPI.java b/src/main/bookingbugAPI/api/AbstractAPI.java new file mode 100644 index 0000000..4c7386c --- /dev/null +++ b/src/main/bookingbugAPI/api/AbstractAPI.java @@ -0,0 +1,133 @@ +package bookingbugAPI.api; + +import bookingbugAPI.services.CacheService; +import bookingbugAPI.services.OkHttpService; + +import java.io.FileNotFoundException; +import java.io.InputStream; +import java.io.StringReader; +import java.util.Properties; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * Abstract API class + * Contains basic methods and members + */ +public abstract class AbstractAPI { + + protected OkHttpService httpService; + + public AbstractAPI(ApiConfig config){ + httpService = new OkHttpService(config); + } + + public ApiConfig newConfig() { + return new ApiConfig(httpService.getConfig()); + } + + public String getAuthToken(){ + return httpService.getConfig().auth_token; + } + + public void setAuthToken(String auth_token) { + httpService.getConfig().withAuthToken(auth_token); + } + + /** + * Class which holds an API configuration + * @param Keep fluent interface for subclasses + */ + public static class ApiConfig { + + static final String propFileName = "bb_sdk_config.properties"; + private final static Logger logger = Logger.getLogger(ApiConfig.class.getName()); + + public String auth_token; + public String appId; + public String appKey; + public String userAgent; + public String serverUrl; + public CacheService cacheService; + + public ApiConfig(ApiConfig config) { + this.auth_token = config.auth_token; + this.appId = config.appId; + this.appKey = config.appKey; + this.userAgent = config.userAgent; + this.serverUrl = config.serverUrl; + this.cacheService = config.cacheService; + } + + public ApiConfig() { + loadConfigFile(null); + cacheService = CacheService.JDBC(); + } + + public T withNothing() { + auth_token = null; + appId = ""; + appKey = ""; + userAgent = ""; + serverUrl = null; + cacheService = null; + return (T) this; + } + + public T withAuthToken(String token) { + this.auth_token = token; + return (T)this; + } + + public T withCache(CacheService cacheService) { + this.cacheService = cacheService; + return (T)this; + } + + public T withApp(String appId, String appKey) { + this.appId = appId; + this.appKey = appKey; + return (T)this; + } + + public T withUserAgent(String userAgent) { + this.userAgent = userAgent; + return (T)this; + } + + public T withServerUrl(String serverUrl) { + this.serverUrl = serverUrl; + return (T)this; + } + + public T withConfigString(String configString) { + loadConfigFile(configString); + return (T)this; + } + + private void loadConfigFile(String configString) { + try{ + Properties prop = new Properties(); + + if(configString != null) { + prop.load(new StringReader(configString)); + } + else { + InputStream inputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(propFileName); + if (inputStream != null) { + prop.load(inputStream); + } else { + throw new FileNotFoundException("property file '" + propFileName + "' not found in the classpath"); + } + } + + appId = prop.getProperty("application.auth.appid"); + appKey = prop.getProperty("application.auth.appkey"); + userAgent = prop.getProperty("application.auth.useragent"); + serverUrl = prop.getProperty("application.auth.serverurl"); + } catch (Exception e) { + logger.log(Level.SEVERE, "Exception @ ApiConfig.withConfigFile(): " + e.getMessage()); + } + } + } +} diff --git a/src/main/bookingbugAPI/api/AdminAPI.java b/src/main/bookingbugAPI/api/AdminAPI.java index b610f46..d7809b3 100644 --- a/src/main/bookingbugAPI/api/AdminAPI.java +++ b/src/main/bookingbugAPI/api/AdminAPI.java @@ -1,139 +1,37 @@ package bookingbugAPI.api; import bookingbugAPI.models.*; +import bookingbugAPI.models.params.BookingListParams; import bookingbugAPI.services.HttpService; +import bookingbugAPI.services.OkHttpService; +import helpers.Utils; import java.io.IOException; import java.net.URL; -public class AdminAPI { +public class AdminAPI extends AbstractAPI { - static public class CompanyAPI extends AuthedAPI { - - public CompanyAPI(String token) { - super(token); - } - - public Company companyList(String companyId) throws IOException { - String uri = AdminURLS.Company.companyList().set("companyId", companyId).expand(); - URL url = new URL(uri); - - return new Company(HttpService.api_GET(url, auth_token)); - } - } - - static public class PersonAPI extends AuthedAPI { - - public PersonAPI(String token) { - super(token); - } - - public People personList(String companyId) throws IOException { - String uri = AdminURLS.Person.personList().set("companyId", companyId).expand(); - URL url = new URL (uri); - - return new People(HttpService.api_GET(url, auth_token)); - } - - public People personRead(String companyId, String personId) throws IOException { - String uri = AdminURLS.Person.personRead().set("companyId", companyId).set("personId", personId).expand(); - URL url = new URL (uri); - - return new People(HttpService.api_GET(url, auth_token)); - } - - public People personGetSchema(String companyId) throws IOException{ - String uri = AdminURLS.Person.personGetSchema().set("companyId", companyId).expand(); - URL url = new URL (uri); - - return new People(HttpService.api_GET(url, auth_token)); - } - - public People personCreate(String companyId, People person) throws IOException{ - String uri = AdminURLS.Person.personCreate().set("companyId", companyId).expand(); - URL url = new URL (uri); - - return new People(HttpService.api_POST(url, person.data, auth_token)); - } - - public People personUpdate(String companyId, People person) throws IOException{ - String uri = AdminURLS.Person.personUpdate().set("companyId", companyId).set("personId", person.id).expand(); - URL url = new URL (uri); - - return new People(HttpService.api_PUT(url, person.data, auth_token)); - } - - public People personDelete(String companyId, String personId) throws IOException{ - String uri = AdminURLS.Person.personDelete().set("companyId", companyId).set("personId", personId).expand(); - URL url = new URL (uri); - - return new People(HttpService.api_DELETE(url, auth_token)); - } + AdminAPI(ApiConfig builder) { + super(builder); } - static public class ServiceAPI extends AuthedAPI { - - public ServiceAPI(String token) { - super(token); - } - - public Service serviceList(String companyId) throws IOException { - String uri = AdminURLS.Service.serviceList().set("companyId", companyId).expand(); - URL url = new URL (uri); - - return new Service(HttpService.api_GET(url, auth_token)); - } - public Service serviceRead(String companyId, String serviceId) throws IOException { - String uri = AdminURLS.Service.serviceRead().set("companyId", companyId).set("serviceId", serviceId).expand(); - URL url = new URL (uri); - - return new Service(HttpService.api_GET(url, auth_token)); - } + public BookingAPI booking() { + return new BookingAPI(newConfig()); } + public class BookingAPI extends AbstractAPI { - static public class ResourceAPI extends AuthedAPI { - - public ResourceAPI(String token) { - super(token); - } - - public Resource getResources(String companyId) throws IOException { - String uri = AdminURLS.Resource.resourceList().set("companyId", companyId).expand(); - URL url = new URL (uri); - - return new Resource(HttpService.api_GET(url, auth_token)); + BookingAPI(ApiConfig config) { + super(config); } - public Resource getResource(String companyId, String resourceId) throws IOException { - String uri = AdminURLS.Resource.resourceRead().set("companyId", companyId).set("resourceId", resourceId).expand(); - URL url = new URL (uri); - - return new Resource(HttpService.api_GET(url, auth_token)); - } - } - - - static public class EventAPI extends AuthedAPI{ - - public EventAPI(String token) { - super(token); - } - - public Event eventList(String companyId) throws IOException { - String uri = AdminURLS.Event.eventList().set("companyId", companyId).expand(); - URL url = new URL (uri); - - return new Event(HttpService.api_GET(url, auth_token)); - } - - public Event eventRead(String companyId, String eventId) throws IOException { - String uri = AdminURLS.Event.eventRead().set("companyId", companyId).set("eventId", eventId).expand(); - URL url = new URL (uri); - - return new Event(HttpService.api_GET(url, auth_token)); + public BBCollection getBookings(Company company, BookingListParams bLParams) throws IOException { + URL url = new URL(Utils.inflateLink(company.get_bookingsLink(), bLParams.getParams())); + BBCollection bookings = new BBCollection(httpService.api_GET(url), getAuthToken(), "bookings", Booking.class); + //BBCollection bookings = new BBCollection(HttpService.api_GET(url, getAuthToken()), getAuthToken(), "bookings", Booking.class); + return bookings; } } diff --git a/src/main/bookingbugAPI/api/AdminURLS.java b/src/main/bookingbugAPI/api/AdminURLS.java index e4ba96e..21141c0 100644 --- a/src/main/bookingbugAPI/api/AdminURLS.java +++ b/src/main/bookingbugAPI/api/AdminURLS.java @@ -11,6 +11,7 @@ public static class Company { public static UriTemplate company() { return UriTemplate.buildFromTemplate(new Config().serverUrl) .literal("/admin") + .path(UriTemplateBuilder.var("companyId")) .literal("/company") .build(); } @@ -85,6 +86,7 @@ public static UriTemplate serviceList(){ .literal("/admin") .path(UriTemplateBuilder.var("companyId")) .literal("/services") + .query(UriTemplateBuilder.var("page"), UriTemplateBuilder.var("per_page")) .build(); } @@ -96,6 +98,16 @@ public static UriTemplate serviceRead() { .path(UriTemplateBuilder.var("serviceId")) .build(); } + + public static UriTemplate serviceNewBooking() { + return UriTemplate.buildFromTemplate(new Config().serverUrl) + .literal("/admin") + .path(UriTemplateBuilder.var("companyId")) + .literal("/services") + .path(UriTemplateBuilder.var("serviceId")) + .literal("/new_booking") + .build(); + } } @@ -269,6 +281,7 @@ public static UriTemplate bookingList(){ .literal("/admin") .path(UriTemplateBuilder.var("companyId")) .literal("/bookings") + .query(UriTemplateBuilder.var("page"), UriTemplateBuilder.var("per_page")) .build(); } @@ -625,6 +638,16 @@ public static UriTemplate eventChainReadUsingRefId() { .path(UriTemplateBuilder.var("refId")) .build(); } + + public static UriTemplate eventChainEventsList() { + return UriTemplate.buildFromTemplate(new Config().serverUrl) + .literal("/admin") + .path(UriTemplateBuilder.var("companyId")) + .literal("/event_chains") + .path(UriTemplateBuilder.var("eventChainId")) + .literal("/events") + .build(); + } } diff --git a/src/main/bookingbugAPI/api/AuthedAPI.java b/src/main/bookingbugAPI/api/AuthedAPI.java index b61da4b..a117351 100644 --- a/src/main/bookingbugAPI/api/AuthedAPI.java +++ b/src/main/bookingbugAPI/api/AuthedAPI.java @@ -1,12 +1,13 @@ package bookingbugAPI.api; /** - * Created by sebi on 5/30/15. + * Created by sebi on 19.05.2016. */ -public abstract class AuthedAPI { +public class AuthedAPI { + String auth_token; - public AuthedAPI(String token){ - auth_token = token; + public AuthedAPI(String auth_token) { + this.auth_token = auth_token; } } diff --git a/src/main/bookingbugAPI/api/PublicURLS.java b/src/main/bookingbugAPI/api/PublicURLS.java index acfae19..1be7644 100644 --- a/src/main/bookingbugAPI/api/PublicURLS.java +++ b/src/main/bookingbugAPI/api/PublicURLS.java @@ -67,7 +67,9 @@ public static class Service { */ public static UriTemplate serviceList(){ return UriTemplate.buildFromTemplate(new Config().serverUrl).path(UriTemplateBuilder.var("companyId")) - .literal("/" + servicesLink).build(); + .literal("/" + servicesLink) + .query(UriTemplateBuilder.var("page"), UriTemplateBuilder.var("per_page")) + .build(); } /** @@ -179,8 +181,13 @@ public static class Event { * @return UriTemplate */ public static UriTemplate eventList(){ - return UriTemplate.buildFromTemplate(new Config().serverUrl).path(UriTemplateBuilder.var("companyId")) - .literal("/" + eventsLink).build(); + return UriTemplate.buildFromTemplate(new Config().serverUrl) + .path(UriTemplateBuilder.var("companyId")) + .literal("/" + eventsLink) + .query("page", "per_page", "event_chain_id", + "start_date", "end_date", "resource_id", "person_id", + "event_group_id", "summary", "member_level_id") + .build(); } /** @@ -244,7 +251,9 @@ public static UriTemplate availabilityDaysForBookableItem() { */ public static UriTemplate availabilityTimesForBookableItem() { return UriTemplate.buildFromTemplate(new Config().serverUrl).path(UriTemplateBuilder.var("companyId")) - .literal("/time_data").build(); + .literal("/time_data") + .query("event_id", "service_id", "resource_id","resource_ids", "person_id", "group_id", "location", + "date", "end_date", "duration", "num_resources").build(); } /** @@ -314,7 +323,9 @@ public static class EventChain { */ public static UriTemplate eventChainList(){ return UriTemplate.buildFromTemplate(new Config().serverUrl).path(UriTemplateBuilder.var("companyId")) - .literal("/" + eventChainsLink).build(); + .literal("/" + eventChainsLink) + .query(UriTemplateBuilder.var("page"), UriTemplateBuilder.var("per_page")) + .build(); } /** diff --git a/src/main/bookingbugAPI/models/Address.java b/src/main/bookingbugAPI/models/Address.java index 2c44b42..f01e559 100644 --- a/src/main/bookingbugAPI/models/Address.java +++ b/src/main/bookingbugAPI/models/Address.java @@ -2,7 +2,6 @@ import helpers.HttpServiceResponse; - public class Address extends BBRoot{ public Address(HttpServiceResponse httpServiceResponse){ @@ -10,4 +9,130 @@ public Address(HttpServiceResponse httpServiceResponse){ } public Address() {} + + /** + * Returns the id. + * + * @return the id associated with the current Address object + */ + public Integer getId() { + return getInteger("id", INTEGER_DEFAULT_VALUE); + } + + /** + * Returns the first address. + * + * @return the first address associated with the current Address object + */ + public String getAddress1() { + return get("address1"); + } + + /** + * Returns the second address. + * + * @return the second address associated with the current Address object + */ + public String getAddress2() { + return get("address2"); + } + + /** + * Returns the third address. + * + * @return the third address associated with the current Address object + */ + public String getAddress3() { + return get("address3"); + } + + /** + * Returns the fourth address. + * + * @return the fourth address associated with the current Address object + */ + public String getAddress4() { + return get("address4"); + } + + /** + * Returns the fifth address. + * + * @return the fifth address associated with the current Address object + */ + public String getAddress5() { + return get("address5"); + } + + /** + * Returns the post code. + * + * @return the post code associated with the current Address object + */ + public String getPostcode() { + return get("postcode"); + } + + /** + * Returns the country from the address. + * + * @return the country associated with the current Address object + */ + public String getCountry() { + return get("country"); + } + + /** + * Returns the latitude expressed in degrees. + * + * @return the latitude associated with the current Address object + */ + public Double getLat() { + return getDouble("lat", DOUBLE_DEFAULT_VALUE); + } + + /** + * Returns the longitude expressed in degrees. + * + * @return the longitude associated with the current Address object + */ + public Double getLong() { + return getDouble("long", DOUBLE_DEFAULT_VALUE); + } + + /** + * Returns the map url. + * + * @return the map url associated with the current Address object + */ + public String getMapUrl() { + return get("map_url"); + } + + /** + * Returns the map marker. + * + * @return the map marker associated with the current Address object + */ + public String getMapMarker() { + return get("map_marker"); + } + + /** + * Returns the phone from address. + * + * @return the phone associated with the current Address object + */ + public String getPhone() { + return get("phone"); + } + + /** + * Returns the home phone from address. + * + * @return the home phone associated with the current Address object + */ + public String getHomephone() { + return get("homephone"); + } } diff --git a/src/main/bookingbugAPI/models/Administrator.java b/src/main/bookingbugAPI/models/Administrator.java index ad07a1c..9bb8875 100644 --- a/src/main/bookingbugAPI/models/Administrator.java +++ b/src/main/bookingbugAPI/models/Administrator.java @@ -11,37 +11,129 @@ public class Administrator extends BBRoot { - private Company company; - private BBRoot schema; - - public Administrator(HttpServiceResponse httpServiceResponse, String auth_token) { super(httpServiceResponse); this.auth_token = auth_token; } + public Administrator(HttpServiceResponse httpServiceResponse) { + super(httpServiceResponse); + } public Company getCompany() throws IOException { - if(company == null){ - String link = response.getRep().getLinkByRel("company").getHref(); - URL url = new URL(UriTemplate.fromTemplate(link).expand()); - company = new Company(HttpService.api_GET(url, auth_token), auth_token); - } - return company; + String link = response.getRep().getLinkByRel("company").getHref(); + URL url = new URL(UriTemplate.fromTemplate(link).expand()); + return new Company(HttpService.api_GET(url, auth_token), auth_token); } public BBRoot getEditSchema() throws IOException { - if(schema == null) { - String link = response.getRep().getLinkByRel("edit").getHref(); - URL url = new URL(UriTemplate.fromTemplate(link).expand()); - schema = new BBRoot(HttpService.api_GET(url, auth_token), auth_token); - } - return schema; + String link = response.getRep().getLinkByRel("edit").getHref(); + URL url = new URL(UriTemplate.fromTemplate(link).expand()); + return new BBRoot(HttpService.api_GET(url, auth_token), auth_token); } - public Login login(Map params) throws IOException { + public Login login(Map params) throws IOException { return auth(params, response.getRep().getLinkByRel("login")); } + + /** + * Returns the name of the admin. + * + * @return the name associated with the current Administrator object + */ + public String getName() { + return get("name"); + } + + /** + * Returns the email of the admin. + * + * @return the email associated with the current Administrator object + */ + public String getEmail() { + return get("email"); + } + + /** + * Returns the role of the admin. + * + * @return the associated with the current administrator object + */ + public String getRole() { + return get("role"); + } + + /** + * Returns the company id. + * + * @return the company id associated with the current administrator object + */ + public Integer getCompanyId() { + return getInteger("company_id", INTEGER_DEFAULT_VALUE); + } + + /** + * Returns the company name. + * + * @return the company name associated with the current administrator object + */ + public String getCompanyName() { + return get("company_name"); + } + + /** + * Returns the person id. + * + * @return the person id associated with the current administrator object + */ + public Integer getPersonId() { + return getInteger("person_id", INTEGER_DEFAULT_VALUE); + } + + /** + * Returns the edit link. + * + * @return the edit link associated with the current administrator object + */ + public String getEditLink() { + return getLink("edit"); + } + + /** + * Returns the company link. + * + * @return the company link associated with the current administrator object + */ + public String getCompanyLink() { + return getLink("company"); + } + + /** + * Returns the person link. + * + * @return the person link associated with the current administrator object + */ + public String getPersonLink() { + return getLink("person"); + } + + /** + * Returns the login link. + * + * @return the login link associated with the current administrator object + */ + public String getLoginLink() { + return getLink("login"); + } + + /** + * Returns the base_login. + * + * @return the base_login associated with the current administrator object + */ + public String getBaseLoginLink() { + return getLink("base_login"); + } } diff --git a/src/main/bookingbugAPI/models/Answer.java b/src/main/bookingbugAPI/models/Answer.java new file mode 100644 index 0000000..6a1e197 --- /dev/null +++ b/src/main/bookingbugAPI/models/Answer.java @@ -0,0 +1,117 @@ +package bookingbugAPI.models; + +import helpers.HttpServiceResponse; + +public class Answer extends BBRoot{ + + public Answer(HttpServiceResponse httpServiceResponse) { + super(httpServiceResponse); + } + + public Answer(HttpServiceResponse httpServiceResponse, String auth_token) { + super(httpServiceResponse, auth_token); + } + + public Answer() { + } + + /** + * Returns the answer's id. + * + * @return The id associated with the current Answer object. + */ + public Integer getId() { + return getInteger("id", INTEGER_DEFAULT_VALUE); + } + + /** + * Returns the answer's value. + * + * @return The value associated with the current Answer object. + */ + public String getValue() { + return get("value"); + } + + /** + * Returns the answer's price. + * + * @return The price associated with the current Answer object. + */ + public Double getPrice() { + return getDouble("price", INTEGER_DEFAULT_VALUE); + } + + /** + * Returns the question id. + * + * @return The question id associated with the current Answer object. + */ + public Integer getQuestionId() { + return getInteger("question_id", INTEGER_DEFAULT_VALUE); + } + + + /** + * Returns the admin only attribute. + * + * @return The admin only attribute associated with the current Answer object. + */ + public Boolean getAdminOnly() { + return getBoolean("admin_only", BOOLEAN_DEFAULT_VALUE); + } + + /** + * Returns the important attribute. + * + * @return The important attribute associated with the current Answer object. + */ + public Boolean getImportant() { + return getBoolean("important", BOOLEAN_DEFAULT_VALUE); + } + + /** + * Returns the question. + * + * @return The question associated with the current Answer object. + */ + public Question getQuestion() { + return new Question(new HttpServiceResponse(getResource("question"))); + } + + /** + * Returns the question text . + * + * @return The question text associated with the current Answer object. + */ + public String getQuestionText() { + return get("question_text"); + } + + /** + * Returns the outcome. + * + * @return The outcome associated with the current Answer object. + */ + public Boolean getOutcome() { + return getBoolean("outcome", BOOLEAN_DEFAULT_VALUE); + } + + /** + * Returns the company id. + * + * @return The company id associated with the current Answer object. + */ + public Integer getCompanyId() { + return getInteger("company_id", INTEGER_DEFAULT_VALUE); + } + + /** + * Returns the question link . + * + * @return The question link associated with the current Answer object. + */ + public String getQuestionLink() { + return getLink("question"); + } +} diff --git a/src/main/bookingbugAPI/models/BBCollection.java b/src/main/bookingbugAPI/models/BBCollection.java index 89061da..e412ed9 100644 --- a/src/main/bookingbugAPI/models/BBCollection.java +++ b/src/main/bookingbugAPI/models/BBCollection.java @@ -83,6 +83,10 @@ public int size() { return getRep().getResourcesByRel(collectionNameSpace).size(); } + public boolean hasNext() { + return getLink("next") != null; + } + public Iterator iterator() { return new BBCollectionIterator(this); diff --git a/src/main/bookingbugAPI/models/BBRoot.java b/src/main/bookingbugAPI/models/BBRoot.java index ac369ea..aabdfca 100644 --- a/src/main/bookingbugAPI/models/BBRoot.java +++ b/src/main/bookingbugAPI/models/BBRoot.java @@ -3,16 +3,24 @@ import bookingbugAPI.services.HttpService; import com.damnhandy.uri.template.UriTemplate; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; import com.theoryinpractise.halbuilder.api.ContentRepresentation; import com.theoryinpractise.halbuilder.api.Link; +import com.theoryinpractise.halbuilder.api.ReadableRepresentation; import com.theoryinpractise.halbuilder.api.RepresentationException; +import com.theoryinpractise.halbuilder.impl.representations.ContentBasedRepresentation; import com.theoryinpractise.halbuilder.json.JsonRepresentationFactory; import helpers.Config; import helpers.HttpServiceResponse; +import helpers.hal_addon.CustomJsonDeserializer; +import org.joda.time.DateTime; import java.io.*; import java.net.URL; -import java.util.*; +import java.util.List; +import java.util.Map; import java.util.logging.Logger; import static com.theoryinpractise.halbuilder.api.RepresentationFactory.HAL_JSON; @@ -23,7 +31,7 @@ * Child classes should implement getters for relevant parts from the response. */ @JsonIgnoreProperties({ - "rep", "auth_token", "id", "data", "links" + "rep", "auth_token", "id", "data", "links" }) public class BBRoot { @@ -33,6 +41,9 @@ public class BBRoot { protected String auth_token = null; public String id; public Map data; + public int INTEGER_DEFAULT_VALUE = 0; + public double DOUBLE_DEFAULT_VALUE = 0.0; + public boolean BOOLEAN_DEFAULT_VALUE = false; protected String curl = "N/A"; @@ -43,7 +54,7 @@ public BBRoot(HttpServiceResponse httpServiceResponse) { } - public BBRoot(String auth_token){ + public BBRoot(String auth_token) { this.auth_token = auth_token; } @@ -55,17 +66,18 @@ public BBRoot(HttpServiceResponse httpServiceResponse, String auth_token) { } - public BBRoot() {} + public BBRoot() { + } public BBRoot getLoginSchema() throws IOException { - URL url = new URL (UriTemplate.fromTemplate(response.getRep().getLinkByRel("new_login").getHref()).expand()); + URL url = new URL(UriTemplate.fromTemplate(response.getRep().getLinkByRel("new_login").getHref()).expand()); HttpServiceResponse response = HttpService.api_GET(url); return new BBRoot(response); } - public Login auth(Map params) throws IOException{ + public Login auth(Map params) throws IOException { HttpServiceResponse resp; try { URL url = new URL(UriTemplate.fromTemplate(new Config().serverUrl + "/login").expand()); @@ -89,24 +101,98 @@ public Login auth(Map params) throws IOException{ } - public Login auth(Map params, Link link) throws IOException{ - URL url = new URL (link.getHref()); + public Login auth(Map params, Link link) throws IOException { + URL url = new URL(link.getHref()); HttpServiceResponse resp = HttpService.api_POST(url, params); auth_token = (String) resp.getRep().getValue("auth_token"); return new Login(resp); } - public String get(String key){ + public String get(String key) { String val = null; - try{ - val = (String)response.getRep().getValue(key); + try { + val = (String) response.getRep().getValue(key); } catch (RepresentationException e) { //e.printStackTrace(); } return val; } + public boolean getBoolean(String key, boolean defaultValue) { + String val = this.get(key); + if (val != null) return Boolean.parseBoolean(val); + return defaultValue; + } + + public int getInteger(String key, int defaultValue) { + String val = this.get(key); + if (val != null) return Integer.parseInt(val); + return defaultValue; + } + + public double getDouble(String key, double defaultValue) { + String val = this.get(key); + if (val != null) return Double.parseDouble(val); + return defaultValue; + } + + public DateTime getDate(String key) { + return new DateTime(get(key)); + } + + public List getArray(String key) { + List val = null; + try { + val = (List) (response.getRep().getValue(key)); + } catch (RepresentationException e) { + e.printStackTrace(); + } + return val; + } + + //TODO: improve this + public T getObject(String key, Class type) { + + try { + ObjectMapper mapper = CustomJsonDeserializer.getMapper(); + String json_obj = mapper.writeValueAsString(response.getRep().getValue(key)); + return mapper.readValue(json_obj, type); + } catch (RepresentationException | IOException e) { + e.printStackTrace(); + } + return null; + } + + public List getObjects(String key, Class type) { + List val = null; + + try { + ObjectMapper mapper = CustomJsonDeserializer.getMapper(); + String json_obj = mapper.writeValueAsString(response.getRep().getValue(key)); + val = mapper.readValue(json_obj, new TypeReference>() { + }); + } catch (IOException e) { + e.printStackTrace(); + } + + return val; + } + + //TODO: fix this + public ContentRepresentation getResource(String key) { + try { + List entries = response.getRep().getResourcesByRel(key); + + for (ReadableRepresentation item : entries) { + if (item instanceof ContentBasedRepresentation) + return (ContentRepresentation) item; + } + } catch (RepresentationException e) { + e.printStackTrace(); + } + return null; + } public String getAuth_token() { return auth_token; @@ -138,6 +224,16 @@ public String toString() { return response.getRep().getContent(); } + public String toPrettyString() { + ObjectMapper mapper = new ObjectMapper(); + try { + return mapper.writerWithDefaultPrettyPrinter().writeValueAsString(response.getRep()); + } catch (JsonProcessingException e) { + e.printStackTrace(); + return toString(); + } + } + public String getCurl() { curl = "curl \"" + getSelf() + "\" " + response.getParamsStr() + " -X " + response.getMethod(); @@ -146,7 +242,7 @@ public String getCurl() { public String getSelf() { - if(response.getRep().getResourceLink() != null) + if (response.getRep().getResourceLink() != null) return response.getRep().getResourceLink().getHref(); return ""; } diff --git a/src/main/bookingbugAPI/models/Basket.java b/src/main/bookingbugAPI/models/Basket.java new file mode 100644 index 0000000..58f70b9 --- /dev/null +++ b/src/main/bookingbugAPI/models/Basket.java @@ -0,0 +1,80 @@ +package bookingbugAPI.models; + +import helpers.HttpServiceResponse; + +import java.util.List; + + +public class Basket extends BBRoot{ + + public Basket(HttpServiceResponse httpServiceResponse) { + super(httpServiceResponse); + } + + public String getCompanyId() { + return get("company_id"); + } + + /** + * Returns the total price of the basket. + * + * @return The total price associated with the current Basket object + */ + public Integer getTotalPrice() { + return getInteger("total_price", INTEGER_DEFAULT_VALUE); + } + + /** + * Returns the total due price of the basket. + * + * @return The total due price associated with the current Basket object + */ + public Integer getTotalDuePrice() { + return getInteger("total_due_price", INTEGER_DEFAULT_VALUE); + } + + /** + * Returns the items from the basket. + * + * @return {@link BBCollection} The items associated with the current Basket object + */ + public BBCollection getItems() { + return new BBCollection<>(new HttpServiceResponse(getResource("items")), auth_token, BasketItem.class); + } + + /** + * Returns the checkout link. + * + * @return The checkout link associated with the current Basket object + */ + public String getCheckoutLink() { + return getLink("checkout"); + } + + /** + * Returns the items link. + * + * @return The items link associated with the current Basket object + */ + public String getItemsLink() { + return getLink("items"); + } + + /** + * Returns the link for adding an item. + * + * @return The link for adding an item associated with the current Basket object + */ + public String getAddItemLink() { + return getLink("add_item"); + } + + /** + * Returns the deal link. + * + * @return The deal link associated with the current Basket object + */ + public String getDealLink() { + return getLink("deal"); + } +} diff --git a/src/main/bookingbugAPI/models/BasketItem.java b/src/main/bookingbugAPI/models/BasketItem.java new file mode 100644 index 0000000..bf837c0 --- /dev/null +++ b/src/main/bookingbugAPI/models/BasketItem.java @@ -0,0 +1,205 @@ +package bookingbugAPI.models; + +import bookingbugAPI.api.PublicURLS; +import bookingbugAPI.services.HttpService; +import com.theoryinpractise.halbuilder.api.ContentRepresentation; +import helpers.HttpServiceResponse; +import org.joda.time.DateTime; + +import java.io.IOException; +import java.net.URL; +import java.util.List; +import java.util.Map; + + +public class BasketItem extends BBRoot { + + + public BasketItem(HttpServiceResponse httpServiceResponse) { + super(httpServiceResponse); + } + + /** + * Returns the event_id. + * + * @return The event_id associated with the current BasketItemsTwo object + */ + public Integer getEventId() { + return getInteger("event_id", INTEGER_DEFAULT_VALUE); + } + + /** + * Returns the person id. + * + * @return The person id associated with the current BasketItemsTwo object + */ + public Integer getPersonId() { + return getInteger("person_id", INTEGER_DEFAULT_VALUE); + } + + /** + * Returns the service id. + * + * @return The service id associated with the current BasketItemsTwo object + */ + public Integer getServiceId() { + return getInteger("service_id", INTEGER_DEFAULT_VALUE); + } + + /** + * Returns the price. + * + * @return The price associated with the current BasketItemsTwo object + */ + public Integer getPrice() { + return getInteger("price", INTEGER_DEFAULT_VALUE); + } + + /** + * Returns the number of bookings. + * + * @return The number of bookings associated with the current BasketItemsTwo object + */ + public Integer getNumBook() { + return getInteger("num_book", INTEGER_DEFAULT_VALUE); + } + + /** + * Returns the person's name. + * + * @return The person's name associated with the current BasketItemsTwo object + */ + public String getPersonName() { + return get("person_name"); + } + + /** + * Returns the service's name. + * + * @return The service's name associated with the current BasketItemsTwo object + */ + public String getServiceName() { + return get("service_name"); + } + + /** + * Returns the status. + * + * @return The status associated with the current BasketItemsTwo object + */ + public Integer getStatus() { + return getInteger("status", INTEGER_DEFAULT_VALUE); + } + + /** + * Returns the id. + * + * @return The id associated with the current BasketItemsTwo object + */ + public String getId() { + return get("id"); + } + + /** + * Returns the date and time, with {@link DateTime DateTime()} as format. + * + * @return The date and time associated with the current BasketItemsTwo object + */ + public DateTime getDate() { + return getDate("date"); + } + + /** + * Returns the time. + * + * @return The time associated with the current BasketItemsTwo object + */ + public Integer getTime() { + return getInteger("time", INTEGER_DEFAULT_VALUE); + } + + /** + * Returns the questions. + * + * @return The questions associated with the current BasketItemsTwo object + */ + public List getQuestions() { + return getObjects("questions", Map.class); + } + + /** + * Returns the duration expressed in minutes. + * + * @return The duration associated with the current BasketItemsTwo object + */ + public Integer getDuration() { + return getInteger("duration", INTEGER_DEFAULT_VALUE); + } + + /** + * Returns the settings. + * + * @return The settings associated with the current BasketItemsTwo object + */ + public BasketItemSettings getSettings() throws IOException{ + if(getRep().getResourcesByRel("settings").size() > 0) { + return new BasketItemSettings(new HttpServiceResponse((ContentRepresentation) getRep().getResourcesByRel("settings").get(0))); + } + + return null; + } + + /** + * Returns the total price. + * + * @return The total price associated with the current BasketItemsTwo object + */ + public Integer getTotalPrice() { + return getInteger("total_price", INTEGER_DEFAULT_VALUE); + } + + /** + * Returns the attachment link. + * + * @return The attachment link associated with the current BasketItemsTwo object + */ + public String getAttachmentLink() { + return getLink("attachment"); + } + + /** + * Returns the link for adding an attachment. + * + * @return The link for adding an attachment associated with the current BasketItemsTwo object + */ + public String getAddAtachmentLink() { + return getLink("add_attachment"); + } + + /** + * Returns the person link. + * + * @return The person link associated with the current BasketItemsTwo object + */ + public String getPersonLink() { + return getLink("person"); + } + + /** + * Returns the service link. + * + * @return The service link associated with the current BasketItemsTwo object + */ + public String getServiceLink() { + return getLink("service"); + } + + /** + * Returns the company link. + * + * @return The company link associated with the current BasketItemsTwo object + */ + public String getCompanyLink() { + return getLink("company"); + } +} diff --git a/src/main/bookingbugAPI/models/BasketItemSettings.java b/src/main/bookingbugAPI/models/BasketItemSettings.java new file mode 100644 index 0000000..038c9d4 --- /dev/null +++ b/src/main/bookingbugAPI/models/BasketItemSettings.java @@ -0,0 +1,40 @@ +package bookingbugAPI.models; + +import helpers.HttpServiceResponse; +import org.joda.time.DateTime; + +/** + * Created by sergiu on 31.05.2016. + */ +public class BasketItemSettings extends BBRoot{ + + public BasketItemSettings(HttpServiceResponse httpServiceResponse) { + super(httpServiceResponse); + } + /** + * Returns the resource. + * + * @return The resource associated with the current BasketItemSettings object + */ + public Integer getResource() { + return getInteger("resource", INTEGER_DEFAULT_VALUE); + } + + /** + * Returns the person. + * + * @return The person associated with the current BasketItemSettings object + */ + public Integer getPerson() { + return getInteger("person", INTEGER_DEFAULT_VALUE); + } + + /** + * Returns the earliest date and time, with {@link DateTime DateTime()} as format. + * + * @return The earliest date and time associated with the current BasketItemSettings object + */ + public DateTime getEarliestTime() { + return getDate("earliest_rime"); + } +} diff --git a/src/main/bookingbugAPI/models/BookableAvailability.java b/src/main/bookingbugAPI/models/BookableAvailability.java index 0a42f4a..7879c42 100644 --- a/src/main/bookingbugAPI/models/BookableAvailability.java +++ b/src/main/bookingbugAPI/models/BookableAvailability.java @@ -50,20 +50,36 @@ public Date getDateTimeObj(){ return datetime; } - public boolean isAvailable(Date datetime){ - Calendar calendar = Calendar.getInstance(); - calendar.setTime(datetime); - int hour_to_check = calendar.get(Calendar.HOUR_OF_DAY); - - ArrayList times = new ArrayList<>(getRep().getResourcesByRel("times")); - for (ReadableRepresentation rep : times) { - int time_min = Integer.parseInt((String) rep.getValue("time")); - int avail = Integer.parseInt((String) rep.getValue("avail")); - - int hour = time_min / 60; - if(hour_to_check >= hour && hour_to_check < hour + 1 && avail == 1) - return true; + public ArrayList getAvailTimes(){ + + ArrayList times_reps = new ArrayList<>(getRep().getResourcesByRel("times")); + ArrayList times = new ArrayList<>(); + + for (ReadableRepresentation rep : times_reps) { + AvailTime timeObj = new AvailTime(); + timeObj.time_minutes = Integer.parseInt((String) rep.getValue("time")); + timeObj.avail = Integer.parseInt((String) rep.getValue("avail")) == 1 ? true : false; + timeObj.price = Integer.parseInt((String) rep.getValue("price")); + times.add(timeObj); + } + return times; + } + + public static class AvailTime { + int time_minutes; + boolean avail; + int price; + + public int getTime_minutes() { + return time_minutes; + } + + public boolean isAvail() { + return avail; + } + + public int getPrice() { + return price; } - return false; } } diff --git a/src/main/bookingbugAPI/models/Booking.java b/src/main/bookingbugAPI/models/Booking.java index 63c470f..e2021a6 100644 --- a/src/main/bookingbugAPI/models/Booking.java +++ b/src/main/bookingbugAPI/models/Booking.java @@ -11,51 +11,18 @@ import java.io.IOException; import java.net.URL; import java.text.ParseException; -import java.text.SimpleDateFormat; + import java.util.Calendar; import java.util.Date; -import java.util.logging.Logger; +import org.joda.time.DateTime; + +import java.util.List; +import java.util.Map; -public class Booking extends BBRoot { - /* - private String updated_at; - private String company_id; - private String session_id; - private String settings; - private String questions; - private String on_waitlist; - private String duration; - private String client_email; - private String id; - private String slot_id; - private String is_cancelled; - private String client_name; - private String client_mobile; - private String attended; - private String full_describe; - private String channel; - private String notes; - private String service_id; - private String client_id; - private String service_name; - private String status; - private String multi_status; - private String created_at; - private String price; - private String datetime; - private String resource_name; - private String slot_settings; - private String quantity; - private String booking_updated; - private String client_phone; - private String resource_id; - private String purchase_id; - private String member_id; - private String paid; - private String purchase_ref; - */ + +public class Booking extends BBRoot { public Booking(HttpServiceResponse httpServiceResponse, String auth_token) { super(httpServiceResponse, auth_token); @@ -65,6 +32,7 @@ public Booking(HttpServiceResponse response) { super(response); } + public Booking(){} public BBRoot getSchema() throws IOException { String link = getRep().getLinkByRel("edit").getHref(); @@ -90,45 +58,16 @@ public Booking bookingUpdate_Admin(BookingUpdateParams bParams) throws IOExcepti */ public Booking bookingCancel_Admin(BookingCancelParams bcParams) throws IOException { URL url = new URL(AdminURLS.Bookings.bookingCancel().set("companyId", getCompany_id()).set("id", this.id).expand()); - return new Booking(HttpService.api_DELETE(url, HttpService.jsonContentType, bcParams.getParams(), auth_token), auth_token); - } - - - public String getFirstName() { - return get("first_name"); - } - - public String getLastName() { - return get("last_name"); - } - - public String getEmail() { - return get("email"); + return new Booking(HttpService.api_DELETE(url, HttpService.jsonContentType, bcParams.getParams(), auth_token), auth_token); } - public String getAddress1() { - return get("address1"); - } - - public String getAddress2() { - return get("address2"); - } - - public String getAddress3() { - return get("address3"); - } - - public String getAddress4() { - return get("address4"); - } - - public String getPostCode() { - return get("postcode"); - } - - - public String getDuration() { - return get("duration"); + /** + * Returns the duration. + * + * @return The duration associated with the current Booking object. + */ + public Integer getDuration() { + return getInteger("duration", INTEGER_DEFAULT_VALUE); } public String getUpdated_at() { @@ -139,12 +78,13 @@ public String getCompany_id() { return get("company_id"); } - public String getSession_id() { - return get("session_id"); - } - public String getSettings() { - return get("settings"); + /** + * Returns the settings. Settings consists of an obfuscated id. + * @return The settings associated with the current Booking object. + */ + public Map getSettings() { + return getObject("settings", Map.class); } public String getQuestions() { @@ -179,10 +119,20 @@ public String getClient_mobile() { return get("client_mobile"); } - public String getAttended() { - return get("attended"); + /** + * Returns true if it's attended, false otherwise. + * + * @return The attended attribute associated with the current Booking object. + */ + public Boolean getAttended() { + return getBoolean("attended", BOOLEAN_DEFAULT_VALUE); } + /** + * Returns the full_describe of the booking. + * + * @return The full_describe associated with the current Booking object. + */ public String getFull_describe() { return get("full_describe"); } @@ -191,8 +141,13 @@ public String getChannel() { return get("channel"); } - public String getNotes() { - return get("notes"); + /** + * Returns the notes map. + * + * @return The notes associated with the current Booking object. + */ + public Notes getNotes() { + return getObject("notes", Notes.class); } public String getService_id() { @@ -211,8 +166,13 @@ public String getStatus() { return get("status"); } - public String getMulti_status() { - return get("multi_status"); + /** + * Returns the multi-status map. + * + * @return The multi-status map associated with the current Booking object. + */ + public Map getMulti_status() { + return getObject("multi_status", Map.class); } public String getCreated_at() { @@ -244,7 +204,7 @@ public Date getEndDateTimeObj(){ try { Calendar cal = Calendar.getInstance(); cal.setTime(startDateTime); - cal.add(Calendar.MINUTE, Integer.parseInt(getDuration())); + cal.add(Calendar.MINUTE, getDuration()); endDateTime = cal.getTime(); }catch (Exception e){ log.warning("Cannot get booking end datetime: " + e.toString()); @@ -256,8 +216,13 @@ public String getResource_name() { return get("resource_name"); } - public String getSlot_settings() { - return get("slot_settings"); + /** + * Returns the slot settings. + * + * @return The slot settings associated with the current Booking object. + */ + public Map getSlot_settings() { + return getObject("slot_settings", Map.class); } public String getQuantity() { @@ -291,4 +256,123 @@ public String getPaid() { public String getPurchase_ref() { return get("purchase_ref"); } + + /** + * Returns the client link. + * + * @return The client link associated with the current Booking object. + */ + public String getClientLink() { + return getLink("client"); + } + + /** + * Returns the check in link. + * + * @return The check in link associated with the current Booking object. + */ + public String getCheckInLink() { + return getLink("check_in"); + } + + /** + * Returns the questions link. + * + * @return The questions link associated with the current Booking object. + */ + public String getQuestionsLink() { + return getLink("questions"); + } + + /** + * Returns the edit link. + * + * @return The edit link associated with the current Booking object. + */ + public String getEditLink() { + return getLink("edit"); + } + + /** + * Returns the event groups link. + * + * @return The event groups link associated with the current Booking object. + */ + public String getEventGroupsLink() { + return getLink("event_groups"); + } + + /** + * Returns the event chain link. + * + * @return The event chain link associated with the current Booking object. + */ + public String getEventChainLink() { + return getLink("event_chain"); + } + + /** + * Returns the cancel link. + * + * @return The cancel link associated with the current Booking object. + */ + public String getCancelLink() { + return getLink("cancel"); + } + + /** + * Returns the address link. + * + * @return The address link associated with the current Booking object. + */ + public String getAddressLink() { + return getLink("address"); + } + + /** + * Returns the event chain id. + * + * @return The event chain id associated with the current Booking object. + */ + public Integer getEventChainId() { + return getInteger("event_chain_id", INTEGER_DEFAULT_VALUE); + } + + /** + * Returns the client resource. + * + * @return The client resource associated with the current Booking object. + */ + public Client getClient() { + return new Client(new HttpServiceResponse(getResource("client"))); + } + + /** + * Returns the answer array resource. + * + * @return The answers resource associated with the current Booking object. + */ + public BBCollection getAnswers() { + return new BBCollection<>(new HttpServiceResponse(getResource("answers")), auth_token, Answer.class); + } + + + /** + * Returns the survey answers summary resource. + * + * @return The survey answers summary resource associated with the current Booking object. + */ + public List getSurveyAnswersSummary() { + return getArray("survey_answers_summary"); + } + + /** + * Returns the minimum date and time of the booking cancel, with {@link DateTime DateTime()} as date format. + * + * @return The minimum date and time of the booking cancel associated with the current Booking object. + */ + public DateTime getMinCancellationTime() { + return getDate("min_cancellation_time"); + } + } diff --git a/src/main/bookingbugAPI/models/Client.java b/src/main/bookingbugAPI/models/Client.java index 5d163cf..a10305e 100644 --- a/src/main/bookingbugAPI/models/Client.java +++ b/src/main/bookingbugAPI/models/Client.java @@ -1,23 +1,247 @@ package bookingbugAPI.models; +import com.fasterxml.jackson.annotation.JsonProperty; import helpers.HttpServiceResponse; -public class Client extends BBRoot { +import java.util.List; +import java.util.Map; - public String first_name; - public String last_name; - public String email; - public String phone; +public class Client extends BBRoot { - public Client(HttpServiceResponse httpServiceResponse){ + public Client(HttpServiceResponse httpServiceResponse) { super(httpServiceResponse); } - - public Client(HttpServiceResponse httpServiceResponse, String auth_token){ + public Client(HttpServiceResponse httpServiceResponse, String auth_token) { super(httpServiceResponse, auth_token); } - public Client() {} + public Client() { + } + + /** + * Returns the client first name. + * + * @return The first name associated with the current Client object. + */ + public String getFirstName() { + return get("first_name"); + } + + /** + * Returns the client last name. + * + * @return The last name associated with the current Client object. + */ + public String getLastName() { + return get("last_name"); + } + + /** + * Returns the client email. + * + * @return The last name associated with the current Client object. + */ + public String getEmail() { + return get("email"); + } + + /** + * Returns the first address, if exists. + * + * @return The first address associated with the current Client object. + */ + public String getAddress1() { + return get("address1"); + } + + /** + * Returns the second address, if exists. + * + * @return The second address associated with the current Client object. + */ + public String getAddress2() { + return get("address2"); + } + + /** + * Returns the third address, if exists. + * + * @return The third address associated with the current Client object. + */ + public String getAddress3() { + return get("address3"); + } + + /** + * Returns the fourth address, if exists. + * + * @return The fourth address associated with the current Client object. + */ + public String getAddress4() { + return get("address4"); + } + + /** + * Returns the fifth address, if exists. + * + * @return The fifth address associated with the current Client object. + */ + public String getAddress5() { + return get("address5"); + } + + /** + * Returns the post code. + * + * @return The post code associated with the current Client object. + */ + public String getPostcode() { + return get("postcode"); + } + + /** + * Returns the country. + * + * @return The country associated with the current Client object. + */ + public String getCountry() { + return get("country"); + } + + /** + * Returns the client phone. + * + * @return The phone associated with the current Client object. + */ + public String getPhone() { + return get("phone"); + } + + /** + * Returns the client mobile. + * + * @return The mobile associated with the current Client object. + */ + public String getMobile() { + return get("mobile"); + } + + + /** + * Returns the client id. + * + * @return The id associated with the current Client object. + */ + public Integer getId() { + return getInteger("id", INTEGER_DEFAULT_VALUE); + } + + /** + * Returns the client's member type. + * + * @return The member type associated with the current Client object. + */ + public Integer getMemberType() { + return getInteger("member_type", INTEGER_DEFAULT_VALUE); + } + + /** + * Returns the reference. + * + * @return The reference associated with the current Client object. + */ + public String getReference() { + return get("reference"); + } + + /** + * Returns the files. + * + * @return The files associated with the current Client object. + */ + public List getFiles() { + return getArray("files"); + } + + /** + * Returns the answers. + * + * @return The answers associated with the current Client object. + */ + public List getAnswers() { + return getObjects("answers", Answer.class); + } + + /** + * Returns the client if it's deleted attribute. + * + * @return True if the client is deleted, false otherwise. + */ + public Boolean getDeleted() { + return getBoolean("deleted", BOOLEAN_DEFAULT_VALUE); + } + /** + * Returns the client phone prefix. + * + * @return The phone prefix associated with the current Client object. + */ + public String getPhonePrefix() { + return get("phone_prefix"); + } + + /** + * Returns the client's mobile prefix. + * + * @return The mobile prefix associated with the current Client object. + */ + public String getMobilePrefix() { + return get("mobile_prefix"); + } + + /** + * Returns the client . + * + * @return The associated with the current Client object. + */ + public Map getQ() { + return getObject("q", Map.class); + } + + /** + * Returns the bookings link. + * + * @return The bookings link associated with the current Client object. + */ + public String getBookingsLink() { + return getLink("bookings"); + } + + /** + * Returns the pre paid bookings link. + * + * @return The pre paid bookings link associated with the current Client object. + */ + public String getPrePaidBookingsLink() { + return getLink("pre_paid_bookings"); + } + + /** + * Returns the questions link. + * + * @return The questions link associated with the current Client object. + */ + public String getQuestionsLink() { + return getLink("questions"); + } + + /** + * Returns the edit link. + * + * @return The edit link associated with the current Client object. + */ + public String getEditLink() { + return getLink("edit"); + } } diff --git a/src/main/bookingbugAPI/models/Company.java b/src/main/bookingbugAPI/models/Company.java index 8c36265..7d8dc4a 100644 --- a/src/main/bookingbugAPI/models/Company.java +++ b/src/main/bookingbugAPI/models/Company.java @@ -43,6 +43,78 @@ public Company(HttpServiceResponse httpServiceResponse, String auth_token){ public Company() {} + public String get_companyID() { + return get("id"); + } + + public String get_numericWidgetID() { + return get("numeric_widget_id"); + } + + public String get_addressID() { + return get("address_id"); + } + + public String get_name() { + return get("name"); + } + + public String get_currencyCode() { + return get("currency_code"); + } + + public String get_timezone() { + return get("timezone"); + } + + public String get_multiStatus() { + return get("multi_status"); + } + + public String get_website() { + return get("website"); + } + + public String get_description() { + return get("description"); + } + + public String get_countryCode() { + return get("country_code"); + } + + public String get_live() { + return get("live"); + } + + public String get_addressLink() { + return getLink("addresses"); + } + + public String get_peopleLink() { + return getLink("people"); + } + + public String get_categoriesLink() { + return getLink("categories"); + } + + public String get_eventsLinks() { + return getLink("events"); + } + + public String get_resourcesLink() { + return getLink("resources"); + } + + public String get_servicesLink() { + return getLink("services"); + } + + public String get_bookingsLink() { + return getLink("bookings"); + } + /* //TODO temp. until get the purchase from the content representation public Purchase getPurchase () { @@ -124,8 +196,10 @@ public Service serviceEdit_Admin(String serviceId) throws IOException { * @throws IOException */ public BBCollection serviceList_Admin(ServiceListParams slParams) throws IOException { - String urlStr = AdminURLS.Service.serviceList().set("companyId", this.id).expand(); - URL url = new URL(Utils.inflateLink(urlStr, slParams.getParams())); + UriTemplate template = Utils.TemplateWithPagination( + AdminURLS.Service.serviceList().set("companyId", this.id), + slParams); + URL url = new URL(template.expand()); BBCollection services = new BBCollection(HttpService.api_GET(url, auth_token), auth_token, "services", Service.class); return services; } @@ -322,9 +396,21 @@ public Resource companyDetails(String companyId) throws IOException { * @throws IOException */ public BBCollection eventList() throws IOException { - URL url = new URL(PublicURLS.Event.eventList().set("companyId", this.id).expand()); - BBCollection events = new BBCollection(HttpService.api_GET(url, auth_token), auth_token, "events", Event.class); - return events; + return eventList(new Params()); + } + + /** + * Get a List of Bookable Events. + * @param params Parameters for pagination + * @return BBCollection + * @throws IOException + */ + public BBCollection eventList(Params params) throws IOException { + UriTemplate template = Utils.TemplateWithPagination( + PublicURLS.Event.eventList().set("companyId", this.id), + params); + URL url = new URL(template.expand()); + return new BBCollection(HttpService.api_GET(url, auth_token), auth_token, "events", Event.class); } @@ -369,9 +455,13 @@ public BBCollection bookableItemsByDate(String date) throws IOExce * @return Resource * @throws IOException */ - public BBCollection availabilityDaysForBookableItem() throws IOException { - URL url = new URL(PublicURLS.Bookable.availabilityDaysForBookableItem().set("companyId", this.id).expand()); - return new BBCollection(HttpService.api_GET(url, auth_token), auth_token, "events", BookableAvailability.class); + public BBRoot availabilityDaysForBookableItem(TimeDataParams params) throws IOException { + URL url = new URL( + PublicURLS.Bookable.availabilityDaysForBookableItem() + .set("companyId", this.id) + .set((Map)params.getParams()) + .expand()); + return new BBRoot(HttpService.api_GET(url, auth_token), auth_token); } @@ -380,9 +470,13 @@ public BBCollection availabilityDaysForBookableItem() thro * @return Resource * @throws IOException */ - public Resource availabilityTimesForBookableItem() throws IOException { - URL url = new URL(PublicURLS.Bookable.availabilityTimesForBookableItem().set("companyId", this.id).expand()); - return new Resource(HttpService.api_GET(url, auth_token), auth_token); + public BBCollection availabilityTimesForBookableItem(TimeDataParams params) throws IOException { + URL url = new URL( + PublicURLS.Bookable.availabilityTimesForBookableItem() + .set("companyId", this.id) + .set((Map)params.getParams()) + .expand()); + return new BBCollection(HttpService.api_GET(url, auth_token), auth_token, "events", BookableAvailability.class); } @@ -439,7 +533,20 @@ public EventGroup eventGroupRead(String eventGroupId) throws IOException { * @throws IOException */ public BBCollection eventChainList() throws IOException { - URL url = new URL (PublicURLS.EventChain.eventChainList().set("companyId", this.id).expand()); + return eventChainList(new Params()); + } + + /** + * Get a List of Courses or Repeating Events for a Company. + * @param params Parameters for pagination + * @return BBCollection + * @throws IOException + */ + public BBCollection eventChainList(Params params) throws IOException { + UriTemplate template = Utils.TemplateWithPagination( + AdminURLS.EventChain.eventChainList().set("companyId", this.id), + params); + URL url = new URL(template.expand()); BBCollection eventChains = new BBCollection(HttpService.api_GET(url, auth_token), auth_token, "event_chains", EventChain.class); return eventChains; } @@ -605,18 +712,24 @@ public Resource spaceStatusList() throws IOException { } + /** * Loads all of the public settings for a company, this allows you to configure a booking widget, * and shows all of the details need to book and show an appropriate widget. - * @return Resource + * @return CompanySettings * @throws IOException */ - public Resource settingsDetails() throws IOException { - URL url = new URL(PublicURLS.Company.settingsDetails().set("companyId", this.id).expand()); - return new Resource(HttpService.api_GET(url)); + public CompanySettings getSettings() throws IOException { + if(getRep().getResourcesByRel("settings").size() > 0) { + //Return settings from embedded + return new CompanySettings(new HttpServiceResponse((ContentRepresentation) getRep().getResourcesByRel("settings").get(0))); + } else { + //Call API + URL url = new URL(PublicURLS.Company.settingsDetails().set("companyId", this.id).expand()); + return new CompanySettings(HttpService.api_GET(url)); + } } - /** * You can either get all the company questions or pass a param to specifiy that you only want company questions * that apply to either a service, resource, person, company: @@ -1036,6 +1149,11 @@ public Resource deleteBasketCoupon() throws IOException { return new Resource(HttpService.api_DELETE(url), auth_token); } + public SchemaForm getNewBookingSchema() throws IOException { + String link = getRep().getLinkByRel("new_booking").getHref(); + URL url = new URL(UriTemplate.fromTemplate(link).expand()); + return new SchemaForm(HttpService.api_GET(url, auth_token)); + } public Booking bookingCreate_Admin(BookingCreateParams bCParams) throws IOException { String urlStr = AdminURLS.Bookings.bookingCreate().set("companyId", this.id).expand(); @@ -1050,8 +1168,13 @@ public Booking bookingCreate_Admin(BookingCreateParams bCParams) throws IOExcept * @throws IOException */ public BBCollection bookingList_Admin(BookingListParams bLParams) throws IOException { - String urlStr = AdminURLS.Bookings.bookingList().set("companyId", this.id).expand(); - URL url = new URL(Utils.inflateLink(urlStr, bLParams.getParams())); + URL url; + if(getLink("bookings") != null) + url = new URL(Utils.inflateLink(getLink("bookings"), bLParams.getParams())); + else { + UriTemplate template = AdminURLS.Bookings.bookingList().set("companyId", this.id); + url = new URL(Utils.inflateLink(template, bLParams.getParams())); + } BBCollection bookings = new BBCollection(HttpService.api_GET(url, auth_token), auth_token, "bookings", Booking.class); return bookings; } @@ -1070,6 +1193,8 @@ public Booking bookingRead_Admin(String bookingId) throws IOException { } + + /** * Get all the coupons for a Company. * @return BBCollection diff --git a/src/main/bookingbugAPI/models/CompanySettings.java b/src/main/bookingbugAPI/models/CompanySettings.java new file mode 100644 index 0000000..a1fd5e1 --- /dev/null +++ b/src/main/bookingbugAPI/models/CompanySettings.java @@ -0,0 +1,55 @@ +package bookingbugAPI.models; + +import helpers.HttpServiceResponse; + +/** + * Created by sebi on 31.03.2016. + */ +public class CompanySettings extends BBRoot { + + public CompanySettings(HttpServiceResponse httpServiceResponse, String auth_token) { + super(httpServiceResponse, auth_token); + } + + public CompanySettings(HttpServiceResponse response) { + super(response); + } + + public boolean has_coupons() { + return getBoolean("has_coupons", false); + } + + public boolean has_deals() { + return getBoolean("has_deals", false); + } + + public boolean has_products() { + return getBoolean("has_products", false); + } + + public boolean has_events() { + return getBoolean("has_events", false); + } + + public boolean has_classes() { + return getBoolean("has_classes", false); + } + + public boolean requires_login() { + return getBoolean("requires_login", false); + } + + public boolean has_wallets() { + return getBoolean("has_wallets", false); + } + + public int getPaymentTax() { + return getInteger("payment_tax", 0); + } + + + + public Currency getCurrency() { + return Currency.fromString(get("currency")); + } +} diff --git a/src/main/bookingbugAPI/models/Coupon.java b/src/main/bookingbugAPI/models/Coupon.java new file mode 100644 index 0000000..c2ddcb5 --- /dev/null +++ b/src/main/bookingbugAPI/models/Coupon.java @@ -0,0 +1,138 @@ +package bookingbugAPI.models; + +import helpers.HttpServiceResponse; +import org.joda.time.DateTime; + + +public class Coupon extends BBRoot { + + public Coupon(HttpServiceResponse httpServiceResponse) { + super(httpServiceResponse); + } + + /** + * Returns the id of the coupon. + * + * @return The id associated with the current Coupon object + */ + public Integer getId() { + return getInteger("id", INTEGER_DEFAULT_VALUE); + } + + /** + * Returns the code of the coupon. + * + * @return The code associated with the current Coupon object + */ + public String getCode() { + return get("code"); + } + + /** + * Returns the title of the coupon. + * + * @return The title associated with the current Coupon object + */ + public String getTitle() { + return get("title"); + } + + /** + * Returns the company's id. + * + * @return The company's id associated with the current Coupon object + */ + public Integer getCompanyId() { + return getInteger("company_id", INTEGER_DEFAULT_VALUE); + } + + /** + * Returns the date and time when the validation starts, with {@link DateTime DateTime()} as format. + * + * @return The date and time associated with the current Coupon object + */ + public DateTime getValidFrom() { + return getDate("valid_from"); + } + + /** + * Returns how many times the coupon has been used. + * + * @return The times used attribute associated with the current Coupon object + */ + public Integer getTimesUsed() { + return getInteger("times_used",INTEGER_DEFAULT_VALUE); + } + + /** + * Returns the public attribute. + * + * @return The public attribute associated with the current Coupon object + */ + public Boolean getPublic() { + return getBoolean("public", BOOLEAN_DEFAULT_VALUE); + } + + /** + * Returns the price of the coupon. + * + * @return The price associated with the current Coupon object + */ + public Double getPrice() { + return getDouble("price", DOUBLE_DEFAULT_VALUE); + } + + /** + * Returns the percentage. + * + * @return The percentage associated with the current Coupon object + */ + public Double getPercentage() { + return getDouble("percentage", DOUBLE_DEFAULT_VALUE); + } + + /** + * Returns the coupon type. + * + * @return The coupon type associated with the current Coupon object + */ + public Integer getCouponType() { + return getInteger("coupon_type", INTEGER_DEFAULT_VALUE); + } + + /** + * Returns the buy attribute. + * + * @return The buy attribute associated with the current Coupon object + */ + public Integer getBuy() { + return getInteger("buy", INTEGER_DEFAULT_VALUE); + } + + /** + * Returns true if the coupon is free, false otherwise. + * + * @return The free attribute associated with the current Coupon object + */ + public Integer getFree() { + return getInteger("free", INTEGER_DEFAULT_VALUE); + } + + /** + * Returns the apply to questions attribute. + * + * @return The apply to questions attribute associated with the current Coupon object + */ + public Boolean getApplyToQuestions() { + return getBoolean("apply_to_questions", BOOLEAN_DEFAULT_VALUE); + } + + /** + * Returns the maximum coupons per person. + * + * @return The maximum coupons per person associated with the current Coupon object + */ + public Integer getMaxPerPerson() { + return getInteger("max_per_person", INTEGER_DEFAULT_VALUE); + } +} diff --git a/src/main/bookingbugAPI/models/Currency.java b/src/main/bookingbugAPI/models/Currency.java new file mode 100644 index 0000000..1cf3c6b --- /dev/null +++ b/src/main/bookingbugAPI/models/Currency.java @@ -0,0 +1,33 @@ +package bookingbugAPI.models; + +/** + * Created by sebi on 31.03.2016. + */ +public enum Currency { + GBP("GBP"), + EUR("EUR"); + + private final String apiValue; + + private Currency(String apiValue) { + this.apiValue = apiValue; + } + + public String symbol() { + switch (this) { + case GBP: return "\u00a3"; + case EUR: return "\u20ac"; + default: return ""; + } + } + + public static Currency fromString(String str) { + if(str != null) { + for(Currency currency : Currency.values()) { + if(str.equalsIgnoreCase(currency.apiValue)) + return currency; + } + } + return null; + } +} diff --git a/src/main/bookingbugAPI/models/Deal.java b/src/main/bookingbugAPI/models/Deal.java index a54e1b1..481c751 100644 --- a/src/main/bookingbugAPI/models/Deal.java +++ b/src/main/bookingbugAPI/models/Deal.java @@ -1,6 +1,7 @@ package bookingbugAPI.models; import helpers.HttpServiceResponse; +import org.joda.time.DateTime; public class Deal extends BBRoot { @@ -17,4 +18,102 @@ public Deal(HttpServiceResponse httpServiceResponse, String auth_token){ public Deal() {} + /** + * Returns the deal id. + * + * @return The deal id associated with the current Deal object + */ + public Integer getId() { + return getInteger("id", INTEGER_DEFAULT_VALUE); + } + + /** + * Returns the deal name. + * + * @return The deal name associated with the current Deal object + */ + public String getName() { + return get("name"); + } + + /** + * Returns the number deal. + * + * @return The number deal associated with the current Deal object + */ + public Integer getNum() { + return getInteger("num", INTEGER_DEFAULT_VALUE); + } + + /** + * Returns the service id. + * + * @return The service id associated with the current Deal object + */ + public Integer getService_id() { + return getInteger("service_id", INTEGER_DEFAULT_VALUE); + } + + /** + * Returns the date and time the deal was created, with {@link DateTime DateTime()} as format. + * + * @return The date and time associated with the current Deal object + */ + public DateTime getCreated_at() { + return getDate("created_at"); + } + + /** + * Returns the deal redemption. + * + * @return The deal redemption associated with the current Deal object + */ + public Integer getRedemption() { + return getInteger("redemption", INTEGER_DEFAULT_VALUE); + } + + /** + * Returns the deal total codes. + * + * @return The deal total codes associated with the current Deal object + */ + public Integer getTotalCodes() { + return getInteger("total_codes", INTEGER_DEFAULT_VALUE); + } + + /** + * Returns the deal used codes. + * + * @return The deal used codes associated with the current Deal object + */ + public Integer getUsedCodes() { + return getInteger("used_codes", INTEGER_DEFAULT_VALUE); + } + + /** + * Returns the deal vendor. + * + * @return The deal vendor associated with the current Deal object + */ + public String getVendor() { + return get("vendor"); + } + + /** + * Returns true if mixed booking are allowed, false otherwise. + * + * @return The allow mixed bookings attribute associated with the current Deal object + */ + public Boolean getAllowMixedBookings() { + return getBoolean("allow_mixed_bookings", BOOLEAN_DEFAULT_VALUE); + } + + /** + * Returns true to show to widget, false otherwise. + * + * @return The widget show attribute associated with the current Deal object + */ + public Boolean getWidgetShow() { + return getBoolean("widget_show", BOOLEAN_DEFAULT_VALUE); + } } diff --git a/src/main/bookingbugAPI/models/Event.java b/src/main/bookingbugAPI/models/Event.java index 575fb38..58b0f7c 100644 --- a/src/main/bookingbugAPI/models/Event.java +++ b/src/main/bookingbugAPI/models/Event.java @@ -1,20 +1,200 @@ package bookingbugAPI.models; +import bookingbugAPI.services.HttpService; +import com.damnhandy.uri.template.UriTemplate; +import com.fasterxml.jackson.databind.util.ISO8601DateFormat; import helpers.HttpServiceResponse; +import org.joda.time.DateTime; +import java.io.IOException; +import java.net.URL; +import java.util.Date; -public class Event extends BBRoot{ +public class Event extends BBRoot { - public Event(HttpServiceResponse httpServiceResponse){ + private int integerDefaultValue = 0; + private boolean booleanDefaultValue = false; + + public Event(HttpServiceResponse httpServiceResponse) { super(httpServiceResponse); } - - public Event(HttpServiceResponse httpServiceResponse, String auth_token){ + public Event(HttpServiceResponse httpServiceResponse, String auth_token) { super(httpServiceResponse, auth_token); } + public Event() { + } + + public SchemaForm getNewBookingSchema() throws IOException { + if (getLink("new_booking") != null) { + String link = getLink("new_booking"); + URL url = new URL(UriTemplate.fromTemplate(link).expand()); + return new SchemaForm(HttpService.api_GET(url, this.auth_token)); + } + // Throw exception: link is missing + throw new IOException("new_booking link missing"); + } + + /** + * Returns the Event id. + * + * @return The id associated with the current Event object. + */ + public Integer getId() { + return getInteger("id", integerDefaultValue); + } + + /** + * Returns the Event date and time in {@link DateTime DateTime()} format. + * + * @return The date associated with the current Event object. + */ + public DateTime getDatetime() { + return getDate("datetime"); + } + + /** + * Returns the Event description. + * + * @return The description associated with the current Event object. + */ + public String getDescription() { + return get("description"); + } + + /** + * Returns the Event status. + * + * @return The status associated with the current Event object. + */ + public Integer getStatus() { + return getInteger("status", integerDefaultValue); + } + + /** + * Returns the Event spaces booked. + * + * @return The spaces booked associated with the current Event object. + */ + public Integer getSpacesBooked() { + return getInteger("spaces_booked", integerDefaultValue); + } - public Event() {} + /** + * Returns the Event spaces reserved. + * + * @return The spaces reserved associated with the current Event object. + */ + public Integer getSpacesReserved() { + return getInteger("spaces_reserved", integerDefaultValue); + } + + /** + * Returns the Event spaces blocked. + * + * @return The spaces blocked associated with the current Event object. + */ + public Integer getSpacesBlocked() { + return getInteger("spaces_blocked", integerDefaultValue); + } + + /** + * Returns the Event spaces held. + * + * @return The spaces held associated with the current Event object. + */ + public Integer getSpacesHeld() { + return getInteger("spaces_held", integerDefaultValue); + } + /** + * Returns the Event number of spaces. + * + * @return The number of spaces associated with the current Event object. + */ + public Integer getNumSpaces() { + return getInteger("num_spaces", integerDefaultValue); + } + + /** + * Returns the Event wait spaces. + * + * @return The wait spaces associated with the current Event object. + */ + public Integer getSpacesWait() { + return getInteger("spaces_wait", integerDefaultValue); + } + + /** + * Returns the Event event chain id. + * + * @return The event chain id associated with the current Event object. + */ + public Integer getEventChainId() { + return getInteger("event_chain_id", integerDefaultValue); + } + + /** + * Returns the Event service id. + * + * @return The service id associated with the current Event object. + */ + public Integer getServiceId() { + return getInteger("service_id", integerDefaultValue); + } + + /** + * Returns the Event duration with unit provided by {@link #getDurationUnits() getDurationUnits()} + * + * @return The duration associated with the current Event object. + */ + public Integer getDuration() { + return getInteger("duration", integerDefaultValue); + } + + /** + * Returns the event duration size unit. + * + * @return The duration size unit associated with the current Event object. + */ + public String getDurationUnits() { + return get("units"); + } + + /** + * Returns the Event price. + * + * @return The price associated with the current Event object. + */ + public Integer getPrice() { + return getInteger("price", integerDefaultValue); + } + + /** + * Returns the Event event groups link. + * + * @return The event groups link associated with the current Event object. + */ + public String getEventGroupsLink() { + return getLink("event_groups"); + } + + /** + * Returns the Event event chains link. + * + * @return The event chains link associated with the current Event object. + */ + public String getEventChainsLink() { + return getLink("event_chains"); + } + + /** + * Returns the Event book link. + * + * @return The book link associated with the current Event object. + */ + public String getBookLink() { + return getLink("book"); + } } diff --git a/src/main/bookingbugAPI/models/EventChain.java b/src/main/bookingbugAPI/models/EventChain.java index dc32cbe..a5164fa 100644 --- a/src/main/bookingbugAPI/models/EventChain.java +++ b/src/main/bookingbugAPI/models/EventChain.java @@ -1,21 +1,248 @@ package bookingbugAPI.models; +import bookingbugAPI.api.PublicURLS; +import bookingbugAPI.models.params.EventListParams; +import bookingbugAPI.services.HttpService; +import com.damnhandy.uri.template.UriTemplate; import helpers.HttpServiceResponse; +import helpers.Utils; +import org.joda.time.DateTime; +import rx.Observable; +import java.io.IOException; +import java.net.URL; +import java.util.concurrent.Callable; -public class EventChain extends BBRoot{ +public class EventChain extends BBRoot { - public EventChain(HttpServiceResponse httpServiceResponse){ + public EventChain(HttpServiceResponse httpServiceResponse) { super(httpServiceResponse); } - public EventChain(HttpServiceResponse httpServiceResponse, String auth_token){ + public EventChain(HttpServiceResponse httpServiceResponse, String auth_token) { super(httpServiceResponse, auth_token); } - public EventChain() {} + public EventChain() { + } + + public SchemaForm getNewBookingSchema() throws IOException { + URL url = new URL(UriTemplate.fromTemplate(this.getRep().getLinkByRel("new_booking").getHref()).expand()); + return new SchemaForm(HttpService.api_GET(url, this.auth_token)); + } + + /** + * Get a List of Bookable Events for an EventChain. + * + * @param params Parameters for pagination + * @return BBCollection + * @throws IOException + */ + public BBCollection eventList(EventListParams params) throws IOException { + UriTemplate template; + if (getLink("events") != null) { + template = Utils.TemplateWithPagination( + Utils.paginatedUriTemplate(getLink("events")), + params); + } else { + params.setEvent_chain_id(this.id); + template = PublicURLS.Event.eventList().set("companyId", get("company_id")); + } + + URL url = new URL(template.expand(params.getParamsMapObj())); + return new BBCollection(HttpService.api_GET(url, auth_token), auth_token, "events", Event.class); + } + + public Observable> eventListObs(final EventListParams params) { + return Observable.fromCallable(new Callable>() { + @Override + public BBCollection call() throws Exception { + return eventList(params); + } + }); + } + + /** + * Returns the id. + * + * @return The id associated with the current EventChain object + */ + public Integer getId() { + return getInteger("id", INTEGER_DEFAULT_VALUE); + } + + /** + * Returns the name. + * + * @return The name associated with the current EventChain object + */ + public String getName() { + return get("name"); + } + + /** + * Returns the description. + * + * @return The description associated with the current EventChain object + */ + public String getDescription() { + return get("description"); + } + + /** + * Returns the duration expressed in minutes. + * + * @return The duration associated with the current EventChain object + */ + public Integer getDuration() { + return getInteger("duration", INTEGER_DEFAULT_VALUE); + } + + /** + * Returns the event group. + * + * @return The group associated with the current EventChain object + */ + public String getGroup() { + return get("group"); + } + + /** + * Returns the date and time, with {@link DateTime DateTime()} as format. + * + * @return The date and time associated with the current EventChain object + */ + public DateTime getTime() { + return getDate("time"); + } + + /** + * Returns the long description of the event. + * + * @return The long description associated with the current EventChain object + */ + public String getLongDescription() { + return get("long_description"); + } + + /** + * Returns the capacity view. + * + * @return The capacity view associated with the current EventChain object + */ + public Integer getCapacityView() { + return getInteger("capacity_view", INTEGER_DEFAULT_VALUE); + } + + /** + * Returns the event start date and time, with {@link DateTime DateTime()} as format. + * + * @return The start date and time associated with the current EventChain object + */ + public DateTime getStartDate() { + return getDate("start_date"); + } + + /** + * Returns the event end date and time. + * + * @return The end date and time associated with the current EventChain object + */ + public DateTime getEndDate() { + return getDate("end_date"); + } + + /** + * Returns the event spaces. + * + * @return The spaces associated with the current EventChain object + */ + public Integer getSpaces() { + return getInteger("spaces", INTEGER_DEFAULT_VALUE); + } + + /** + * Returns the event price. + * + * @return The price associated with the current EventChain object + */ + public Integer getPrice() { + return getInteger("price", INTEGER_DEFAULT_VALUE); + } + + /** + * Returns the maximum number of bookings. + * + * @return The maximum number of bookings associated with the current EventChain object + */ + public Integer getMaxNumBookings() { + return getInteger("max_num_bookings", INTEGER_DEFAULT_VALUE); + } + + /** + * Returns the date and time of the minimum advance time, with {@link DateTime DateTime()} as format. + * + * @return The date and time of the minimum advance time associated with the current EventChain object + */ + public DateTime getMinAdvanceTime() { + return getDate("min_advance_time"); + } + + /** + * Returns the event ticket space. + * + * @return The ticket space associated with the current EventChain object + */ + public String getTicketType() { + return get("ticket_type"); + } + + /** + * Returns the email per ticket attribute. + * + * @return The email per ticket attribute associated with the current EventChain object + */ + public Boolean getEmailPerTicket() { + return getBoolean("email_per_ticket", BOOLEAN_DEFAULT_VALUE); + } + + /** + * Returns the question per ticket attribute. + * + * @return The question per ticket attribute associated with the current EventChain object + */ + public Boolean getQuestionPerTicket() { + return getBoolean("questions_per_ticket", BOOLEAN_DEFAULT_VALUE); + } + + /** + * Returns the event course. + * + * @return The course associated with the current EventChain object + */ + public Boolean getCourse() { + return getBoolean("course", BOOLEAN_DEFAULT_VALUE); + } + + /** + * Returns the questions link. + * + * @return The question link associated with the current EventChain object + */ + public String getQuestionsLink() { + return getLink("questions"); + } + + /** + * Returns the child event chains. + * + * @return The child event chains assoiciated with the currnet EventChain object + */ + public BBCollection getChildEventChains() { + return new BBCollection<>(new HttpServiceResponse(getResource("child_event_chains")), auth_token, EventChain.class); + } } diff --git a/src/main/bookingbugAPI/models/EventGroup.java b/src/main/bookingbugAPI/models/EventGroup.java index 7ab870a..4e49870 100644 --- a/src/main/bookingbugAPI/models/EventGroup.java +++ b/src/main/bookingbugAPI/models/EventGroup.java @@ -1,12 +1,7 @@ package bookingbugAPI.models; -import bookingbugAPI.api.PublicURLS; -import bookingbugAPI.services.HttpService; import helpers.HttpServiceResponse; -import java.io.IOException; -import java.net.URL; - public class EventGroup extends BBRoot { @@ -23,4 +18,39 @@ public EventGroup(HttpServiceResponse httpServiceResponse, String auth_token){ public EventGroup() {} + /** + * Returns the id + * + * @return The id associated with the current EventGroup object + */ + public Integer getId() { + return getInteger("id", INTEGER_DEFAULT_VALUE); + } + + /** + * Returns the name. + * + * @return The name associated with the current EventGroup object + */ + public String getName() { + return get("name"); + } + + /** + * Returns the description. + * + * @return The description associated with the current EventGroup object + */ + public String getDescription() { + return get("description"); + } + + /** + * Returns the imagesLink. + * + * @return The imagesLink associated with the current EventGroup object + */ + public String getImagesLink() { + return getLink("images"); + } } diff --git a/src/main/bookingbugAPI/models/Login.java b/src/main/bookingbugAPI/models/Login.java index 303f445..c8a9956 100644 --- a/src/main/bookingbugAPI/models/Login.java +++ b/src/main/bookingbugAPI/models/Login.java @@ -38,7 +38,7 @@ public Login(HttpServiceResponse httpServiceResponse, Map creden } - public Login login(Map params) throws IOException { + public Login login(Map params) throws IOException { return auth(params, response.getRep().getLinkByRel("login")); } @@ -62,20 +62,20 @@ public String getPassword() { public Administrator getAdministrator() throws IOException { - if(administrator == null){ + if (administrator == null) { List admin_reps = (List) response.getRep().getResourcesByRel("administrators"); Link getAdministratorLink = response.getRep().getLinkByRel("administrator"); if (admin_reps.size() > 0) { //search matching link - for(ContentRepresentation representation : admin_reps) { - if(representation.getLinkByRel("self").getHref().equals(getAdministratorLink.getHref())) + for (ContentRepresentation representation : admin_reps) { + if (representation.getLinkByRel("self").getHref().equals(getAdministratorLink.getHref())) administrator = new Administrator(new HttpServiceResponse(representation), auth_token); } } //If not found - if(admin_reps.size() == 0 || administrator == null){ + if (admin_reps.size() == 0 || administrator == null) { String link = getRep().getLinkByRel("administrator").getHref(); URL url = new URL(UriTemplate.fromTemplate(link).expand()); administrator = new Administrator(HttpService.api_GET(url, auth_token), auth_token); @@ -94,7 +94,7 @@ public Administrator getAdministrator(Link link) throws IOException { public ArrayList getAdministrators() { ArrayList admins = new ArrayList(); List admin_reps = (List) getRep().getResourcesByRel("administrators"); - for(ContentRepresentation representation : admin_reps) { + for (ContentRepresentation representation : admin_reps) { //admins.add(new Administrator(response, auth_token)); admins.add(new Administrator(new HttpServiceResponse(representation), auth_token)); } @@ -104,7 +104,7 @@ public ArrayList getAdministrators() { public Administrator createAdministrator(Map data) throws HttpException, MalformedURLException { String uri = AdminURLS.Administrator.administratorCreate().set("companyId", get("company_id")).expand(); - URL url = new URL (uri); + URL url = new URL(uri); return new Administrator(HttpService.api_POST(url, data, auth_token), auth_token); } diff --git a/src/main/bookingbugAPI/models/Note.java b/src/main/bookingbugAPI/models/Note.java new file mode 100644 index 0000000..f1f9661 --- /dev/null +++ b/src/main/bookingbugAPI/models/Note.java @@ -0,0 +1,31 @@ +package bookingbugAPI.models; + +import helpers.HttpServiceResponse; + + +public class Note extends BBRoot { + + public Note(){} + + public Note(HttpServiceResponse httpServiceResponse) { + super(httpServiceResponse); + } + + /** + * Returns the note id. + * + * @return The note id associated with the Note Object + */ + public Integer getId() { + return getInteger("id", INTEGER_DEFAULT_VALUE); + } + + /** + * Returns the note text. + * + * @return The note text associated with the Note Object + */ + public String getNote() { + return get("note"); + } +} diff --git a/src/main/bookingbugAPI/models/Notes.java b/src/main/bookingbugAPI/models/Notes.java new file mode 100644 index 0000000..06c087d --- /dev/null +++ b/src/main/bookingbugAPI/models/Notes.java @@ -0,0 +1,31 @@ +package bookingbugAPI.models; + +import com.fasterxml.jackson.annotation.JsonProperty; + +import java.util.List; + + +public class Notes extends BBRoot { + @JsonProperty("private") + private List privateNotes; + @JsonProperty("public") + private List publicNotes; + + /** + * Returns public notes. + * + * @return The private notes associated with the Note Object + */ + public List getPublicNotes() { + return publicNotes; + } + + /** + * Returns the private notes. + * + * @return The private notes associated with the Note Object + */ + public List getPrivateNotes() { + return privateNotes; + } +} diff --git a/src/main/bookingbugAPI/models/Option.java b/src/main/bookingbugAPI/models/Option.java new file mode 100644 index 0000000..25f192e --- /dev/null +++ b/src/main/bookingbugAPI/models/Option.java @@ -0,0 +1,42 @@ +package bookingbugAPI.models; + + + +public class Option extends BBRoot{ + + /** + * Returns the option name. + * + * @return The option name associated with the current Option object. + */ + public String getName() { + return get("name"); + } + + /** + * Returns the price. + * + * @return The price associated with the current Option object. + */ + public Integer getPrice() { + return getInteger("price", INTEGER_DEFAULT_VALUE); + } + + /** + * Returns the is default attribute. + * + * @return The is default attribute associated with the current Option object. + */ + public Boolean getIsDefault() { + return getBoolean("is_default", BOOLEAN_DEFAULT_VALUE); + } + + /** + * Returns the option id. + * + * @return The option id associated with the current Option object. + */ + public Integer getId() { + return getInteger("id", INTEGER_DEFAULT_VALUE); + } +} diff --git a/src/main/bookingbugAPI/models/Question.java b/src/main/bookingbugAPI/models/Question.java index b77de8b..a801e78 100644 --- a/src/main/bookingbugAPI/models/Question.java +++ b/src/main/bookingbugAPI/models/Question.java @@ -1,22 +1,140 @@ package bookingbugAPI.models; -import bookingbugAPI.models.BBRoot; +import com.fasterxml.jackson.annotation.JsonProperty; import helpers.HttpServiceResponse; +import java.util.List; +import java.util.Map; -public class Question extends BBRoot{ +public class Question extends BBRoot { - public Question(HttpServiceResponse httpServiceResponse){ + public Question(HttpServiceResponse httpServiceResponse) { super(httpServiceResponse); } - public Question(HttpServiceResponse httpServiceResponse, String auth_token){ + public Question(HttpServiceResponse httpServiceResponse, String auth_token) { super(httpServiceResponse, auth_token); } + public Question() { + } + + /** + * Returns the question's id. + * + * @return The id associated with the current Question object. + */ + public Integer getId() { + return getInteger("id", INTEGER_DEFAULT_VALUE); + } - public Question() {} + /** + * Returns the question's name. + * + * @return The name associated with the current Question object. + */ + public String getName() { + return get("name"); + } + /** + * Returns the question's required attribute. + * + * @return The required attribute associated with the current Question object. + */ + public Boolean getRequired() { + return getBoolean("required", BOOLEAN_DEFAULT_VALUE); + } + + /** + * Returns the question's important attribute. + * + * @return The important attribute associated with the current Question object. + */ + public Boolean getImportant() { + return getBoolean("important", BOOLEAN_DEFAULT_VALUE); + } + + /** + * Returns the question's admin only attribute. + * + * @return The admin only attribute associated with the current Question object. + */ + public Boolean getAdminOnly() { + return getBoolean("admin_only", BOOLEAN_DEFAULT_VALUE); + } + + /** + * Returns the question's apllies to attribute. + * + * @return The apllies to attribute associated with the current Question object. + */ + public Integer getAppliesTo() { + return getInteger("applies_to", INTEGER_DEFAULT_VALUE); + } + + /** + * Returns the question's ask member attribute. + * + * @return The ask member attribute associated with the current Question object. + */ + public Boolean getAskMember() { + return getBoolean("ask_member", BOOLEAN_DEFAULT_VALUE); + } + + /** + * Returns the question's detail type. + * + * @return The detail type associated with the current Question object. + */ + public String getDetailType() { + return get("detail_type"); + } + + /** + * Returns the question's option. + * + * @return The option associated with the current Question object. + */ + public List