Skip to content

Commit e03c4cc

Browse files
committed
Use Publishing API v2
The new V2 endpoint: - works by content_id, which means we can more easily change slugs in the future - allows us to only send the content, not the links. The links will contain the taggings for this content item, and tagging them separately will enable us to tag from more than one tool. Without this "content-only", this app would overwrite taggings done by other apps.
1 parent 642c4f6 commit e03c4cc

File tree

7 files changed

+23
-12
lines changed

7 files changed

+23
-12
lines changed

Gemfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ end
4949
if ENV['API_DEV']
5050
gem 'gds-api-adapters', path: '../gds-api-adapters'
5151
else
52-
gem 'gds-api-adapters', '~> 24.4.0'
52+
gem 'gds-api-adapters', '~> 25.1'
5353
end
5454

5555
if ENV['GOVSPEAK_DEV']

Gemfile.lock

+5-5
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,12 @@ GEM
6666
safe_yaml (~> 1.0.0)
6767
debug_inspector (0.0.2)
6868
docile (1.1.5)
69-
domain_name (0.5.24)
69+
domain_name (0.5.25)
7070
unf (>= 0.0.5, < 1.0.0)
7171
erubis (2.7.0)
7272
execjs (2.4.0)
7373
extlib (0.9.16)
74-
gds-api-adapters (24.4.0)
74+
gds-api-adapters (25.1.0)
7575
link_header
7676
lrucache (~> 0.1.1)
7777
null_logger
@@ -121,7 +121,7 @@ GEM
121121
mocha (1.1.0)
122122
metaclass (~> 0.0.1)
123123
multi_json (1.11.2)
124-
netrc (0.10.3)
124+
netrc (0.11.0)
125125
nokogiri (1.6.6.2)
126126
mini_portile (~> 0.6.0)
127127
null_logger (0.0.1)
@@ -139,7 +139,7 @@ GEM
139139
method_source (~> 0.8.1)
140140
slop (~> 3.4)
141141
rack (1.6.4)
142-
rack-cache (1.2)
142+
rack-cache (1.5.1)
143143
rack (>= 0.4)
144144
rack-test (0.6.3)
145145
rack (>= 1.0)
@@ -265,7 +265,7 @@ DEPENDENCIES
265265
capybara (= 2.1.0)
266266
ci_reporter
267267
extlib (= 0.9.16)
268-
gds-api-adapters (~> 24.4.0)
268+
gds-api-adapters (~> 25.1)
269269
govspeak (~> 3.3.0)
270270
govuk-content-schema-test-helpers (~> 1.3.0)
271271
govuk-lint

app/presenters/flow_content_item.rb

+7-1
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ def initialize(flow_presenter)
77

88
def payload
99
{
10+
base_path: base_path,
1011
title: flow_presenter.title,
1112
content_id: flow_presenter.content_id,
1213
format: 'placeholder_smart_answer',
1314
publishing_app: 'smartanswers',
1415
rendering_app: 'smartanswers',
15-
update_type: 'minor',
1616
locale: 'en',
1717
public_updated_at: Time.now.iso8601,
1818
routes: [
@@ -21,6 +21,12 @@ def payload
2121
}
2222
end
2323

24+
def content_id
25+
flow_presenter.content_id
26+
end
27+
28+
private
29+
2430
def base_path
2531
'/' + flow_presenter.slug
2632
end

app/services/content_item_publisher.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ class ContentItemPublisher
22
def publish(flow_presenters)
33
flow_presenters.each do |smart_answer|
44
content_item = FlowContentItem.new(smart_answer)
5-
Services.publishing_api.put_content_item(content_item.base_path, content_item.payload)
5+
Services.publishing_api.put_content(content_item.content_id, content_item.payload)
6+
Services.publishing_api.publish(content_item.content_id, 'minor')
67
end
78
end
89
end

lib/services.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
require 'gds_api/publishing_api'
1+
require 'gds_api/publishing_api_v2'
22
require 'gds_api/imminence'
33
require 'gds_api/worldwide'
44

55
module Services
66
def self.publishing_api
7-
@publishing_api ||= GdsApi::PublishingApi.new(Plek.new.find('publishing-api'))
7+
@publishing_api ||= GdsApi::PublishingApiV2.new(Plek.new.find('publishing-api'))
88
end
99

1010
def self.imminence_api

lib/smart_answer_flows/pay-leave-for-parents.rb

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
module SmartAnswer
22
class PayLeaveForParentsFlow < Flow
33
def define
4+
content_id "1f6b4ecc-ce2c-488a-b9c7-b78b3bba5598"
45
name "pay-leave-for-parents"
56
status :published
67
satisfies_need "101018"

test/unit/services/content_item_publisher_test.rb

+5-2
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,14 @@ class ContentItemPublisherTest < ActiveSupport::TestCase
77
end
88

99
test 'sending item to content store' do
10-
request = stub_request(:put, "http://publishing-api.dev.gov.uk/content/bridge-of-death")
10+
draft_request = stub_request(:put, "http://publishing-api.dev.gov.uk/v2/content/3e6f33b8-0723-4dd5-94a2-cab06f23a685")
11+
publishing_request = stub_request(:post, "http://publishing-api.dev.gov.uk/v2/content/3e6f33b8-0723-4dd5-94a2-cab06f23a685/publish")
12+
1113
presenter = FlowRegistrationPresenter.new(stub('flow', name: 'bridge-of-death', content_id: '3e6f33b8-0723-4dd5-94a2-cab06f23a685'))
1214

1315
ContentItemPublisher.new.publish([presenter])
1416

15-
assert_requested request
17+
assert_requested draft_request
18+
assert_requested publishing_request
1619
end
1720
end

0 commit comments

Comments
 (0)