gds-api-adapters 5.5.0 → 6.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,490 @@
1
+ {
2
+ "results": [
3
+ {
4
+ "id": "https://www.gov.uk/api/worldwide-organisations/uk-trade-investment-australia",
5
+ "title": "UK Trade & Investment Australia",
6
+ "format": "Worldwide Organisation",
7
+ "updated_at": "2013-04-10T13:51:59+01:00",
8
+ "web_url": "https://www.gov.uk/government/world/organisations/uk-trade-investment-australia",
9
+ "details": {
10
+ "slug": "uk-trade-investment-australia",
11
+ "summary": "UK Trade & Investment (UKTI) helps UK-based companies succeed in the global economy. We also help overseas companies bring their high-quality investment to the UK’s dynamic economy.",
12
+ "description": "<div class=\"govspeak\"><p>UKTI offers expertise and contacts through its extensive network of specialists in the UK, and in British embassies and other diplomatic offices around the world. We provide companies with the tools they require to be competitive on the world stage.</p>\n\n<h2 id=\"responsibilities\">Responsibilities</h2>\n\n<p>UKTI in Australia helps companies in Britain increase their competitiveness through overseas trade in Australia. We also offer professional, authoritative and personalised assistance to help companies in Australia locate and expand in the UK.</p>\n\n<p>You can find out more about how we are <a href=\"https://www.gov.uk/government/priority/increasing-business-with-australia\" title=\"GOV.UK website\">increasing business with Australia</a>.</p></div>",
13
+ "services": "<div class=\"govspeak\"><h2 id=\"start-a-business-in-the-uk\">Start a business in the UK</h2>\n\n<p><abbr title=\"UK Trade &amp; Investment\">UKTI</abbr> offers dedicated, professional, personalised assistance to help you locate and expand your business in the UK, <a rel=\"external\" href=\"http://www.ukti.gov.uk/invest.html?guid=none\" title=\"UKTI website\">read about our investment services</a> or contact our office in Australia to find out more.</p>\n\n<h2 id=\"export-from-the-uk\">Export from the UK</h2>\n\n<p><abbr title=\"UK Trade &amp; Investment\">UKTI</abbr> can assist you on every step of the exporting journey in both the UK and overseas, <a rel=\"external\" href=\"http://www.ukti.gov.uk/export.html\" title=\"UKTI website\">read about our exporting services</a> or contact our office in Australia.</p>\n\n<h2 id=\"events\">Events</h2>\n\n<p><abbr title=\"UK Trade &amp; Investment\">UKTI</abbr> and its partners stage events in the UK and abroad to help companies looking to export. You can <a rel=\"external\" href=\"http://www.ukti.gov.uk/export/eventssearch.html\" title=\"UKTI website\">browse scheduled events and register for alerts</a>.</p>\n\n<h2 id=\"business-opportunities\">Business opportunities</h2>\n\n<p><abbr title=\"UK Trade &amp; Investment\">UKTI</abbr> is always looking to provide an international network of opportunities for UK Companies looking to export. You can <a rel=\"external\" href=\"http://www.ukti.gov.uk/en_gb/export/howwehelp/businessopportunityalerts.html\" title=\"UKTI website\">search these opportunities and register for alerts</a>.</p></div>"
14
+ },
15
+ "offices": {
16
+ "main": {
17
+ "title": "UK Trade & Investment, Sydney",
18
+ "format": "World Office",
19
+ "updated_at": "2013-03-25T10:37:53+00:00",
20
+ "details": {
21
+ "email": "",
22
+ "description": "",
23
+ "contact_form_url": "",
24
+ "type": "Other"
25
+ },
26
+ "address": {
27
+ "adr": {
28
+ "fn": "British Consulate",
29
+ "street-address": "Level 16, Gateway Building\r\n1 Macquarie Place",
30
+ "postal-code": "2000",
31
+ "locality": "Sydney",
32
+ "region": "New South Wales",
33
+ "country-name": "Australia"
34
+ },
35
+ "label": {
36
+ "value": "British Consulate\nLevel 16, Gateway Building\r\n1 Macquarie Place\nSydney New South Wales 2000\nAustralia"
37
+ }
38
+ },
39
+ "contact_numbers": [
40
+ {
41
+ "label": "Switchboard",
42
+ "number": "+61 (0) 2 9247 7521 "
43
+ }
44
+ ],
45
+ "services": [ ]
46
+ },
47
+ "other": [
48
+ {
49
+ "title": "UK Trade & Investment Brisbane",
50
+ "format": "World Office",
51
+ "updated_at": "2013-03-25T10:37:53+00:00",
52
+ "details": {
53
+ "email": "",
54
+ "description": "",
55
+ "contact_form_url": "",
56
+ "type": "Other"
57
+ },
58
+ "address": {
59
+ "adr": {
60
+ "fn": "British Consulate",
61
+ "street-address": "Level 9, 100 Eagle Street",
62
+ "postal-code": "4000",
63
+ "locality": "Brisbane",
64
+ "region": "Queensland",
65
+ "country-name": "Australia"
66
+ },
67
+ "label": {
68
+ "value": "British Consulate\nLevel 9, 100 Eagle Street\nBrisbane Queensland 4000\nAustralia"
69
+ }
70
+ },
71
+ "contact_numbers": [
72
+ {
73
+ "label": "Switchboard",
74
+ "number": "+61 (0) 7 3223 3200 "
75
+ }
76
+ ],
77
+ "services": [ ]
78
+ },
79
+ {
80
+ "title": "UK Trade & Investment Melbourne",
81
+ "format": "World Office",
82
+ "updated_at": "2013-03-25T10:37:53+00:00",
83
+ "details": {
84
+ "email": "",
85
+ "description": "",
86
+ "contact_form_url": "",
87
+ "type": "Other"
88
+ },
89
+ "address": {
90
+ "adr": {
91
+ "fn": "British Consulate",
92
+ "street-address": "17th Floor, 90 Collins Street",
93
+ "postal-code": "",
94
+ "locality": "Melbourne",
95
+ "region": "Victoria",
96
+ "country-name": "Australia"
97
+ },
98
+ "label": {
99
+ "value": "British Consulate\n17th Floor, 90 Collins Street\nMelbourne Victoria \nAustralia"
100
+ }
101
+ },
102
+ "contact_numbers": [
103
+ {
104
+ "label": "Switchboard",
105
+ "number": "+61 (0) 3 9652 1600 "
106
+ }
107
+ ],
108
+ "services": [ ]
109
+ },
110
+ {
111
+ "title": "UK Trade & Investment Perth",
112
+ "format": "World Office",
113
+ "updated_at": "2013-03-25T10:37:53+00:00",
114
+ "details": {
115
+ "email": "",
116
+ "description": "",
117
+ "contact_form_url": "",
118
+ "type": "Other"
119
+ },
120
+ "address": {
121
+ "adr": {
122
+ "fn": "British Consulate",
123
+ "street-address": "Level 12, 251 Adelaide Terrace Perth",
124
+ "postal-code": "",
125
+ "locality": "Perth",
126
+ "region": "Western Australia",
127
+ "country-name": "Australia"
128
+ },
129
+ "label": {
130
+ "value": "British Consulate\nLevel 12, 251 Adelaide Terrace Perth\nPerth Western Australia \nAustralia"
131
+ }
132
+ },
133
+ "contact_numbers": [
134
+ {
135
+ "label": "Switchboard",
136
+ "number": "+61 (0) 8 9224 4700 "
137
+ }
138
+ ],
139
+ "services": [ ]
140
+ },
141
+ {
142
+ "title": "Director of Investment, Australia and New Zealand",
143
+ "format": "World Office",
144
+ "updated_at": "2013-03-25T10:37:53+00:00",
145
+ "details": {
146
+ "email": "paul.webster@fco.gov.uk ",
147
+ "description": "",
148
+ "contact_form_url": "",
149
+ "type": "Other"
150
+ },
151
+ "address": {
152
+ "adr": {
153
+ "fn": "Paul Webster",
154
+ "street-address": "Level 16, Gateway Building\r\n1 Macquarie Place",
155
+ "postal-code": "2000",
156
+ "locality": "Sydney",
157
+ "region": "New South Wales",
158
+ "country-name": "Australia"
159
+ },
160
+ "label": {
161
+ "value": "Paul Webster\nLevel 16, Gateway Building\r\n1 Macquarie Place\nSydney New South Wales 2000\nAustralia"
162
+ }
163
+ },
164
+ "contact_numbers": [
165
+ {
166
+ "label": "Direct line",
167
+ "number": "+61 (0)2 8247 2234"
168
+ }
169
+ ],
170
+ "services": [ ]
171
+ },
172
+ {
173
+ "title": "Head of Investment New South Wales, ACT and Western Australia",
174
+ "format": "World Office",
175
+ "updated_at": "2013-03-25T10:37:53+00:00",
176
+ "details": {
177
+ "email": "nicky.vandomburg@fco.gov.uk ",
178
+ "description": "",
179
+ "contact_form_url": "",
180
+ "type": "Other"
181
+ },
182
+ "address": {
183
+ "adr": {
184
+ "fn": "Nicky van Domburg",
185
+ "street-address": "Level 16, Gateway Building\r\n1 Macquarie Place",
186
+ "postal-code": "2000",
187
+ "locality": "Sydney",
188
+ "region": "New South Wales",
189
+ "country-name": "Australia"
190
+ },
191
+ "label": {
192
+ "value": "Nicky van Domburg\nLevel 16, Gateway Building\r\n1 Macquarie Place\nSydney New South Wales 2000\nAustralia"
193
+ }
194
+ },
195
+ "contact_numbers": [
196
+ {
197
+ "label": "Direct line",
198
+ "number": "+61 (0)2 8247 2205"
199
+ }
200
+ ],
201
+ "services": [ ]
202
+ },
203
+ {
204
+ "title": "Head of Investment Victoria, South Australia, Tasmania",
205
+ "format": "World Office",
206
+ "updated_at": "2013-03-25T10:37:53+00:00",
207
+ "details": {
208
+ "email": "",
209
+ "description": "",
210
+ "contact_form_url": "",
211
+ "type": "Other"
212
+ },
213
+ "address": {
214
+ "adr": {
215
+ "fn": "Majella Hamilton",
216
+ "street-address": "17th Floor, 90 Collins Street",
217
+ "postal-code": "",
218
+ "locality": "Melbourne",
219
+ "region": "Victoria",
220
+ "country-name": "Australia"
221
+ },
222
+ "label": {
223
+ "value": "Majella Hamilton\n17th Floor, 90 Collins Street\nMelbourne Victoria \nAustralia"
224
+ }
225
+ },
226
+ "contact_numbers": [
227
+ {
228
+ "label": "Direct line",
229
+ "number": "+61 (0)3 9652 1621"
230
+ }
231
+ ],
232
+ "services": [ ]
233
+ },
234
+ {
235
+ "title": "Head of Investment Queensland and Northern Territory & Head of Institutional Investment Australia and New Zealand",
236
+ "format": "World Office",
237
+ "updated_at": "2013-03-25T10:37:53+00:00",
238
+ "details": {
239
+ "email": "craig.o'kane@fco.gov.uk ",
240
+ "description": "",
241
+ "contact_form_url": "",
242
+ "type": "Other"
243
+ },
244
+ "address": {
245
+ "adr": {
246
+ "fn": "Craig O'Kane",
247
+ "street-address": "Level 9, 100 Eagle Street\r\n",
248
+ "postal-code": "4000",
249
+ "locality": "Brisbane",
250
+ "region": "Queensland",
251
+ "country-name": "Australia"
252
+ },
253
+ "label": {
254
+ "value": "Craig O'Kane\nLevel 9, 100 Eagle Street\r\nBrisbane Queensland 4000\nAustralia"
255
+ }
256
+ },
257
+ "contact_numbers": [
258
+ {
259
+ "label": "Direct line",
260
+ "number": "+61 (0)7 3223 3205"
261
+ }
262
+ ],
263
+ "services": [ ]
264
+ }
265
+ ]
266
+ },
267
+ "sponsors": [
268
+ {
269
+ "title": "UK Trade & Investment",
270
+ "web_url": "https://www.gov.uk/government/organisations/uk-trade-investment",
271
+ "details": {
272
+ "acronym": "UKTI"
273
+ }
274
+ }
275
+ ]
276
+ },
277
+ {
278
+ "id": "https://www.gov.uk/api/worldwide-organisations/british-high-commission-canberra",
279
+ "title": "British High Commission Canberra",
280
+ "format": "Worldwide Organisation",
281
+ "updated_at": "2013-03-25T06:21:38+00:00",
282
+ "web_url": "https://www.gov.uk/government/world/organisations/british-high-commission-canberra",
283
+ "details": {
284
+ "slug": "british-high-commission-canberra",
285
+ "summary": "The UK and Australia share a longstanding relationship, as both partners and allies. ",
286
+ "description": "<div class=\"govspeak\"><p>We represent the British government in its relations with the Australian government and present British policies to the Australian government and to Australians. We report and explain Australian policies to the British government and support British interests as well as co-ordinating the political, economic, environmental and commercial activities of the British government. </p>\n\n<p>We have consulate-generals in Sydney and Melbourne and consulates in Brisbane and Perth. With over one million Britons living in Australia and over 640,000 visiting every year, the consulates support British nationals if they require assistance. </p></div>",
287
+ "services": "<div class=\"govspeak\"><h2 id=\"visashttpwwwukbahomeofficegovukvisas-immigration-uk-border-agency-website\"><a rel=\"external\" href=\"http://www.ukba.homeoffice.gov.uk/visas-immigration/\" title=\"UK Border Agency website\">Visas</a></h2>\n<p>For information on whether you require a visa for the United Kingdom and how to apply go to the <a rel=\"external\" href=\"http://www.ukba.homeoffice.gov.uk/visas-immigration/\" title=\"UK Border Agency website\">UK Border Agency website</a> </p>\n\n<h2 id=\"births-deaths-and-marriageshttpswwwgovukbrowsebirths-deaths-marriages-births-deaths-and-marriages\"><a href=\"https://www.gov.uk/browse/births-deaths-marriages/\" title=\"Births, deaths and marriages\">Births, deaths and marriages</a></h2>\n<p>Information on how you can register a birth or death which occurred overseas, and legal documents for couples marrying or entering into civil partnerships abroad. </p>\n\n<h2 id=\"passports-and-emergency-travel-documentshttpswwwgovukoverseas-passports-passports-and-emergency-travel-documents\"><a href=\"https://www.gov.uk/overseas-passports/\" title=\"Passports and emergency travel documents\">Passports and emergency travel documents</a></h2>\n<p>How to renew or replace your British passport when visiting the UK and information on getting replacement travel documents if your passport is lost or stolen. </p>\n\n<h2 id=\"travel-advicehttpswwwgovukforeign-travel-adviceaustralia-travel-advice\"><a href=\"https://www.gov.uk/foreign-travel-advice/australia/\" title=\"Travel advice\">Travel advice</a></h2>\n<p>Information on staying safe and avoiding problems when living or travelling abroad, with links to our embassies, high commissions and other diplomatic posts across the world. </p></div>"
288
+ },
289
+ "offices": {
290
+ "main": {
291
+ "title": "British High Commission Canberra",
292
+ "format": "World Office",
293
+ "updated_at": "2013-03-25T10:37:54+00:00",
294
+ "details": {
295
+ "email": "",
296
+ "description": "Opening Hours:\r\nMonday to Friday, 8.45am to 12.30pm/1.30pm to 5.00pm",
297
+ "contact_form_url": "",
298
+ "type": "High Commission"
299
+ },
300
+ "address": {
301
+ "adr": {
302
+ "fn": "High Commissioner: His Excellency Paul Madden",
303
+ "street-address": "Commonwealth Avenue, Yarralumla",
304
+ "postal-code": "2600",
305
+ "locality": "Canberra",
306
+ "region": "ACT",
307
+ "country-name": "Australia"
308
+ },
309
+ "label": {
310
+ "value": "High Commissioner: His Excellency Paul Madden\nCommonwealth Avenue, Yarralumla\nCanberra ACT 2600\nAustralia"
311
+ }
312
+ },
313
+ "contact_numbers": [
314
+ {
315
+ "label": "Telephone:",
316
+ "number": "+61 (0)2 6270 6666"
317
+ }
318
+ ],
319
+ "services": [ ]
320
+ },
321
+ "other": [
322
+ {
323
+ "title": "British Consulate-General Sydney",
324
+ "format": "World Office",
325
+ "updated_at": "2013-03-25T10:37:54+00:00",
326
+ "details": {
327
+ "email": "",
328
+ "description": "Opening Hours:\r\nMonday to Friday: 9.00am to 12.30pm/1.30pm to 5.00pm\r\nConsular counter hours:\r\nMonday to Friday 9.00am to 1.00pm\r\nSwitchboard hours:\r\nMonday to Friday 9.00am to 5.00pm",
329
+ "contact_form_url": "",
330
+ "type": "Consulate"
331
+ },
332
+ "address": {
333
+ "adr": {
334
+ "fn": "Consul-General and Director General UK Trade & Investment: Mr Nick McInnes",
335
+ "street-address": "Level 16, Gateway Building, 1 Macquarie Place",
336
+ "postal-code": "2000",
337
+ "locality": "Sydney",
338
+ "region": "NSW",
339
+ "country-name": "Australia"
340
+ },
341
+ "label": {
342
+ "value": "Consul-General and Director General UK Trade & Investment: Mr Nick McInnes\nLevel 16, Gateway Building, 1 Macquarie Place\nSydney NSW 2000\nAustralia"
343
+ }
344
+ },
345
+ "contact_numbers": [
346
+ {
347
+ "label": "Telephone:",
348
+ "number": "+61 (0) 9247 7521"
349
+ }
350
+ ],
351
+ "services": [ ]
352
+ },
353
+ {
354
+ "title": "British Consulate-General Melbourne",
355
+ "format": "World Office",
356
+ "updated_at": "2013-03-25T10:37:54+00:00",
357
+ "details": {
358
+ "email": "",
359
+ "description": "Opening Hours:\r\nMonday to Friday 9.00am to 5.00pm \r\nPublic counter hours: \r\nMonday to Friday 10.00am to 2.00pm",
360
+ "contact_form_url": "",
361
+ "type": "Consulate"
362
+ },
363
+ "address": {
364
+ "adr": {
365
+ "fn": "Consul-General: Mr Gareth Hoar",
366
+ "street-address": "17th Floor, 90 Collins St",
367
+ "postal-code": "3000",
368
+ "locality": "Melbourne",
369
+ "region": "VIC",
370
+ "country-name": "Australia"
371
+ },
372
+ "label": {
373
+ "value": "Consul-General: Mr Gareth Hoar\n17th Floor, 90 Collins St\nMelbourne VIC 3000\nAustralia"
374
+ }
375
+ },
376
+ "contact_numbers": [
377
+ {
378
+ "label": "Telephone:",
379
+ "number": "+61 (0)3 9652 1600"
380
+ }
381
+ ],
382
+ "services": [ ]
383
+ },
384
+ {
385
+ "title": "British Consulate Perth",
386
+ "format": "World Office",
387
+ "updated_at": "2013-03-25T10:37:54+00:00",
388
+ "details": {
389
+ "email": "",
390
+ "description": "Opening Hours Mondays to Fridays:\r\nPublic counter hours: 10.00am to 1.00pm\r\nUK Visa (biometric) appointments: 10.00am to 2.00pm\r\nSwitchboard hours: 9.00am to 4.30pm",
391
+ "contact_form_url": "",
392
+ "type": "Consulate"
393
+ },
394
+ "address": {
395
+ "adr": {
396
+ "fn": "Vice Consul and Head of Consular Services: Mr James Frew",
397
+ "street-address": "Level 12\r\n251 Adelaide Terrace",
398
+ "postal-code": "6000",
399
+ "locality": "Perth",
400
+ "region": "WA",
401
+ "country-name": "Australia"
402
+ },
403
+ "label": {
404
+ "value": "Vice Consul and Head of Consular Services: Mr James Frew\nLevel 12\r\n251 Adelaide Terrace\nPerth WA 6000\nAustralia"
405
+ }
406
+ },
407
+ "contact_numbers": [
408
+ {
409
+ "label": "Telephone:",
410
+ "number": "+61 (0)8 9224 4700"
411
+ }
412
+ ],
413
+ "services": [
414
+ {
415
+ "title": "Emergency Travel Documents service",
416
+ "type": "Assistance Services"
417
+ },
418
+ {
419
+ "title": "Transferring funds for prisoners / for financial assistance service",
420
+ "type": "Assistance Services"
421
+ },
422
+ {
423
+ "title": "Marriage or Civil Partnership registrations",
424
+ "type": "Documentary Services"
425
+ },
426
+ {
427
+ "title": "Citizenship Ceremony service",
428
+ "type": "Documentary Services"
429
+ }
430
+ ]
431
+ },
432
+ {
433
+ "title": "British Consulate Brisbane",
434
+ "format": "World Office",
435
+ "updated_at": "2013-03-25T10:37:54+00:00",
436
+ "details": {
437
+ "email": "",
438
+ "description": "Opening Hours Mondays to Fridays:\r\nCounter hours: 10.00am to 3.00pm\r\nSwitchboard hours: 9.30am to 4.30pm",
439
+ "contact_form_url": "",
440
+ "type": "Consulate"
441
+ },
442
+ "address": {
443
+ "adr": {
444
+ "fn": "Vice Consul and Head of Consular Services: Mrs Megan Hunt",
445
+ "street-address": "Level 9\r\n100 Eagle Street \r\n",
446
+ "postal-code": "4000",
447
+ "locality": "Brisbane",
448
+ "region": "QLD",
449
+ "country-name": "Australia"
450
+ },
451
+ "label": {
452
+ "value": "Vice Consul and Head of Consular Services: Mrs Megan Hunt\nLevel 9\r\n100 Eagle Street \r\nBrisbane QLD 4000\nAustralia"
453
+ }
454
+ },
455
+ "contact_numbers": [
456
+ {
457
+ "label": "Telephone:",
458
+ "number": "+61 (0)7 3223 3200"
459
+ }
460
+ ],
461
+ "services": [ ]
462
+ }
463
+ ]
464
+ },
465
+ "sponsors": [
466
+ {
467
+ "title": "Foreign & Commonwealth Office",
468
+ "web_url": "https://www.gov.uk/government/organisations/foreign-commonwealth-office",
469
+ "details": {
470
+ "acronym": "FCO"
471
+ }
472
+ }
473
+ ]
474
+ }
475
+ ],
476
+ "current_page": 1,
477
+ "total": 2,
478
+ "pages": 1,
479
+ "page_size": 20,
480
+ "start_index": 1,
481
+ "_response_info": {
482
+ "status": "ok",
483
+ "links": [
484
+ {
485
+ "href": "https://www.gov.uk/api/world-locations/australia/organisations?page=1",
486
+ "rel": "self"
487
+ }
488
+ ]
489
+ }
490
+ }
@@ -56,6 +56,11 @@ class GdsApiBaseTest < MiniTest::Unit::TestCase
56
56
  assert_equal 4, api.client.cache.max_size
57
57
  end
58
58
 
59
+ def test_disabling_cache
60
+ api = ConcreteApi.new("http://bar", disable_cache: true)
61
+ assert api.client.cache.is_a? GdsApi::NullCache
62
+ end
63
+
59
64
  def test_should_barf_if_not_given_valid_URL
60
65
  proc do
61
66
  ConcreteApi.new('invalid-url')
@@ -6,7 +6,13 @@ require 'base64'
6
6
  class JsonClientTest < MiniTest::Spec
7
7
  def setup
8
8
  @json_client_cache = GdsApi::JsonClient.cache
9
- GdsApi::JsonClient.cache = {}
9
+
10
+ # Set the cache to nil so the JsonClient recreates it on each test run
11
+ # This used to initialise the cache to an empty Hash, eliminating the
12
+ # potential problem of cache entries expiring during a test run, but that
13
+ # no longer works now our code calls the `store` method with an expiry time
14
+ GdsApi::JsonClient.cache = nil
15
+
10
16
  @client = GdsApi::JsonClient.new
11
17
  end
12
18
 
@@ -66,8 +72,6 @@ class JsonClientTest < MiniTest::Spec
66
72
  end
67
73
 
68
74
  def test_should_cache_multiple_requests_to_same_url_across_instances
69
- GdsApi::JsonClient.cache = nil # clear the stubbed cache instance
70
-
71
75
  url = "http://some.endpoint/some.json"
72
76
  result = {"foo" => "bar"}
73
77
  stub_request(:get, url).to_return(:body => JSON.dump(result), :status => 200)
@@ -77,30 +81,10 @@ class JsonClientTest < MiniTest::Spec
77
81
  assert_requested :get, url, times: 1
78
82
  end
79
83
 
80
- def test_should_cache_up_to_10_items_by_default
81
- GdsApi::JsonClient.cache = nil # clear the stubbed cache instance
82
-
83
- url = "http://some.endpoint/"
84
- result = {"foo" => "bar"}
85
- stub_request(:get, %r{\A#{url}}).to_return do |request|
86
- {:body => {"url" => request.uri}.to_json, :status => 200}
87
- end
88
-
89
- response_a = GdsApi::JsonClient.new.get_json("#{url}/first.json")
90
- response_b = GdsApi::JsonClient.new.get_json("#{url}/second.json")
91
- 9.times { |n| GdsApi::JsonClient.new.get_json("#{url}/#{n}.json") }
92
-
93
- response_c = GdsApi::JsonClient.new.get_json("#{url}/second.json")
94
- response_d = GdsApi::JsonClient.new.get_json("#{url}/first.json")
95
-
96
- assert_requested :get, "#{url}/second.json", times: 1
97
- assert_requested :get, "#{url}/first.json", times: 2
98
- assert_equal response_b.to_hash, response_c.to_hash
99
- assert_equal response_a.to_hash, response_d.to_hash
100
- end
101
-
102
84
  def test_allow_overriding_the_number_of_cached_items
103
- GdsApi::JsonClient.cache = nil # clear the stubbed cache instance
85
+ # Clear out the default cache instance, because otherwise the customisation
86
+ # doesn't take effect, due to some non-obvious behaviour in JsonClient.
87
+ GdsApi::JsonClient.cache = nil
104
88
 
105
89
  url = "http://some.endpoint/"
106
90
  result = {"foo" => "bar"}
@@ -122,8 +106,6 @@ class JsonClientTest < MiniTest::Spec
122
106
  end
123
107
 
124
108
  def test_should_cache_requests_for_15_mins_by_default
125
- GdsApi::JsonClient.cache = nil # cause it to contruct a new cache instance.
126
-
127
109
  url = "http://some.endpoint/some.json"
128
110
  result = {"foo" => "bar"}
129
111
  stub_request(:get, url).to_return(:body => JSON.dump(result), :status => 200)#.times(1)
@@ -149,7 +131,9 @@ class JsonClientTest < MiniTest::Spec
149
131
  end
150
132
 
151
133
  def test_should_allow_overriding_cache_ttl
152
- GdsApi::JsonClient.cache = nil # cause it to contruct a new cache instance.
134
+ # Clear out the default cache instance, because otherwise the customisation
135
+ # doesn't take effect, due to some non-obvious behaviour in JsonClient.
136
+ GdsApi::JsonClient.cache = nil
153
137
 
154
138
  url = "http://some.endpoint/some.json"
155
139
  result = {"foo" => "bar"}
@@ -175,6 +159,49 @@ class JsonClientTest < MiniTest::Spec
175
159
  end
176
160
  end
177
161
 
162
+ def test_should_allow_disabling_caching
163
+ url = "http://some.endpoint/some.json"
164
+ result = {"foo" => "bar"}
165
+ stub_request(:get, url).to_return(:body => JSON.dump(result), :status => 200)
166
+
167
+ client = GdsApi::JsonClient.new(disable_cache: true)
168
+
169
+ response_a = client.get_json(url)
170
+ response_b = client.get_json(url)
171
+
172
+ assert_requested :get, url, times: 2
173
+
174
+ [response_a, response_b].each do |r|
175
+ assert_equal result, r.to_hash
176
+ end
177
+ end
178
+
179
+ def test_should_respect_expiry_headers
180
+ url = "http://some.endpoint/some.json"
181
+ result = {"foo" => "bar"}
182
+ stub_request(:get, url).to_return(
183
+ :body => JSON.dump(result),
184
+ :status => 200,
185
+ :headers => { "Expires" => (Time.now + 7 * 60).utc.httpdate }
186
+ )
187
+
188
+ response_a = GdsApi::JsonClient.new.get_json(url)
189
+
190
+ Timecop.travel( 7 * 60 - 30) do # now + 6 mins 30 secs
191
+ response_b = GdsApi::JsonClient.new.get_json(url)
192
+
193
+ assert_requested :get, url, times: 1
194
+ assert_equal response_a.to_hash, response_b.to_hash
195
+ end
196
+
197
+ Timecop.travel( 7 * 60 + 30) do # now + 7 mins 30 secs
198
+ response_c = GdsApi::JsonClient.new.get_json(url)
199
+
200
+ assert_requested :get, url, times: 2
201
+ assert_equal response_a.to_hash, response_c.to_hash
202
+ end
203
+ end
204
+
178
205
  def test_should_raise_http_not_found_if_404_returned_from_endpoint
179
206
  url = "http://some.endpoint/some.json"
180
207
  stub_request(:get, url).to_return(:body => "{}", :status => 404)
@@ -228,7 +255,7 @@ class JsonClientTest < MiniTest::Spec
228
255
  new_url = "http://some.endpoint/other.json"
229
256
  stub_request(:get, url).to_return(
230
257
  :body => "",
231
- :status => 302,
258
+ :status => 303,
232
259
  :headers => {"Location" => new_url}
233
260
  )
234
261
  stub_request(:get, new_url).to_return(:body => '{"a": 1}', :status => 200)
@@ -477,4 +504,13 @@ class JsonClientTest < MiniTest::Spec
477
504
  @client.post_multipart("http://some.endpoint/some.json", {"a" => "123"})
478
505
  end
479
506
  end
507
+
508
+ def test_should_raise_error_if_attempting_to_disable_timeout
509
+ assert_raises RuntimeError do
510
+ GdsApi::JsonClient.new(:disable_timeout => true)
511
+ end
512
+ assert_raises RuntimeError do
513
+ GdsApi::JsonClient.new(:timeout => -1)
514
+ end
515
+ end
480
516
  end