Monday, September 19, 2011

Project Remote: Report 1

The mobile remote for Stoffi is now underway!

Last week
I began by researching how to best implement the low level networking and communications with the upcoming REST-api of Stoffi. I also tried several existing RESTful frameworks but found none that had the simplicity I wanted.

The last few days, I ended up creating my own set of classes to handle all of the projects networking needs. Since I knew the project would require a lot of communication with the REST api, my goal was simplicity. I wanted to be able to perform the basic CRUD (create, read, update, delete) operations with as few lines of code as possible. I decided to create a singleton class with the general networking information, such as the server base URL. This singleton class was then to be populated with methods responding to the CRUD operations. After abstracting all but the absolutely essential information of such a call I ended up with the following method:

- (RESTRequest *)get:(NSString *)path delegate:(id)delegate

The method above takes the resource path (assuming it is located on the base URL set on the singleton) and a delegate to receive call-backs once the server returns a result.
Any class that wants to communicate with the REST-api now only needs to implement two call-back methods:

- (void)restRequestDidFail
- (void)restRequestDidLoadResult:(id)jsonObject

Since all returned data is expected in JSON, any data that the json-parser (SBJSON) cannot parse will simply register as a failed call. I plan to add an error to the didFail-callback that describes what has gone wrong. In its current state, the didFail-method is called regardless of what went wrong: The device could be lacking internet connection, or the server could be returning trash.

Designing the interface of the REST communication classes without requiring the caller to care about multithreading. I think the call-back technique used makes it really easy to use while keeping it on a background thread for efficiency.

This Week
Starting today, I will begin integrating my app with the Stoffi REST-api, starting with the ability to create a user and login. I will use the classes I created last week to handle the call required to create a new user and login.

Since we are considering using OAuth to login, I think the greatest challenge this week will be understanding OAuth and integrating my own networking classes with an existing OAuth-framework.

That's all for this week, see ya'll next week! :)