11
11
#import " YLPCoordinate.h"
12
12
#import " YLPGeoBoundingBox.h"
13
13
#import " YLPGeoCoordinate.h"
14
+ #import " YLPQuery.h"
15
+ #import " YLPQueryPrivate.h"
14
16
#import " YLPResponsePrivate.h"
15
17
#import " YLPClientPrivate.h"
16
18
17
19
@implementation YLPClient (Search)
18
20
19
21
- (void )searchWithLocation : (NSString *)location
20
22
completionHandler : (YLPSearchCompletionHandler)completionHandler {
21
-
22
- NSDictionary *params = @{@" location" : location};
23
- [self searchWithParams: params completionHandler: completionHandler];
23
+ YLPQuery *query = [[YLPQuery alloc ] initWithLocation: location currentLatLong: nil ];
24
+ [self searchWithQuery: query completionHandler: completionHandler];
24
25
}
25
26
26
27
- (void )searchWithLocation : (NSString *)location
@@ -30,9 +31,12 @@ - (void)searchWithLocation:(NSString *)location
30
31
offset : (NSUInteger )offset
31
32
sort : (YLPSortType)sort
32
33
completionHandler : (YLPSearchCompletionHandler)completionHandler {
33
-
34
- NSMutableDictionary *params = [[NSMutableDictionary alloc ] initWithDictionary: @{@" location" : location}];
35
- [self buildParamsAndCallSearch: params currentLatLong: cll term: term limit: limit offset: offset sort: sort completionHandler: completionHandler];
34
+ YLPQuery *query = [[YLPQuery alloc ] initWithLocation: location currentLatLong: cll];
35
+ query.term = term;
36
+ query.limit = limit;
37
+ query.offset = offset;
38
+ query.sort = sort;
39
+ [self searchWithQuery: query completionHandler: completionHandler];
36
40
}
37
41
38
42
- (void )searchWithBounds : (YLPGeoBoundingBox *)bounds
@@ -41,15 +45,19 @@ - (void)searchWithBounds:(YLPGeoBoundingBox *)bounds
41
45
offset : (NSUInteger )offset
42
46
sort : (YLPSortType)sort
43
47
completionHandler : (YLPSearchCompletionHandler)completionHandler {
44
-
45
- NSMutableDictionary *params = [[NSMutableDictionary alloc ] initWithDictionary: @{@" bounds" : bounds.description }];
46
- [self buildParamsAndCallSearch: params currentLatLong: cll term: term limit: limit offset: offset sort: sort completionHandler: completionHandler];
48
+ YLPQuery *query = [[YLPQuery alloc ] initWithBounds: bounds];
49
+ query.currentLatLong = cll;
50
+ query.term = term;
51
+ query.limit = limit;
52
+ query.offset = offset;
53
+ query.sort = sort;
54
+ [self searchWithQuery: query completionHandler: completionHandler];
47
55
}
48
56
49
57
- (void )searchWithBounds : (YLPGeoBoundingBox *)bounds
50
58
completionHandler : (YLPSearchCompletionHandler)completionHandler {
51
-
52
- [self searchWithBounds: bounds currentLatLong: nil term: nil limit: 0 offset: 0 sort: 0 completionHandler: completionHandler];
59
+ YLPQuery *query = [[YLPQuery alloc ] initWithBounds: bounds];
60
+ [self searchWithQuery: query completionHandler: completionHandler];
53
61
}
54
62
55
63
- (void )searchWithGeoCoordinate : (YLPGeoCoordinate *)geoCoordinate
@@ -58,63 +66,28 @@ - (void)searchWithGeoCoordinate:(YLPGeoCoordinate *)geoCoordinate
58
66
offset : (NSUInteger )offset
59
67
sort : (YLPSortType)sort
60
68
completionHandler : (YLPSearchCompletionHandler)completionHandler {
61
-
62
- NSMutableDictionary *params = [[NSMutableDictionary alloc ] initWithDictionary: @{@" ll" : geoCoordinate.description }];
63
- [self buildParamsAndCallSearch: params currentLatLong: cll term: term limit: limit offset: offset sort: sort completionHandler: completionHandler];
69
+ YLPQuery *query = [[YLPQuery alloc ] initWithGeoCoordinate: geoCoordinate];
70
+ query.currentLatLong = cll;
71
+ query.term = term;
72
+ query.limit = limit;
73
+ query.offset = offset;
74
+ query.sort = sort;
75
+ [self searchWithQuery: query completionHandler: completionHandler];
64
76
}
65
77
66
- - (void )searchWithGeoCoordinate : (YLPGeoCoordinate *)geoCoordiante
78
+ - (void )searchWithGeoCoordinate : (YLPGeoCoordinate *)geoCoordinate
67
79
completionHandler : (YLPSearchCompletionHandler)completionHandler {
68
-
69
- [self searchWithGeoCoordinate: geoCoordiante currentLatLong: nil term: nil limit: 0 offset: 0 sort: 0 completionHandler: completionHandler];
70
- }
71
-
72
- - (void )buildParamsAndCallSearch : (NSMutableDictionary *)params
73
- currentLatLong : (YLPCoordinate *)cll
74
- term : (NSString *)term
75
- limit : (NSUInteger )limit
76
- offset : (NSUInteger )offset
77
- sort : (YLPSortType)sort
78
- completionHandler : (YLPSearchCompletionHandler)completionHandler {
79
-
80
- [params addEntriesFromDictionary: [self paramsWithTerm: term currentLatLong: cll limit: limit offset: offset sort: sort]];
81
- [self searchWithParams: params completionHandler: completionHandler];
82
- }
83
-
84
- - (NSDictionary *)paramsWithTerm : (NSString *)term
85
- currentLatLong : (YLPCoordinate *)cll
86
- limit : (NSUInteger )limit
87
- offset : (NSUInteger )offset
88
- sort : (YLPSortType)sort {
89
-
90
- NSMutableDictionary *params = [[NSMutableDictionary alloc ] init ];
91
-
92
- if (cll) {
93
- params[@" cll" ] = cll.description ;
94
- }
95
- if (term) {
96
- params[@" term" ] = term;
97
- }
98
- if (limit) {
99
- params[@" limit" ] = [NSNumber numberWithInteger: limit];
100
- }
101
- if (offset) {
102
- params[@" offset" ] = [NSNumber numberWithInteger: offset];
103
- }
104
- if (sort) {
105
- params[@" sort" ] = [NSNumber numberWithInteger: sort];
106
- }
107
-
108
- return params;
80
+ YLPQuery *query = [[YLPQuery alloc ] initWithGeoCoordinate: geoCoordinate];
81
+ [self searchWithQuery: query completionHandler: completionHandler];
109
82
}
110
83
111
84
- (NSURLRequest *)searchRequestWithParams : (NSDictionary *)params {
112
85
return [self requestWithPath: @" /v2/search/" params: params];
113
86
}
114
87
115
- - (void )searchWithParams : ( NSDictionary *)params
116
- completionHandler : (YLPSearchCompletionHandler)completionHandler {
117
-
88
+ - (void )searchWithQuery : (YLPQuery *)query
89
+ completionHandler : (YLPSearchCompletionHandler)completionHandler {
90
+ NSDictionary *params = [query parameters ];
118
91
NSURLRequest *req = [self searchRequestWithParams: params];
119
92
120
93
[self queryWithRequest: req completionHandler: ^(NSDictionary *responseDict, NSError *error) {
0 commit comments