gds-api-adapters 13.0.0 → 14.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1,2 @@
1
1
  require 'gds_api/railtie' if defined?(Rails)
2
+ require 'gds_api/exceptions'
@@ -11,10 +11,6 @@ class GdsApi::ContentStore < GdsApi::Base
11
11
  get_json!(content_item_url(base_path))
12
12
  end
13
13
 
14
- def put_content_item(base_path, payload)
15
- put_json!(content_item_url(base_path), payload)
16
- end
17
-
18
14
  private
19
15
 
20
16
  def content_item_url(base_path)
@@ -0,0 +1,15 @@
1
+ require_relative 'base'
2
+ require_relative 'exceptions'
3
+
4
+ class GdsApi::PublishingApi < GdsApi::Base
5
+
6
+ def put_content_item(base_path, payload)
7
+ put_json!(content_item_url(base_path), payload)
8
+ end
9
+
10
+ private
11
+
12
+ def content_item_url(base_path)
13
+ "#{endpoint}/content#{base_path}"
14
+ end
15
+ end
@@ -0,0 +1,29 @@
1
+
2
+ module GdsApi
3
+ module TestHelpers
4
+ module ContentItemHelpers
5
+
6
+ def content_item_for_base_path(base_path)
7
+ {
8
+ "title" => titleize_base_path(base_path),
9
+ "description" => "Description for #{base_path}",
10
+ "format" => "guide",
11
+ "need_ids" => ["100001"],
12
+ "public_updated_at" => "2014-05-06T12:01:00+00:00",
13
+ "base_path" => base_path,
14
+ "details" => {
15
+ "body" => "Some content for #{base_path}",
16
+ }
17
+ }
18
+ end
19
+
20
+ def titleize_base_path(base_path, options = {})
21
+ if options[:title_case]
22
+ base_path.gsub("-", " ").gsub(/\b./) {|m| m.upcase }
23
+ else
24
+ base_path.gsub(%r{[-/]}, " ").strip.capitalize
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -1,15 +1,15 @@
1
1
  require 'gds_api/test_helpers/json_client_helper'
2
- require 'gds_api/test_helpers/common_responses'
2
+ require 'gds_api/test_helpers/content_item_helpers'
3
3
  require 'json'
4
4
 
5
5
  module GdsApi
6
6
  module TestHelpers
7
7
  module ContentStore
8
- include CommonResponses
8
+ include ContentItemHelpers
9
9
 
10
10
  CONTENT_STORE_ENDPOINT = Plek.current.find('content-store')
11
11
 
12
- def content_store_has_item(base_path, body = item_for_base_path(base_path), expires_in = 900)
12
+ def content_store_has_item(base_path, body = content_item_for_base_path(base_path), expires_in = 900)
13
13
  url = CONTENT_STORE_ENDPOINT + "/content" + base_path
14
14
  body = body.to_json unless body.is_a?(String)
15
15
  stub_request(:get, url).to_return(status: 200, body: body, headers: {cache_control: "public, max-age=#{expires_in}", date: Time.now.httpdate})
@@ -20,44 +20,6 @@ module GdsApi
20
20
  stub_request(:get, url).to_return(status: 404, headers: {})
21
21
  end
22
22
 
23
- def stub_content_store_put_item(base_path, body = item_for_base_path(base_path))
24
- url = CONTENT_STORE_ENDPOINT + "/content" + base_path
25
- body = body.to_json unless body.is_a?(String)
26
- stub_request(:put, url).with(body: body).to_return(status: 201, body: body, headers: {})
27
- end
28
-
29
- def stub_default_content_store_put()
30
- stub_request(:put, %r{\A#{CONTENT_STORE_ENDPOINT}/content})
31
- end
32
-
33
- def item_for_base_path(base_path)
34
- {
35
- "title" => titleize_slug(base_path),
36
- "description" => "Description for #{base_path}",
37
- "format" => "guide",
38
- "need_ids" => ["100001"],
39
- "public_updated_at" => "2014-05-06T12:01:00+00:00",
40
- "base_path" => base_path,
41
- "details" => {
42
- "body" => "Some content for #{base_path}",
43
- }
44
- }
45
- end
46
-
47
- def assert_content_store_put_item(base_path, attributes = {})
48
- url = CONTENT_STORE_ENDPOINT + "/content" + base_path
49
- if attributes.empty?
50
- assert_requested(:put, url)
51
- else
52
- assert_requested(:put, url) do |req|
53
- data = JSON.parse(req.body)
54
- attributes.to_a.all? do |key, value|
55
- data[key.to_s] == value
56
- end
57
- end
58
- end
59
- end
60
-
61
23
  def content_store_isnt_available
62
24
  stub_request(:any, /#{CONTENT_STORE_ENDPOINT}\/.*/).to_return(:status => 503)
63
25
  end
@@ -0,0 +1,41 @@
1
+ require 'gds_api/test_helpers/json_client_helper'
2
+ require 'gds_api/test_helpers/content_item_helpers'
3
+ require 'json'
4
+
5
+ module GdsApi
6
+ module TestHelpers
7
+ module PublishingApi
8
+ include ContentItemHelpers
9
+
10
+ PUBLISHING_API_ENDPOINT = Plek.current.find('publishing-api')
11
+
12
+ def stub_publishing_api_put_item(base_path, body = content_item_for_base_path(base_path))
13
+ url = PUBLISHING_API_ENDPOINT + "/content" + base_path
14
+ body = body.to_json unless body.is_a?(String)
15
+ stub_request(:put, url).with(body: body).to_return(status: 201, body: body, headers: {})
16
+ end
17
+
18
+ def stub_default_publishing_api_put()
19
+ stub_request(:put, %r{\A#{PUBLISHING_API_ENDPOINT}/content})
20
+ end
21
+
22
+ def assert_publishing_api_put_item(base_path, attributes = {})
23
+ url = PUBLISHING_API_ENDPOINT + "/content" + base_path
24
+ if attributes.empty?
25
+ assert_requested(:put, url)
26
+ else
27
+ assert_requested(:put, url) do |req|
28
+ data = JSON.parse(req.body)
29
+ attributes.to_a.all? do |key, value|
30
+ data[key.to_s] == value
31
+ end
32
+ end
33
+ end
34
+ end
35
+
36
+ def publishing_api_isnt_available
37
+ stub_request(:any, /#{PUBLISHING_API_ENDPOINT}\/.*/).to_return(:status => 503)
38
+ end
39
+ end
40
+ end
41
+ end
@@ -1,3 +1,3 @@
1
1
  module GdsApi
2
- VERSION = '13.0.0'
2
+ VERSION = '14.0.0'
3
3
  end
@@ -17,12 +17,5 @@ describe GdsApi::ContentStore do
17
17
  response = @api.content_item(base_path)
18
18
  assert_equal base_path, response["base_path"]
19
19
  end
20
-
21
- it "should create the item" do
22
- base_path = "/test-to-content-store"
23
- stub_content_store_put_item(base_path)
24
- response = @api.put_content_item(base_path, item_for_base_path(base_path))
25
- assert_equal base_path, response["base_path"]
26
- end
27
20
  end
28
21
  end
@@ -0,0 +1,21 @@
1
+ require 'test_helper'
2
+ require 'gds_api/publishing_api'
3
+ require 'gds_api/test_helpers/publishing_api'
4
+
5
+ describe GdsApi::PublishingApi do
6
+ include GdsApi::TestHelpers::PublishingApi
7
+
8
+ before do
9
+ @base_api_url = Plek.current.find("publishing-api")
10
+ @api = GdsApi::PublishingApi.new(@base_api_url)
11
+ end
12
+
13
+ describe "item" do
14
+ it "should create the item" do
15
+ base_path = "/test-to-publishing-api"
16
+ stub_publishing_api_put_item(base_path)
17
+ response = @api.put_content_item(base_path, content_item_for_base_path(base_path))
18
+ assert_equal base_path, response["base_path"]
19
+ end
20
+ end
21
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gds-api-adapters
3
3
  version: !ruby/object:Gem::Version
4
- version: 13.0.0
4
+ version: 14.0.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-07-30 00:00:00.000000000 Z
12
+ date: 2014-08-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: plek
@@ -313,10 +313,12 @@ files:
313
313
  - lib/gds_api/test_helpers/content_api/artefact_stub.rb
314
314
  - lib/gds_api/test_helpers/performance_platform/data_in.rb
315
315
  - lib/gds_api/test_helpers/licence_application.rb
316
+ - lib/gds_api/test_helpers/content_item_helpers.rb
316
317
  - lib/gds_api/test_helpers/organisations.rb
317
318
  - lib/gds_api/test_helpers/business_support_helper.rb
318
319
  - lib/gds_api/test_helpers/imminence.rb
319
320
  - lib/gds_api/test_helpers/worldwide.rb
321
+ - lib/gds_api/test_helpers/publishing_api.rb
320
322
  - lib/gds_api/test_helpers/mapit.rb
321
323
  - lib/gds_api/test_helpers/panopticon.rb
322
324
  - lib/gds_api/test_helpers/json_client_helper.rb
@@ -337,6 +339,7 @@ files:
337
339
  - lib/gds_api/govuk_request_id.rb
338
340
  - lib/gds_api/maslow.rb
339
341
  - lib/gds_api/worldwide.rb
342
+ - lib/gds_api/publishing_api.rb
340
343
  - lib/gds_api/mapit.rb
341
344
  - lib/gds_api/helpers.rb
342
345
  - lib/gds_api/middleware/govuk_request_id_sniffer.rb
@@ -357,6 +360,7 @@ files:
357
360
  - Rakefile
358
361
  - test/support_api_test.rb
359
362
  - test/mapit_test.rb
363
+ - test/publishing_api_test.rb
360
364
  - test/pp_data_in_test.rb
361
365
  - test/finder_schema_test.rb
362
366
  - test/need_api_test.rb
@@ -405,7 +409,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
405
409
  version: '0'
406
410
  segments:
407
411
  - 0
408
- hash: -1627753500350458436
412
+ hash: -3050602615371028442
409
413
  required_rubygems_version: !ruby/object:Gem::Requirement
410
414
  none: false
411
415
  requirements:
@@ -414,7 +418,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
414
418
  version: '0'
415
419
  segments:
416
420
  - 0
417
- hash: -1627753500350458436
421
+ hash: -3050602615371028442
418
422
  requirements: []
419
423
  rubyforge_project:
420
424
  rubygems_version: 1.8.23
@@ -424,6 +428,7 @@ summary: Adapters to work with GDS APIs
424
428
  test_files:
425
429
  - test/support_api_test.rb
426
430
  - test/mapit_test.rb
431
+ - test/publishing_api_test.rb
427
432
  - test/pp_data_in_test.rb
428
433
  - test/finder_schema_test.rb
429
434
  - test/need_api_test.rb