Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
f5e0587
Added rxjava. Events, EventChain and EventChain-Events calls, paginat…
sebastianmacarescu Mar 24, 2016
5e8cfa4
Added call and model for company settings. Added basic ignore test fo…
sebastianmacarescu Mar 31, 2016
1f385e9
Implemented Custom UrlEncoder for Map, GenericEncoder, JsonEncoder. P…
sebastianmacarescu Apr 13, 2016
30f7226
Added some params test, call for schema in services and events. Final…
sebastianmacarescu Apr 28, 2016
4653d2f
wip
sebastianmacarescu May 3, 2016
a3e5765
WIP: new API Structure with fluent interface. Added sql interface wit…
sebastianmacarescu May 3, 2016
f691c02
Added OkHttpService which uses OkHttp to make requests. Refactored Co…
sebastianmacarescu May 25, 2016
2fb0916
Implemented put and delete methods. Added javadoc for OkHttpService. …
sebastianmacarescu May 26, 2016
102cf3c
Event model: getters, unittesting, javadoc
sebastianmacarescu May 26, 2016
0581837
Client model: getters, unittesting, javadoc. Empty Answer model.
sebastianmacarescu May 27, 2016
ae14d6f
Admin model: getters, unittesting, javadoc
sebastianmacarescu May 27, 2016
14c4eeb
Question model: getters, unittesting, javadoc. Added test.db on gitig…
sebastianmacarescu May 27, 2016
33f99c8
Booking model: getters, unittesting, javadoc. Added note model
sebastianmacarescu May 27, 2016
502eeb9
Note model: getters, unittesting, javadoc
sebastianmacarescu May 27, 2016
587cea8
Address model: getters, unittesting, javadoc. Fix getDouble in BBRoot…
sebastianmacarescu May 27, 2016
bfc38c3
Basket and BasketItem models: getters, unittesting, javadoc. Fix gett…
sebastianmacarescu May 27, 2016
07e840c
Coupon model: getters, unittesting, javadoc
sebastianmacarescu May 27, 2016
2005793
Deal model: getters, unittesting, javadoc
sebastianmacarescu May 27, 2016
0a86582
EventChain model: getters, unittesting, javadoc
sebastianmacarescu May 27, 2016
8b50227
EventGroup model: getters, unittesting, javadoc
sebastianmacarescu May 27, 2016
53719bb
Remove wrong assert with json strings compares
sebastianmacarescu May 27, 2016
a1e0d76
Removed json-simple library from dependencies
sebastianmacarescu Jun 1, 2016
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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ dist
/.project
/RUNNING_PID
/.settings

test.db

34 changes: 30 additions & 4 deletions 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.9</version>


<distributionManagement>
Expand Down Expand Up @@ -68,10 +68,36 @@
<artifactId>commons-lang3</artifactId>
<version>3.0</version>
</dependency>

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

<dependency>
<groupId>org.xerial</groupId>
<artifactId>sqlite-jdbc</artifactId>
<version>3.8.11.2</version>
</dependency>

<dependency>
<groupId>com.j256.ormlite</groupId>
<artifactId>ormlite-jdbc</artifactId>
<version>4.43</version>
</dependency>

<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>3.2.0</version>
</dependency>

<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1</version>
<groupId>com.squareup.okhttp</groupId>
<artifactId>mockwebserver</artifactId>
<version>2.7.0</version>
<scope>test</scope>
</dependency>

</dependencies>
Expand Down
22 changes: 22 additions & 0 deletions src/main/bookingbugAPI/api/API.java
Original file line number Diff line number Diff line change
@@ -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<APIBuilder> {

public API build() {
return new API(this);
}
}
}
133 changes: 133 additions & 0 deletions src/main/bookingbugAPI/api/AbstractAPI.java
Original file line number Diff line number Diff line change
@@ -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 <T> Keep fluent interface for subclasses
*/
public static class ApiConfig<T extends 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());
}
}
}
}
134 changes: 16 additions & 118 deletions src/main/bookingbugAPI/api/AdminAPI.java
Original file line number Diff line number Diff line change
@@ -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<Booking> getBookings(Company company, BookingListParams bLParams) throws IOException {
URL url = new URL(Utils.inflateLink(company.get_bookingsLink(), bLParams.getParams()));
BBCollection<Booking> bookings = new BBCollection<Booking>(httpService.api_GET(url), getAuthToken(), "bookings", Booking.class);
//BBCollection<Booking> bookings = new BBCollection<Booking>(HttpService.api_GET(url, getAuthToken()), getAuthToken(), "bookings", Booking.class);
return bookings;
}
}

Expand Down
Loading