Skip to content

Instantly share code, notes, and snippets.

@ruckus
Created July 7, 2012 19:29
Show Gist options
  • Select an option

  • Save ruckus/3067798 to your computer and use it in GitHub Desktop.

Select an option

Save ruckus/3067798 to your computer and use it in GitHub Desktop.
#import "Account.h"
#import "JSONKit.h"
@implementation Account
@synthesize name = _name;
@synthesize accountId = _accountId;
@synthesize initial = _initial;
@synthesize code = _code;
@synthesize tastingHours = _tastingHours;
@synthesize abcNo = _abcNo;
@synthesize taxIdNo = _taxIdNo;
@synthesize deliveryRestrictions = _deliveryRestrictions;
@synthesize resaleNum = _resaleNum;
@synthesize website = _website;
#pragma mark - Networking
+ (void)findById:(NSInteger)accountId block:(void (^)(Account *account))block
{
NSString *url = [[[NSString alloc] initWithFormat:@"/api/accounts/%d", accountId] autorelease];
NSMutableDictionary *params = [[[NSMutableDictionary alloc] init] autorelease];
[[AFVinosmithAPIClient sharedClient] getPath:url parameters:params
success:^(AFHTTPRequestOperation *operation, id JSON) {
JSONDecoder* decoder = [[JSONDecoder alloc]
initWithParseOptions:JKParseOptionNone];
NSDictionary *resultsDictionary = [decoder objectWithData:[operation responseData]];
NSDictionary *attributes = [resultsDictionary objectForKey:@"account"];
Account *account = [[Account alloc] initWithAttributes:attributes];
[decoder release];
if(block) {
block(account);
}
}
failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"ERROR: %@", [operation responseString]);
}
];
}
@implementation AccountViewController
- (void) fetchAccount
{
[Account findById:[self accountId] block:^(Account *account) {
if(account) {
// do something with your Account object
}
}];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment