CoreCloud is a project mainly written in JAVASCRIPT and OBJECTIVE-C, it's free.
Library (Mac & iPhone) for developing an application connected to the web (REST, OAuth, HTTP Basic, ...)
== Installation CoreCloud is compiled as a static library, and the easiest way to add it to your project is to use Xcode’s “dependent project” facilities. Here is how:
Clone the repository (and its submodules in lib/ !) and make sure you store it in a permanent place, because Xcode will need to reference the files every time you compile your project.
Tell your project where to find the CoreCloud headers:
While you are in Project Settings, go to “Other Linker Flags” under the “Linker” section, and add “-ObjC” and “-all_load” to the list of flags. You’re ready to go. Just #import “CoreCloud/CoreCloud.h” anywhere you want to use CoreCloud classes in your project.
== Usage CoreCloud is based on an engine chain. The order you build your chain is important.
(void)setUpCoreCloud { //This engine will define the correct URL, according your Routes.plist CCRoutesEngine routesEngine; NSURL routesURL= [[NSBundle mainBundle] URLForResource:@"Routes" withExtension:@"plist"]; routesEngine= [[CCRoutesEngine alloc] initWithRoutesURL:routesURL]; [[CCManager defaultConfiguration] addEngine:routesEngine withKey:@"RouteEngine"]; [routesEngine release];
//This engine will eventually convert the objects your POSTing into NSDictionary CCDictionarizerEngine *dictionarizerEngine; dictionarizerEngine= [[CCDictionarizerEngine alloc] initWithLocalPrefix:@"S"]; [[CCManager defaultConfiguration] addEngine:dictionarizerEngine withKey:@"DictionarizerEngine"]; [dictionarizerEngine release];
//This engine will convert the previous dictionary into JSON CCJSONEngine *JSONEngine; JSONEngine= [[CCJSONEngine alloc] init]; [[CCManager defaultConfiguration] addEngine:JSONEngine withKey:@"JSONEngine"]; [JSONEngine release];
//This engine will add the authentication elements on the request CCHTTPBasicAuthenticationEngine *HTTPBasicEngine; HTTPBasicEngine= [[CCHTTPBasicAuthenticationEngine alloc] init]; [[CCManager defaultConfiguration] addEngine:HTTPBasicEngine withKey:@"HTTPBasicEngine"]; [HTTPBasicEngine release]; }
(void)applicationDidFinishLaunching:(UIApplication *)application { [self setUpCoreCloud]; }
Engines are used in the order you declared it for a request, and reversed order for responses. An engine is a simple class implementing the following protocol:
@protocol CCEngine
@required
(void)processResponse:(NSHTTPURLResponse *)response withParams:(NSDictionary )params andData:(id *)data;
@end
Once you've configured CoreCloud, your interlocutor will be CCManager:
(void)loadUsers:(id)sender { NSMutableURLRequest *request; request= [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"user#index"]]; [[CCManager defaultConfiguration] sendRequest:request withParams:nil andDelegate:self]; }
(void)request:(NSMutableURLRequest *)request didSucceedWithData:(id)data { // data usage }
(void)request:(NSMutableURLRequest )request didFailWithError:(NSError )error { // error handling }
That's it, we've just obtained an array of objects from the cloud.
More documentation coming soon.