Last active
February 23, 2016 05:57
-
-
Save pavangandhi/b6649bce6e47603b1ad7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (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