-
Notifications
You must be signed in to change notification settings - Fork 0
/
AFFoursquareClient.m
57 lines (50 loc) · 1.86 KB
/
AFFoursquareClient.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// FSClient.m
//
// Created by Dmitry Shmidt on 11/24/12.
// MIT license
#import "AFFoursquareClient.h"
#import "AFJSONRequestOperation.h"
@implementation AFFoursquareClient
+ (AFFoursquareClient *)sharedClient {
static AFFoursquareClient *_sharedClient = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
_sharedClient = [[AFFoursquareClient alloc] initWithBaseURL:[NSURL URLWithString:kAPIBaseURLString]];
});
return _sharedClient;
}
- (id)initWithBaseURL:(NSURL *)url {
self = [super initWithBaseURL:url];
if (!self) {
return nil;
}
[self registerHTTPOperationClass:[AFJSONRequestOperation class]];
// Accept HTTP Header; see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.1
[self setDefaultHeader:@"Accept" value:@"application/json"];
// [self setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
// NSLog(@"changed %d", status);
// //your code here
// }];
return self;
}
- (void)exploreVenues:(void (^)(NSArray *venues))success inRadius:(int)radiusMeters coordinate:(CLLocationCoordinate2D)coordinate failure:(void (^)(NSError *error))failure{
[self getPath:@"venues/explore" parameters:@{
@"limit": @"10",
@"client_id":kFoursquareClientID,
@"client_secret":kFoursquareClientSecret,
@"radius":@(radiusMeters).stringValue,
@"ll":[NSString stringWithFormat:@"%g,%g",coordinate.latitude, coordinate.longitude],
@"v":kFoursquareVersion
} success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSArray *items = responseObject[@"response"][@"groups"][0][@"items"];
if (success)
{
success(items);
}
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
if (failure) {
failure(error);
}
}];
}
@end