@@ -13,6 +13,7 @@ typedef NS_ENUM(NSUInteger, CTVViewControllerSection) {
13
13
CTVViewControllerSectionHistoricalPrices = 1
14
14
};
15
15
16
+
16
17
@implementation CTCViewController
17
18
18
19
- (void )viewDidLoad {
@@ -110,4 +111,127 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
110
111
return cell;
111
112
}
112
113
114
+
115
+ #pragma mark - JSON responses
116
+
117
+ - (NSString *)jsonStringForResponse : (NSUInteger )responseIndex {
118
+ switch (responseIndex) {
119
+ case 0 :
120
+ default :
121
+ /* Response A: happy path
122
+
123
+ {
124
+ "description":"7/11 Fake St.",
125
+ "price":3.50,
126
+ "sellsDiesel": true,
127
+ "address": {
128
+ "street":"123 Fake Street",
129
+ "city":"Newark",
130
+ "state":"NJ",
131
+ "zip":"07105"
132
+ },
133
+ "historicalPrices":[
134
+ {
135
+ "date":"2013-02-18T15:43:24-05:00",
136
+ "price":4.60
137
+ }
138
+ ]
139
+ }
140
+
141
+ */
142
+
143
+ return @" { \" description\" :\" 7/11 Fake St.\" , \" price\" :3.50, \" sellsDiesel\" : true, \" address\" : { \" street\" :\" 123 Fake Street\" , \" city\" :\" Newark\" , \" state\" :\" NJ\" , \" zip\" :\" 07105\" }, \" historicalPrices\" :[ { \" date\" :\" 2013-02-18T15:43:24-05:00\" , \" price\" :4.60 } ] }" ;
144
+
145
+ case 1 :
146
+ /* Response B: price & sellsDiesel are strings, zip is an integer
147
+
148
+ {
149
+ "description":"7/11 Fake St.",
150
+ "price":"$3.50",
151
+ "sellsDiesel": "yes",
152
+ "address": {
153
+ "street":"123 Fake Street",
154
+ "city":"Newark",
155
+ "state":"NJ",
156
+ "zip":7105
157
+ },
158
+ "historicalPrices":[
159
+ {
160
+ "date":"2013-02-18T15:43:24-05:00",
161
+ "price":"$4.60"
162
+ }
163
+ ]
164
+ }
165
+
166
+ */
167
+
168
+ return @" { \" description\" :\" 7/11 Fake St.\" , \" price\" :\" $3.50\" , \" sellsDiesel\" : \" yes\" , \" address\" : { \" street\" :\" 123 Fake Street\" , \" city\" :\" Newark\" , \" state\" :\" NJ\" , \" zip\" :7105 }, \" historicalPrices\" :[ { \" date\" :\" 2013-02-18T15:43:24-05:00\" , \" price\" :\" $4.60\" } ] }" ;
169
+
170
+
171
+ case 2 :
172
+ /* Response C: price & sellsDiesel are integers, historicalPrices/price is a decimal, date is a UNIX timestamp
173
+
174
+ {
175
+ "description":"7/11 Fake St.",
176
+ "price":4,
177
+ "sellsDiesel": 1,
178
+ "address": {
179
+ "street":"123 Fake Street",
180
+ "city":"Newark",
181
+ "state":"NJ",
182
+ "zip":7105
183
+ },
184
+ "historicalPrices":[
185
+ {
186
+ "date":1361202204,
187
+ "price":4.6
188
+ }
189
+ ]
190
+ }
191
+
192
+ */
193
+
194
+ return @" { \" description\" :\" 7/11 Fake St.\" , \" price\" :4, \" sellsDiesel\" : 1, \" address\" : { \" street\" :\" 123 Fake Street\" , \" city\" :\" Newark\" , \" state\" :\" NJ\" , \" zip\" :7105 }, \" historicalPrices\" :[ { \" date\" :1361202204, \" price\" :4.6 } ] }" ;
195
+
196
+
197
+ case 3 :
198
+ /* Response D: historicalPrices is a dictionary instead of an array
199
+
200
+ {
201
+ "description":"7/11 Fake St.",
202
+ "price":3.50,
203
+ "sellsDiesel": true,
204
+ "address": {
205
+ "street":"123 Fake Street",
206
+ "city":"Newark",
207
+ "state":"NJ",
208
+ "zip":"07105"
209
+ },
210
+ "historicalPrices":{
211
+ "date":"2013-02-18T15:43:24-05:00",
212
+ "price":4.60
213
+ }
214
+ }
215
+
216
+ */
217
+
218
+ return @" { \" description\" :\" 7/11 Fake St.\" , \" price\" :3.50, \" sellsDiesel\" : true, \" address\" : { \" street\" :\" 123 Fake Street\" , \" city\" :\" Newark\" , \" state\" :\" NJ\" , \" zip\" :\" 07105\" }, \" historicalPrices\" :{ \" date\" :\" 2013-02-18T15:43:24-05:00\" , \" price\" :4.60 } }" ;
219
+
220
+ case 4 :
221
+ /* Response E: description, price and sellsDiesel are null; address and historicalPrices are strings
222
+
223
+ {
224
+ "description":null,
225
+ "price":null,
226
+ "sellsDiesel": null,
227
+ "address":"error looking up address",
228
+ "historicalPrices":"error fetching prices"
229
+ }
230
+
231
+ */
232
+
233
+ return @" { \" description\" :null, \" price\" :null, \" sellsDiesel\" : null, \" address\" :\" error looking up address\" , \" historicalPrices\" :\" error fetching prices\" }" ;
234
+ }
235
+ }
236
+
113
237
@end
0 commit comments