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.5</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
11 changes: 11 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 @@ -625,6 +626,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
17 changes: 13 additions & 4 deletions src/main/bookingbugAPI/api/PublicURLS.java
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,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 +249,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 +321,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
12 changes: 12 additions & 0 deletions src/main/bookingbugAPI/models/BBRoot.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,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
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;
}
}
71 changes: 56 additions & 15 deletions src/main/bookingbugAPI/models/Company.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@
import com.fasterxml.jackson.module.jsonSchema.factories.SchemaFactoryWrapper;
import com.theoryinpractise.halbuilder.api.ContentRepresentation;
import bookingbugAPI.services.HttpService;
import com.theoryinpractise.halbuilder.api.ReadableRepresentation;
import com.theoryinpractise.halbuilder.json.JsonRepresentationFactory;
import helpers.HttpServiceResponse;
import helpers.Utils;

import java.io.*;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;
import java.util.Map;

import static com.theoryinpractise.halbuilder.api.RepresentationFactory.HAL_JSON;
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(
PublicURLS.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
55 changes: 55 additions & 0 deletions src/main/bookingbugAPI/models/CompanySettings.java
Original file line number Diff line number Diff line change
@@ -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"));
}
}
33 changes: 33 additions & 0 deletions src/main/bookingbugAPI/models/Currency.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
Loading