Skip to content

Commit

Permalink
[DROID-38] Added RxJava Observable wrappers over api calls
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianmacarescu committed Jul 8, 2016
1 parent c6596b8 commit 9b87489
Show file tree
Hide file tree
Showing 3 changed files with 144 additions and 2 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ language: java
jdk:
- openjdk7
- oraclejdk7
- openjdk8

script: mvn clean test
47 changes: 45 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,54 @@
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
<source>1.8</source>
<target>1.8</target>
<testSource>1.7</testSource>
<testTarget>1.7</testTarget>
</configuration>
</plugin>

<plugin>
<groupId>net.orfjackal.retrolambda</groupId>
<artifactId>retrolambda-maven-plugin</artifactId>
<version>2.3.0</version>
<executions>
<execution>
<goals>
<goal>process-main</goal>
<goal>process-test</goal>
</goals>
</execution>
</executions>
<configuration>
<target>${testBytecodeTarget}</target>
<defaultMethods>${testDefaultMethods}</defaultMethods>
<fork>${testFork}</fork>
</configuration>
</plugin>
</plugins>
</build>

<profiles>
<profile>
<id>noDefaultMethods</id>
<properties>
<testDefaultMethods>false</testDefaultMethods>
</properties>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<testExcludes>
<pattern>**/DefaultMethodsTest.java</pattern>
<pattern>**/InterfaceStaticMethodsTest.java</pattern>
</testExcludes>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>

</project>
98 changes: 98 additions & 0 deletions src/main/bookingbugAPI/api/AdminAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
import com.damnhandy.uri.template.UriTemplate;
import helpers.Http;
import helpers.Utils;
import rx.Observable;

import java.io.IOException;
import java.net.URL;
import java.util.concurrent.Callable;


public class AdminAPI extends AbstractAPI {
Expand Down Expand Up @@ -45,6 +47,10 @@ public BBCollection<Booking> bookingList(Company company, BookingListParams bLPa
return bookings;
}

public Observable<BBCollection<Booking>> bookingListObs(final Company company, final BookingListParams bLParams) {
return Observable.fromCallable(() -> bookingList(company, bLParams));
}

/**
* Get all details about a specific booking
* @param company the company owning the booking
Expand All @@ -60,6 +66,10 @@ public Booking bookingRead(Company company, String bookingId) throws IOException
return new Booking(httpService().api_GET(url));
}

public Observable<Booking> bookingReadObs(final Company company, final String bookingId) {
return Observable.fromCallable(()->bookingRead(company, bookingId));
}

/**
* Get the edit schema for booking
* @param booking
Expand All @@ -70,6 +80,10 @@ public SchemaForm getEditBookingSchema(Booking booking) throws IOException {
URL url = new URL(UriTemplate.fromTemplate(booking.getEditLink()).expand());
return new SchemaForm(httpService().api_GET(url));
}

public Observable<SchemaForm> getEditBookingSchemaObs(final Booking booking) {
return Observable.fromCallable(()->getEditBookingSchema(booking));
}
}


Expand Down Expand Up @@ -99,6 +113,10 @@ public Company companyRead(String companyId) throws IOException {
return new Company(httpService().api_GET(url));
}

public Observable<Company> companyReadObs(final String companyId) {
return Observable.fromCallable(()->companyRead(companyId));
}

}


Expand Down Expand Up @@ -132,6 +150,10 @@ public BBCollection<Service> serviceList(Company company, ServiceListParams slPa
return services;
}

public Observable<BBCollection<Service>> 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
Expand All @@ -147,6 +169,10 @@ public Service serviceRead(Company company, String serviceId) throws IOException
return new Service(httpService().api_GET(url));
}

public Observable<Service> 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
Expand All @@ -158,6 +184,10 @@ public SchemaForm getNewServiceSchema(Company company) throws IOException {
return new SchemaForm(httpService().api_GET(url));
}

public Observable<SchemaForm> getNewServiceSchemaObs(final Company company) {
return Observable.fromCallable(()->getNewServiceSchema(company));
}

/**
* Create a service
* @param company the company to own the service
Expand All @@ -172,6 +202,10 @@ public Service serviceCreate(Company company, ServiceParams.ServiceCreateParams
return new Service(httpService().api_POST(url, sCParams.getParams()));
}

public Observable<Service> serviceCreateObs(final Company company, final ServiceParams.ServiceCreateParams sCParams) {
return Observable.fromCallable(()->serviceCreate(company, sCParams));
}

/**
* Update a service
* @param service the service to update
Expand All @@ -186,6 +220,10 @@ public Service serviceUpdate(Service service, ServiceParams.ServiceUpdateParams
return new Service(httpService().api_POST(url, sUParams.getParams()));
}

public Observable<Service> 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
Expand All @@ -197,6 +235,10 @@ public SchemaForm getNewBookingSchema(Service service) throws IOException {
return new SchemaForm(httpService().api_GET(url));
}

public Observable<SchemaForm> getNewBookingSchemaObs(final Service service) {
return Observable.fromCallable(()->getNewBookingSchema(service));
}

/**
* Get a schema for editing a service
* @param service The service to be edited
Expand All @@ -207,6 +249,10 @@ public SchemaForm getEditServiceSchema(Service service) throws IOException {
URL url = new URL(UriTemplate.fromTemplate(service.getEditLink()).expand());
return new SchemaForm(httpService().api_GET(url));
}

public Observable<SchemaForm> getEditServiceSchemaObs(final Service service) {
return Observable.fromCallable(()->getEditServiceSchema(service));
}
}


Expand Down Expand Up @@ -240,6 +286,10 @@ public BBCollection<Client> clientList(Company company, Params clParams) throws
return clients;
}

public Observable<BBCollection<Client>> clientListObs(final Company company, final Params clParams) {
return Observable.fromCallable(()->clientList(company, clParams));
}

/**
* Load a specific client details
* @param company The owning company for client
Expand All @@ -255,6 +305,10 @@ public Client clientRead(Company company, String clientId) throws IOException {
return new Client(httpService().api_GET(url));
}

public Observable<Client> 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
Expand All @@ -267,6 +321,10 @@ public Client clientReadByEmail(Company company, String email) throws IOExceptio
return new Client(httpService().api_GET(url));
}

public Observable<Client> 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
Expand All @@ -278,6 +336,10 @@ public SchemaForm getEditClientSchema(Client client) throws IOException {
return new SchemaForm(httpService().api_GET(url));
}

public Observable<SchemaForm> getEditClientSchemaObs(final Client client) {
return Observable.fromCallable(()->getEditClientSchema(client));
}

/**
* Enable/Disable specific client
* @param company The company for the client
Expand All @@ -290,6 +352,10 @@ public Client clientEnableDisable(Company company, ClientToggleParams ctParams)
return new Client(httpService().api_PUT(url, Http.urlEncodedContentType, ctParams.getParams()));
}

public Observable<Client> clientEnableDisableObs(final Company company, final ClientToggleParams ctParams) {
return Observable.fromCallable(()->clientEnableDisable(company, ctParams));
}

/**
* Update a client
* @param client the client to update
Expand All @@ -304,6 +370,10 @@ public Client clientUpdate(Client client, ClientParams.Update cuParams) throws I
return new Client(httpService().api_PUT(url, cuParams.getParams()));
}

public Observable<Client> clientUpdateObs(final Client client, final ClientParams.Update cuParams) {
return Observable.fromCallable(()->clientUpdate(client, cuParams));
}

/**
* Create a client
* @param company the company for client
Expand All @@ -318,6 +388,10 @@ public Client clientCreate(Company company, ClientParams.Create clParams) throws
return new Client(httpService().api_POST(url, clParams.getParams()));
}

public Observable<Client> clientCreateObs(final Company company, final ClientParams.Create clParams) {
return Observable.fromCallable(()->clientCreate(company, clParams));
}

}


Expand Down Expand Up @@ -350,6 +424,10 @@ public Resource resourceRead(Company company, String resourceId) throws IOExcept
return new Resource(httpService().api_GET(url));
}

public Observable<Resource> 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
Expand All @@ -365,6 +443,10 @@ public BBCollection<Resource> resourceList(Company company, Params rlParams) thr
return resources;
}

public Observable<BBCollection<Resource>> resourceListObs(final Company company, final Params rlParams) {
return Observable.fromCallable(()->resourceList(company, rlParams));
}

/**
* Create a new resource
* @param company the company for resource
Expand All @@ -379,6 +461,10 @@ public Resource resourceCreate(Company company, ResourceParams.Create rcParams)
return new Resource(httpService().api_POST(url, rcParams.getParams()));
}

public Observable<Resource> resourceCreateObs(final Company company, final ResourceParams.Create rcParams) {
return Observable.fromCallable(()->resourceCreate(company, rcParams));
}

/**
* Update a resource
* @param resource the resource to update
Expand All @@ -393,6 +479,10 @@ public Resource resourceUpdate(Resource resource, ResourceParams.Update ruParams
return new Resource(httpService().api_PUT(url, ruParams.getParams()));
}

public Observable<Resource> 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
Expand All @@ -404,6 +494,10 @@ public SchemaForm getNewResourceSchema(Company company) throws IOException {
return new SchemaForm(httpService().api_GET(url));
}

public Observable<SchemaForm> getNewResourceSchemaObs(final Company company) {
return Observable.fromCallable(()->getNewResourceSchema(company));
}

/**
* Get the schema for editing a resource
* @param resource The resource to edit
Expand All @@ -415,6 +509,10 @@ public SchemaForm getEditResourceSchema(Resource resource) throws IOException {
return new SchemaForm(httpService().api_GET(url));
}

public Observable<SchemaForm> getEditResourceSchemaObs(final Resource resource) {
return Observable.fromCallable(()->getEditResourceSchema(resource));
}

//TODO: Add block and schedule calls
}
}

0 comments on commit 9b87489

Please sign in to comment.