diff --git a/.travis.yml b/.travis.yml
index b0c9864..4c17bc9 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,7 +1,6 @@
language: java
jdk:
- - openjdk7
- - oraclejdk7
+ - oraclejdk8
script: mvn clean test
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index 5ce3e3e..16a0c48 100644
--- a/pom.xml
+++ b/pom.xml
@@ -5,15 +5,15 @@
4.0.0
BookingBug-SDK
- BookingBug-SDK
- 1.9
+ BookingBug-SDK2
+ 2.2
- bintray-acornel-bb-java
- acornel-bb-java
- https://api.bintray.com/maven/acornel/bb-java/bookingbug-java/;publish=1
+ bintray-bookingbug-bookingbug-java
+ BookingBug-bookingbug-java
+ https://api.bintray.com/maven/bookingbug/bookingbug-java/BookingBug-JavaSDK/;publish=1
@@ -113,16 +113,100 @@
src/test/resources
+
+ src/main/resources
+
maven-compiler-plugin
- 1.7
- 1.7
+ 1.8
+ 1.8
+ 1.7
+ 1.7
+
+
+
+
+ maven-surefire-plugin
+
+
+
+ maven-failsafe-plugin
+
+
+
+ integration-test
+ verify
+
+
+
+
+
+
+ net.orfjackal.retrolambda
+ retrolambda-maven-plugin
+ 2.3.0
+
+
+
+ process-main
+ process-test
+
+
+
+
+ ${testBytecodeTarget}
+ ${testDefaultMethods}
+ ${testFork}
+
+
+
+
+ org.codehaus.mojo
+ animal-sniffer-maven-plugin
+ 1.7
+
+
+ signature-check
+ verify
+
+ check
+
+
+
+
+
+ org.codehaus.mojo.signature
+ java17
+ 1.0
+
+
+
+ noDefaultMethods
+
+ false
+
+
+
+
+ maven-compiler-plugin
+
+
+ **/DefaultMethodsTest.java
+ **/InterfaceStaticMethodsTest.java
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/main/bookingbugAPI/api/API.java b/src/main/bookingbugAPI/api/API.java
deleted file mode 100644
index 358e675..0000000
--- a/src/main/bookingbugAPI/api/API.java
+++ /dev/null
@@ -1,22 +0,0 @@
-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
deleted file mode 100644
index 4c7386c..0000000
--- a/src/main/bookingbugAPI/api/AbstractAPI.java
+++ /dev/null
@@ -1,133 +0,0 @@
-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
deleted file mode 100644
index b1872a0..0000000
--- a/src/main/bookingbugAPI/api/AdminAPI.java
+++ /dev/null
@@ -1,184 +0,0 @@
-package bookingbugAPI.api;
-
-import bookingbugAPI.models.*;
-import bookingbugAPI.models.params.BookingListParams;
-import bookingbugAPI.models.params.ServiceListParams;
-import bookingbugAPI.services.HttpService;
-import bookingbugAPI.services.OkHttpService;
-import com.damnhandy.uri.template.UriTemplate;
-import helpers.Utils;
-
-import java.io.IOException;
-import java.net.URL;
-
-
-public class AdminAPI extends AbstractAPI {
-
- AdminAPI(ApiConfig builder) {
- super(builder);
- }
-
- /**
- * Accessor to create an instance of {@link BookingAPI} with current configuration
- * @return BookingAPI instance
- */
- public BookingAPI booking() {
- return new BookingAPI(newConfig());
- }
-
- public class BookingAPI extends AbstractAPI {
-
- BookingAPI(ApiConfig config) {
- super(config);
- }
-
- /**
- * Get a list of admin bookings for a company
- * @param company The owning company for bookin
- * @param bLParams The parameters for this call
- * @return Collection of bookings
- * @throws IOException
- */
- public BBCollection bookingList(Company company, BookingListParams bLParams) throws IOException {
- URL url = new URL(Utils.inflateLink(company.getBookingsLink(), 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;
- }
-
- /**
- * Get all details about a specific booking
- * @param company the company owning the booking
- * @param bookingId the id of booking to read
- * @return Booking
- * @throws IOException
- */
- public Booking bookingRead(Company company, String bookingId) throws IOException {
- URL url = new URL(AdminURLS.Bookings.bookingRead()
- .set("companyId", company.id)
- .set("bookingId", bookingId)
- .expand());
- return new Booking(httpService.api_GET(url));
- }
-
- /**
- * Get the edit schema for booking
- * @param booking
- * @return SchemaForm
- * @throws IOException
- */
- public SchemaForm getEditBookingSchema(Booking booking) throws IOException {
- URL url = new URL(UriTemplate.fromTemplate(booking.getEditLink()).expand());
- return new SchemaForm(HttpService.api_GET(url, httpService.getConfig().auth_token));
- }
- }
-
-
- /**
- * Accessor to create an instance of {@link CompanyAPI} with current configuration
- * @return CompanyAPI instance
- */
- public CompanyAPI company() {
- return new CompanyAPI(newConfig());
- }
-
- public class CompanyAPI extends AbstractAPI {
-
- public CompanyAPI(ApiConfig config) {
- super(config);
- }
-
-
- /**
- * Load All of the Links and Properties of a Company
- * @param companyId the id of company
- * @return Company
- * @throws IOException
- */
- public Company companyRead(String companyId) throws IOException {
- URL url = new URL(AdminURLS.Company.companyRead().set("companyId", companyId).expand());
- return new Company(httpService.api_GET(url));
- }
-
- }
-
-
- /**
- * Accessor to create an instance of {@link ServiceAPI} with current configuration
- * @return ServiceAPI instance
- */
- public ServiceAPI service() {
- return new ServiceAPI(newConfig());
- }
-
- public class ServiceAPI extends AbstractAPI {
-
- public ServiceAPI(ApiConfig config) {
- super(config);
- }
-
- /**
- * List of Services for a company. Results are returned as a paginated list
- * @param company The owning company for services
- * @param slParams Parameters for this call
- * @return Collection of Service
- * @throws IOException
- */
- public BBCollection serviceList(Company company, ServiceListParams slParams) throws IOException {
- UriTemplate template = Utils.TemplateWithPagination(company.getServicesLink(), slParams);
- URL url = new URL(template.expand());
-
- BBCollection services = new BBCollection(httpService.api_GET(url), httpService.getConfig().auth_token, "services", Service.class);
- return services;
- }
-
- /**
- * Load a Specific Service Details
- * @param company The owning company for service
- * @param serviceId the id of service to load
- * @return Service
- * @throws IOException
- */
- public Service serviceRead(Company company, String serviceId) throws IOException{
- URL url = new URL(AdminURLS.Service.serviceRead()
- .set("companyId", company.id)
- .set("serviceId", serviceId)
- .expand());
- return new Service(httpService.api_GET(url));
- }
-
- /**
- * Get schema for creating a new service
- * @param company The owning company
- * @return SchemaForm
- * @throws IOException
- */
- public SchemaForm getNewServiceSchema(Company company) throws IOException {
- URL url = new URL(UriTemplate.fromTemplate(company.getNewServiceLink()).expand());
- return new SchemaForm(HttpService.api_GET(url, httpService.getConfig().auth_token));
- }
-
- /**
- * Get a schema for creating a new booking with provided service
- * @param service The service
- * @return SchemaForm
- * @throws IOException
- */
- public SchemaForm getNewBookingSchema(Service service) throws IOException {
- URL url = new URL(UriTemplate.fromTemplate(service.get_newBookingLik()).expand());
- return new SchemaForm(HttpService.api_GET(url, httpService.getConfig().auth_token));
- }
-
- /**
- * Get a schema for editing a service
- * @param service The service to be edited
- * @return SchemaForm
- * @throws IOException
- */
- public SchemaForm getEditServiceSchema(Service service) throws IOException {
- URL url = new URL(UriTemplate.fromTemplate(service.get_editServiceLik()).expand());
- return new SchemaForm(HttpService.api_GET(url, httpService.getConfig().auth_token));
- }
- }
-
-}
diff --git a/src/main/bookingbugAPI/models/params/ClientListParams.java b/src/main/bookingbugAPI/models/params/ClientListParams.java
deleted file mode 100644
index e8eb7b2..0000000
--- a/src/main/bookingbugAPI/models/params/ClientListParams.java
+++ /dev/null
@@ -1,118 +0,0 @@
-package bookingbugAPI.models.params;
-
-import java.util.HashMap;
-import java.util.Map;
-
-
-public class ClientListParams {
-
- String page;
- String per_page;
- String filter_by;
- String filter_by_fields;
- String order_by;
- String order_by_reverse;
-
-
- public ClientListParams(){}
-
-
- public ClientListParams(Map args){
- if (args==null || args.isEmpty()) {
- return;
- }
-
- String strValue;
-
- for (Map.Entry entry : args.entrySet()) {
- final String[] value = entry.getValue();
- if (value[0]!=null && !value[0].trim().isEmpty()) {
- strValue = null;
- } else {
- strValue = value[0];
- }
-
- switch(entry.getKey()) {
- case "page": page = strValue;
- break;
- case "per_page": per_page = strValue;
- break;
- case "filter_by": filter_by = strValue;
- break;
- case "filter_by_fields": filter_by_fields = strValue;
- break;
- case "order_by": order_by = strValue;
- break;
- case "order_by_reverse": order_by_reverse = strValue;
- break;
- }
- }
- }
-
-
- /**
- * getParams
- * @return Map
- */
- public Map getParams() {
- Map params = new HashMap();
-
- params.put("page", new String[]{page});
- params.put("per_page", new String[]{per_page});
- params.put("filter_by", new String[]{filter_by});
- params.put("filter_by_fields", new String[]{filter_by_fields});
- params.put("order_by", new String[]{order_by});
- params.put("order_by_reverse", new String[]{order_by_reverse});
-
- return params;
- }
-
-
- public String getPage() {
- return page;
- }
-
- public void setPage(String page) {
- this.page = page;
- }
-
- public String getPerPage() {
- return per_page;
- }
-
- public void setPerPage(String per_page) {
- this.per_page = per_page;
- }
-
- public String getFilterBy() {
- return filter_by;
- }
-
- public void setFilterBy(String filter_by) {
- this.filter_by = filter_by;
- }
-
- public String getFilterByFields() {
- return filter_by_fields;
- }
-
- public void setFilterByFields(String filter_by_fields) {
- this.filter_by_fields = filter_by_fields;
- }
-
- public String getOrderBy() {
- return order_by;
- }
-
- public void setOrderBy(String order_by) {
- this.order_by = order_by;
- }
-
- public String getOrderByReverse() {
- return order_by_reverse;
- }
-
- public void setOrderByReverse(String order_by_reverse) {
- this.order_by_reverse = order_by_reverse;
- }
-}
diff --git a/src/main/bookingbugAPI/models/params/PurchaseListParams.java b/src/main/bookingbugAPI/models/params/PurchaseListParams.java
deleted file mode 100644
index c0c1ff6..0000000
--- a/src/main/bookingbugAPI/models/params/PurchaseListParams.java
+++ /dev/null
@@ -1,106 +0,0 @@
-package bookingbugAPI.models.params;
-
-import java.util.HashMap;
-import java.util.Map;
-
-
-public class PurchaseListParams {
-
- String created_from;
- String created_to;
- String admin_bookings_only;
- String order_by;
- String order_by_reverse;
-
-
- public PurchaseListParams(){}
-
-
- public PurchaseListParams(Map args){
- if (args==null || args.isEmpty()) {
- return;
- }
-
- String strValue;
-
- for (Map.Entry entry : args.entrySet()) {
- final String[] value = entry.getValue();
- if (value[0]!=null && !value[0].trim().isEmpty()) {
- strValue = null;
- } else {
- strValue = value[0];
- }
-
- switch(entry.getKey()) {
- case "created_from": created_from = strValue;
- break;
- case "created_to": created_to = strValue;
- break;
- case "admin_bookings_only": admin_bookings_only = strValue;
- break;
- case "order_by": order_by = strValue;
- break;
- case "order_by_reverse": order_by_reverse = strValue;
- break;
- }
- }
- }
-
-
- /**
- * getParams
- * @return Map
- */
- public Map getParams() {
- Map params = new HashMap();
-
- params.put("created_from", new String[]{created_from});
- params.put("created_to", new String[]{created_to});
- params.put("admin_bookings_only", new String[]{admin_bookings_only});
- params.put("order_by", new String[]{order_by});
- params.put("order_by_reverse", new String[]{order_by_reverse});
-
- return params;
- }
-
-
- public String getCreated_from() {
- return created_from;
- }
-
- public void setCreated_from(String created_from) {
- this.created_from = created_from;
- }
-
- public String getCreated_to() {
- return created_to;
- }
-
- public void setCreated_to(String created_to) {
- this.created_to = created_to;
- }
-
- public String getAdmin_bookings_only() {
- return admin_bookings_only;
- }
-
- public void setAdmin_bookings_only(String admin_bookings_only) {
- this.admin_bookings_only = admin_bookings_only;
- }
-
- public String getOrder_by() {
- return order_by;
- }
-
- public void setOrder_by(String order_by) {
- this.order_by = order_by;
- }
-
- public String getOrder_by_reverse() {
- return order_by_reverse;
- }
-
- public void setOrder_by_reverse(String order_by_reverse) {
- this.order_by_reverse = order_by_reverse;
- }
-}
diff --git a/src/main/bookingbugAPI/models/params/QuestionListParams.java b/src/main/bookingbugAPI/models/params/QuestionListParams.java
deleted file mode 100644
index a84a708..0000000
--- a/src/main/bookingbugAPI/models/params/QuestionListParams.java
+++ /dev/null
@@ -1,59 +0,0 @@
-package bookingbugAPI.models.params;
-
-import java.util.HashMap;
-import java.util.Map;
-
-
-public class QuestionListParams {
-
- String detail_group_id;
-
-
- public QuestionListParams(){}
-
-
- public QuestionListParams(Map args){
- if (args==null || args.isEmpty()) {
- return;
- }
-
- String strValue;
-
- for (Map.Entry entry : args.entrySet()) {
- final String[] value = entry.getValue();
- if (value[0]!=null && !value[0].trim().isEmpty()) {
- strValue = null;
- } else {
- strValue = value[0];
- }
-
- switch(entry.getKey()) {
- case "detail_group_id": detail_group_id = strValue;
- break;
- }
- }
- }
-
-
- /**
- * getParams
- * @return Map
- */
- public Map getParams() {
- Map params = new HashMap();
-
- params.put("detail_group_id", new String[]{detail_group_id});
-
- return params;
- }
-
-
- public String getDetailGroupId() {
- return detail_group_id;
- }
-
- public void setDetailGroupId(String detail_group_id) {
- this.detail_group_id = detail_group_id;
- }
-
-}
diff --git a/src/main/bookingbugAPI/services/CacheService.java b/src/main/bookingbugAPI/services/CacheService.java
deleted file mode 100644
index 3f448c5..0000000
--- a/src/main/bookingbugAPI/services/CacheService.java
+++ /dev/null
@@ -1,107 +0,0 @@
-package bookingbugAPI.services;
-
-import com.j256.ormlite.dao.Dao;
-import com.j256.ormlite.dao.DaoManager;
-import com.j256.ormlite.jdbc.JdbcConnectionSource;
-import com.j256.ormlite.stmt.QueryBuilder;
-import com.j256.ormlite.support.ConnectionSource;
-import com.j256.ormlite.table.TableUtils;
-
-import java.sql.SQLException;
-import java.util.List;
-
-/**
- * Class used for caching HTTP Responses
- */
-public class CacheService {
-
- SQLite db;
- boolean mock;
-
- public CacheService(SQLite db, boolean mock) {
- this.db = db;
- this.mock = mock;
- }
-
- public static CacheService JDBC() {
- return new CacheService(new JDBC_Sqlite(), false);
- }
-
- public static CacheService MOCK() {
- return new CacheService(new JDBC_Sqlite(), true);
- }
-
- public void storeResult(String url, String method, String resp) {
- if(mock) return;
-
- Dao respDao;
-
- try {
- db.createIfNotExists();
- respDao = db.getDao();
-
- HttpService.NetResponse response = new HttpService.NetResponse(url, method, resp);
- respDao.create(response);
-
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
-
- public HttpService.NetResponse getDBResponse(String url, String method) {
- if(mock) return null;
- try {
- db.createIfNotExists();
- Dao respDao = db.getDao();
- QueryBuilder builder = respDao.queryBuilder();
- builder.where().eq("url", url).and().eq("method", method);
- List responses = respDao.query(builder.prepare());
- if(responses.size() > 0)
- return responses.get(0);
-
- } catch (SQLException e) {
- e.printStackTrace();
- }
- return null;
- }
-
-
- /**
- * Classes should implement this interface to provide proper handling for SQLite db
- */
- public interface SQLite {
-
- Dao getDao() throws SQLException;
- ConnectionSource getConnectionSource() throws SQLException;
- void createIfNotExists() throws SQLException;
-
- }
-
- /**
- * Implementation for SQLite with JDBC
- */
- public static final class JDBC_Sqlite implements SQLite {
-
- ConnectionSource connectionSource;
- Dao dao;
-
- @Override
- public void createIfNotExists() throws SQLException {
- TableUtils.createTableIfNotExists(getConnectionSource(), HttpService.NetResponse.class);
- }
-
- @Override
- public Dao getDao() throws SQLException {
- if(dao == null)
- dao = DaoManager.createDao(getConnectionSource(), HttpService.NetResponse.class);
- return dao;
- }
-
- @Override
- public ConnectionSource getConnectionSource() throws SQLException {
- if(connectionSource == null)
- connectionSource = new JdbcConnectionSource("jdbc:sqlite:test.db");
- return connectionSource;
- }
- }
-}
diff --git a/src/main/bookingbugAPI/services/OkHttpService.java b/src/main/bookingbugAPI/services/OkHttpService.java
deleted file mode 100644
index 8a7f9da..0000000
--- a/src/main/bookingbugAPI/services/OkHttpService.java
+++ /dev/null
@@ -1,200 +0,0 @@
-package bookingbugAPI.services;
-
-import bookingbugAPI.api.AbstractAPI;
-import bookingbugAPI.models.HttpException;
-import helpers.Http;
-import helpers.HttpServiceResponse;
-import helpers.Utils;
-import okhttp3.*;
-
-import java.io.IOException;
-import java.net.URL;
-import java.util.Map;
-import java.util.Objects;
-
-
-/**
- * Created by sebi on 23.05.2016.
- */
-public class OkHttpService {
-
- AbstractAPI.ApiConfig config;
- private final OkHttpClient client = new OkHttpClient();
-
- public OkHttpService(AbstractAPI.ApiConfig config) {
- this.config = config;
- }
-
- /**
- * Get current service configuration
- * @return {@link bookingbugAPI.api.AbstractAPI.ApiConfig}
- */
- public AbstractAPI.ApiConfig getConfig() {
- return config;
- }
-
-
- /**
- * Makes a synchronous GET request
- * @param url URL to get
- * @return {@link HttpServiceResponse}
- * @throws HttpException
- */
- public HttpServiceResponse api_GET(URL url) throws HttpException {
- return callApi(url, "GET", HttpService.urlEncodedContentType, null);
- }
-
-
- /**
- * Makes a synchronous POST request with {@link Http#urlEncodedContentType} contentType
- * @param url URL to post to
- * @param params Map, a generic Map containing data to post
- * @return {@link HttpServiceResponse}
- * @throws HttpException
- */
- public HttpServiceResponse api_POST(URL url, Map params) throws HttpException {
- return callApi(url, "POST", HttpService.urlEncodedContentType, params);
- }
-
-
- /**
- * Makes a synchronous POST request with specific contentType
- * @param url URL to post to
- * @param contentType String, can be {@link Http#urlEncodedContentType} or {@link Http#jsonContentType}.
- * @param params Map, a generic Map containing data to post
- * @return {@link HttpServiceResponse}
- * @throws HttpException
- */
- public HttpServiceResponse api_POST(URL url, String contentType, Map params) throws HttpException {
- return callApi(url, "POST", contentType, params);
- }
-
-
- /**
- * Makes a synchronous PUT request with {@link Http#urlEncodedContentType} contentType
- * @param url URL to put to
- * @param params Map, a generic Map containing data to put
- * @return {@link HttpServiceResponse}
- * @throws HttpException
- */
- public HttpServiceResponse api_PUT(URL url, Map params) throws HttpException {
- return callApi(url, "PUT", HttpService.urlEncodedContentType, params);
- }
-
-
- /**
- * Makes a synchronous PUT request with specific contentType
- * @param url URL to put to
- * @param contentType String, can be {@link Http#urlEncodedContentType} or {@link Http#jsonContentType}.
- * @param params Map, a generic Map containing data to put
- * @return {@link HttpServiceResponse}
- * @throws HttpException
- */
- public HttpServiceResponse api_PUT(URL url, String contentType, Map params) throws HttpException {
- return callApi(url, "PUT", contentType, params);
- }
-
-
- /**
- * Makes a synchronous DELETE request
- * @param url URL to delete to
- * @return {@link HttpServiceResponse}
- * @throws HttpException
- */
- public HttpServiceResponse api_DELETE(URL url) throws HttpException {
- return callApi(url, "DELETE", HttpService.urlEncodedContentType, null);
- }
-
-
- /**
- * Makes a synchronous DELETE request with parameters and {@link Http#urlEncodedContentType} contentType
- * @param url URL to delete to
- * @param params Map, a generic Map containing data to put
- * @return {@link HttpServiceResponse}
- * @throws HttpException
- */
- public HttpServiceResponse api_DELETE(URL url, Map params) throws HttpException {
- return callApi(url, "DELETE", HttpService.urlEncodedContentType, params);
- }
-
-
- /**
- * Makes a synchronous DELETE request with parameters and specific contentType
- * @param url URL to delete to
- * @param contentType String, can be {@link Http#urlEncodedContentType} or {@link Http#jsonContentType}.
- * @param params Map, a generic Map containing data to put
- * @return {@link HttpServiceResponse}
- * @throws HttpException
- */
- public HttpServiceResponse api_DELETE(URL url, String contentType, Map params) throws HttpException {
- return callApi(url, "DELETE", contentType, params);
- }
-
-
- /**
- * Make a synchronous configurable network request. Uses headers and other config from {@link OkHttpService#config}
- * @param url URL to call
- * @param method String, can be GET, POST, PUT, DELETE, UPDATE
- * @param contentType String, can be {@link Http#urlEncodedContentType} or {@link Http#jsonContentType}
- * @param params Map, a generic Map with parameters for POST, PUT or UPDATE. Will be serialized according
- * to {@code contentType}
- * @return {@link HttpServiceResponse}
- * @throws HttpException
- */
- private HttpServiceResponse callApi(URL url, String method, String contentType, Map params) throws HttpException {
- HttpService.NetResponse cache = config.cacheService.getDBResponse(url.toString(), method);
-
- if(cache != null) {
- return new HttpServiceResponse(Utils.stringToContentRep(cache.getResp()), method, contentType, params, config.auth_token);
- }
-
- //http://stackoverflow.com/questions/7615645/ssl-handshake-alert-unrecognized-name-error-since-upgrade-to-java-1-7-0
- System.setProperty("jsse.enableSNIExtension", "false");
-
- Request.Builder builder = new Request.Builder()
- .header("User-Agent", config.userAgent)
- .header("App-Id", config.appId)
- .header("App-Key", config.appKey)
- .url(url.toString());
-
- if(config.auth_token != null)
- builder.header("Auth-Token", config.auth_token);
-
- String body = null;
- if(params != null) {
- try {
- body = Http.getEncoder(contentType).encode(params);
- } catch (Http.EncodingException | Http.UnknownContentType e) {
- throw new HttpException("Error", e) ;
- }
- }
-
- if(Objects.equals(method, "POST") && body != null) {
- builder.post(RequestBody.create(MediaType.parse(contentType), body));
- } else if(Objects.equals(method, "PUT") && body != null) {
- builder.put(RequestBody.create(MediaType.parse(contentType), body));
- } else if(Objects.equals(method, "DELETE") && body != null) {
- builder.delete(RequestBody.create(MediaType.parse(contentType), body));
- } else if(Objects.equals(method, "DELETE")) {
- builder.delete();
- }
-
- Request request = builder.build();
-
- Response response;
- try {
- response = client.newCall(request).execute();
- if (!response.isSuccessful())
- throw new HttpException("Unexpected code " + response, response.message(), response.code());
-
- String raw_resp = response.body().string();
- config.cacheService.storeResult(url.toString(), method, raw_resp);
-
- return new HttpServiceResponse(Utils.stringToContentRep(raw_resp), method, contentType, params, config.auth_token);
- } catch (IOException e) {
- if(e instanceof HttpException) throw (HttpException)e;
- throw new HttpException("Error", e) ;
- }
-
- }
-}
diff --git a/src/main/bookingbugAPI2/api/API.java b/src/main/bookingbugAPI2/api/API.java
new file mode 100644
index 0000000..d0ac51f
--- /dev/null
+++ b/src/main/bookingbugAPI2/api/API.java
@@ -0,0 +1,18 @@
+package bookingbugAPI2.api;
+
+import bookingbugAPI2.services.ServiceProvider;
+
+/**
+ * Created by sebi on 19.05.2016.
+ */
+public class API extends AbstractAPI {
+
+
+ public API(ServiceProvider provider) {
+ super(provider);
+ }
+
+ public AdminAPI admin() {
+ return new AdminAPI(newProvider());
+ }
+}
diff --git a/src/main/bookingbugAPI2/api/AbstractAPI.java b/src/main/bookingbugAPI2/api/AbstractAPI.java
new file mode 100644
index 0000000..250f917
--- /dev/null
+++ b/src/main/bookingbugAPI2/api/AbstractAPI.java
@@ -0,0 +1,210 @@
+package bookingbugAPI2.api;
+
+import bookingbugAPI2.services.http.AbstractHttpService;
+import bookingbugAPI2.services.cache.AbstractCacheService;
+import bookingbugAPI2.services.cache.SQLiteCacheService;
+import bookingbugAPI2.services.ConfigService;
+import bookingbugAPI2.services.logger.AbstractLoggerService;
+import bookingbugAPI2.services.logger.JavaLoggerService;
+import bookingbugAPI2.services.http.OkHttpService;
+import bookingbugAPI2.services.ServiceProvider;
+
+/**
+ * Abstract API class
+ * Contains basic methods and members
+ */
+public abstract class AbstractAPI implements ServiceProvider {
+
+ final String CACHE_TAG;
+ ServiceProvider provider;
+
+ public AbstractAPI(ServiceProvider provider){
+ this.provider = provider;
+ this.CACHE_TAG = this.getClass().getName();
+ }
+
+ /**
+ * Calls {@link AbstractAPI#fresh(boolean)} with true
+ * @return API instance
+ */
+ public T fresh() {
+ return fresh(true);
+ }
+
+ /**
+ * Calls {@link bookingbugAPI2.services.cache.AbstractCacheService#setOneTimeFresh(boolean)}
+ * Disables and clears the cache just for the next api call if {@code fresh} is true
+ * @return API instance
+ */
+ public T fresh(boolean fresh) {
+ provider.cacheService().setOneTimeFresh(fresh);
+ return (T)this;
+ }
+
+ /**
+ * Calls {@link AbstractAPI#freshAndClear(boolean)} with true
+ * @return API instance
+ */
+ public T freshAndClear() {
+ return freshAndClear(true);
+ }
+
+ /**
+ * Calls {@link bookingbugAPI2.services.cache.AbstractCacheService#setOneTimeFresh(boolean)}
+ * {@link bookingbugAPI2.services.cache.AbstractCacheService#invalidateResultsByTag(String)}
+ * Disables the cache just for the next call and clears all cache records with same CACHE_TAG if {@code fresh} is true
+ * Must be called on terminal api instances (CompanyAPI, etc)
+ * @return
+ */
+ public T freshAndClear(boolean fresh) {
+ if(fresh) {
+ provider.cacheService().invalidateResultsByTag(CACHE_TAG);
+ provider.cacheService().setOneTimeFresh(true);
+ }
+ return (T)this;
+ }
+
+ /**
+ * Returns an ApiConfig with the same configuration as the current one, except that the ConfigService is a clone
+ * @return current configuration with ConfigService clone
+ */
+ public ApiConfig newConfig() {
+ ApiConfig clone = new ApiConfig(provider);
+ ConfigService newConfig = new ConfigService(provider.configService());
+ return clone.withConfigService(newConfig);
+ }
+
+ public ServiceProvider newProvider() {
+ return (ServiceProvider)newConfig();
+ }
+
+ public String getAuthToken(){
+ return provider.configService().auth_token;
+ }
+
+ @Override
+ public AbstractHttpService httpService() {
+ return provider.httpService();
+ }
+
+ @Override
+ public AbstractLoggerService loggerService() {
+ return provider.loggerService();
+ }
+
+ @Override
+ public AbstractCacheService cacheService() {
+ return provider.cacheService();
+ }
+
+ @Override
+ public ConfigService configService() {
+ return provider.configService();
+ }
+
+ /**
+ * Class which holds an API configuration
+ * @param Keep fluent interface for subclasses
+ */
+ public static class ApiConfig implements ServiceProvider {
+
+ //Services
+ public AbstractCacheService cacheService;
+ public AbstractLoggerService loggerService;
+ public AbstractHttpService httpService;
+ public ConfigService configService;
+
+ //TODO: fix references to services (same for all instances)
+ public ApiConfig(ServiceProvider provider) {
+ this.cacheService = provider.cacheService();
+ this.loggerService = provider.loggerService();
+ this.httpService = provider.httpService();
+ this.configService = provider.configService();
+ }
+
+ public ApiConfig() {
+ //Load default services
+ configService = new ConfigService();
+ configService.loadConfigFile(null);
+
+ httpService = new OkHttpService(this);
+ cacheService = new SQLiteCacheService(this);
+ loggerService = new JavaLoggerService();
+ }
+
+ public T withNothing() {
+ /*cacheService = null;
+ loggerService = null;
+ httpService = null;*/
+ configService = new ConfigService();
+
+ return (T) this;
+ }
+
+ public T withAuthToken(String token) {
+ this.configService.auth_token = token;
+ return (T)this;
+ }
+
+ public T withApp(String appId, String appKey) {
+ this.configService.appId = appId;
+ this.configService.appKey = appKey;
+ return (T)this;
+ }
+
+ public T withUserAgent(String userAgent) {
+ this.configService.userAgent = userAgent;
+ return (T)this;
+ }
+
+ public T withServerUrl(String serverUrl) {
+ this.configService.serverUrl = serverUrl;
+ return (T)this;
+ }
+
+ public T withConfigString(String configString) {
+ configService.loadConfigFile(configString);
+ return (T)this;
+ }
+
+ public T withCacheService(AbstractCacheService cacheService) {
+ this.cacheService = cacheService;
+ return (T)this;
+ }
+
+ public T withConfigService(ConfigService configService) {
+ this.configService = configService;
+ return (T)this;
+ }
+
+ public T withHttpService(AbstractHttpService httpService) {
+ this.httpService = httpService;
+ return (T)this;
+ }
+
+ public T withLoggerService(AbstractLoggerService loggerService) {
+ this.loggerService = loggerService;
+ return (T)this;
+ }
+
+ @Override
+ public AbstractHttpService httpService() {
+ return httpService;
+ }
+
+ @Override
+ public AbstractLoggerService loggerService() {
+ return loggerService;
+ }
+
+ @Override
+ public AbstractCacheService cacheService() {
+ return cacheService;
+ }
+
+ @Override
+ public ConfigService configService() {
+ return configService;
+ }
+ }
+}
diff --git a/src/main/bookingbugAPI2/api/AdminAPI.java b/src/main/bookingbugAPI2/api/AdminAPI.java
new file mode 100644
index 0000000..112dc4f
--- /dev/null
+++ b/src/main/bookingbugAPI2/api/AdminAPI.java
@@ -0,0 +1,2033 @@
+package bookingbugAPI2.api;
+
+import bookingbugAPI2.models.*;
+import bookingbugAPI2.models.params.*;
+import bookingbugAPI2.services.ServiceProvider;
+import com.damnhandy.uri.template.UriTemplate;
+import helpers2.Http;
+import helpers2.HttpServiceResponse;
+import helpers2.Utils;
+import rx.Observable;
+
+import java.io.IOException;
+import java.net.URL;
+import java.util.HashMap;
+import java.util.Map;
+
+
+public class AdminAPI extends AbstractAPI {
+
+ AdminURLS urls;
+
+ public AdminAPI(ServiceProvider provider) {
+ super(provider);
+ urls = new AdminURLS(provider);
+ }
+
+
+ /**
+ * Accessor to create an instance of {@link LoginAPI} with current configuration
+ *
+ * @return LoginAPI instance
+ */
+ public LoginAPI login() {
+ return new LoginAPI(provider);
+ }
+
+ public class LoginAPI extends AbstractAPI {
+
+ public LoginAPI(ServiceProvider provider) {
+ super(provider);
+ }
+
+ /**
+ * Authenticate with email and password
+ *
+ * @param email the user email
+ * @param password the user password
+ * @return Login instance
+ * @throws IOException
+ */
+ public Login auth(String email, String password) throws IOException {
+ URL url = new URL(urls.login().auth().expand());
+ Map params = new HashMap<>();
+ params.put("email", email);
+ params.put("password", password);
+ HttpServiceResponse resp;
+ try {
+ resp = httpService().api_POST(url, params);
+ } catch (HttpException e) {
+ if (e.getStatusCode() == 400) {
+ resp = new HttpServiceResponse(Utils.stringToContentRep(e.getRawResponse()), url.toString(), "POST", Http.urlEncodedContentType, params, provider.configService().auth_token);
+ } else throw e;
+ }
+
+ return new Login(resp);
+ }
+
+ public Observable authObs(final String email, final String password) {
+ return Observable.fromCallable(() -> auth(email, password));
+ }
+
+ /**
+ * Authenticate the company administrator with provided credentials
+ *
+ * @param administrator The administrator to login with
+ * @param email the administrator email
+ * @param password the administrator password
+ * @return Login instance
+ * @throws IOException
+ */
+ public Login authWithCompanyAdministrator(Administrator administrator, String email, String password) throws IOException {
+ URL url = new URL(administrator.getLoginLink());
+ Map params = new HashMap<>();
+ params.put("email", email);
+ params.put("password", password);
+ return new Login(httpService().api_POST(url, params));
+ }
+
+ public Observable authWithCompanyAdministratorObs(final Administrator administrator, final String email, final String password) {
+ return Observable.fromCallable(() -> authWithCompanyAdministrator(administrator, email, password));
+ }
+ }
+
+
+ /**
+ * Accessor to create an instance of {@link BookingAPI} with current configuration
+ *
+ * @return BookingAPI instance
+ */
+ public BookingAPI booking() {
+ return new BookingAPI(newProvider());
+ }
+
+ public class BookingAPI extends AbstractAPI {
+
+ public BookingAPI(ServiceProvider provider) {
+ super(provider);
+ }
+
+ /**
+ * Get a list of admin bookings for a company
+ *
+ * @param company The owning company for booking
+ * @param bLParams The parameters for this call
+ * @return Collection of bookings
+ * @throws IOException
+ */
+ public BBCollection bookingList(Company company, BookingParams.List bLParams) throws IOException {
+ URL url = new URL(Utils.inflateLink(company.getBookingsLink(), bLParams.getParams()));
+ return new BBCollection<>(httpService().api_GET(url, CACHE_TAG), getAuthToken(), "bookings", Booking.class);
+ }
+
+ public Observable> bookingListObs(final Company company, final BookingParams.List bLParams) {
+ return Observable.fromCallable(() -> bookingList(company, bLParams));
+ }
+
+ /**
+ * Get all details about a specific booking
+ *
+ * @param company the company owning the booking
+ * @param bookingId the id of booking to read
+ * @return Booking
+ * @throws IOException
+ */
+ public Booking bookingRead(Company company, String bookingId) throws IOException {
+ URL url = new URL(AdminURLS.Bookings.bookingRead()
+ .set("companyId", company.id)
+ .set("bookingId", bookingId)
+ .expand());
+ return new Booking(httpService().api_GET(url, CACHE_TAG));
+ }
+
+ public Observable bookingReadObs(final Company company, final String bookingId) {
+ return Observable.fromCallable(() -> bookingRead(company, bookingId));
+ }
+
+ /**
+ * Get the edit schema for booking
+ *
+ * @param booking
+ * @return SchemaForm
+ * @throws IOException
+ */
+ public SchemaForm getEditBookingSchema(Booking booking) throws IOException {
+ URL url = new URL(UriTemplate.fromTemplate(booking.getEditLink()).expand());
+ return new SchemaForm(httpService().api_GET(url, CACHE_TAG));
+ }
+
+ public Observable getEditBookingSchemaObs(final Booking booking) {
+ return Observable.fromCallable(() -> getEditBookingSchema(booking));
+ }
+
+ /**
+ * Create a booking for a company with provided parameters
+ *
+ * @param company The company for booking
+ * @param bCParams The parameters to create the booking with
+ * @return Booking
+ * @throws IOException
+ */
+ public Booking bookingCreate(Company company, BookingParams.Create bCParams) throws IOException {
+ String urlStr = AdminURLS.Bookings.bookingCreate().set("companyId", company.id).expand();
+ URL url = new URL(urlStr);
+
+ return new Booking(httpService().api_POST(url, bCParams.getParams()));
+ }
+
+ public Observable bookingCreateObs(final Company company, final BookingParams.Create bCParams) {
+ return Observable.fromCallable(() -> bookingCreate(company, bCParams));
+ }
+
+ /**
+ * Update a booking
+ *
+ * @param booking the booking to update
+ * @param buParams Contains parameters for booking update. If the schema is used, then set the json form output
+ * to this through {@link bookingbugAPI2.models.params.Params#setJson(String)}
+ * in order to ignore declared fields
+ * @return Booking
+ * @throws IOException
+ */
+ public Booking bookingUpdate(Booking booking, BookingParams.Update buParams) throws IOException {
+ URL url = new URL(booking.getSelf());
+ return new Booking(httpService().api_PUT(url, buParams.getParams(), CACHE_TAG), configService().auth_token);
+ }
+
+ public Observable bookingUpdateObs(final Booking booking, final BookingParams.Update buParams) {
+ return Observable.fromCallable(() -> bookingUpdate(booking, buParams));
+ }
+
+ /**
+ * Cancel a booking
+ *
+ * @param booking the booking to cancel
+ * @param params parameters for this call
+ * @return Booking instance
+ * @throws IOException
+ */
+ public Booking cancelBooking(Booking booking, BookingParams.Cancel params) throws IOException {
+ URL url = new URL(booking.getSelf());
+ return new Booking(httpService().api_DELETE(url, Http.jsonContentType, params.getParams(), CACHE_TAG));
+ }
+
+ public Observable cancelBookingObs(final Booking booking, final BookingParams.Cancel params) {
+ return Observable.fromCallable(() -> cancelBooking(booking, params));
+ }
+ }
+
+
+ /**
+ * Accessor to create an instance of {@link CompanyAPI} with current configuration
+ *
+ * @return CompanyAPI instance
+ */
+ public CompanyAPI company() {
+ return new CompanyAPI(newProvider());
+ }
+
+ public class CompanyAPI extends AbstractAPI {
+
+
+ public CompanyAPI(ServiceProvider provider) {
+ super(provider);
+ }
+
+ /**
+ * Load All of the Links and Properties of a Company
+ *
+ * @param companyId the id of company
+ * @return Company
+ * @throws IOException
+ */
+ public Company companyRead(String companyId) throws IOException {
+ URL url = new URL(AdminURLS.Company.companyRead(configService().serverUrl).set("companyId", companyId).expand());
+ return new Company(httpService().api_GET(url, CACHE_TAG));
+ }
+
+ public Observable companyReadObs(final String companyId) {
+ return Observable.fromCallable(() -> companyRead(companyId));
+ }
+
+ /**
+ * Get the company for specified administrator
+ *
+ * @param administrator the administrator for the company
+ * @return Company
+ * @throws IOException
+ */
+ public Company getCompanyForAdministrator(Administrator administrator) throws IOException {
+ URL url = new URL(administrator.getCompanyLink());
+ return new Company(httpService().api_GET(url, CACHE_TAG));
+ }
+
+ public Observable getCompanyForAdministratorObs(final Administrator administrator) {
+ return Observable.fromCallable(() -> getCompanyForAdministrator(administrator));
+ }
+
+ /**
+ * Return the settings for provided company
+ *
+ * @param company the company to retrieve settings for
+ * @return CompanySettings instance
+ * @throws IOException
+ */
+ public CompanySettings getSettingsForCompany(Company company) throws IOException {
+ if (company.getResource("settings") != null)
+ return new CompanySettings(new HttpServiceResponse(company.getResource("settings")));
+ URL url = new URL(company.getSettingsLink());
+ return new CompanySettings(httpService().api_GET(url, CACHE_TAG));
+ }
+
+ public Observable getSettingsForCompanyObs(final Company company) {
+ return Observable.fromCallable(() -> getSettingsForCompany(company));
+ }
+
+ /**
+ * Get all the events for a company with provided params. Returns as paginated list
+ *
+ * @param company The company owning the events
+ * @param params The params to filter the events
+ * @return Collection of Event
+ * @throws IOException
+ */
+ public BBCollection getEventsForCompany(Company company, CompanyParams.EventList params) throws IOException {
+ URL url = new URL(UriTemplate.fromTemplate(company.getEventsLink()).set(params.getParams()).expand());
+ return new BBCollection<>(httpService().api_GET(url, CACHE_TAG), configService().auth_token, "events", Event.class);
+ }
+
+ public Observable> getEventsForCompanyObs(final Company company, final CompanyParams.EventList params) {
+ return Observable.fromCallable(() -> getEventsForCompany(company, params));
+ }
+ }
+
+
+ /**
+ * Accessor to create an instance of {@link ServiceAPI} with current configuration
+ *
+ * @return ServiceAPI instance
+ */
+ public ServiceAPI service() {
+ return new ServiceAPI(newProvider());
+ }
+
+ public class ServiceAPI extends AbstractAPI {
+
+
+ public ServiceAPI(ServiceProvider provider) {
+ super(provider);
+ }
+
+
+ /**
+ * List of Services for a company. Results are returned as a paginated list
+ *
+ * @param company The owning company for services
+ * @param slParams Parameters for this call
+ * @return Collection of Service
+ * @throws IOException
+ */
+ public BBCollection serviceList(Company company, ServiceListParams slParams) throws IOException {
+ UriTemplate template = Utils.TemplateWithPagination(company.getServicesLink(), slParams);
+ URL url = new URL(template.expand());
+
+ return new BBCollection<>(httpService().api_GET(url, CACHE_TAG), configService().auth_token, "services", Service.class);
+ }
+
+ public Observable> serviceListObs(final Company company, final ServiceListParams slParams) {
+ return Observable.fromCallable(() -> serviceList(company, slParams));
+ }
+
+ /**
+ * Load a Specific Service Details
+ *
+ * @param company The owning company for service
+ * @param serviceId the id of service to load
+ * @return Service
+ * @throws IOException
+ */
+ public Service serviceRead(Company company, String serviceId) throws IOException {
+ URL url = new URL(AdminURLS.Service.serviceRead()
+ .set("companyId", company.id)
+ .set("serviceId", serviceId)
+ .expand());
+ return new Service(httpService().api_GET(url, CACHE_TAG));
+ }
+
+ public Observable serviceReadObs(final Company company, final String serviceId) {
+ return Observable.fromCallable(() -> serviceRead(company, serviceId));
+ }
+
+ /**
+ * Get schema for creating a new service
+ *
+ * @param company The owning company
+ * @return SchemaForm
+ * @throws IOException
+ */
+ public SchemaForm getNewServiceSchema(Company company) throws IOException {
+ URL url = new URL(UriTemplate.fromTemplate(company.getNewServiceLink()).expand());
+ return new SchemaForm(httpService().api_GET(url, CACHE_TAG));
+ }
+
+ public Observable getNewServiceSchemaObs(final Company company) {
+ return Observable.fromCallable(() -> getNewServiceSchema(company));
+ }
+
+ /**
+ * Create a service
+ *
+ * @param company the company to own the service
+ * @param sCParams Contains parameters for service creation. If the schema is used, then set the json form output
+ * to this through {@link bookingbugAPI2.models.params.Params#setJson(String)}
+ * in order to ignore declared fields
+ * @return Service
+ * @throws IOException
+ */
+ public Service serviceCreate(Company company, ServiceParams.ServiceCreateParams sCParams) throws IOException {
+ URL url = new URL(company.getServicesLink());
+ return new Service(httpService().api_POST(url, sCParams.getParams(), CACHE_TAG));
+ }
+
+ public Observable serviceCreateObs(final Company company, final ServiceParams.ServiceCreateParams sCParams) {
+ return Observable.fromCallable(() -> serviceCreate(company, sCParams));
+ }
+
+ /**
+ * Update a service
+ *
+ * @param service the service to update
+ * @param sUParams Contains parameters for service update. If the schema is used, then set the json form output
+ * to this through {@link bookingbugAPI2.models.params.Params#setJson(String)}
+ * in order to ignore declared fields
+ * @return Service
+ * @throws IOException
+ */
+ public Service serviceUpdate(Service service, ServiceParams.ServiceUpdateParams sUParams) throws IOException {
+ URL url = new URL(service.getEditLink());
+ return new Service(httpService().api_POST(url, sUParams.getParams(), CACHE_TAG));
+ }
+
+ public Observable serviceUpdateObs(final Service service, final ServiceParams.ServiceUpdateParams sUParams) {
+ return Observable.fromCallable(() -> serviceUpdate(service, sUParams));
+ }
+
+ /**
+ * Get a schema for creating a new booking with provided service
+ *
+ * @param service The service
+ * @return SchemaForm
+ * @throws IOException
+ */
+ public SchemaForm getNewBookingSchema(Service service) throws IOException {
+ URL url = new URL(UriTemplate.fromTemplate(service.getNewBookingLink()).expand());
+ return new SchemaForm(httpService().api_GET(url, CACHE_TAG));
+ }
+
+ public Observable getNewBookingSchemaObs(final Service service) {
+ return Observable.fromCallable(() -> getNewBookingSchema(service));
+ }
+
+ /**
+ * Get a schema for editing a service
+ *
+ * @param service The service to be edited
+ * @return SchemaForm
+ * @throws IOException
+ */
+ public SchemaForm getEditServiceSchema(Service service) throws IOException {
+ URL url = new URL(UriTemplate.fromTemplate(service.getEditLink()).expand());
+ return new SchemaForm(httpService().api_GET(url, CACHE_TAG));
+ }
+
+ public Observable getEditServiceSchemaObs(final Service service) {
+ return Observable.fromCallable(() -> getEditServiceSchema(service));
+ }
+ }
+
+
+ /**
+ * Accessor to create an instance of {@link ServiceAPI} with current configuration
+ *
+ * @return ServiceAPI instance
+ */
+ public ClientAPI client() {
+ return new ClientAPI(newProvider());
+ }
+
+ public class ClientAPI extends AbstractAPI {
+
+
+ public ClientAPI(ServiceProvider provider) {
+ super(provider);
+ }
+
+
+ /**
+ * List of Clients for a company. Results are returned as a paginated list
+ *
+ * @param company The owning company for clients
+ * @param clParams Parameters for this call
+ * @return Collection of Client
+ * @throws IOException
+ */
+ public BBCollection clientList(Company company, ClientListParams clParams) throws IOException {
+ URL url = new URL(Utils.inflateLink(company.getClientLink(), clParams.getParams()));
+ return new BBCollection<>(httpService().api_GET(url, CACHE_TAG), configService().auth_token, "clients", Client.class);
+ }
+
+ public Observable> clientListObs(final Company company, final ClientListParams clParams) {
+ return Observable.fromCallable(() -> clientList(company, clParams));
+ }
+
+ /**
+ * Load a specific client details
+ *
+ * @param company The owning company for client
+ * @param clientId The client's id
+ * @return Client
+ * @throws IOException
+ */
+ public Client clientRead(Company company, String clientId) throws IOException {
+ URL url = new URL(urls.client().clientRead()
+ .set("companyId", company.id)
+ .set("clientId", clientId)
+ .expand());
+ return new Client(httpService().api_GET(url, CACHE_TAG));
+ }
+
+ public Observable clientReadObs(final Company company, final String clientId) {
+ return Observable.fromCallable(() -> clientRead(company, clientId));
+ }
+
+ /**
+ * Load a specific client details
+ *
+ * @param company The owning company for client
+ * @param email The client's email
+ * @return Client
+ * @throws IOException
+ */
+ public Client clientReadByEmail(Company company, String email) throws IOException {
+ URL url = new URL(UriTemplate.fromTemplate(company.getClientByEmailLink()).set("email", email).expand());
+ return new Client(httpService().api_GET(url, CACHE_TAG));
+ }
+
+ public Observable clientReadByEmailObs(final Company company, final String email) {
+ return Observable.fromCallable(() -> clientReadByEmail(company, email));
+ }
+
+ /**
+ * Get the schema for editing a client
+ *
+ * @param client The client to edit
+ * @return SchemaForm
+ * @throws IOException
+ */
+ public SchemaForm getEditClientSchema(Client client) throws IOException {
+ URL url = new URL(UriTemplate.fromTemplate(client.getEditLink()).expand());
+ return new SchemaForm(httpService().api_GET(url, CACHE_TAG));
+ }
+
+ public Observable getEditClientSchemaObs(final Client client) {
+ return Observable.fromCallable(() -> getEditClientSchema(client));
+ }
+
+ /**
+ * Enable/Disable specific client
+ *
+ * @param company The company for the client
+ * @param ctParams parameters for this call
+ * @return Client TODO: check return type after 401 is solved
+ * @throws IOException
+ */
+ public Client clientEnableDisable(Company company, ClientToggleParams ctParams) throws IOException {
+ URL url = new URL(UriTemplate.fromTemplate(company.getClientLink()).expand());
+ return new Client(httpService().api_PUT(url, Http.urlEncodedContentType, ctParams.getParams(), CACHE_TAG));
+ }
+
+ public Observable clientEnableDisableObs(final Company company, final ClientToggleParams ctParams) {
+ return Observable.fromCallable(() -> clientEnableDisable(company, ctParams));
+ }
+
+ /**
+ * Update a client
+ *
+ * @param client the client to update
+ * @param cuParams Contains parameters for client update. If the schema is used, then set the json form output
+ * to this through {@link bookingbugAPI2.models.params.Params#setJson(String)}
+ * in order to ignore declared fields
+ * @return Client
+ * @throws IOException
+ */
+ public Client clientUpdate(Client client, ClientParams.Update cuParams) throws IOException {
+ URL url = new URL(client.getSelf());
+ return new Client(httpService().api_PUT(url, cuParams.getParams(), CACHE_TAG));
+ }
+
+ public Observable clientUpdateObs(final Client client, final ClientParams.Update cuParams) {
+ return Observable.fromCallable(() -> clientUpdate(client, cuParams));
+ }
+
+ /**
+ * Create a client
+ *
+ * @param company the company for client
+ * @param clParams Contains parameters for client creation. If the schema is used, then set the json form output
+ * to this through {@link bookingbugAPI2.models.params.Params#setJson(String)}
+ * in order to ignore declared fields
+ * @return Client
+ * @throws IOException
+ */
+ public Client clientCreate(Company company, ClientParams.Create clParams) throws IOException {
+ URL url = new URL(UriTemplate.fromTemplate(company.getClientLink()).expand());
+ return new Client(httpService().api_POST(url, clParams.getParams(), CACHE_TAG));
+ }
+
+ public Observable clientCreateObs(final Company company, final ClientParams.Create clParams) {
+ return Observable.fromCallable(() -> clientCreate(company, clParams));
+ }
+
+ }
+
+
+ /**
+ * Accessor to create an instance of {@link ResourceAPI} with current configuration
+ *
+ * @return ResourceAPI instance
+ */
+ public ResourceAPI resource() {
+ return new ResourceAPI(newProvider());
+ }
+
+ public class ResourceAPI extends AbstractAPI {
+
+ public ResourceAPI(ServiceProvider provider) {
+ super(provider);
+ }
+
+
+ /**
+ * Load specific resource details
+ *
+ * @param company
+ * @param resourceId
+ * @return Resource
+ * @throws IOException
+ */
+ public Resource resourceRead(Company company, String resourceId) throws IOException {
+ URL url = new URL(AdminURLS.Resource.resourceRead()
+ .set("companyId", company.id)
+ .set("resourceId", resourceId)
+ .expand());
+ return new Resource(httpService().api_GET(url, CACHE_TAG));
+ }
+
+ public Observable resourceReadObs(final Company company, final String resourceId) {
+ return Observable.fromCallable(() -> resourceRead(company, resourceId));
+ }
+
+ /**
+ * List of Resources for a company. Results are returned as a paginated list
+ *
+ * @param company The owning company for services
+ * @param rlParams Parameters for this call
+ * @return Collection of Resource
+ * @throws IOException
+ */
+ public BBCollection resourceList(Company company, Params rlParams) throws IOException {
+ UriTemplate template = Utils.TemplateWithPagination(company.getResourcesLink(), rlParams);
+ URL url = new URL(template.expand());
+
+ return new BBCollection<>(httpService().api_GET(url, CACHE_TAG), configService().auth_token, "resources", Resource.class);
+ }
+
+ public Observable> resourceListObs(final Company company, final Params rlParams) {
+ return Observable.fromCallable(() -> resourceList(company, rlParams));
+ }
+
+ /**
+ * Create a new resource
+ *
+ * @param company the company for resource
+ * @param rcParams Contains parameters for resource creation. If the schema is used, then set the json form output
+ * to this through {@link bookingbugAPI2.models.params.Params#setJson(String)}
+ * in order to ignore declared fields
+ * @return Resource
+ * @throws IOException
+ */
+ public Resource resourceCreate(Company company, ResourceParams.Create rcParams) throws IOException {
+ URL url = new URL(UriTemplate.fromTemplate(company.getResourcesLink()).expand());
+ return new Resource(httpService().api_POST(url, rcParams.getParams(), CACHE_TAG));
+ }
+
+ public Observable resourceCreateObs(final Company company, final ResourceParams.Create rcParams) {
+ return Observable.fromCallable(() -> resourceCreate(company, rcParams));
+ }
+
+ /**
+ * Update a resource
+ *
+ * @param resource the resource to update
+ * @param ruParams Contains parameters for resource update. If the schema is used, then set the json form output
+ * to this through {@link bookingbugAPI2.models.params.Params#setJson(String)}
+ * in order to ignore declared fields
+ * @return Resource
+ * @throws IOException
+ */
+ public Resource resourceUpdate(Resource resource, ResourceParams.Update ruParams) throws IOException {
+ URL url = new URL(resource.getSelf());
+ return new Resource(httpService().api_PUT(url, ruParams.getParams(), CACHE_TAG));
+ }
+
+ public Observable resourceUpdateObs(final Resource resource, final ResourceParams.Update ruParams) {
+ return Observable.fromCallable(() -> resourceUpdate(resource, ruParams));
+ }
+
+ /**
+ * Get the schema for creating a new resource
+ *
+ * @param company The company to own the resource
+ * @return SchemaForm
+ * @throws IOException
+ */
+ public SchemaForm getNewResourceSchema(Company company) throws IOException {
+ URL url = new URL(UriTemplate.fromTemplate(company.getNewResourceLink()).expand());
+ return new SchemaForm(httpService().api_GET(url, CACHE_TAG));
+ }
+
+ public Observable getNewResourceSchemaObs(final Company company) {
+ return Observable.fromCallable(() -> getNewResourceSchema(company));
+ }
+
+ /**
+ * Get the schema for editing a resource
+ *
+ * @param resource The resource to edit
+ * @return SchemaForm
+ * @throws IOException
+ */
+ public SchemaForm getEditResourceSchema(Resource resource) throws IOException {
+ URL url = new URL(UriTemplate.fromTemplate(resource.getEditLink()).expand());
+ return new SchemaForm(httpService().api_GET(url, CACHE_TAG));
+ }
+
+ public Observable getEditResourceSchemaObs(final Resource resource) {
+ return Observable.fromCallable(() -> getEditResourceSchema(resource));
+ }
+
+ //TODO: Add block and schedule calls
+ }
+
+
+ /**
+ * Accessor to create an instance of {@link EventChainAPI} with current configuration
+ *
+ * @return EventChainAPI instance
+ */
+ public EventChainAPI eventChain() {
+ return new EventChainAPI(newProvider());
+ }
+
+ public class EventChainAPI extends AbstractAPI {
+ public EventChainAPI(ServiceProvider provider) {
+ super(provider);
+ }
+
+
+ /**
+ * Load specific event chain details
+ *
+ * @param company
+ * @param eventChainId
+ * @return EventChain
+ * @throws IOException
+ */
+ public EventChain eventChainRead(Company company, String eventChainId) throws IOException {
+ URL url = new URL(AdminURLS.EventChain.eventChainRead()
+ .set("companyId", company.id)
+ .set("eventChainId", eventChainId)
+ .expand());
+ return new EventChain(httpService().api_GET(url, CACHE_TAG));
+ }
+
+ public Observable eventChainReadObs(final Company company, final String eventChainId) {
+ return Observable.fromCallable(() -> eventChainRead(company, eventChainId));
+ }
+
+ /**
+ * Load specific event chain details by reference
+ *
+ * @param company
+ * @param refId the reference to the event chain to read
+ * @return EventChain
+ * @throws IOException
+ */
+ public EventChain eventChainReadByRefId(Company company, String refId) throws IOException {
+ URL url = new URL(AdminURLS.EventChain.eventChainReadUsingRefId()
+ .set("companyId", company.id)
+ .set("refId", refId)
+ .expand());
+ return new EventChain(httpService().api_GET(url, CACHE_TAG));
+ }
+
+ public Observable eventChainReadByRefIdObs(final Company company, final String refId) {
+ return Observable.fromCallable(() -> eventChainReadByRefId(company, refId));
+ }
+
+ /**
+ * List of event chains for a company. Results are returned as a paginated list
+ *
+ * @param company The owning company for services
+ * @param rlParams Parameters for this call
+ * @return Collection of EventChain
+ * @throws IOException
+ */
+ public BBCollection eventChainList(Company company, Params rlParams) throws IOException {
+ UriTemplate template = Utils.TemplateWithPagination(company.getEventChainsLink(), rlParams);
+ URL url = new URL(template.expand());
+
+ return new BBCollection<>(httpService().api_GET(url, CACHE_TAG), configService().auth_token, "event_chains", EventChain.class);
+ }
+
+ public Observable> eventChainListObs(final Company company, final Params rlParams) {
+ return Observable.fromCallable(() -> eventChainList(company, rlParams));
+ }
+
+ /**
+ * Create a new event chain
+ *
+ * @param company the company for event chain
+ * @param eccParams Contains parameters for event chain creation. If the schema is used, then set the json form output
+ * to this through {@link bookingbugAPI2.models.params.Params#setJson(String)}
+ * in order to ignore declared fields
+ * @return EventChain
+ * @throws IOException
+ */
+ public EventChain eventChainCreate(Company company, EventChainParams.Create eccParams) throws IOException {
+ URL url = new URL(UriTemplate.fromTemplate(company.getEventChainsLink()).expand());
+ return new EventChain(httpService().api_POST(url, eccParams.getParams(), CACHE_TAG));
+ }
+
+ public Observable eventChainCreateObs(final Company company, final EventChainParams.Create rcParams) {
+ return Observable.fromCallable(() -> eventChainCreate(company, rcParams));
+ }
+
+ /**
+ * Update an event chain
+ *
+ * @param eventChain the event chain to update
+ * @param ecuParams Contains parameters for event chain update. If the schema is used, then set the json form output
+ * to this through {@link bookingbugAPI2.models.params.Params#setJson(String)}
+ * in order to ignore declared fields
+ * @return EventChain
+ * @throws IOException
+ */
+
+ public EventChain eventChainUpdate(EventChain eventChain, EventChainParams.Update ecuParams) throws IOException {
+ URL url = new URL(eventChain.getSelf());
+ return new EventChain(httpService().api_PUT(url, ecuParams.getParams(), CACHE_TAG));
+ }
+
+ public Observable eventChainUpdateObs(final EventChain eventChain, final EventChainParams.Update ruParams) {
+ return Observable.fromCallable(() -> eventChainUpdate(eventChain, ruParams));
+ }
+
+
+ /**
+ * Get a schema for editing a eventChain
+ *
+ * @param company
+ * @param eventChainId the event chain to edit
+ * @return SchemaForm
+ * @throws IOException
+ */
+ public SchemaForm getEditEventChainSchema(Company company, String eventChainId) throws IOException {
+ URL url = new URL(AdminURLS.EventChain.eventChainEdit()
+ .set("companyId", company.id)
+ .set("eventChainId", eventChainId)
+ .expand());
+ return new SchemaForm(httpService().api_GET(url, CACHE_TAG));
+ }
+
+ public Observable getEditEventChainSchemaObs(final Company company, final String eventChainId) {
+ return Observable.fromCallable(() -> getEditEventChainSchema(company, eventChainId));
+ }
+
+ /**
+ * Get the schema for creating a new event chain
+ *
+ * @param company The company to own the event chain
+ * @return SchemaForm
+ * @throws IOException
+ */
+ public SchemaForm getNewEventChainSchema(Company company) throws IOException {
+ URL url = new URL(UriTemplate.fromTemplate(company.getEventChainsLink()).expand());
+ return new SchemaForm(httpService().api_GET(url, CACHE_TAG));
+ }
+
+ public Observable getNewEventChainSchemaObs(final Company company) {
+ return Observable.fromCallable(() -> getNewEventChainSchema(company));
+ }
+
+ /**
+ * Get the events for an eventChain
+ *
+ * @param eventChain The eventChain for events
+ * @param params Pagination params
+ * @return Collection of Event
+ * @throws IOException
+ */
+ public BBCollection getEventsForEventChain(EventChain eventChain, Params params) throws IOException {
+ UriTemplate template = Utils.TemplateWithPagination(eventChain.getEventsLink(), params);
+ URL url = new URL(template.expand());
+ return new BBCollection<>(httpService().api_GET(url, CACHE_TAG), configService().auth_token, "events", Event.class);
+ }
+
+ public Observable> getEventsForEventChainObs(final EventChain eventChain, final Params params) {
+ return Observable.fromCallable(() -> getEventsForEventChain(eventChain, params));
+ }
+ }
+
+
+ /**
+ * Accessor to create an instance of {@link EventGroupAPI} with current configuration
+ *
+ * @return EventGroupAPI instance
+ */
+ public EventGroupAPI eventGroup() {
+ return new EventGroupAPI(newProvider());
+ }
+
+ public class EventGroupAPI extends AbstractAPI {
+ public EventGroupAPI(ServiceProvider provider) {
+ super(provider);
+ }
+
+
+ /**
+ * Load specific event group details
+ *
+ * @param company
+ * @param eventGroupId
+ * @return EventGroup
+ * @throws IOException
+ */
+ public EventGroup eventGroupRead(Company company, String eventGroupId) throws IOException {
+ URL url = new URL(AdminURLS.EventGroup.eventGroupRead()
+ .set("companyId", company.id)
+ .set("eventGroupId", eventGroupId)
+ .expand());
+ return new EventGroup(httpService().api_GET(url, CACHE_TAG));
+ }
+
+ public Observable eventGroupReadObs(final Company company, final String eventGroupId) {
+ return Observable.fromCallable(() -> eventGroupRead(company, eventGroupId));
+ }
+
+ /**
+ * List of event groups for a company. Results are returned as a paginated list
+ *
+ * @param company The owning company for services
+ * @param rlParams Parameters for this call
+ * @return Collection of EventGroup
+ * @throws IOException
+ */
+ public BBCollection eventGroupList(Company company, Params rlParams) throws IOException {
+ UriTemplate template = Utils.TemplateWithPagination(company.getEventGroupsLink(), rlParams);
+ URL url = new URL(template.expand());
+
+ return new BBCollection<>(httpService().api_GET(url, CACHE_TAG), configService().auth_token, "eventGroups", EventGroup.class);
+ }
+
+ public Observable> eventGroupListObs(final Company company, final Params rlParams) {
+ return Observable.fromCallable(() -> eventGroupList(company, rlParams));
+ }
+
+ /**
+ * Get a schema for editing a eventGroup
+ *
+ * @param company
+ * @param eventGroupId the event group to edit
+ * @return
+ * @throws IOException
+ */
+ public SchemaForm getEditEventGroupSchema(Company company, String eventGroupId) throws IOException {
+ URL url = new URL(AdminURLS.EventGroup.eventGroupEdit()
+ .set("companyId", company.id)
+ .set("eventGroupId", eventGroupId)
+ .expand());
+ return new SchemaForm(httpService().api_GET(url, CACHE_TAG));
+ }
+
+ public Observable getEditEventGroupSchemaObs(final Company company, final String eventGroupId) {
+ return Observable.fromCallable(() -> getEditEventGroupSchema(company, eventGroupId));
+ }
+
+ /**
+ * Get the schema for creating a new event group
+ *
+ * @param company The company to own the event group
+ * @return SchemaForm
+ * @throws IOException
+ */
+ public SchemaForm getNewEventGroupSchema(Company company) throws IOException {
+ URL url = new URL(UriTemplate.fromTemplate(company.getEventGroupsLink()).expand());
+ return new SchemaForm(httpService().api_GET(url, CACHE_TAG));
+ }
+
+ public Observable getNewEventGroupSchemaObs(final Company company) {
+ return Observable.fromCallable(() -> getNewEventGroupSchema(company));
+ }
+ }
+
+
+ /**
+ * Accessor to create an instance of {@link EventAPI} with current configuration
+ *
+ * @return EventAPI instance
+ */
+ public EventAPI event() {
+ return new EventAPI(newProvider());
+ }
+
+ public class EventAPI extends AbstractAPI {
+
+ public EventAPI(ServiceProvider provider) {
+ super(provider);
+ }
+
+ /**
+ * Get a schema for creating a new booking with provided event
+ *
+ * @param event The event
+ * @return SchemaForm
+ * @throws IOException
+ */
+ public SchemaForm getNewBookingSchema(Event event) throws IOException {
+ URL url = new URL(UriTemplate.fromTemplate(event.getNewBookingLink()).expand());
+ return new SchemaForm(httpService().api_GET(url, CACHE_TAG));
+ }
+
+ public Observable getNewBookingSchemaObs(final Event event) {
+ return Observable.fromCallable(() -> getNewBookingSchema(event));
+ }
+ }
+
+ /**
+ * Accessor to create an instance of {@link ScheduleAPI} with current configuration
+ *
+ * @return ScheduleAPI instance
+ */
+ public ScheduleAPI schedule() {
+ return new ScheduleAPI(newProvider());
+ }
+
+ public class ScheduleAPI extends AbstractAPI {
+
+ public ScheduleAPI(ServiceProvider provider) {
+ super(provider);
+ }
+
+
+ /**
+ * Get a list of admin schedules for a company
+ *
+ * @param company The owning company for schedule
+ * @param sLParams The parameters for this call
+ * @return Collection of Schedule
+ * @throws IOException
+ */
+ public BBCollection scheduleList(Company company, Params sLParams) throws IOException {
+ UriTemplate template = Utils.TemplateWithPagination(company.getSchedulesLink(), sLParams);
+ URL url = new URL(template.expand());
+ return new BBCollection<>(httpService().api_GET(url, CACHE_TAG), getAuthToken(), "schedules", Schedule.class);
+ }
+
+ public Observable> scheduleListObs(final Company company, final Params sLParams) {
+ return Observable.fromCallable(() -> scheduleList(company, sLParams));
+ }
+
+ /**
+ * Create a schedule
+ *
+ * @param company the company to own the schedule
+ * @param sCParams Contains parameters for schedule creation. If the schema is used, then set the json form output
+ * to this through {@link bookingbugAPI2.models.params.Params#setJson(String)}
+ * in order to ignore declared fields
+ * @return Service
+ * @throws IOException
+ */
+ public Schedule scheduleCreate(Company company, ScheduleParams.Create sCParams) throws IOException {
+ URL url = new URL(company.getSchedulesLink());
+ return new Schedule(httpService().api_POST(url, sCParams.getParams(), CACHE_TAG));
+ }
+
+ public Observable scheduleCreateObs(final Company company, final ScheduleParams.Create sCParams) {
+ return Observable.fromCallable(() -> scheduleCreate(company, sCParams));
+ }
+
+ /**
+ * Get schema for creating a new schedule
+ *
+ * @param company The owning company
+ * @return SchemaForm
+ * @throws IOException
+ */
+ public SchemaForm getNewScheduleSchema(Company company) throws IOException {
+ URL url = new URL(UriTemplate.fromTemplate(company.getNewScheduleLink()).expand());
+ return new SchemaForm(httpService().api_GET(url, CACHE_TAG));
+ }
+
+ public Observable getNewScheduleSchemaObs(final Company company) {
+ return Observable.fromCallable(() -> getNewScheduleSchema(company));
+ }
+
+ /**
+ * Delete a schedule
+ *
+ * @param company The owning company
+ * @param scheduleId The id of schedule
+ * @return Schedule
+ * @throws IOException
+ */
+ public Schedule deleteSchedule(Company company, String scheduleId) throws IOException {
+ URL url = new URL(AdminURLS.Schedule.scheduleDelete()
+ .set("companyId", company.id)
+ .set("scheduleId", scheduleId)
+ .expand());
+ return new Schedule(httpService().api_DELETE(url, CACHE_TAG));
+ }
+
+ public Observable deleteScheduleObs(final Company company, final String scheduleID) {
+ return Observable.fromCallable(() -> deleteSchedule(company, scheduleID));
+ }
+
+ /**
+ * Get all details about a specific schedule
+ *
+ * @param company the company owning the schedule
+ * @param scheduleId the id of schedule to read
+ * @return Schedule
+ * @throws IOException
+ */
+ public Schedule scheduleRead(Company company, String scheduleId) throws IOException {
+ URL url = new URL(AdminURLS.Schedule.scheduleRead()
+ .set("companyId", company.id)
+ .set("scheduleId", scheduleId)
+ .expand());
+ return new Schedule(httpService().api_GET(url, CACHE_TAG));
+ }
+
+ public Observable scheduleReadObs(final Company company, final String scheduleId) {
+ return Observable.fromCallable(() -> scheduleRead(company, scheduleId));
+ }
+
+ /**
+ * Update a schedule
+ *
+ * @param company the company owning the schedule
+ * @param scheduleId the schedule to update
+ * @param sUParams Contains parameters for schedule update. If the schema is used, then set the json form output
+ * to this through {@link bookingbugAPI2.models.params.Params#setJson(String)}
+ * in order to ignore declared fields
+ * @return Schedule
+ * @throws IOException
+ */
+ public Schedule scheduleUpdate(Company company, String scheduleId, ScheduleParams.Update sUParams) throws IOException {
+ URL url = new URL(AdminURLS.Schedule.scheduleUpdate()
+ .set("companyId", company.id)
+ .set("scheduleId", scheduleId)
+ .expand());
+
+ return new Schedule(httpService().api_PUT(url, sUParams.getParams(), CACHE_TAG));
+ }
+
+ public Observable scheduleUpdateObs(final Company company, final String scheduleId, final ScheduleParams.Update sUParams) {
+ return Observable.fromCallable(() -> scheduleUpdate(company, scheduleId, sUParams));
+ }
+
+ /**
+ * Get the edit schema for schedule
+ *
+ * @param company the company owning the schedule
+ * @param scheduleId the id of schedule to edit
+ * @return SchemaForm
+ * @throws IOException
+ */
+ public SchemaForm getEditScheduleSchema(Company company, String scheduleId) throws IOException {
+ URL url = new URL(AdminURLS.Schedule.scheduleEdit()
+ .set("companyId", company.id)
+ .set("scheduleId", scheduleId)
+ .expand());
+
+ return new SchemaForm(httpService().api_GET(url, CACHE_TAG));
+ }
+
+ public Observable getEditScheduleSchemaObs(Company company, String scheduleId) {
+ return Observable.fromCallable(() -> getEditScheduleSchema(company, scheduleId));
+ }
+ }
+
+
+ /**
+ * Accessor to create an instance of {@link AddressAPI} with current configuration
+ *
+ * @return AddressAPI instance
+ */
+ public AddressAPI address() {
+ return new AddressAPI(newProvider());
+ }
+
+ public class AddressAPI extends AbstractAPI {
+
+ public AddressAPI(ServiceProvider provider) {
+ super(provider);
+ }
+
+
+ /**
+ * Get a list of addresses for a company
+ *
+ * @param company The owning company for address
+ * @param aLParams The parameters for this call
+ * @return Collection of Address
+ * @throws IOException
+ */
+ public BBCollection addressList(Company company, Params aLParams) throws IOException {
+ URL url = new URL(Utils.inflateLink(company.getAddressesLink(), aLParams.getParams()));
+
+ return new BBCollection<>(httpService().api_GET(url, CACHE_TAG), getAuthToken(), "addresses", Address.class);
+ }
+
+ public Observable> addressListObs(final Company company, final Params aLParams) {
+ return Observable.fromCallable(() -> addressList(company, aLParams));
+ }
+
+ /**
+ * Create an address
+ *
+ * @param company the company to own the address
+ * @param aCParams Contains parameters for address creation. If the schema is used, then set the json form output
+ * to this through {@link bookingbugAPI2.models.params.Params#setJson(String)}
+ * in order to ignore declared fields
+ * @return Address
+ * @throws IOException
+ */
+ public Address addressCreate(Company company, AddressParams.Create aCParams) throws IOException {
+ URL url = new URL(company.getAddressLink());
+ return new Address(httpService().api_POST(url, aCParams.getParams(), CACHE_TAG));
+ }
+
+ public Observable addressCreateObs(final Company company, final AddressParams.Create sCParams) {
+ return Observable.fromCallable(() -> addressCreate(company, sCParams));
+ }
+
+ /**
+ * Delete an address
+ *
+ * @param company the company to own the address
+ * @param addressId the address id
+ * @return SchemaForm
+ * @throws IOException
+ */
+ public Address deleteAddress(Company company, String addressId) throws IOException {
+ URL url = new URL(AdminURLS.Address.addressDelete()
+ .set("companyId", company.id)
+ .set("addressId", addressId)
+ .expand());
+ return new Address(httpService().api_DELETE(url, CACHE_TAG));
+ }
+
+ public Observable deleteAddressObs(final Company company, final String addressID) {
+ return Observable.fromCallable(() -> deleteAddress(company, addressID));
+ }
+
+ /**
+ * Get all details about a specific address
+ *
+ * @param company the company owning the address
+ * @param addressId the id of address to read
+ * @return Address
+ * @throws IOException
+ */
+ public Address addressRead(Company company, String addressId) throws IOException {
+ URL url = new URL(AdminURLS.Address.addressRead()
+ .set("companyId", company.id)
+ .set("addressId", addressId)
+ .expand());
+ return new Address(httpService().api_GET(url, CACHE_TAG));
+ }
+
+ public Observable addressReadObs(final Company company, final String addressId) {
+ return Observable.fromCallable(() -> addressRead(company, addressId));
+ }
+
+ /**
+ * Update an address
+ *
+ * @param company the company owning the address
+ * @param sUParams Contains parameters for address update. If the schema is used, then set the json form output
+ * to this through {@link bookingbugAPI2.models.params.Params#setJson(String)}
+ * in order to ignore declared fields
+ * @return Address
+ * @throws IOException
+ */
+ public Address addressUpdate(Company company, AddressParams.Update sUParams) throws IOException {
+ URL url = new URL(company.getAddressLink());
+
+ return new Address(httpService().api_PUT(url, sUParams.getParams(), CACHE_TAG));
+ }
+
+ public Observable addressUpdateObs(final Company company, final AddressParams.Update sUParams) {
+ return Observable.fromCallable(() -> addressUpdate(company, sUParams));
+ }
+ }
+
+
+ /**
+ * Accessor to create an instance of {@link AdministratorAPI} with current configuration
+ *
+ * @return AdministratorAPI instance
+ */
+ public AdministratorAPI administrator() {
+ return new AdministratorAPI(newProvider());
+ }
+
+ public class AdministratorAPI extends AbstractAPI {
+
+ public AdministratorAPI(ServiceProvider provider) {
+ super(provider);
+ }
+
+ /**
+ * Get the administrator for a specific login. It searches in embedded objects and if not found calls
+ * the administrator link
+ *
+ * @param login The login
+ * @return Administrator instance
+ * @throws IOException
+ */
+ public Administrator getAdministratorForLogin(Login login) throws IOException {
+ String adminLink = login.getAdministratorLink();
+ BBCollection admins = login.getAdministrators();
+ //search embedded object
+ for (Administrator admin : admins) {
+ if (admin.getSelf().equals(adminLink))
+ return admin;
+ }
+ URL url = new URL(adminLink);
+ return new Administrator(httpService().api_GET(url, CACHE_TAG), getAuthToken());
+ }
+
+ public Observable getAdministratorForLoginObs(Login login) {
+ return Observable.fromCallable(() -> getAdministratorForLogin(login));
+ }
+
+ /**
+ * Get a list of administrators for a company
+ *
+ * @param company The owning company for administrator
+ * @param aLParams The parameters for this call
+ * @return Collection of Administrator
+ * @throws IOException
+ */
+ public BBCollection administratorList(Company company, Params aLParams) throws IOException {
+ UriTemplate template = Utils.TemplateWithPagination(company.getAdministratorsLink(), aLParams);
+ URL url = new URL(template.expand());
+ return new BBCollection<>(httpService().api_GET(url, CACHE_TAG), getAuthToken(), "administrators", Administrator.class);
+ }
+
+ public Observable> administratorListObs(final Company company, final Params aLParams) {
+ return Observable.fromCallable(() -> administratorList(company, aLParams));
+ }
+
+ /**
+ * Create an administrator
+ *
+ * @param company the company to own the administrator
+ * @param aCParams Contains parameters for administrator creation. If the schema is used, then set the json form output
+ * to this through {@link bookingbugAPI2.models.params.Params#setJson(String)}
+ * in order to ignore declared fields
+ * @return Administrator
+ * @throws IOException
+ */
+ public Administrator administratorCreate(Company company, AdministratorParams.Create aCParams) throws IOException {
+ URL url = new URL(AdminURLS.Administrator.administratorCreate()
+ .set("companyId", company.id)
+ .expand());
+
+ return new Administrator(httpService().api_POST(url, aCParams.getParams(), CACHE_TAG));
+ }
+
+ public Observable administratorCreateObs(final Company company, final AdministratorParams.Create aCParams) {
+ return Observable.fromCallable(() -> administratorCreate(company, aCParams));
+ }
+
+ /**
+ * Delete an administrator
+ *
+ * @param company The owning company
+ * @param administratorId the id of administrator to be deleted
+ * @return SchemaForm
+ * @throws IOException
+ */
+ public Administrator deleteAdministrator(Company company, String administratorId) throws IOException {
+ URL url = new URL(AdminURLS.Administrator.administratorDelete()
+ .set("companyId", company.id)
+ .set("administratorId", administratorId)
+ .expand());
+ return new Administrator(httpService().api_DELETE(url, CACHE_TAG));
+ }
+
+ public Observable deleteAdministratorObs(final Company company, final String administratorID) {
+ return Observable.fromCallable(() -> deleteAdministrator(company, administratorID));
+ }
+
+ /**
+ * Get all details about a specific administrator
+ *
+ * @param company the company owning the administrator
+ * @param administratorId the id of administrator to read
+ * @return Administrator
+ * @throws IOException
+ */
+ public Administrator administratorRead(Company company, String administratorId) throws IOException {
+ URL url = new URL(AdminURLS.Administrator.administratorRead()
+ .set("companyId", company.id)
+ .set("administratorId", administratorId)
+ .expand());
+ return new Administrator(httpService().api_GET(url, CACHE_TAG));
+ }
+
+ public Observable administratorReadObs(final Company company, final String administratorId) {
+ return Observable.fromCallable(() -> administratorRead(company, administratorId));
+ }
+
+ /**
+ * Update an administrator
+ *
+ * @param company the company owning the administrator
+ * @param aUParams Contains parameters for administrator update. If the schema is used, then set the json form output
+ * to this through {@link bookingbugAPI2.models.params.Params#setJson(String)}
+ * in order to ignore declared fields
+ * @return Administrator
+ * @throws IOException
+ */
+ public Administrator administratorUpdate(Company company, String adminId, AdministratorParams.Update aUParams) throws IOException {
+ URL url = new URL(AdminURLS.Administrator.administratorUpdate()
+ .set("companyId", company.id)
+ .set("adminId", adminId)
+ .expand());
+ return new Administrator(httpService().api_PUT(url, aUParams.getParams(), CACHE_TAG));
+ }
+
+ public Observable administratorUpdateObs(final Company company, final String adminId, final AdministratorParams.Update aUParams) {
+ return Observable.fromCallable(() -> administratorUpdate(company, adminId, aUParams));
+ }
+
+ /**
+ * Get the edit schema for administrator
+ *
+ * @param administrator
+ * @return SchemaForm
+ * @throws IOException
+ */
+ public SchemaForm getEditAdministratorSchema(Administrator administrator) throws IOException {
+ URL url = new URL(UriTemplate.fromTemplate(administrator.getEditLink()).expand());
+ return new SchemaForm(httpService().api_GET(url, CACHE_TAG));
+ }
+
+ public Observable getEditAdministratorSchemaObs(final Administrator administrator) {
+ return Observable.fromCallable(() -> getEditAdministratorSchema(administrator));
+ }
+
+ /**
+ * Get schema for creating a new administrator
+ *
+ * @param company The owning company
+ * @return SchemaForm
+ * @throws IOException
+ */
+ public SchemaForm getNewAdministratorSchema(Company company) throws IOException {
+ URL url = new URL(UriTemplate.fromTemplate(company.getNewAdministratorLink()).expand());
+ return new SchemaForm(httpService().api_GET(url, CACHE_TAG));
+ }
+
+ public Observable getNewAdministratorSchemaObs(final Company company) {
+ return Observable.fromCallable(() -> getNewAdministratorSchema(company));
+ }
+ }
+
+
+ /**
+ * Accessor to create an instance of {@link PersonAPI} with current configuration
+ *
+ * @return PersonAPI instance
+ */
+ public PersonAPI person() {
+ return new PersonAPI(newProvider());
+ }
+
+ public class PersonAPI extends AbstractAPI {
+ public PersonAPI(ServiceProvider provider) {
+ super(provider);
+ }
+
+
+ /**
+ * Load a specific person details by reference
+ *
+ * @param company
+ * @param personId
+ * @return
+ * @throws IOException
+ */
+ public Person personRead(Company company, String personId) throws IOException {
+ URL url = new URL(AdminURLS.Person.personRead()
+ .set("companyId", company.id)
+ .set("personId", personId)
+ .expand());
+ return new Person(httpService().api_GET(url, CACHE_TAG));
+ }
+
+ public Observable personReadObs(final Company company, final String refId) {
+ return Observable.fromCallable(() -> personRead(company, refId));
+ }
+
+ /**
+ * Load specific person details by reference
+ *
+ * @param company
+ * @param refId the reference to the person to read
+ * @return People
+ * @throws IOException
+ */
+ public Person personReadByRefId(Company company, String refId) throws IOException {
+ URL url = new URL(AdminURLS.Person.personReadUsingRefId()
+ .set("companyId", company.id)
+ .set("refId", refId)
+ .expand());
+ return new Person(httpService().api_GET(url, CACHE_TAG));
+ }
+
+ public Observable personReadByRefIdObs(final Company company, final String refId) {
+ return Observable.fromCallable(() -> personReadByRefId(company, refId));
+ }
+
+ /**
+ * List of persons for a company. Results are returned as a paginated list
+ *
+ * @param company The owning company for people
+ * @param plParams Parameters for this call
+ * @return Collection of People
+ * @throws IOException
+ */
+ public BBCollection personList(Company company, Params plParams) throws IOException {
+ UriTemplate template = Utils.TemplateWithPagination(company.getPeopleLink(), plParams);
+ URL url = new URL(template.expand());
+
+ return new BBCollection<>(httpService().api_GET(url, CACHE_TAG), configService().auth_token, "people", Person.class);
+ }
+
+ public Observable> personListObs(final Company company, final Params plParams) {
+ return Observable.fromCallable(() -> personList(company, plParams));
+ }
+
+ /**
+ * Create a new person
+ *
+ * @param company the company for person
+ * @param pcParams Contains parameters for person creation. If the schema is used, then set the json form output
+ * to this through {@link bookingbugAPI2.models.params.Params#setJson(String)}
+ * in order to ignore declared fields
+ * @return People
+ * @throws IOException
+ */
+ public Person personCreate(Company company, PersonParams.Create pcParams) throws IOException {
+ URL url = new URL(AdminURLS.Person.personCreate()
+ .set("companyId", company.id)
+ .expand());
+ return new Person(httpService().api_POST(url, pcParams.getParams(), CACHE_TAG));
+ }
+
+ public Observable personCreateObs(final Company company, final PersonParams.Create rcParams) {
+ return Observable.fromCallable(() -> personCreate(company, rcParams));
+ }
+
+ /**
+ * Update a person
+ *
+ * @param company the company the person is part of.
+ * @param personId the person to update
+ * @param puParams Contains parameters for person update. If the schema is used, then set the json form output
+ * to this through {@link bookingbugAPI2.models.params.Params#setJson(String)}
+ * in order to ignore declared fields
+ * @return People
+ * @throws IOException
+ */
+
+ public Person personUpdate(Company company, String personId, PersonParams.Update puParams) throws IOException {
+ URL url = new URL(AdminURLS.Person.personUpdate()
+ .set("companyId", company.id)
+ .set("personId", personId)
+ .expand());
+ return new Person(httpService().api_PUT(url, puParams.getParams(), CACHE_TAG));
+ }
+
+ public Observable personUpdateObs(final Company company, final String personId, final PersonParams.Update puParams) {
+ return Observable.fromCallable(() -> personUpdate(company, personId, puParams));
+ }
+
+
+ /**
+ * Get a schema for editing a person
+ *
+ * @param person the person to edit
+ * @return SchemaForm
+ * @throws IOException
+ */
+ public SchemaForm getEditPersonSchema(Person person) throws IOException {
+ URL url = new URL(person.getEditLink());
+ return new SchemaForm(httpService().api_GET(url, CACHE_TAG));
+ }
+
+ public Observable getEditPersonSchemaObs(final Person person) {
+ return Observable.fromCallable(() -> getEditPersonSchema(person));
+ }
+
+ /**
+ * Get the schema for creating a new person
+ *
+ * @param company The company to own the person
+ * @return SchemaForm
+ * @throws IOException
+ */
+ public SchemaForm getNewPersonSchema(Company company) throws IOException {
+ URL url = new URL(UriTemplate.fromTemplate(company.getNewPersonLink()).expand());
+ return new SchemaForm(httpService().api_GET(url, CACHE_TAG));
+ }
+
+ public Observable getNewPersonSchemaObs(final Company company) {
+ return Observable.fromCallable(() -> getNewPersonSchema(company));
+ }
+
+ /**
+ * Set a staff member attendance
+ *
+ * @param company the company the person is part of.
+ * @param personId the person to update
+ * @return People
+ * @throws IOException
+ */
+
+ public Person setPersonAttendance(Company company, String personId, PersonParams.Update puParams) throws IOException {
+ URL url = new URL(new Person().getAttendanceLink());
+ return new Person(httpService().api_PUT(url, puParams.getParams(), CACHE_TAG));
+ }
+
+ public Observable setPersonAttendanceObs(final Company company, final String personId, final PersonParams.Update puParams) {
+ return Observable.fromCallable(() -> personUpdate(company, personId, puParams));
+ }
+
+ // TODO: 15.07.2016 Test setPersonAttendance
+
+ // TODO: 15.07.2016 Implement getQueuersToAMember()
+ }
+
+
+ /**
+ * Accessor to create an instance of {@link ClinicAPI} with current configuration
+ *
+ * @return ClinicAPI instance
+ */
+ public ClinicAPI clinic() {
+ return new ClinicAPI(newProvider());
+ }
+
+ public class ClinicAPI extends AbstractAPI {
+
+ public ClinicAPI(ServiceProvider provider) {
+ super(provider);
+ }
+
+
+ /**
+ * Load specific clinic details
+ *
+ * @param company
+ * @param clinicId
+ * @return Clinic
+ * @throws IOException
+ */
+ public Clinic clinicRead(Company company, String clinicId) throws IOException {
+ URL url = new URL(AdminURLS.Clinic.clinicRead()
+ .set("companyId", company.id)
+ .set("clinicId", clinicId)
+ .expand());
+ return new Clinic(httpService().api_GET(url, CACHE_TAG));
+ }
+
+ public Observable clinicReadObs(final Company company, final String clinicId) {
+ return Observable.fromCallable(() -> clinicRead(company, clinicId));
+ }
+
+ /**
+ * List of clinics for a company. Results are returned as a paginated list
+ *
+ * @param company The owning company for services
+ * @param clParams Parameters for this call
+ * @return Collection of Clinic
+ * @throws IOException
+ */
+ public BBCollection clinicList(Company company, Params clParams) throws IOException {
+ UriTemplate template = Utils.TemplateWithPagination(company.getClinicsLink(), clParams);
+ URL url = new URL(template.expand());
+
+ return new BBCollection<>(httpService().api_GET(url, CACHE_TAG), configService().auth_token, "clinics", Clinic.class);
+ }
+
+ public Observable> clinicListObs(final Company company, final Params rlParams) {
+ return Observable.fromCallable(() -> clinicList(company, rlParams));
+ }
+
+ /**
+ * Create a new clinic
+ *
+ * @param company the company for clinic
+ * @param ccParams Contains parameters for clinic creation. If the schema is used, then set the json form output
+ * to this through {@link bookingbugAPI2.models.params.Params#setJson(String)}
+ * in order to ignore declared fields
+ * @return Clinic
+ * @throws IOException
+ */
+ public Clinic clinicCreate(Company company, ClinicParams.Create ccParams) throws IOException {
+ URL url = new URL(UriTemplate.fromTemplate(company.getClinicsLink()).expand());
+ return new Clinic(httpService().api_POST(url, ccParams.getParams(), CACHE_TAG));
+ }
+
+ public Observable clinicCreateObs(final Company company, final ClinicParams.Create rcParams) {
+ return Observable.fromCallable(() -> clinicCreate(company, rcParams));
+ }
+
+ /**
+ * Cancel a clinic
+ *
+ * @param company the company for clinic
+ * @param clinicId the clinic to cancel
+ * @return Clinic
+ * @throws IOException
+ */
+ public Clinic clinicCancel(Company company, String clinicId, Params ccparams) throws IOException {
+ URL url = new URL(AdminURLS.Clinic.clinicCancel()
+ .set("companyId", company.id)
+ .set("clinicID", clinicId)
+ .expand());
+ return new Clinic(httpService().api_POST(url, ccparams.getParams(), CACHE_TAG));
+ }
+
+ public Observable clinicCancelObs(final Company company, String clinicId, Params ccParams) {
+ return Observable.fromCallable(() -> clinicCancel(company, clinicId, ccParams));
+ }
+
+ /**
+ * Update a clinic
+ *
+ * @param clinic the clinic to update
+ * @param cuParams Contains parameters for clinic update. If the schema is used, then set the json form output
+ * to this through {@link bookingbugAPI2.models.params.Params#setJson(String)}
+ * in order to ignore declared fields
+ * @return Clinic
+ * @throws IOException
+ */
+ public Clinic clinicUpdate(Clinic clinic, ClinicParams.Update cuParams) throws IOException {
+ URL url = new URL(clinic.getSelf());
+ return new Clinic(httpService().api_PUT(url, cuParams.getParams(), CACHE_TAG));
+ }
+
+ public Observable clinicUpdateObs(final Clinic clinic, final ClinicParams.Update cuParams) {
+ return Observable.fromCallable(() -> clinicUpdate(clinic, cuParams));
+ }
+ }
+
+
+ /**
+ * Accessor to create an instance of {@link PurchaseAPI} with current configuration
+ *
+ * @return PurchaseAPI instance
+ */
+ public PurchaseAPI purchase() {
+ return new PurchaseAPI(newProvider());
+ }
+
+ public class PurchaseAPI extends AbstractAPI {
+
+ public PurchaseAPI(ServiceProvider provider) {
+ super(provider);
+ }
+
+ /**
+ * List of purchases for a company
+ *
+ * @param company The owning company for services
+ * @param plParams Parameters for this call
+ * @return Collection of Purchase
+ * @throws IOException
+ */
+ public BBCollection purchaseList(Company company, PurchaseListParams plParams) throws IOException {
+ UriTemplate template = AdminURLS.Purchase.purchaseList()
+ .set("companyId", company.id)
+ .set(plParams.getParams());
+ URL url = new URL(template.expand());
+ return new BBCollection<>(httpService().api_GET(url, CACHE_TAG), configService().auth_token, "purchases", Purchase.class);
+ }
+
+ public Observable> purchaseListObs(final Company company, final PurchaseListParams plParams) {
+ return Observable.fromCallable(() -> purchaseList(company, plParams));
+ }
+
+ /**
+ * Get all details about a specific purchase
+ *
+ * @param company the company that owns the purchase
+ * @param purchaseId the purchase to read
+ * @return Purchase
+ * @throws IOException
+ */
+ public Purchase purchaseRead(Company company, String purchaseId) throws IOException {
+ URL url = new URL(AdminURLS.Purchase.purchaseRead()
+ .set("companyId", company.id)
+ .set("purchaseId", purchaseId)
+ .expand());
+
+ return new Purchase(httpService().api_GET(url, CACHE_TAG));
+ }
+
+ public Observable purchaseReadObs(final Company company, String purchaseId) {
+ return Observable.fromCallable(() -> purchaseRead(company, purchaseId));
+ }
+
+ /**
+ * Make a purchase as paid
+ *
+ * @param company the company that owns the purchase
+ * @param purchaseId the purchase to mark as paid
+ * @param ppParams
+ * @return Purchase
+ * @throws IOException
+ */
+ public Purchase purchasePay(Company company, String purchaseId, PurchaseParams ppParams) throws IOException {
+ URL url = new URL(AdminURLS.Purchase.purchasePay()
+ .set("companyId", company.id)
+ .set("purchaseId", purchaseId)
+ .expand());
+
+ return new Purchase(httpService().api_PUT(url, ppParams.getParams(), CACHE_TAG));
+ }
+
+ public Observable purchasePayObs(final Company company, final String purchaseId, final PurchaseParams ppParams) {
+ return Observable.fromCallable(() -> purchasePay(company, purchaseId, ppParams));
+ }
+ }
+
+
+ /**
+ * Accessor to create an instance of {@link QuestionAPI} with current configuration
+ *
+ * @return QuestionAPI instance
+ */
+ public QuestionAPI question() {
+ return new QuestionAPI(newProvider());
+ }
+
+ public class QuestionAPI extends AbstractAPI {
+ public QuestionAPI(ServiceProvider provider) {
+ super(provider);
+ }
+
+ /**
+ * List of questions for a company
+ *
+ * @param company The owning company for questions
+ * @param qlParams Parameters for this call
+ * @return Collection of Question
+ * @throws IOException
+ */
+ public BBCollection questionList(Company company, QuestionListParams qlParams) throws IOException {
+ URL url = new URL(Utils.inflateLink(AdminURLS.Question.questionList()
+ .set("companyId", company.id).expand(), qlParams.getParams()));
+
+ return new BBCollection<>(httpService().api_GET(url, CACHE_TAG), configService().auth_token, "questions", Question.class);
+ }
+
+ public Observable> questionListObs(final Company company, final QuestionListParams qlParams) {
+ return Observable.fromCallable(() -> questionList(company, qlParams));
+ }
+ }
+
+
+ /**
+ * Accessor to create an instance of {@link SessionAPI} with current configuration
+ *
+ * @return SessionAPI instance
+ */
+ public SessionAPI session() {
+ return new SessionAPI(newProvider());
+ }
+
+ public class SessionAPI extends AbstractAPI {
+ public SessionAPI(ServiceProvider provider) {
+ super(provider);
+ }
+
+
+ /**
+ * List of sessions for a company
+ *
+ * @param company The owning company for sessions
+ * @param slParams Parameters for this call
+ * @return Collection of Session
+ * @throws IOException
+ */
+ public BBCollection sessionList(Company company, SessionListParams slParams) throws IOException {
+ URL url = new URL(Utils.inflateLink(AdminURLS.Session.sessionList()
+ .set("companyId", company.id)
+ .expand(), slParams.getParams()));
+
+ return new BBCollection<>(httpService().api_GET(url, CACHE_TAG), configService().auth_token, "sessions", Session.class);
+ }
+
+ /**
+ * Get all details about a specific session
+ *
+ * @param company the company that owns the session
+ * @param sessionId the session to read
+ * @return Session
+ * @throws IOException
+ */
+ public Session sessionRead(Company company, String sessionId) throws IOException {
+ URL url = new URL(AdminURLS.Session.sessionRead()
+ .set("companyId", company.id)
+ .set("sessionId", sessionId)
+ .expand());
+
+ return new Session(httpService().api_GET(url, CACHE_TAG));
+ }
+ }
+
+
+ /**
+ * Accessor to create an instance of {@link SlotAPI} with current configuration
+ *
+ * @return SlotAPI instance
+ */
+ public SlotAPI slot() {
+ return new SlotAPI(newProvider());
+ }
+
+ public class SlotAPI extends AbstractAPI {
+ public SlotAPI(ServiceProvider provider) {
+ super(provider);
+ }
+
+
+ /**
+ * List of slots for a company. Results are returned as a paginated list
+ *
+ * @param company The owning company for slots
+ * @param slParams Parameters for this call
+ * @return Collection of Slot
+ * @throws IOException
+ */
+ public BBCollection slotList(Company company, SlotListParams slParams) throws IOException {
+ URL url = new URL(Utils.inflateLink(AdminURLS.Slot.slotList()
+ .set("companyId", company.id)
+ .expand(), slParams.getParams()));
+
+ return new BBCollection<>(httpService().api_GET(url, CACHE_TAG), configService().auth_token, "slots", Slot.class);
+ }
+
+ public Observable> slotListObs(final Company company, final SlotListParams slParams) {
+ return Observable.fromCallable(() -> slotList(company, slParams));
+ }
+
+ /**
+ * Create a new slot
+ *
+ * @param company the company for slot
+ * @param scParams Contains parameters for slot creation. If the schema is used, then set the json form output
+ * to this through {@link bookingbugAPI2.models.params.Params#setJson(String)}
+ * in order to ignore declared fields
+ * @return Slot
+ * @throws IOException
+ */
+ public Slot slotCreate(Company company, SlotParams.Create scParams) throws IOException {
+ URL url = new URL(UriTemplate.fromTemplate(company.getSlotsLink()).expand());
+ return new Slot(httpService().api_POST(url, scParams.getParams(), CACHE_TAG));
+ }
+
+ public Observable slotCreateObs(final Company company, final SlotParams.Create scParams) {
+ return Observable.fromCallable(() -> slotCreate(company, scParams));
+ }
+
+ /**
+ * Cancel a slot
+ *
+ * @param company the company for slot
+ * @param slotId the slot to cancel
+ * @return SchemaForm
+ * @throws IOException
+ */
+ public Slot deleteSlot(Company company, String slotId) throws IOException {
+ URL url = new URL(AdminURLS.Slot.slotDelete()
+ .set("companyId", company.id)
+ .set("slotID", slotId)
+ .expand());
+ return new Slot(httpService().api_DELETE(url, CACHE_TAG));
+ }
+
+ public Observable deleteSlotObs(final Company company, String slotId) {
+ return Observable.fromCallable(() -> deleteSlot(company, slotId));
+ }
+
+ /**
+ * Get all the details about a specific slot
+ *
+ * @param company the company that owns the slot
+ * @param slotId the slot to read
+ * @return Slot
+ * @throws IOException
+ */
+ public Slot slotRead(Company company, String slotId) throws IOException {
+ URL url = new URL(AdminURLS.Slot.slotRead()
+ .set("companyId", company.id)
+ .set("slotId", slotId)
+ .expand());
+
+ return new Slot(httpService().api_GET(url, CACHE_TAG));
+ }
+
+ public Observable slotReadObs(final Company company, final String slotId) {
+ return Observable.fromCallable(() -> slotRead(company, slotId));
+ }
+
+ /**
+ * Update a slot
+ *
+ * @param slot the slot to update
+ * @param suParams Contains parameters for slot update. If the schema is used, then set the json form output
+ * to this through {@link bookingbugAPI2.models.params.Params#setJson(String)}
+ * in order to ignore declared fields
+ * @return Slot
+ * @throws IOException
+ */
+ public Slot slotUpdate(Slot slot, SlotParams.Update suParams) throws IOException {
+ URL url = new URL(slot.getSelf());
+ return new Slot(httpService().api_PUT(url, suParams.getParams(), CACHE_TAG));
+ }
+
+ public Observable slotUpdateObs(final Slot slot, final SlotParams.Update suParams) {
+ return Observable.fromCallable(() -> slotUpdate(slot, suParams));
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/main/bookingbugAPI/api/AdminURLS.java b/src/main/bookingbugAPI2/api/AdminURLS.java
similarity index 83%
rename from src/main/bookingbugAPI/api/AdminURLS.java
rename to src/main/bookingbugAPI2/api/AdminURLS.java
index f34da2b..87f9e9b 100644
--- a/src/main/bookingbugAPI/api/AdminURLS.java
+++ b/src/main/bookingbugAPI2/api/AdminURLS.java
@@ -1,15 +1,52 @@
-package bookingbugAPI.api;
+package bookingbugAPI2.api;
+import bookingbugAPI2.services.ServiceProvider;
import com.damnhandy.uri.template.UriTemplate;
import com.damnhandy.uri.template.UriTemplateBuilder;
-import helpers.Config;
-
+import helpers2.Config;
+//TODO: Fix URLS (refactor to be same with Login)
public class AdminURLS {
+ ServiceProvider provider;
+
+ public AdminURLS(ServiceProvider provider) {
+ this.provider = provider;
+ }
+
+ /**
+ * Accessor to create an instance of {@link Login}
+ *
+ * @return Login instance
+ */
+ public Login login() {
+ return new Login();
+ }
+
+ public class Login {
+ public UriTemplate auth() {
+ return UriTemplate.buildFromTemplate(provider.configService().serverUrl)
+ .literal("/login")
+ .build();
+ }
+
+ public UriTemplate sso() {
+ return UriTemplate.buildFromTemplate(provider.configService().serverUrl)
+ .literal("/login/sso")
+ .path(UriTemplateBuilder.var("companyId"))
+ .query(UriTemplateBuilder.var("token"))
+ .build();
+ }
+ }
+
public static class Company {
+
public static UriTemplate companyRead() {
- return UriTemplate.buildFromTemplate(new Config().serverUrl)
+ return companyRead(new Config().serverUrl);
+ }
+
+ public static UriTemplate companyRead(String serverUrl) {
+ return UriTemplate.buildFromTemplate(serverUrl)
.literal("/admin")
.path(UriTemplateBuilder.var("companyId"))
.literal("/company")
@@ -23,27 +60,28 @@ public static UriTemplate companyConfigRead() {
.literal("/company_configuration")
.build();
}
-/*
- public static UriTemplate administratorCreate() {
+
+ }
+
+ public static class Address {
+ public static UriTemplate addressList(){
return UriTemplate.buildFromTemplate(new Config().serverUrl)
.literal("/admin")
.path(UriTemplateBuilder.var("companyId"))
- .literal("/administrators")
+ .literal("/addresses")
.build();
}
-*/
- }
- public static class Address {
- public static UriTemplate addressList(){
+ public static UriTemplate addressRead(){
return UriTemplate.buildFromTemplate(new Config().serverUrl)
.literal("/admin")
.path(UriTemplateBuilder.var("companyId"))
.literal("/addresses")
+ .path(UriTemplateBuilder.var("addressId"))
.build();
}
- public static UriTemplate addressRead(){
+ public static UriTemplate addressDelete() {
return UriTemplate.buildFromTemplate(new Config().serverUrl)
.literal("/admin")
.path(UriTemplateBuilder.var("companyId"))
@@ -175,6 +213,16 @@ public static UriTemplate personDelete(){
.path(UriTemplateBuilder.var("personId"))
.build();
}
+
+ public static UriTemplate personReadUsingRefId() {
+ return UriTemplate.buildFromTemplate(new Config().serverUrl)
+ .literal("/admin")
+ .path(UriTemplateBuilder.var("companyId"))
+ .literal("/people")
+ .literal("/find_by_ref")
+ .path(UriTemplateBuilder.var("refId"))
+ .build();
+ }
}
@@ -245,6 +293,15 @@ public static UriTemplate slotRead() {
.path(UriTemplateBuilder.var("slotId"))
.build();
}
+
+ public static UriTemplate slotDelete() {
+ return UriTemplate.buildFromTemplate(new Config().serverUrl)
+ .literal("admin")
+ .path(UriTemplateBuilder.var("companyId"))
+ .literal("slots")
+ .path(UriTemplateBuilder.var("slotId"))
+ .build();
+ }
}
@@ -375,26 +432,34 @@ public static UriTemplate bookingAnswerQuestion(){
}
}
+ /**
+ * Accessor to create an instance of {@link Client}
+ *
+ * @return Client instance
+ */
+ public Client client() {
+ return new Client();
+ }
- public static class Client {
- public static UriTemplate clientList() {
- return UriTemplate.buildFromTemplate(new Config().serverUrl)
+ public class Client {
+ public UriTemplate clientList() {
+ return UriTemplate.buildFromTemplate(provider.configService().serverUrl)
.literal("/admin")
.path(UriTemplateBuilder.var("companyId"))
.literal("/client")
.build();
}
- public static UriTemplate clientCreate() {
- return UriTemplate.buildFromTemplate(new Config().serverUrl)
+ public UriTemplate clientCreate() {
+ return UriTemplate.buildFromTemplate(provider.configService().serverUrl)
.literal("/admin")
.path(UriTemplateBuilder.var("companyId"))
.literal("/client")
.build();
}
- public static UriTemplate clientRead() {
- return UriTemplate.buildFromTemplate(new Config().serverUrl)
+ public UriTemplate clientRead() {
+ return UriTemplate.buildFromTemplate(provider.configService().serverUrl)
.literal("/admin")
.path(UriTemplateBuilder.var("companyId"))
.literal("/client")
@@ -402,8 +467,8 @@ public static UriTemplate clientRead() {
.build();
}
- public static UriTemplate clientReadUsingRefId() {
- return UriTemplate.buildFromTemplate(new Config().serverUrl)
+ public UriTemplate clientReadUsingRefId() {
+ return UriTemplate.buildFromTemplate(provider.configService().serverUrl)
.literal("/admin")
.path(UriTemplateBuilder.var("companyId"))
.literal("/client")
@@ -412,8 +477,8 @@ public static UriTemplate clientReadUsingRefId() {
.build();
}
- public static UriTemplate clientReadUsingEmail() {
- return UriTemplate.buildFromTemplate(new Config().serverUrl)
+ public UriTemplate clientReadUsingEmail() {
+ return UriTemplate.buildFromTemplate(provider.configService().serverUrl)
.literal("/admin")
.path(UriTemplateBuilder.var("companyId"))
.literal("/client")
@@ -442,6 +507,12 @@ public static UriTemplate purchaseList() {
.literal("/admin")
.path(UriTemplateBuilder.var("companyId"))
.literal("/purchases")
+ .query(
+ UriTemplateBuilder.var("created_from"),
+ UriTemplateBuilder.var("created_to"),
+ UriTemplateBuilder.var("admin_booking"),
+ UriTemplateBuilder.var("order_by"),
+ UriTemplateBuilder.var("order_by_reverse"))
.build();
}
@@ -453,6 +524,16 @@ public static UriTemplate purchaseRead() {
.path(UriTemplateBuilder.var("purchaseId"))
.build();
}
+
+ public static UriTemplate purchasePay() {
+ return UriTemplate.buildFromTemplate(new Config().serverUrl)
+ .literal("/admin")
+ .path(UriTemplateBuilder.var("companyId"))
+ .literal("/purchases")
+ .path(UriTemplateBuilder.var("purchaseId"))
+ .literal("/pay")
+ .build();
+ }
}
@@ -542,6 +623,24 @@ public static UriTemplate administratorRead() {
.path(UriTemplateBuilder.var("adminId"))
.build();
}
+
+ public static UriTemplate administratorDelete() {
+ return UriTemplate.buildFromTemplate(new Config().serverUrl)
+ .literal("/admin")
+ .path(UriTemplateBuilder.var("companyId"))
+ .literal("/administrators")
+ .path(UriTemplateBuilder.var("adminId"))
+ .build();
+ }
+
+ public static UriTemplate administratorUpdate() {
+ return UriTemplate.buildFromTemplate(new Config().serverUrl)
+ .literal("/admin")
+ .path(UriTemplateBuilder.var("companyId"))
+ .literal("/administrators")
+ .path(UriTemplateBuilder.var("adminId"))
+ .build();
+ }
}
@@ -581,6 +680,24 @@ public static UriTemplate scheduleRead() {
.path(UriTemplateBuilder.var("scheduleId"))
.build();
}
+
+ public static UriTemplate scheduleDelete(){
+ return UriTemplate.buildFromTemplate(new Config().serverUrl)
+ .literal("/admin")
+ .path(UriTemplateBuilder.var("companyId"))
+ .literal("/schedules")
+ .path(UriTemplateBuilder.var("scheduleId"))
+ .build();
+ }
+
+ public static UriTemplate scheduleUpdate() {
+ return UriTemplate.buildFromTemplate(new Config().serverUrl)
+ .literal("/admin")
+ .path(UriTemplateBuilder.var("companyId"))
+ .literal("/schedules")
+ .path(UriTemplateBuilder.var("scheduleId"))
+ .build();
+ }
}
@@ -743,4 +860,24 @@ public static UriTemplate eventRead(){
.build();
}
}
+
+ public static class Clinic {
+ public static UriTemplate clinicRead() {
+ return UriTemplate.buildFromTemplate(new Config().serverUrl)
+ .literal("/admin")
+ .path(UriTemplateBuilder.var("companyId"))
+ .literal("/clinics")
+ .build();
+ }
+
+ public static UriTemplate clinicCancel() {
+ return UriTemplate.buildFromTemplate(new Config().serverUrl)
+ .literal("/admin")
+ .path(UriTemplateBuilder.var("companyId"))
+ .literal("/clinics")
+ .path(UriTemplateBuilder.var("clinicId"))
+ .literal("/cancel")
+ .build();
+ }
+ }
}
diff --git a/src/main/bookingbugAPI/api/AuthedAPI.java b/src/main/bookingbugAPI2/api/AuthedAPI.java
similarity index 86%
rename from src/main/bookingbugAPI/api/AuthedAPI.java
rename to src/main/bookingbugAPI2/api/AuthedAPI.java
index a117351..03c3d26 100644
--- a/src/main/bookingbugAPI/api/AuthedAPI.java
+++ b/src/main/bookingbugAPI2/api/AuthedAPI.java
@@ -1,4 +1,4 @@
-package bookingbugAPI.api;
+package bookingbugAPI2.api;
/**
* Created by sebi on 19.05.2016.
diff --git a/src/main/bookingbugAPI/api/PublicURLS.java b/src/main/bookingbugAPI2/api/PublicURLS.java
similarity index 99%
rename from src/main/bookingbugAPI/api/PublicURLS.java
rename to src/main/bookingbugAPI2/api/PublicURLS.java
index 1be7644..740a54b 100644
--- a/src/main/bookingbugAPI/api/PublicURLS.java
+++ b/src/main/bookingbugAPI2/api/PublicURLS.java
@@ -1,8 +1,8 @@
-package bookingbugAPI.api;
+package bookingbugAPI2.api;
import com.damnhandy.uri.template.UriTemplate;
import com.damnhandy.uri.template.UriTemplateBuilder;
-import helpers.Config;
+import helpers2.Config;
//@SuppressWarnings("unused") //use it just to highlight TODOs - comment it back afterwards
diff --git a/src/main/bookingbugAPI/models/Address.java b/src/main/bookingbugAPI2/models/Address.java
similarity index 93%
rename from src/main/bookingbugAPI/models/Address.java
rename to src/main/bookingbugAPI2/models/Address.java
index f01e559..1667590 100644
--- a/src/main/bookingbugAPI/models/Address.java
+++ b/src/main/bookingbugAPI2/models/Address.java
@@ -1,6 +1,6 @@
-package bookingbugAPI.models;
+package bookingbugAPI2.models;
-import helpers.HttpServiceResponse;
+import helpers2.HttpServiceResponse;
public class Address extends BBRoot{
@@ -8,7 +8,9 @@ public Address(HttpServiceResponse httpServiceResponse){
super(httpServiceResponse);
}
- public Address() {}
+ public Address(HttpServiceResponse httpServiceResponse, String auth_token) {
+ super(httpServiceResponse, auth_token);
+ }
/**
* Returns the id.
diff --git a/src/main/bookingbugAPI/models/Administrator.java b/src/main/bookingbugAPI2/models/Administrator.java
similarity index 92%
rename from src/main/bookingbugAPI/models/Administrator.java
rename to src/main/bookingbugAPI2/models/Administrator.java
index 9bb8875..3cff15c 100644
--- a/src/main/bookingbugAPI/models/Administrator.java
+++ b/src/main/bookingbugAPI2/models/Administrator.java
@@ -1,8 +1,8 @@
-package bookingbugAPI.models;
+package bookingbugAPI2.models;
-import bookingbugAPI.services.HttpService;
+import bookingbugAPI2.services.http.PlainHttpService;
import com.damnhandy.uri.template.UriTemplate;
-import helpers.HttpServiceResponse;
+import helpers2.HttpServiceResponse;
import java.io.IOException;
import java.net.URL;
@@ -23,14 +23,14 @@ public Administrator(HttpServiceResponse httpServiceResponse) {
public Company getCompany() throws IOException {
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);
+ return new Company(PlainHttpService.api_GET(url, auth_token), auth_token);
}
public BBRoot getEditSchema() throws IOException {
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);
+ return new BBRoot(PlainHttpService.api_GET(url, auth_token), auth_token);
}
diff --git a/src/main/bookingbugAPI/models/Answer.java b/src/main/bookingbugAPI2/models/Answer.java
similarity index 97%
rename from src/main/bookingbugAPI/models/Answer.java
rename to src/main/bookingbugAPI2/models/Answer.java
index 6a1e197..53ff891 100644
--- a/src/main/bookingbugAPI/models/Answer.java
+++ b/src/main/bookingbugAPI2/models/Answer.java
@@ -1,6 +1,6 @@
-package bookingbugAPI.models;
+package bookingbugAPI2.models;
-import helpers.HttpServiceResponse;
+import helpers2.HttpServiceResponse;
public class Answer extends BBRoot{
diff --git a/src/main/bookingbugAPI/models/BBCollection.java b/src/main/bookingbugAPI2/models/BBCollection.java
similarity index 97%
rename from src/main/bookingbugAPI/models/BBCollection.java
rename to src/main/bookingbugAPI2/models/BBCollection.java
index e412ed9..0f714b3 100644
--- a/src/main/bookingbugAPI/models/BBCollection.java
+++ b/src/main/bookingbugAPI2/models/BBCollection.java
@@ -1,7 +1,7 @@
-package bookingbugAPI.models;
+package bookingbugAPI2.models;
import com.theoryinpractise.halbuilder.api.ContentRepresentation;
-import helpers.HttpServiceResponse;
+import helpers2.HttpServiceResponse;
import java.lang.reflect.InvocationTargetException;
import java.util.Iterator;
diff --git a/src/main/bookingbugAPI/models/BBRoot.java b/src/main/bookingbugAPI2/models/BBRoot.java
similarity index 93%
rename from src/main/bookingbugAPI/models/BBRoot.java
rename to src/main/bookingbugAPI2/models/BBRoot.java
index cfa0e37..d9ef2a6 100644
--- a/src/main/bookingbugAPI/models/BBRoot.java
+++ b/src/main/bookingbugAPI2/models/BBRoot.java
@@ -1,6 +1,6 @@
-package bookingbugAPI.models;
+package bookingbugAPI2.models;
-import bookingbugAPI.services.HttpService;
+import bookingbugAPI2.services.http.PlainHttpService;
import com.damnhandy.uri.template.UriTemplate;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.core.JsonProcessingException;
@@ -12,9 +12,9 @@
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 helpers2.Config;
+import helpers2.HttpServiceResponse;
+import helpers2.hal_addon.CustomJsonDeserializer;
import org.joda.time.DateTime;
import java.io.*;
@@ -42,7 +42,6 @@ public class BBRoot {
protected HttpServiceResponse response;
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;
@@ -74,7 +73,7 @@ public BBRoot() {
public BBRoot getLoginSchema() throws IOException {
URL url = new URL(UriTemplate.fromTemplate(response.getRep().getLinkByRel("new_login").getHref()).expand());
- HttpServiceResponse response = HttpService.api_GET(url);
+ HttpServiceResponse response = PlainHttpService.api_GET(url);
return new BBRoot(response);
}
@@ -83,7 +82,7 @@ public Login auth(Map params) throws IOException {
HttpServiceResponse resp;
try {
URL url = new URL(UriTemplate.fromTemplate(new Config().serverUrl + "/login").expand());
- resp = HttpService.api_POST(url, params);
+ resp = PlainHttpService.api_POST(url, params);
auth_token = (String) resp.getRep().getValue("auth_token");
} catch (HttpException e) {
//e.printStackTrace();
@@ -105,7 +104,7 @@ public Login auth(Map params) throws IOException {
public Login auth(Map params, Link link) throws IOException {
URL url = new URL(link.getHref());
- HttpServiceResponse resp = HttpService.api_POST(url, params);
+ HttpServiceResponse resp = PlainHttpService.api_POST(url, params);
auth_token = (String) resp.getRep().getValue("auth_token");
return new Login(resp);
}
@@ -219,7 +218,7 @@ public String getLink(String rel) {
String link = null;
try {
link = response.getRep().getLinkByRel(rel).getHref();
- } catch (RepresentationException e) {
+ } catch (RepresentationException | NullPointerException e) {
//e.printStackTrace();
}
return link;
@@ -252,9 +251,9 @@ public String toString() {
}
public String toPrettyString() {
- ObjectMapper mapper = new ObjectMapper();
+ ObjectMapper mapper = CustomJsonDeserializer.getMapper();
try {
- return mapper.writerWithDefaultPrettyPrinter().writeValueAsString(response.getRep());
+ return mapper.writerWithDefaultPrettyPrinter().writeValueAsString(response);
} catch (JsonProcessingException e) {
e.printStackTrace();
return toString();
diff --git a/src/main/bookingbugAPI/models/Basket.java b/src/main/bookingbugAPI2/models/Basket.java
similarity index 95%
rename from src/main/bookingbugAPI/models/Basket.java
rename to src/main/bookingbugAPI2/models/Basket.java
index 58f70b9..7ac70ca 100644
--- a/src/main/bookingbugAPI/models/Basket.java
+++ b/src/main/bookingbugAPI2/models/Basket.java
@@ -1,8 +1,6 @@
-package bookingbugAPI.models;
+package bookingbugAPI2.models;
-import helpers.HttpServiceResponse;
-
-import java.util.List;
+import helpers2.HttpServiceResponse;
public class Basket extends BBRoot{
diff --git a/src/main/bookingbugAPI/models/BasketItem.java b/src/main/bookingbugAPI2/models/BasketItem.java
similarity index 96%
rename from src/main/bookingbugAPI/models/BasketItem.java
rename to src/main/bookingbugAPI2/models/BasketItem.java
index bf837c0..97602c7 100644
--- a/src/main/bookingbugAPI/models/BasketItem.java
+++ b/src/main/bookingbugAPI2/models/BasketItem.java
@@ -1,13 +1,10 @@
-package bookingbugAPI.models;
+package bookingbugAPI2.models;
-import bookingbugAPI.api.PublicURLS;
-import bookingbugAPI.services.HttpService;
import com.theoryinpractise.halbuilder.api.ContentRepresentation;
-import helpers.HttpServiceResponse;
+import helpers2.HttpServiceResponse;
import org.joda.time.DateTime;
import java.io.IOException;
-import java.net.URL;
import java.util.List;
import java.util.Map;
diff --git a/src/main/bookingbugAPI/models/BasketItemSettings.java b/src/main/bookingbugAPI2/models/BasketItemSettings.java
similarity index 93%
rename from src/main/bookingbugAPI/models/BasketItemSettings.java
rename to src/main/bookingbugAPI2/models/BasketItemSettings.java
index 038c9d4..9fb79b8 100644
--- a/src/main/bookingbugAPI/models/BasketItemSettings.java
+++ b/src/main/bookingbugAPI2/models/BasketItemSettings.java
@@ -1,6 +1,6 @@
-package bookingbugAPI.models;
+package bookingbugAPI2.models;
-import helpers.HttpServiceResponse;
+import helpers2.HttpServiceResponse;
import org.joda.time.DateTime;
/**
diff --git a/src/main/bookingbugAPI/models/BookableAvailability.java b/src/main/bookingbugAPI2/models/BookableAvailability.java
similarity index 93%
rename from src/main/bookingbugAPI/models/BookableAvailability.java
rename to src/main/bookingbugAPI2/models/BookableAvailability.java
index 7879c42..0f89462 100644
--- a/src/main/bookingbugAPI/models/BookableAvailability.java
+++ b/src/main/bookingbugAPI2/models/BookableAvailability.java
@@ -1,13 +1,11 @@
-package bookingbugAPI.models;
+package bookingbugAPI2.models;
import com.fasterxml.jackson.databind.util.ISO8601DateFormat;
-import com.theoryinpractise.halbuilder.api.ContentRepresentation;
import com.theoryinpractise.halbuilder.api.ReadableRepresentation;
-import helpers.HttpServiceResponse;
+import helpers2.HttpServiceResponse;
import java.text.ParseException;
import java.util.ArrayList;
-import java.util.Calendar;
import java.util.Date;
/**
diff --git a/src/main/bookingbugAPI/models/BookableItem.java b/src/main/bookingbugAPI2/models/BookableItem.java
similarity index 83%
rename from src/main/bookingbugAPI/models/BookableItem.java
rename to src/main/bookingbugAPI2/models/BookableItem.java
index ca3cf7a..b0634a8 100644
--- a/src/main/bookingbugAPI/models/BookableItem.java
+++ b/src/main/bookingbugAPI2/models/BookableItem.java
@@ -1,6 +1,6 @@
-package bookingbugAPI.models;
+package bookingbugAPI2.models;
-import helpers.HttpServiceResponse;
+import helpers2.HttpServiceResponse;
public class BookableItem extends BBRoot {
diff --git a/src/main/bookingbugAPI/models/Booking.java b/src/main/bookingbugAPI2/models/Booking.java
similarity index 88%
rename from src/main/bookingbugAPI/models/Booking.java
rename to src/main/bookingbugAPI2/models/Booking.java
index 3c2980a..034a715 100644
--- a/src/main/bookingbugAPI/models/Booking.java
+++ b/src/main/bookingbugAPI2/models/Booking.java
@@ -1,17 +1,15 @@
-package bookingbugAPI.models;
+package bookingbugAPI2.models;
-import bookingbugAPI.api.AdminURLS;
-import bookingbugAPI.models.params.BookingCancelParams;
-import bookingbugAPI.models.params.BookingUpdateParams;
-import bookingbugAPI.services.HttpService;
+import bookingbugAPI2.api.AdminURLS;
+import bookingbugAPI2.models.params.BookingCancelParams;
+import bookingbugAPI2.models.params.BookingUpdateParams;
+import bookingbugAPI2.services.http.PlainHttpService;
import com.damnhandy.uri.template.UriTemplate;
-import com.j256.ormlite.stmt.query.In;
-import helpers.HttpServiceResponse;
+import helpers2.HttpServiceResponse;
import org.joda.time.DateTime;
import java.io.IOException;
import java.net.URL;
-import java.util.List;
import java.util.Map;
@@ -25,37 +23,6 @@ public Booking(HttpServiceResponse response) {
super(response);
}
- public Booking() {
- }
-
- public BBRoot getSchema() throws IOException {
- String link = getRep().getLinkByRel("edit").getHref();
- URL url = new URL(UriTemplate.fromTemplate(link).expand());
- return new BBRoot(HttpService.api_GET(url, auth_token));
- }
-
- /**
- * Returns a new Booking - update the current booking with provided params
- *
- * @param bParams
- * @throws IOException
- */
- public Booking bookingUpdate_Admin(BookingUpdateParams bParams) throws IOException {
- URL url = new URL(AdminURLS.Bookings.bookingUpdate().set("companyId", getCompanyId()).set("id", this.id).expand());
- return new Booking(HttpService.api_PUT(url, bParams.getParams(), auth_token), auth_token);
- }
-
- /**
- * Deletes the booking
- *
- * @param bcParams
- * @return
- * @throws IOException
- */
- public Booking bookingCancel_Admin(BookingCancelParams bcParams) throws IOException {
- URL url = new URL(AdminURLS.Bookings.bookingCancel().set("companyId", getCompanyId()).set("id", this.id).expand());
- return new Booking(HttpService.api_DELETE(url, HttpService.jsonContentType, bcParams.getParams(), auth_token), auth_token);
- }
/**
* Returns the booking id.
diff --git a/src/main/bookingbugAPI/models/BookingQuestion.java b/src/main/bookingbugAPI2/models/BookingQuestion.java
similarity index 83%
rename from src/main/bookingbugAPI/models/BookingQuestion.java
rename to src/main/bookingbugAPI2/models/BookingQuestion.java
index fdbf525..142c2f3 100644
--- a/src/main/bookingbugAPI/models/BookingQuestion.java
+++ b/src/main/bookingbugAPI2/models/BookingQuestion.java
@@ -1,6 +1,6 @@
-package bookingbugAPI.models;
+package bookingbugAPI2.models;
-import helpers.HttpServiceResponse;
+import helpers2.HttpServiceResponse;
public class BookingQuestion extends BBRoot{
diff --git a/src/main/bookingbugAPI/models/Category.java b/src/main/bookingbugAPI2/models/Category.java
similarity index 92%
rename from src/main/bookingbugAPI/models/Category.java
rename to src/main/bookingbugAPI2/models/Category.java
index fbc95ea..cfe6ff7 100644
--- a/src/main/bookingbugAPI/models/Category.java
+++ b/src/main/bookingbugAPI2/models/Category.java
@@ -1,6 +1,6 @@
-package bookingbugAPI.models;
+package bookingbugAPI2.models;
-import helpers.HttpServiceResponse;
+import helpers2.HttpServiceResponse;
public class Category extends BBRoot{
diff --git a/src/main/bookingbugAPI/models/Client.java b/src/main/bookingbugAPI2/models/Client.java
similarity index 98%
rename from src/main/bookingbugAPI/models/Client.java
rename to src/main/bookingbugAPI2/models/Client.java
index 5b04f17..5eeaa44 100644
--- a/src/main/bookingbugAPI/models/Client.java
+++ b/src/main/bookingbugAPI2/models/Client.java
@@ -1,6 +1,6 @@
-package bookingbugAPI.models;
+package bookingbugAPI2.models;
-import helpers.HttpServiceResponse;
+import helpers2.HttpServiceResponse;
import java.util.List;
import java.util.Map;
diff --git a/src/main/bookingbugAPI2/models/Clinic.java b/src/main/bookingbugAPI2/models/Clinic.java
new file mode 100644
index 0000000..ffedc8d
--- /dev/null
+++ b/src/main/bookingbugAPI2/models/Clinic.java
@@ -0,0 +1,61 @@
+package bookingbugAPI2.models;
+
+import helpers2.HttpServiceResponse;
+import org.joda.time.DateTime;
+
+import java.util.List;
+
+
+public class Clinic extends BBRoot{
+ public Clinic(HttpServiceResponse httpServiceResponse) {
+ super(httpServiceResponse);
+ }
+
+ /**
+ * Returns the name of the clinic.
+ * @return the name of the clinic associated with the current Clinic object.
+ */
+ public String getName() {
+ return get("name");
+ }
+
+ /**
+ * Returns the starting time with {@link DateTime DateTime()} as format.
+ * @return the starting time associated with the current Clinic object.
+ */
+ public DateTime getStartTime() {
+ return getDate("start_time");
+ }
+
+ /**
+ * Returns the ending time with {@link DateTime DateTime()} as format.
+ * @return the ending time associated with the current Clinic object.
+ */
+ public DateTime getEndTime() {
+ return getDate("end_time");
+ }
+
+ /**
+ * Returns the resource ids.
+ * @return the resource ids associated with the current Clinic object.
+ */
+ public List getResourceIds() {
+ return getStringArray("resource_ids");
+ }
+
+ /**
+ * Returns the person ids.
+ * @return the person ids associated with the current Clinic object.
+ */
+ public List getPersonIds() {
+ return getStringArray("person_ids");
+ }
+
+ /**
+ * Returns the service ids.
+ * @return the service ids associated with the current Clinic object.
+ */
+ public List getServiceIds() {
+ return getStringArray("service_ids");
+ }
+}
diff --git a/src/main/bookingbugAPI/models/Company.java b/src/main/bookingbugAPI2/models/Company.java
similarity index 77%
rename from src/main/bookingbugAPI/models/Company.java
rename to src/main/bookingbugAPI2/models/Company.java
index 82059e4..f17e88e 100644
--- a/src/main/bookingbugAPI/models/Company.java
+++ b/src/main/bookingbugAPI2/models/Company.java
@@ -1,8 +1,8 @@
-package bookingbugAPI.models;
+package bookingbugAPI2.models;
-import bookingbugAPI.api.AdminURLS;
-import bookingbugAPI.api.PublicURLS;
-import bookingbugAPI.models.params.*;
+import bookingbugAPI2.api.AdminURLS;
+import bookingbugAPI2.api.PublicURLS;
+import bookingbugAPI2.models.params.*;
import com.damnhandy.uri.template.UriTemplate;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
@@ -10,12 +10,11 @@
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.module.jsonSchema.JsonSchema;
import com.fasterxml.jackson.module.jsonSchema.factories.SchemaFactoryWrapper;
-import com.j256.ormlite.stmt.query.In;
import com.theoryinpractise.halbuilder.api.ContentRepresentation;
-import bookingbugAPI.services.HttpService;
+import bookingbugAPI2.services.http.PlainHttpService;
import com.theoryinpractise.halbuilder.json.JsonRepresentationFactory;
-import helpers.HttpServiceResponse;
-import helpers.Utils;
+import helpers2.HttpServiceResponse;
+import helpers2.Utils;
import java.io.*;
import java.net.MalformedURLException;
@@ -24,25 +23,26 @@
import static com.theoryinpractise.halbuilder.api.RepresentationFactory.HAL_JSON;
-public class Company extends BBRoot{
+public class Company extends BBRoot {
private Service servicesList;
private Administrator administratorList;
private BBRoot administratorSchema;
- public Company(HttpServiceResponse httpServiceResponse){
+ public Company(HttpServiceResponse httpServiceResponse) {
super(httpServiceResponse);
}
- public Company(HttpServiceResponse httpServiceResponse, String auth_token){
+ public Company(HttpServiceResponse httpServiceResponse, String auth_token) {
super(httpServiceResponse);
this.auth_token = auth_token;
}
- public Company() {}
+ public Company() {
+ }
/*
@@ -70,18 +70,20 @@ public Service getServicesList() throws IOException {
/**
* Load All of the Links and Properties of a Company
+ *
* @return CompanyConfig
* @throws IOException
*/
public CompanyConfig companyRead_Admin() throws IOException {
- URL url = new URL (AdminURLS.Company.companyConfigRead().set("companyId", this.id).expand());
- BBCollection config = new BBCollection(HttpService.api_GET(url, auth_token), auth_token, "config", CompanyConfig.class);
+ URL url = new URL(AdminURLS.Company.companyConfigRead().set("companyId", this.id).expand());
+ BBCollection config = new BBCollection(PlainHttpService.api_GET(url, auth_token), auth_token, "config", CompanyConfig.class);
return config.getObjectAtIndex(0);
}
/**
* Get the Bookable Items Based on Another Item
+ *
* @param bilParams
* @return BBCollection
* @throws IOException
@@ -89,39 +91,41 @@ public CompanyConfig companyRead_Admin() throws IOException {
public BBCollection bookableItemsList_Admin(BookableItemListParams bilParams) throws IOException {
String urlStr = AdminURLS.BookableItem.bookableItemList().set("companyId", this.id).expand();
URL url = new URL(Utils.inflateLink(urlStr, bilParams.getParams()));
- BBCollection bookableItems = new BBCollection(HttpService.api_GET(url, auth_token), auth_token, "bookable_items", BookableItem.class);
+ BBCollection bookableItems = new BBCollection(PlainHttpService.api_GET(url, auth_token), auth_token, "bookable_items", BookableItem.class);
return bookableItems;
}
/**
* Get All Bookable Services
+ *
* @return BBCollection
* @throws IOException
*/
public BBCollection serviceList() throws IOException {
URL url = new URL(PublicURLS.Service.serviceList().set("companyId", this.id).expand());
- BBCollection services = new BBCollection(HttpService.api_GET(url, auth_token), auth_token, "services", Service.class);
+ BBCollection services = new BBCollection(PlainHttpService.api_GET(url, auth_token), auth_token, "services", Service.class);
return services;
}
public Service serviceNew_Admin() throws IOException {
URL url = new URL(AdminURLS.Service.serviceNew().set("companyId", this.id).expand());
- BBCollection services = new BBCollection(HttpService.api_GET(url, auth_token), auth_token, "service", Service.class);
+ BBCollection services = new BBCollection(PlainHttpService.api_GET(url, auth_token), auth_token, "service", Service.class);
return services.getObjectAtIndex(0);
}
public Service serviceEdit_Admin(String serviceId) throws IOException {
URL url = new URL(AdminURLS.Service.serviceEdit().set("companyId", this.id).set("serviceId", serviceId).expand());
- BBCollection services = new BBCollection(HttpService.api_GET(url, auth_token), auth_token, "service", Service.class);
+ BBCollection services = new BBCollection(PlainHttpService.api_GET(url, auth_token), auth_token, "service", Service.class);
return services.getObjectAtIndex(0);
}
/**
* List of Services for a Company.
+ *
* @return BBCollection
* @throws IOException
*/
@@ -130,86 +134,91 @@ public BBCollection serviceList_Admin(ServiceListParams slParams) throw
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);
+ BBCollection services = new BBCollection(PlainHttpService.api_GET(url, auth_token), auth_token, "services", Service.class);
return services;
}
/**
* Get a Specific Service.
+ *
* @param serviceId Service Id
* @return Service
* @throws IOException
*/
public Service serviceRead(String serviceId) throws IOException {
URL url = new URL(PublicURLS.Service.serviceRead().set("companyId", this.id).set("serviceId", serviceId).expand());
- BBCollection services = new BBCollection(HttpService.api_GET(url, auth_token), auth_token, "service", Service.class);
+ BBCollection services = new BBCollection(PlainHttpService.api_GET(url, auth_token), auth_token, "service", Service.class);
return services.getObjectAtIndex(0);
}
/**
* Load a Specific Service Details
+ *
* @param serviceId
* @return Service
* @throws IOException
*/
public Service serviceRead_Admin(String serviceId) throws IOException {
URL url = new URL(AdminURLS.Service.serviceRead().set("companyId", this.id).set("serviceId", serviceId).expand());
- BBCollection service = new BBCollection(HttpService.api_GET(url, auth_token), auth_token, "service", Service.class);
+ BBCollection service = new BBCollection(PlainHttpService.api_GET(url, auth_token), auth_token, "service", Service.class);
return service.getObjectAtIndex(0);
}
//TODO: kept for compatibility with AdminController until checked there
- public People getPeopleList() throws IOException {
+ public Person getPeopleList() throws IOException {
String link = response.getRep().getLinkByRel("people").getHref();
URL url = new URL(UriTemplate.fromTemplate(link).expand());
- return new People(HttpService.api_GET(url, auth_token), auth_token);
+ return new Person(PlainHttpService.api_GET(url, auth_token), auth_token);
}
/**
* Get All Bookable People for a Company.
+ *
* @return BBCollection
* @throws IOException
*/
- public BBCollection personList() throws IOException {
+ public BBCollection personList() throws IOException {
URL url = new URL(PublicURLS.Person.personList().set("companyId", this.id).expand());
- BBCollection people = new BBCollection(HttpService.api_GET(url, auth_token), auth_token, "people", People.class);
+ BBCollection people = new BBCollection(PlainHttpService.api_GET(url, auth_token), auth_token, "people", Person.class);
return people;
}
- public BBCollection personList_Admin(PeopleListParams plParams) throws IOException {
+ public BBCollection personList_Admin(PersonListParams plParams) throws IOException {
String urlStr = AdminURLS.Person.personList().set("companyId", this.id).expand();
URL url = new URL(Utils.inflateLink(urlStr, plParams.getParams()));
- BBCollection people = new BBCollection(HttpService.api_GET(url, auth_token), auth_token, "people", People.class);
+ BBCollection people = new BBCollection(PlainHttpService.api_GET(url, auth_token), auth_token, "people", Person.class);
return people;
}
/**
* Get a Specific Bookable Person’s Details.
+ *
* @param personId Person Id
* @return People
* @throws IOException
*/
- public People personRead(String personId) throws IOException {
+ public Person personRead(String personId) throws IOException {
URL url = new URL(PublicURLS.Person.personRead().set("companyId", this.id).set("personId", personId).expand());
- BBCollection people = new BBCollection(HttpService.api_GET(url, auth_token), auth_token, "person", People.class);
+ BBCollection people = new BBCollection(PlainHttpService.api_GET(url, auth_token), auth_token, "person", Person.class);
return people.getObjectAtIndex(0);
}
/**
* Get a Specific Person Details using a Reference ID
+ *
* @return People
* @throws IOException
*/
- public People personReadUsingReferenceId(String ref) throws IOException {
+ public Person personReadUsingReferenceId(String ref) throws IOException {
URL url = new URL(PublicURLS.Person.personReadUsingReferenceId().set("companyId", this.id).set("ref", ref).expand());
- BBCollection people = new BBCollection(HttpService.api_GET(url, auth_token), auth_token, "person", People.class);
+ BBCollection people = new BBCollection(PlainHttpService.api_GET(url, auth_token), auth_token, "person", Person.class);
return people.getObjectAtIndex(0);
}
@@ -217,18 +226,20 @@ public People personReadUsingReferenceId(String ref) throws IOException {
/**
* Get All Bookable Resources
* Results are returned as a paginated list.
+ *
* @return BBCollection
* @throws IOException
*/
public BBCollection resourceList() throws IOException {
URL url = new URL(PublicURLS.Resource.resourceList().set("companyId", this.id).expand());
- BBCollection resources = new BBCollection(HttpService.api_GET(url, auth_token), auth_token, "resources", Resource.class);
+ BBCollection resources = new BBCollection(PlainHttpService.api_GET(url, auth_token), auth_token, "resources", Resource.class);
return resources;
}
/**
* Get All Questions for a Company
+ *
* @param qlParams
* @return BBCollection
* @throws IOException
@@ -236,13 +247,14 @@ public BBCollection resourceList() throws IOException {
public BBCollection questionList_Admin(QuestionListParams qlParams) throws IOException {
String urlStr = AdminURLS.Question.questionList().set("companyId", this.id).expand();
URL url = new URL(Utils.inflateLink(urlStr, qlParams.getParams()));
- BBCollection questions = new BBCollection(HttpService.api_GET(url, auth_token), auth_token, "questions", Question.class);
+ BBCollection questions = new BBCollection(PlainHttpService.api_GET(url, auth_token), auth_token, "questions", Question.class);
return questions;
}
/**
* resourceList_Admin
+ *
* @param rlParams
* @return BBCollection
* @throws IOException
@@ -250,39 +262,42 @@ public BBCollection questionList_Admin(QuestionListParams qlParams) th
public BBCollection resourceList_Admin(ResourceListParams rlParams) throws IOException {
String urlStr = AdminURLS.Resource.resourceList().set("companyId", this.id).expand();
URL url = new URL(Utils.inflateLink(urlStr, rlParams.getParams()));
- BBCollection resources = new BBCollection(HttpService.api_GET(url, auth_token), auth_token, "resources", Resource.class);
+ BBCollection resources = new BBCollection(PlainHttpService.api_GET(url, auth_token), auth_token, "resources", Resource.class);
return resources;
}
/**
* Get a Specific Bookable Resource
+ *
* @param resourceId Resource Id
* @return Resource
* @throws IOException
*/
public Resource resourceRead(String resourceId) throws IOException {
URL url = new URL(PublicURLS.Resource.resourceRead().set("companyId", this.id).set("resourceId", resourceId).expand());
- BBCollection resource = new BBCollection(HttpService.api_GET(url, auth_token), auth_token, "resources", Resource.class);
+ BBCollection resource = new BBCollection(PlainHttpService.api_GET(url, auth_token), auth_token, "resources", Resource.class);
return resource.getObjectAtIndex(0);
}
/**
* Load a Specific Resource Details
+ *
* @param resourceId
* @return Resource
* @throws IOException
*/
public Resource resourceRead_Admin(String resourceId) throws IOException {
URL url = new URL(AdminURLS.Resource.resourceRead().set("companyId", this.id).set("resourceId", resourceId).expand());
- BBCollection resource = new BBCollection(HttpService.api_GET(url, auth_token), auth_token, "resources", Resource.class);
+ BBCollection