Skip to content

Commit bf71348

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 bf71348

9 files changed

+27
-15
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

+8-1
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@ 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',
16+
update_type: 'minor', # This is not used, but required by the schema.
1617
locale: 'en',
1718
public_updated_at: Time.now.iso8601,
1819
routes: [
@@ -21,6 +22,12 @@ def payload
2122
}
2223
end
2324

25+
def content_id
26+
flow_presenter.content_id
27+
end
28+
29+
private
30+
2431
def base_path
2532
'/' + flow_presenter.slug
2633
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/data/pay-leave-for-parents-files.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
lib/smart_answer_flows/pay-leave-for-parents.rb: 2e88417e998adfcf81610f01d9434e1b
2+
lib/smart_answer_flows/pay-leave-for-parents.rb: 1c29ac285bf104fbda7c7592a590aae1
33
lib/smart_answer_flows/locales/en/pay-leave-for-parents.yml: 4fbf50de17ab9c2082b335519cce6b69
44
test/data/pay-leave-for-parents-questions-and-responses.yml: 6aae67d1b585e8445878fb2994bac8d1
55
test/data/pay-leave-for-parents-responses-and-expected-results.yml: 2cdd65aad00267bdf9a534e22858f03d

test/unit/flow_content_item_test.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ class FlowContentItemTest < ActiveSupport::TestCase
1919
end
2020

2121
test '#base_path is the name of the flow' do
22-
presenter = FlowRegistrationPresenter.new(stub('flow', name: 'bridge-of-death'))
22+
presenter = FlowRegistrationPresenter.new(stub('flow', name: 'bridge-of-death', content_id: '25b98dfb-fabe-4b16-b587-072c8233f6bc'))
2323
content_item = FlowContentItem.new(presenter)
2424

25-
base_path = content_item.base_path
25+
base_path = content_item.payload[:base_path]
2626

2727
assert_equal "/bridge-of-death", base_path
2828
end

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)