Skip to content

Instantly share code, notes, and snippets.

@pavangandhi
Last active February 23, 2016 05:57
Show Gist options
  • Save pavangandhi/b6649bce6e47603b1ad7 to your computer and use it in GitHub Desktop.
Save pavangandhi/b6649bce6e47603b1ad7 to your computer and use it in GitHub Desktop.
- (void)configureRestKit
{
// initialize AFNetworking HTTPClient
///pradeep/easygov/public/api/requests/show
NSURL *baseURL = [NSURL URLWithString:@"http://neuweg.co.in"];
//NSURL *baseURL = [NSURL URLWithString:@"http://jsonplaceholder.typicode.com"];
AFHTTPClient *client = [[AFHTTPClient alloc] initWithBaseURL:baseURL];
// initialize RestKit
RKObjectManager *objectManager = [[RKObjectManager alloc] initWithHTTPClient:client];
// setup object mappings
RKObjectMapping *venueMapping = [RKObjectMapping mappingForClass:[Venue class]];
[venueMapping addAttributeMappingsFromArray:@[@"user_id"]];
// register mappings with the provider using a response descriptor
RKResponseDescriptor *responseDescriptor =
[RKResponseDescriptor responseDescriptorWithMapping:venueMapping
method:RKRequestMethodAny
pathPattern:@"/pradeep/easygov/public/api/requests/show"
keyPath:nil
statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];
[[RKObjectManager sharedManager] addResponseDescriptor:responseDescriptor];
[self loadVenues];
}
- (void)loadVenues
{
// NSString *latLon = @"37.33,-122.03"; // approximate latLon of The Mothership (a.k.a Apple headquarters)
// NSString *clientID = kCLIENTID;
// NSString *clientSecret = kCLIENTSECRET;
//
// NSDictionary *queryParams = @{@"ll" : latLon,
// @"client_id" : clientID,
// @"client_secret" : clientSecret,
// @"categoryId" : @"4bf58dd8d48988d1e0931735",
// @"v" : @"20140118"};
/*[[RKObjectManager sharedManager] getObject:nil path:@"posts" parameters:nil success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
NSLog(@"Loaded Data Response : %@", [mappingResult array]);
} failure:^(RKObjectRequestOperation *operation, NSError *error) {
NSLog(@"What do you mean by 'there is no coffee?': %@", error);
}];*/
// POST METHOD
[[RKObjectManager sharedManager] postObject:nil path:@"/pradeep/easygov/public/api/requests/show?user_id=1" parameters:nil success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
NSError *err;
NSDictionary *dictFromData = [NSJSONSerialization JSONObjectWithData:operation.HTTPRequestOperation.responseData
options:NSJSONReadingMutableContainers
error:&err];
NSLog(@"Loaded Data Response : %@", dictFromData);
_venues = [dictFromData valueForKey:@"data"];
[self.tblData reloadData];
} failure:^(RKObjectRequestOperation *operation, NSError *error) {
NSLog(@"There was error : %@", error);
}];
// GET METHOD
/*[[RKObjectManager sharedManager] getObjectsAtPath:@"/posts"
parameters:nil
success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
NSError *err;
NSMutableArray *dictFromData = [NSJSONSerialization JSONObjectWithData:operation.HTTPRequestOperation.responseData
options:NSJSONReadingMutableContainers
error:&err];
NSLog(@"Loaded Data Response : %lu", (unsigned long)dictFromData.count);
_venues = dictFromData;
[self.tblData reloadData];
}
failure:^(RKObjectRequestOperation *operation, NSError *error) {
NSLog(@"There was error : %@", error);
}];*/
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment