Last active
December 11, 2015 06:29
-
-
Save rscarvalho/4559837 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 <Foundation/Foundation.h> | |
| #import "AFNetworking.h" | |
| @interface WPApi : AFHTTPClient | |
| + (WPApi *)sharedApi; | |
| - (void)getPostsWithSuccess:(void (^)(NSArray *))successBlock | |
| failure:(void (^)(NSError *))failureBlock; | |
| @end |
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 "WPApi.h" | |
| #define WP_ATOM_BASE_URL @"http://en.blog.wordpress.com" | |
| @implementation WPApi | |
| +(WPApi *)sharedApi | |
| { | |
| static WPApi *__sharedInstance; | |
| static dispatch_once_t onceToken; | |
| dispatch_once(&onceToken, ^{ | |
| __sharedInstance = [[WPApi alloc] initWithBaseURL:[NSURL URLWithString:WP_ATOM_BASE_URL]]; | |
| }); | |
| return __sharedInstance; | |
| } | |
| - (void)getPostsWithSuccess:(void (^)(NSArray *))successBlock | |
| failure:(void (^)(NSError *))failureBlock | |
| { | |
| [self getPath:@"feed/atom/" parameters:nil | |
| success:^(AFHTTPRequestOperation *operation, id responseObject) { | |
| if (successBlock) { | |
| // parse Atom XML Response | |
| } | |
| } | |
| failure:^(AFHTTPRequestOperation *operation, NSError *error) { | |
| if (failureBlock) { | |
| failureBlock(error); | |
| } | |
| }]; | |
| } | |
| @end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment