TestsTested | ✗ |
LangLanguage | Obj-CObjective C |
License | MIT |
ReleasedLast Release | May 2015 |
Maintained by Heather Snepenger, Brian Weinreich.
To run the example project, clone the repo, and run pod install
from the Example directory first.
iOS 7 or greater
RObot is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod "RoundedRobot"
RObot a stand alone libraby that handles CRUD methods for NSManagedObjects
. Calling create, read, update, delete, or index, will make the API and update the database appropriately.
To begin, call this line:
[ROBotManager initializeWithBaseURL:@"https://your_base_url"];
If you plan on using the index methods or caching, you'll also need to set your persistent store coordinator:
[ROBotManager sharedInstance].persistentStoreCoordinator = [self persistentStoreCoordinator];
Next, #import "ROBot.h"
into the classes you plan on using ROBot in.
You'll need to override the CRUD urls in your NSManagedObject
(or corresponding catorgory). Ex:
+ (NSString *)indexURL
{
return @"/users";
}
- (NSString *)createURL
{
return @"/users";
}
- (NSString *)readURL
{
return [NSString stringWithFormat:@"/users/%@", self.user_id];
}
- (NSString *)updateURL
{
return [NSString stringWithFormat:@"/users/%@", self.user_id];
}
Note that the url path are instance methods, and will populate the variables in the url string when the url methods is called.
You can then call CRUD methods on the instances of the model, and the changes will be made to your database and API.
Get all Users:
[User index:^{} failure:^(ROBotError *error) {}];
Create Example:
WRUser *user = [NSEntityDescription insertNewObjectForEntityForName:@"WRUser" inManagedObjectContext:[NSManagedObjectContext MR_defaultContext]];
user.fname = @"Heather";
user.lname = @"Sneps";
[user create:^{} failure:^(ROBotError *error) {}]
You can specify a custom mapping from the API response to the database object. If you don't specify a mapping, RObot will map the results from the API directly to the corresponding fields in your database.
To specify a mapping, do the following:
[User setMapping:@[@"last_name": @"lname", @"first_name": @"fname"]];
Note that a partial mapping can be used. In the case above, the email will still map to email.
By default, logging is disabled. To enable logging for all your ROBotManagedObjects
, use
ROBotManagedObject.verboseLogging = true
to enable logging for a single ROBotManagedObject
class, use
User.verboseLogging = true
We're working on the following:
Feel free to submit a pull request and add your own contributions!
Heather Snepenger, [email protected]
RObot is available under the MIT license. See the LICENSE file for more info.