Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>BookingBug-SDK</groupId>
<artifactId>BookingBug-SDK</artifactId>
<version>1.4</version>
<version>1.8</version>


<distributionManagement>
Expand Down Expand Up @@ -74,6 +74,12 @@
<version>1.1</version>
</dependency>

<dependency>
<groupId>io.reactivex</groupId>
<artifactId>rxjava</artifactId>
<version>1.1.0</version>
</dependency>

</dependencies>

<build>
Expand Down
23 changes: 23 additions & 0 deletions src/main/bookingbugAPI/api/AdminURLS.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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();
}

Expand All @@ -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();
}
}


Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -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();
}
}


Expand Down
21 changes: 16 additions & 5 deletions src/main/bookingbugAPI/api/PublicURLS.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

/**
Expand Down Expand Up @@ -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();
}

/**
Expand Down Expand Up @@ -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();
}

/**
Expand Down Expand Up @@ -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();
}

/**
Expand Down
25 changes: 25 additions & 0 deletions src/main/bookingbugAPI/models/BBRoot.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
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.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.theoryinpractise.halbuilder.api.ContentRepresentation;
import com.theoryinpractise.halbuilder.api.Link;
import com.theoryinpractise.halbuilder.api.RepresentationException;
Expand Down Expand Up @@ -107,6 +110,18 @@ public String get(String key){
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 String getAuth_token() {
return auth_token;
Expand Down Expand Up @@ -138,6 +153,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();
Expand Down
44 changes: 30 additions & 14 deletions src/main/bookingbugAPI/models/BookableAvailability.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<ReadableRepresentation> 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<AvailTime> getAvailTimes(){

ArrayList<ReadableRepresentation> times_reps = new ArrayList<>(getRep().getResourcesByRel("times"));
ArrayList<AvailTime> 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;
}
}
91 changes: 72 additions & 19 deletions src/main/bookingbugAPI/models/Company.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,10 @@ public Service serviceEdit_Admin(String serviceId) throws IOException {
* @throws IOException
*/
public BBCollection<Service> 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<Service> services = new BBCollection<Service>(HttpService.api_GET(url, auth_token), auth_token, "services", Service.class);
return services;
}
Expand Down Expand Up @@ -322,9 +324,21 @@ public Resource companyDetails(String companyId) throws IOException {
* @throws IOException
*/
public BBCollection<Event> eventList() throws IOException {
URL url = new URL(PublicURLS.Event.eventList().set("companyId", this.id).expand());
BBCollection<Event> events = new BBCollection<Event>(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<Event>
* @throws IOException
*/
public BBCollection<Event> 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<Event>(HttpService.api_GET(url, auth_token), auth_token, "events", Event.class);
}


Expand Down Expand Up @@ -369,9 +383,13 @@ public BBCollection<BookableItem> bookableItemsByDate(String date) throws IOExce
* @return Resource
* @throws IOException
*/
public BBCollection<BookableAvailability> availabilityDaysForBookableItem() throws IOException {
URL url = new URL(PublicURLS.Bookable.availabilityDaysForBookableItem().set("companyId", this.id).expand());
return new BBCollection<BookableAvailability>(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);
}


Expand All @@ -380,9 +398,13 @@ public BBCollection<BookableAvailability> 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<BookableAvailability> availabilityTimesForBookableItem(TimeDataParams params) throws IOException {
URL url = new URL(
PublicURLS.Bookable.availabilityTimesForBookableItem()
.set("companyId", this.id)
.set((Map)params.getParams())
.expand());
return new BBCollection<BookableAvailability>(HttpService.api_GET(url, auth_token), auth_token, "events", BookableAvailability.class);
}


Expand Down Expand Up @@ -439,7 +461,20 @@ public EventGroup eventGroupRead(String eventGroupId) throws IOException {
* @throws IOException
*/
public BBCollection<EventChain> 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<EventChain>
* @throws IOException
*/
public BBCollection<EventChain> eventChainList(Params params) throws IOException {
UriTemplate template = Utils.TemplateWithPagination(
AdminURLS.EventChain.eventChainList().set("companyId", this.id),
params);
URL url = new URL(template.expand());
BBCollection<EventChain> eventChains = new BBCollection<EventChain>(HttpService.api_GET(url, auth_token), auth_token, "event_chains", EventChain.class);
return eventChains;
}
Expand Down Expand Up @@ -605,18 +640,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:
Expand Down Expand Up @@ -1036,6 +1077,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();
Expand All @@ -1050,8 +1096,13 @@ public Booking bookingCreate_Admin(BookingCreateParams bCParams) throws IOExcept
* @throws IOException
*/
public BBCollection<Booking> 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<Booking> bookings = new BBCollection<Booking>(HttpService.api_GET(url, auth_token), auth_token, "bookings", Booking.class);
return bookings;
}
Expand All @@ -1070,6 +1121,8 @@ public Booking bookingRead_Admin(String bookingId) throws IOException {
}




/**
* Get all the coupons for a Company.
* @return BBCollection<Coupons>
Expand Down
Loading