66import com .damnhandy .uri .template .UriTemplate ;
77import helpers .Http ;
88import helpers .Utils ;
9+ import rx .Observable ;
910
1011import java .io .IOException ;
1112import java .net .URL ;
13+ import java .util .concurrent .Callable ;
1214
1315
1416public class AdminAPI extends AbstractAPI {
@@ -45,6 +47,10 @@ public BBCollection<Booking> bookingList(Company company, BookingListParams bLPa
4547 return bookings ;
4648 }
4749
50+ public Observable <BBCollection <Booking >> bookingListObs (final Company company , final BookingListParams bLParams ) {
51+ return Observable .fromCallable (() -> bookingList (company , bLParams ));
52+ }
53+
4854 /**
4955 * Get all details about a specific booking
5056 * @param company the company owning the booking
@@ -60,6 +66,10 @@ public Booking bookingRead(Company company, String bookingId) throws IOException
6066 return new Booking (httpService ().api_GET (url ));
6167 }
6268
69+ public Observable <Booking > bookingReadObs (final Company company , final String bookingId ) {
70+ return Observable .fromCallable (()->bookingRead (company , bookingId ));
71+ }
72+
6373 /**
6474 * Get the edit schema for booking
6575 * @param booking
@@ -70,6 +80,10 @@ public SchemaForm getEditBookingSchema(Booking booking) throws IOException {
7080 URL url = new URL (UriTemplate .fromTemplate (booking .getEditLink ()).expand ());
7181 return new SchemaForm (httpService ().api_GET (url ));
7282 }
83+
84+ public Observable <SchemaForm > getEditBookingSchemaObs (final Booking booking ) {
85+ return Observable .fromCallable (()->getEditBookingSchema (booking ));
86+ }
7387 }
7488
7589
@@ -99,6 +113,10 @@ public Company companyRead(String companyId) throws IOException {
99113 return new Company (httpService ().api_GET (url ));
100114 }
101115
116+ public Observable <Company > companyReadObs (final String companyId ) {
117+ return Observable .fromCallable (()->companyRead (companyId ));
118+ }
119+
102120 }
103121
104122
@@ -132,6 +150,10 @@ public BBCollection<Service> serviceList(Company company, ServiceListParams slPa
132150 return services ;
133151 }
134152
153+ public Observable <BBCollection <Service >> serviceListObs (final Company company , final ServiceListParams slParams ){
154+ return Observable .fromCallable (()->serviceList (company , slParams ));
155+ }
156+
135157 /**
136158 * Load a Specific Service Details
137159 * @param company The owning company for service
@@ -147,6 +169,10 @@ public Service serviceRead(Company company, String serviceId) throws IOException
147169 return new Service (httpService ().api_GET (url ));
148170 }
149171
172+ public Observable <Service > serviceReadObs (final Company company , final String serviceId ) {
173+ return Observable .fromCallable (()->serviceRead (company , serviceId ));
174+ }
175+
150176 /**
151177 * Get schema for creating a new service
152178 * @param company The owning company
@@ -158,6 +184,10 @@ public SchemaForm getNewServiceSchema(Company company) throws IOException {
158184 return new SchemaForm (httpService ().api_GET (url ));
159185 }
160186
187+ public Observable <SchemaForm > getNewServiceSchemaObs (final Company company ) {
188+ return Observable .fromCallable (()->getNewServiceSchema (company ));
189+ }
190+
161191 /**
162192 * Create a service
163193 * @param company the company to own the service
@@ -172,6 +202,10 @@ public Service serviceCreate(Company company, ServiceParams.ServiceCreateParams
172202 return new Service (httpService ().api_POST (url , sCParams .getParams ()));
173203 }
174204
205+ public Observable <Service > serviceCreateObs (final Company company , final ServiceParams .ServiceCreateParams sCParams ) {
206+ return Observable .fromCallable (()->serviceCreate (company , sCParams ));
207+ }
208+
175209 /**
176210 * Update a service
177211 * @param service the service to update
@@ -186,6 +220,10 @@ public Service serviceUpdate(Service service, ServiceParams.ServiceUpdateParams
186220 return new Service (httpService ().api_POST (url , sUParams .getParams ()));
187221 }
188222
223+ public Observable <Service > serviceUpdateObs (final Service service , final ServiceParams .ServiceUpdateParams sUParams ) {
224+ return Observable .fromCallable (()->serviceUpdate (service , sUParams ));
225+ }
226+
189227 /**
190228 * Get a schema for creating a new booking with provided service
191229 * @param service The service
@@ -197,6 +235,10 @@ public SchemaForm getNewBookingSchema(Service service) throws IOException {
197235 return new SchemaForm (httpService ().api_GET (url ));
198236 }
199237
238+ public Observable <SchemaForm > getNewBookingSchemaObs (final Service service ) {
239+ return Observable .fromCallable (()->getNewBookingSchema (service ));
240+ }
241+
200242 /**
201243 * Get a schema for editing a service
202244 * @param service The service to be edited
@@ -207,6 +249,10 @@ public SchemaForm getEditServiceSchema(Service service) throws IOException {
207249 URL url = new URL (UriTemplate .fromTemplate (service .getEditLink ()).expand ());
208250 return new SchemaForm (httpService ().api_GET (url ));
209251 }
252+
253+ public Observable <SchemaForm > getEditServiceSchemaObs (final Service service ) {
254+ return Observable .fromCallable (()->getEditServiceSchema (service ));
255+ }
210256 }
211257
212258
@@ -240,6 +286,10 @@ public BBCollection<Client> clientList(Company company, Params clParams) throws
240286 return clients ;
241287 }
242288
289+ public Observable <BBCollection <Client >> clientListObs (final Company company , final Params clParams ) {
290+ return Observable .fromCallable (()->clientList (company , clParams ));
291+ }
292+
243293 /**
244294 * Load a specific client details
245295 * @param company The owning company for client
@@ -255,6 +305,10 @@ public Client clientRead(Company company, String clientId) throws IOException {
255305 return new Client (httpService ().api_GET (url ));
256306 }
257307
308+ public Observable <Client > clientReadObs (final Company company , final String clientId ) {
309+ return Observable .fromCallable (()->clientRead (company , clientId ));
310+ }
311+
258312 /**
259313 * Load a specific client details
260314 * @param company The owning company for client
@@ -267,6 +321,10 @@ public Client clientReadByEmail(Company company, String email) throws IOExceptio
267321 return new Client (httpService ().api_GET (url ));
268322 }
269323
324+ public Observable <Client > clientReadByEmailObs (final Company company , final String email ) {
325+ return Observable .fromCallable (()->clientReadByEmail (company , email ));
326+ }
327+
270328 /**
271329 * Get the schema for editing a client
272330 * @param client The client to edit
@@ -278,6 +336,10 @@ public SchemaForm getEditClientSchema(Client client) throws IOException {
278336 return new SchemaForm (httpService ().api_GET (url ));
279337 }
280338
339+ public Observable <SchemaForm > getEditClientSchemaObs (final Client client ) {
340+ return Observable .fromCallable (()->getEditClientSchema (client ));
341+ }
342+
281343 /**
282344 * Enable/Disable specific client
283345 * @param company The company for the client
@@ -290,6 +352,10 @@ public Client clientEnableDisable(Company company, ClientToggleParams ctParams)
290352 return new Client (httpService ().api_PUT (url , Http .urlEncodedContentType , ctParams .getParams ()));
291353 }
292354
355+ public Observable <Client > clientEnableDisableObs (final Company company , final ClientToggleParams ctParams ) {
356+ return Observable .fromCallable (()->clientEnableDisable (company , ctParams ));
357+ }
358+
293359 /**
294360 * Update a client
295361 * @param client the client to update
@@ -304,6 +370,10 @@ public Client clientUpdate(Client client, ClientParams.Update cuParams) throws I
304370 return new Client (httpService ().api_PUT (url , cuParams .getParams ()));
305371 }
306372
373+ public Observable <Client > clientUpdateObs (final Client client , final ClientParams .Update cuParams ) {
374+ return Observable .fromCallable (()->clientUpdate (client , cuParams ));
375+ }
376+
307377 /**
308378 * Create a client
309379 * @param company the company for client
@@ -318,6 +388,10 @@ public Client clientCreate(Company company, ClientParams.Create clParams) throws
318388 return new Client (httpService ().api_POST (url , clParams .getParams ()));
319389 }
320390
391+ public Observable <Client > clientCreateObs (final Company company , final ClientParams .Create clParams ) {
392+ return Observable .fromCallable (()->clientCreate (company , clParams ));
393+ }
394+
321395 }
322396
323397
@@ -350,6 +424,10 @@ public Resource resourceRead(Company company, String resourceId) throws IOExcept
350424 return new Resource (httpService ().api_GET (url ));
351425 }
352426
427+ public Observable <Resource > resourceReadObs (final Company company , final String resourceId ) {
428+ return Observable .fromCallable (()->resourceRead (company , resourceId ));
429+ }
430+
353431 /**
354432 * List of Resources for a company. Results are returned as a paginated list
355433 * @param company The owning company for services
@@ -365,6 +443,10 @@ public BBCollection<Resource> resourceList(Company company, Params rlParams) thr
365443 return resources ;
366444 }
367445
446+ public Observable <BBCollection <Resource >> resourceListObs (final Company company , final Params rlParams ) {
447+ return Observable .fromCallable (()->resourceList (company , rlParams ));
448+ }
449+
368450 /**
369451 * Create a new resource
370452 * @param company the company for resource
@@ -379,6 +461,10 @@ public Resource resourceCreate(Company company, ResourceParams.Create rcParams)
379461 return new Resource (httpService ().api_POST (url , rcParams .getParams ()));
380462 }
381463
464+ public Observable <Resource > resourceCreateObs (final Company company , final ResourceParams .Create rcParams ) {
465+ return Observable .fromCallable (()->resourceCreate (company , rcParams ));
466+ }
467+
382468 /**
383469 * Update a resource
384470 * @param resource the resource to update
@@ -393,6 +479,10 @@ public Resource resourceUpdate(Resource resource, ResourceParams.Update ruParams
393479 return new Resource (httpService ().api_PUT (url , ruParams .getParams ()));
394480 }
395481
482+ public Observable <Resource > resourceUpdateObs (final Resource resource , final ResourceParams .Update ruParams ) {
483+ return Observable .fromCallable (()->resourceUpdate (resource , ruParams ));
484+ }
485+
396486 /**
397487 * Get the schema for creating a new resource
398488 * @param company The company to own the resource
@@ -404,6 +494,10 @@ public SchemaForm getNewResourceSchema(Company company) throws IOException {
404494 return new SchemaForm (httpService ().api_GET (url ));
405495 }
406496
497+ public Observable <SchemaForm > getNewResourceSchemaObs (final Company company ) {
498+ return Observable .fromCallable (()->getNewResourceSchema (company ));
499+ }
500+
407501 /**
408502 * Get the schema for editing a resource
409503 * @param resource The resource to edit
@@ -415,6 +509,10 @@ public SchemaForm getEditResourceSchema(Resource resource) throws IOException {
415509 return new SchemaForm (httpService ().api_GET (url ));
416510 }
417511
512+ public Observable <SchemaForm > getEditResourceSchemaObs (final Resource resource ) {
513+ return Observable .fromCallable (()->getEditResourceSchema (resource ));
514+ }
515+
418516 //TODO: Add block and schedule calls
419517 }
420518}
0 commit comments