-
Notifications
You must be signed in to change notification settings - Fork 0
/
brewerydbconnect.m
102 lines (65 loc) · 3.08 KB
/
brewerydbconnect.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
//
// brewerydbconnect.m
// Beer.io
//
// Created by AJ DaNelz on 8/23/13.
// Copyright (c) 2013 Tony Winters. All rights reserved.
//
#import "brewerydbconnect.h"
#define apiKey @"fb8684f5499a9dad231f262efca6b2f5"
@implementation brewerydbconnect
- (NSString *) getResponse:(NSString *) url{
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setHTTPMethod:@"GET"];
[request setURL:[NSURL URLWithString:url]];
NSLog(url);
NSError *error = [[NSError alloc] init];
NSHTTPURLResponse *responseCode = nil;
NSData *oResponseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&responseCode error:&error];
if([responseCode statusCode] != 200){
NSLog(@"Error getting %@, HTTP status code %i", url, [responseCode statusCode]);
return nil;
}
return [[NSString alloc] initWithData:oResponseData encoding:NSUTF8StringEncoding];
}
- (NSString *) getLocations:(NSString *)city withRegion:(NSString *)region{
NSString *url = [NSString stringWithFormat:@"http://api.brewerydb.com/v2/locations?key=%@&locality=%@®ion=%@",apiKey, city, region];
return [self getResponse:url];
}
- (NSString *) getLocations:(NSString *)region{
NSString *url = [NSString stringWithFormat:@"http://api.brewerydb.com/v2/locations?key=%@®ion=%@",apiKey, region];
return [self getResponse:url];
}
- (NSString *) getAllLocations{
NSString *url = [NSString stringWithFormat:@"http://api.brewerydb.com/v2/locations?key=%@",apiKey];
return [self getResponse:url];
}
- (NSString *) getAllLocations: (int)page{
NSString *url = [NSString stringWithFormat:@"http://api.brewerydb.com/v2/locations?key=%@&p=%i",apiKey, page];
return [self getResponse:url];
}
- (NSString *) getLocation: (NSString *)locationId{
NSString *url = [NSString stringWithFormat:@"http://api.brewerydb.com/v2/location/%@?key=%@", locationId,apiKey];
return [self getResponse:url];
}
- (NSString *) searchBrewerys: (NSString *)query{
NSString *url = [NSString stringWithFormat:@"http://api.brewerydb.com/v2/search?key=%@&q=%@", apiKey, query];
return [self getResponse:url];
}
- (NSString *) getBrewery: (NSString *)brewId{
NSString *url = [NSString stringWithFormat:@"http://api.brewerydb.com/v2/brewery/%@?key=%@", brewId, apiKey];
return [self getResponse:url];
}
- (NSString *) getBreweryBeers: (NSString *)brewId{
NSString *url = [NSString stringWithFormat:@"http://api.brewerydb.com/v2/brewery/%@/beers?key=%@", brewId, apiKey];
return [self getResponse:url];
}
- (NSString *) getCityState:(float)lat withLon:(float)lon{
NSString *url = [NSString stringWithFormat:@"http://maps.googleapis.com/maps/api/geocode/json?latlng=%f,%f&sensor=false", lat, lon];
return [self getResponse:url];
}
- (NSString *) getCityState:(NSString *)q{
NSString *url = [NSString stringWithFormat:@"http://maps.googleapis.com/maps/api/geocode/json?address=%@&sensor=false", q];
return [self getResponse:url];
}
@end