Created
July 7, 2012 19:29
-
-
Save ruckus/3067798 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| #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]); | |
| } | |
| ]; | |
| } |
This file contains hidden or 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
| @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