gds-api-adapters 30.0.1 → 30.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0894ef0f3de4c61534ca85eb7dd7c82c6c422d0b
4
- data.tar.gz: aac9d1fc32b38127c3421b76019c4feaf87b6268
3
+ metadata.gz: 8d3faeb6ebc0f0dd3bc81f25e0ce1337105f456b
4
+ data.tar.gz: dd3f80e588b4bffc76b292cbf032404717a5bdeb
5
5
  SHA512:
6
- metadata.gz: c7b0c1cfd3bcd4ec5076ab4ddebcda7b8c825caf5d6185a9e9aa0c8068740810e22ad9f7e59bb4685b57c9a95f5c02ec43b25c0b45b17b197e233be879d42e80
7
- data.tar.gz: 2f044b2df6c847766ac17be5bce711decc187c145f1ef01af7dd64e2486e721b538918ddf1e15e3aa3584ba99cd38bb2f203cb791a93502506f28f612d09dae5
6
+ metadata.gz: 3e0a6924f8b8462d93dfb9be1389d6b36cfdce70993bd5ba9831fb108e5e2cfcda52d04f00c7d380b95d264640e3318d275dbed8b89d83b6874e5a66d3aa47fb
7
+ data.tar.gz: 826ee63e166b5f6a390769aab68612f17f83509c6cb3353840ff4f690c1ffad7e1e086b21398d5544e4359b98712f1eb0de79b4746f40884d2fe1d9af8953855
@@ -3,7 +3,6 @@ require 'gds_api/business_support_api'
3
3
  require 'gds_api/content_api'
4
4
  require 'gds_api/content_register'
5
5
  require 'gds_api/content_store'
6
- require 'gds_api/fact_cave'
7
6
  require 'gds_api/imminence'
8
7
  require 'gds_api/licence_application'
9
8
  require 'gds_api/need_api'
@@ -34,10 +33,6 @@ module GdsApi
34
33
  @content_store ||= GdsApi::ContentStore.new(Plek.current.find("content-store"), options)
35
34
  end
36
35
 
37
- def fact_cave_api(options = {})
38
- @fact_cave_api ||= GdsApi::FactCave.new(Plek.current.find("fact-cave"), options)
39
- end
40
-
41
36
  def publisher_api(options = {})
42
37
  @api ||= GdsApi::Publisher.new(Plek.current.find("publisher"), options)
43
38
  end
@@ -139,6 +139,22 @@ module GdsApi
139
139
  end
140
140
  end
141
141
 
142
+ # Example of use:
143
+
144
+ # publishing_api_has_content(
145
+ # vehicle_recalls_and_faults, # this is a variable containing an array of content items
146
+ # document_type: described_class.publishing_api_document_type, #example of a document_type: "vehicle_recalls_and_faults_alert"
147
+ # fields: fields, #example: let(:fields) { %i[base_path content_id public_updated_at title publication_state] }
148
+ # page: 1,
149
+ # per_page: 50
150
+ #)
151
+ def publishing_api_has_content(items, params = {})
152
+ url = PUBLISHING_API_V2_ENDPOINT + "/content"
153
+ stub_request(:get, url).with(:query => params).to_return(status: 200, body: { results: items }.to_json, headers: {})
154
+ end
155
+
156
+ # This method has been refactored into publishing_api_has_content (above)
157
+ # publishing_api_has_content allows for flexible passing in of arguments, please use instead
142
158
  def publishing_api_has_fields_for_document(format, items, fields)
143
159
  body = Array(items).map { |item|
144
160
  item.with_indifferent_access.slice(*fields)
@@ -1,3 +1,3 @@
1
1
  module GdsApi
2
- VERSION = '30.0.1'
2
+ VERSION = '30.1.0'
3
3
  end
data/test/helpers_test.rb CHANGED
@@ -14,7 +14,6 @@ describe GdsApi::Helpers do
14
14
  refute_nil test_with_helpers.content_api
15
15
  refute_nil test_with_helpers.content_register
16
16
  refute_nil test_with_helpers.content_store
17
- refute_nil test_with_helpers.fact_cave_api
18
17
  refute_nil test_with_helpers.publisher_api
19
18
  refute_nil test_with_helpers.imminence_api
20
19
  refute_nil test_with_helpers.licence_application_api
@@ -16,4 +16,14 @@ describe GdsApi::TestHelpers::PublishingApiV2 do
16
16
  assert_equal publishing_api.lookup_content_id(base_path: "/foo"), "2878337b-bed9-4e7f-85b6-10ed2cbcd504"
17
17
  end
18
18
  end
19
+
20
+ describe "#publishing_api_has_content" do
21
+ it "stubs the call to get content items" do
22
+ publishing_api_has_content([{"content_id" => "2878337b-bed9-4e7f-85b6-10ed2cbcd504"}])
23
+
24
+ response = publishing_api.get_content_items({})['results']
25
+
26
+ assert_equal([{ "content_id" => "2878337b-bed9-4e7f-85b6-10ed2cbcd504" }], response)
27
+ end
28
+ end
19
29
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gds-api-adapters
3
3
  version: !ruby/object:Gem::Version
4
- version: 30.0.1
4
+ version: 30.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Stewart
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-04-05 00:00:00.000000000 Z
11
+ date: 2016-04-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: plek
@@ -280,16 +280,16 @@ dependencies:
280
280
  name: webmock
281
281
  requirement: !ruby/object:Gem::Requirement
282
282
  requirements:
283
- - - "~>"
283
+ - - '='
284
284
  - !ruby/object:Gem::Version
285
- version: '1.19'
285
+ version: 1.24.2
286
286
  type: :development
287
287
  prerelease: false
288
288
  version_requirements: !ruby/object:Gem::Requirement
289
289
  requirements:
290
- - - "~>"
290
+ - - '='
291
291
  - !ruby/object:Gem::Version
292
- version: '1.19'
292
+ version: 1.24.2
293
293
  - !ruby/object:Gem::Dependency
294
294
  name: pact_broker-client
295
295
  requirement: !ruby/object:Gem::Requirement
@@ -324,7 +324,6 @@ files:
324
324
  - lib/gds_api/email_alert_api.rb
325
325
  - lib/gds_api/exceptions.rb
326
326
  - lib/gds_api/external_link_tracker.rb
327
- - lib/gds_api/fact_cave.rb
328
327
  - lib/gds_api/gov_uk_delivery.rb
329
328
  - lib/gds_api/govuk_headers.rb
330
329
  - lib/gds_api/helpers.rb
@@ -363,7 +362,6 @@ files:
363
362
  - lib/gds_api/test_helpers/content_register.rb
364
363
  - lib/gds_api/test_helpers/content_store.rb
365
364
  - lib/gds_api/test_helpers/email_alert_api.rb
366
- - lib/gds_api/test_helpers/fact_cave.rb
367
365
  - lib/gds_api/test_helpers/gov_uk_delivery.rb
368
366
  - lib/gds_api/test_helpers/imminence.rb
369
367
  - lib/gds_api/test_helpers/intent_helpers.rb
@@ -393,7 +391,6 @@ files:
393
391
  - test/content_store_test.rb
394
392
  - test/email_alert_api_test.rb
395
393
  - test/external_link_tracker_test.rb
396
- - test/fact_cave_test.rb
397
394
  - test/fixtures/finder_api/cma-case-schema.json
398
395
  - test/fixtures/hello.txt
399
396
  - test/fixtures/new_policies_for_dwp.json
@@ -460,54 +457,53 @@ signing_key:
460
457
  specification_version: 4
461
458
  summary: Adapters to work with GDS APIs
462
459
  test_files:
463
- - test/content_api_test.rb
464
- - test/json_client_test.rb
465
- - test/content_store_test.rb
466
- - test/publishing_api_test.rb
467
- - test/business_support_api_test.rb
468
- - test/middleware/govuk_header_sniffer_test.rb
469
- - test/whitehall_admin_api_test.rb
470
- - test/list_response_test.rb
471
- - test/maslow_test.rb
472
- - test/panopticon_registerer_test.rb
473
- - test/support_test.rb
474
- - test/asset_manager_test.rb
475
- - test/helpers_test.rb
476
- - test/licence_application_api_test.rb
477
- - test/test_helper.rb
478
- - test/publisher_api_test.rb
460
+ - test/support_api_test.rb
479
461
  - test/mapit_test.rb
480
- - test/rummager_helpers_test.rb
481
- - test/publishing_api_v2_test.rb
462
+ - test/publishing_api_test.rb
482
463
  - test/publishing_api_v2/lookup_test.rb
483
- - test/support_api_test.rb
484
- - test/organisations_api_test.rb
485
- - test/gds_api_base_test.rb
486
- - test/router_test.rb
464
+ - test/whitehall_admin_api_test.rb
465
+ - test/pp_data_in_test.rb
487
466
  - test/publishing_api/special_route_publisher_test.rb
488
- - test/external_link_tracker_test.rb
489
- - test/fact_cave_test.rb
490
467
  - test/need_api_test.rb
468
+ - test/publisher_api_test.rb
469
+ - test/rummager_helpers_test.rb
470
+ - test/support_test.rb
491
471
  - test/content_register_test.rb
472
+ - test/test_helpers/publishing_api_test.rb
473
+ - test/test_helpers/pact_helper.rb
474
+ - test/test_helpers/panopticon_test.rb
475
+ - test/test_helpers/email_alert_api_test.rb
476
+ - test/test_helpers/publishing_api_v2_test.rb
477
+ - test/licence_application_api_test.rb
478
+ - test/gov_uk_delivery_test.rb
479
+ - test/maslow_test.rb
480
+ - test/helpers_test.rb
481
+ - test/panopticon_registerer_test.rb
492
482
  - test/panopticon_test.rb
493
- - test/pp_data_in_test.rb
483
+ - test/middleware/govuk_header_sniffer_test.rb
484
+ - test/rummager_test.rb
485
+ - test/json_client_test.rb
486
+ - test/email_alert_api_test.rb
487
+ - test/content_api_test.rb
488
+ - test/response_test.rb
489
+ - test/organisations_api_test.rb
490
+ - test/imminence_api_test.rb
491
+ - test/content_store_test.rb
492
+ - test/asset_manager_test.rb
494
493
  - test/fixtures/hello.txt
495
494
  - test/fixtures/new_policies_for_dwp.json
495
+ - test/fixtures/world_organisations_australia.json
496
496
  - test/fixtures/no_services_and_info_data_found_fixture.json
497
- - test/fixtures/services_and_info_fixture.json
498
497
  - test/fixtures/old_policies_for_dwp.json
499
- - test/fixtures/world_organisations_australia.json
498
+ - test/fixtures/services_and_info_fixture.json
500
499
  - test/fixtures/sub_sector_organisations.json
501
500
  - test/fixtures/finder_api/cma-case-schema.json
501
+ - test/router_test.rb
502
+ - test/list_response_test.rb
503
+ - test/external_link_tracker_test.rb
504
+ - test/gds_api_base_test.rb
502
505
  - test/worldwide_api_test.rb
503
- - test/test_helpers/publishing_api_test.rb
504
- - test/test_helpers/publishing_api_v2_test.rb
505
- - test/test_helpers/pact_helper.rb
506
- - test/test_helpers/panopticon_test.rb
507
- - test/test_helpers/email_alert_api_test.rb
508
- - test/gov_uk_delivery_test.rb
509
- - test/imminence_api_test.rb
510
- - test/email_alert_api_test.rb
511
- - test/response_test.rb
512
- - test/rummager_test.rb
506
+ - test/test_helper.rb
507
+ - test/publishing_api_v2_test.rb
508
+ - test/business_support_api_test.rb
513
509
  has_rdoc:
@@ -1,12 +0,0 @@
1
- require 'gds_api/base'
2
-
3
- module GdsApi
4
- class FactCave < Base
5
-
6
- def fact(slug)
7
- return nil if slug.nil? || slug == ""
8
- get_json("#{endpoint}/facts/#{slug}")
9
- end
10
-
11
- end
12
- end
@@ -1,67 +0,0 @@
1
- require 'gds_api/test_helpers/json_client_helper'
2
- require 'gds_api/test_helpers/common_responses'
3
-
4
- module GdsApi
5
- module TestHelpers
6
- module FactCave
7
- include GdsApi::TestHelpers::CommonResponses
8
-
9
- FACT_CAVE_ENDPOINT = Plek.current.find('fact-cave')
10
-
11
- def fact_cave_has_a_fact(slug, value, options={})
12
- response = fact_for_slug(slug, value, options)
13
-
14
- stub_request(:get, "#{FACT_CAVE_ENDPOINT}/facts/#{slug}")
15
- .to_return(:body => response.to_json, :status => 200)
16
- stub_request(:get, "#{FACT_CAVE_ENDPOINT}/facts/#{slug}.json")
17
- .to_return(:body => response.to_json, :status => 200)
18
- end
19
-
20
- def fact_cave_does_not_have_a_fact(slug)
21
- response = {
22
- "_response_info" => { "status" => "not found" }
23
- }
24
-
25
- stub_request(:get, "#{FACT_CAVE_ENDPOINT}/facts/#{slug}")
26
- .to_return(:body => response.to_json, :status => 404)
27
- stub_request(:get, "#{FACT_CAVE_ENDPOINT}/facts/#{slug}.json")
28
- .to_return(:body => response.to_json, :status => 404)
29
- end
30
-
31
- # Creates a sample fact-cave response hash.
32
- # slug - the slug for the fact (also used to generate the title)
33
- # value - the raw value for the fact
34
- # options:
35
- # formatted_value - the formatted value to use. If unspecified, this is generated based on the type
36
- # type - the type of the fact - one of [:currency, :date, :numeric, :text]. Defaults to :text
37
- # currency - for the :currency type, an optional currency symbol to prepend to the generated formatted_value
38
- # unit - for :numeric types, an optional unit to append to the generated formatted_value
39
- def fact_for_slug(slug, value = "Sample Value", options = {})
40
- formatted_value = options[:formatted_value]
41
- formatted_value ||= case options[:type]
42
- when :date
43
- value.strftime("%e %B %Y")
44
- when :numeric
45
- "#{value.to_s}#{options[:unit]}"
46
- when :currency
47
- "#{options[:currency]}#{sprintf("%.2f", value)}"
48
- when :text, nil
49
- value
50
- else
51
- raise "Unknown fact type #{options[:type]}"
52
- end
53
-
54
- singular_response_base.merge({
55
- "id" => "#{FACT_CAVE_ENDPOINT}/facts/#{slug}",
56
- "details" => {
57
- "description" => "",
58
- "value" => value,
59
- "formatted_value" => formatted_value,
60
- },
61
- "name" => titleize_slug(slug),
62
- "updated_at" => Time.now.utc.xmlschema,
63
- })
64
- end
65
- end
66
- end
67
- end
@@ -1,39 +0,0 @@
1
- require "test_helper"
2
- require "gds_api/fact_cave"
3
-
4
- describe GdsApi::FactCave do
5
- it "should raise an exception if the service at the fact cave URI returns a 500" do
6
- stub_request(:get, /example.com\/facts/).to_return(status: [500, "Internal Server Error"])
7
- assert_raises(GdsApi::HTTPServerError) do
8
- GdsApi::FactCave.new("http://example.com").fact("foo")
9
- end
10
- end
11
-
12
- it "should return nil if the service at the fact cave URI returns a 404" do
13
- stub_request(:get, /example.com\/facts/).to_return(status: [404, "Not Found"])
14
- assert_nil GdsApi::FactCave.new("http://example.com").fact("bar")
15
- end
16
-
17
- it "should raise an exception if the service at the fact cave URI times out" do
18
- stub_request(:get, /example.com\/facts/).to_timeout
19
- assert_raises(GdsApi::TimedOutException) do
20
- GdsApi::FactCave.new("http://example.com").fact("meh")
21
- end
22
- end
23
-
24
- it "should return the fact deserialized from json" do
25
- fact_cave_result = {"id" => "vat-rate", "title" => "VAT rate", "details" => {
26
- "value" => "20%", "description" => "Value Added Tax rate" }}
27
- stub_request(:get, "http://example.com/facts/vat-rate").to_return(body: fact_cave_result.to_json)
28
- result = GdsApi::FactCave.new("http://example.com").fact("vat-rate")
29
-
30
- assert_equal fact_cave_result, result.to_hash
31
- end
32
-
33
- it "should return an empty result without making request if slug is empty" do
34
- result = GdsApi::FactCave.new("http://example.com").fact("")
35
-
36
- assert_nil result
37
- assert_not_requested :get, /example.com/
38
- end
39
- end