publishing_platform_api_adapters 0.6.0 → 0.7.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: eb62fed6a72d2512d1f471e22d685569e135cf51778862f55144b232b2de6c60
4
- data.tar.gz: ccd79815a040973a078ae707d4dfcf5d3b1f7b8c27347d3c8c190f2f651a022a
3
+ metadata.gz: 546721a4d7c247b0de3d3aed7767d8c355b79628b77248fb3624889f751a3f26
4
+ data.tar.gz: 664183ea7606c204354531ffb4a69b392e6475a01477af2256074c7608aeeeee
5
5
  SHA512:
6
- metadata.gz: f3266daeaf38ba3f4faef257188f1a4e8cb06dad0ec451aba60aa285eec5b380c1e247569c072de8b5394df39c67b5813288ab24f50cfa7635c381bc105c37b1
7
- data.tar.gz: 91291529747a1d3f6b6182f633411e23c7df07214238f4fa44352666da0430c5451ac742c0f31575b3286dc9dc0f48e8745c2c3b846916f4d603f7f328df8e10
6
+ metadata.gz: 89072fe076a7b666ca0b661e2f1ae3c51402c163d1c7a6d91fd80fecfa6bcd8e2fa23a3fe02342156af2389f1b3c5475e37333133f0dca6ba6e22c74b1ac74bf
7
+ data.tar.gz: cf14d5aaed20522dea8ebe2d83c1dd87a70fcdb035ea7182181049c9093a8bbbe4bdf7f5dc2a6d18de50322ac9950830deb25806537a2b575cdd271ba22900e4
data/Rakefile CHANGED
@@ -1,8 +1,8 @@
1
- # frozen_string_literal: true
2
-
3
1
  require "bundler/gem_tasks"
2
+ require "rubocop/rake_task"
4
3
  require "rspec/core/rake_task"
5
4
 
6
5
  RSpec::Core::RakeTask.new(:spec)
6
+ RuboCop::RakeTask.new
7
7
 
8
- task default: :spec
8
+ task default: %i[rubocop spec]
@@ -198,4 +198,4 @@ module PublishingPlatformApi
198
198
  raise PublishingPlatformApi::SocketErrorException, e.message
199
199
  end
200
200
  end
201
- end
201
+ end
@@ -0,0 +1,17 @@
1
+ require_relative "base"
2
+
3
+ class PublishingPlatformApi::Organisations < PublishingPlatformApi::Base
4
+ def organisations
5
+ get_list "#{base_url}/organisations"
6
+ end
7
+
8
+ def organisation(organisation_slug)
9
+ get_json "#{base_url}/organisations/#{organisation_slug}"
10
+ end
11
+
12
+ private
13
+
14
+ def base_url
15
+ "#{endpoint}/api"
16
+ end
17
+ end
@@ -0,0 +1,51 @@
1
+ require "publishing_platform_api/publishing_api"
2
+ require "time"
3
+
4
+ module PublishingPlatformApi
5
+ class PublishingApi < PublishingPlatformApi::Base
6
+ class SpecialRoutePublisher
7
+ def initialize(options = {})
8
+ @logger = options[:logger] || PublishingPlatformApi::Base.logger
9
+ @publishing_api = options[:publishing_api] || PublishingPlatformApi::PublishingApi.new(PublishingPlatformLocation.find("publishing-api"))
10
+ end
11
+
12
+ def publish(options)
13
+ logger.info("Publishing #{options.fetch(:type)} route #{options.fetch(:base_path)}, routing to #{options.fetch(:rendering_app)}")
14
+
15
+ update_type = options.fetch(:update_type, "major")
16
+
17
+ put_content_response = publishing_api.put_content(
18
+ options.fetch(:content_id),
19
+ base_path: options.fetch(:base_path),
20
+ document_type: options.fetch(:document_type, "special_route"),
21
+ schema_name: options.fetch(:schema_name, "special_route"),
22
+ title: options.fetch(:title),
23
+ description: options.fetch(:description, ""),
24
+ details: {},
25
+ routes: [
26
+ {
27
+ path: options.fetch(:base_path),
28
+ type: options.fetch(:type),
29
+ },
30
+ ],
31
+ publishing_app: options.fetch(:publishing_app),
32
+ rendering_app: options.fetch(:rendering_app),
33
+ public_updated_at: time.now.iso8601,
34
+ update_type:,
35
+ )
36
+
37
+ publishing_api.patch_links(options.fetch(:content_id), links: options[:links]) if options[:links]
38
+ publishing_api.publish(options.fetch(:content_id))
39
+ put_content_response
40
+ end
41
+
42
+ private
43
+
44
+ attr_reader :logger, :publishing_api
45
+
46
+ def time
47
+ (Time.respond_to?(:zone) && Time.zone) || Time
48
+ end
49
+ end
50
+ end
51
+ end
@@ -10,7 +10,7 @@ class PublishingPlatformApi::PublishingApi < PublishingPlatformApi::Base
10
10
  # Put a content item
11
11
  #
12
12
  # @param content_id [UUID]
13
- # @param payload [Hash] A valid content item
13
+ # @param payload [Hash] A valid content item
14
14
  def put_content(content_id, payload)
15
15
  put_json(content_url(content_id), payload)
16
16
  end
@@ -123,13 +123,13 @@ class PublishingPlatformApi::PublishingApi < PublishingPlatformApi::Base
123
123
  # }
124
124
  def get_links(content_id)
125
125
  get_json(links_url(content_id))
126
- end
126
+ end
127
127
 
128
128
  # Get expanded links
129
129
  #
130
130
  # Return the expanded links of the item.
131
131
  #
132
- # @param content_id [UUID]
132
+ # @param content_id [UUID]
133
133
  # @param with_drafts [Bool] Whether links to draft-only editions are returned, defaulting to `true`.
134
134
  # @param generate [Bool] Whether to require publishing-api to generate the expanded links, which may be slow. Defaults to `false`.
135
135
  #
@@ -155,14 +155,14 @@ class PublishingPlatformApi::PublishingApi < PublishingPlatformApi::Base
155
155
  query = query_string(params)
156
156
  validate_content_id(content_id)
157
157
  get_json("#{endpoint}/expanded-links/#{content_id}#{query}")
158
- end
158
+ end
159
159
 
160
160
  # Patch the links of a content item
161
161
  #
162
162
  # @param content_id [UUID]
163
163
  # @param params [Hash]
164
164
  # @option params [Hash] links A "links hash"
165
- # @option params [Integer] previous_version The previous version (returned by `get_links`). If this version is not the current version, the publishing-api will reject the change and return 409 Conflict. (optional)
165
+ # @option params [Integer] previous_version The previous version (returned by `get_links`). If this version is not the current version, the publishing-api will reject the change and return 409 Conflict. (optional)
166
166
  # @example
167
167
  #
168
168
  # publishing_api.patch_links(
@@ -214,7 +214,7 @@ class PublishingPlatformApi::PublishingApi < PublishingPlatformApi::Base
214
214
  end
215
215
 
216
216
  get_json("#{endpoint}/linkables?document_type=#{document_type}")
217
- end
217
+ end
218
218
 
219
219
  # Reserves a path for a publishing application
220
220
  #
@@ -278,4 +278,4 @@ private
278
278
  def validate_content_id(content_id)
279
279
  raise ArgumentError, "content_id cannot be nil" unless content_id
280
280
  end
281
- end
281
+ end
@@ -60,4 +60,4 @@ class PublishingPlatformApi::Router < PublishingPlatformApi::Base
60
60
 
61
61
  delete_json(url)
62
62
  end
63
- end
63
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PublishingPlatformApi
4
- VERSION = "0.6.0"
4
+ VERSION = "0.7.0"
5
5
  end
@@ -20,6 +20,18 @@ module PublishingPlatformApi
20
20
  )
21
21
  end
22
22
 
23
+ # Creates a PublishingPlatformApi::Organisations adapter for accessing
24
+ # APIs through the origin, where the requests will be handled by
25
+ # Collections frontend.
26
+ #
27
+ # @return [PublishingPlatformApi::Organisations]
28
+ def self.organisations(options = {})
29
+ PublishingPlatformApi::Organisations.new(
30
+ PublishingPlatformLocation.new.website_root,
31
+ options,
32
+ )
33
+ end
34
+
23
35
  # Creates a PublishingPlatformApi::PublishingApi adapter
24
36
  #
25
37
  # This will set a bearer token if a PUBLISHING_API_BEARER_TOKEN environment
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: publishing_platform_api_adapters
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Publishing Platform
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2024-08-28 00:00:00.000000000 Z
10
+ date: 2025-02-06 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: addressable
@@ -95,7 +94,6 @@ dependencies:
95
94
  - !ruby/object:Gem::Version
96
95
  version: '0'
97
96
  description: Adapters to work with Publishing Platform APIs
98
- email:
99
97
  executables: []
100
98
  extensions: []
101
99
  extra_rdoc_files: []
@@ -109,18 +107,18 @@ files:
109
107
  - lib/publishing_platform_api/json_client.rb
110
108
  - lib/publishing_platform_api/list_response.rb
111
109
  - lib/publishing_platform_api/middleware/publishing_platform_header_sniffer.rb
110
+ - lib/publishing_platform_api/organisations.rb
112
111
  - lib/publishing_platform_api/publishing_api.rb
112
+ - lib/publishing_platform_api/publishing_api/special_route_publisher.rb
113
113
  - lib/publishing_platform_api/publishing_platform_headers.rb
114
114
  - lib/publishing_platform_api/railtie.rb
115
115
  - lib/publishing_platform_api/response.rb
116
116
  - lib/publishing_platform_api/router.rb
117
117
  - lib/publishing_platform_api/version.rb
118
118
  - lib/publishing_platform_api_adapters.rb
119
- homepage:
120
119
  licenses:
121
120
  - MIT
122
121
  metadata: {}
123
- post_install_message:
124
122
  rdoc_options: []
125
123
  require_paths:
126
124
  - lib
@@ -128,15 +126,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
128
126
  requirements:
129
127
  - - ">="
130
128
  - !ruby/object:Gem::Version
131
- version: '3.0'
129
+ version: '3.1'
132
130
  required_rubygems_version: !ruby/object:Gem::Requirement
133
131
  requirements:
134
132
  - - ">="
135
133
  - !ruby/object:Gem::Version
136
134
  version: '0'
137
135
  requirements: []
138
- rubygems_version: 3.3.7
139
- signing_key:
136
+ rubygems_version: 3.6.3
140
137
  specification_version: 4
141
138
  summary: Adapters to work with Publishing Platform APIs
142
139
  test_files: []