publishing_platform_api_adapters 0.5.0 → 0.6.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
  SHA256:
3
- metadata.gz: dadc8a7f07684d3fad45a0efcfaa222a0763dbebd20fe3e0d5b7fc551196f65d
4
- data.tar.gz: ecfbc92e940928e42f4d7e09b0a211fb2ebf5edf94dd6c86f5156c533d104a54
3
+ metadata.gz: eb62fed6a72d2512d1f471e22d685569e135cf51778862f55144b232b2de6c60
4
+ data.tar.gz: ccd79815a040973a078ae707d4dfcf5d3b1f7b8c27347d3c8c190f2f651a022a
5
5
  SHA512:
6
- metadata.gz: 0ed8d5992d01a25a5313d0e5f7beeb21ff4b46541abca773617adc6398bd33b4847303cc89f086fed0b355b9c896c78f7098e650f77605903b09cbfa78a349f1
7
- data.tar.gz: 907d770b9ed8568d12e861a04a6b184e20ec5eba029450d27ff40f6349ac0bb249bd465a85056853ae7a23ad44fffec144d31166514a9f26b74a18e79f4eb27a
6
+ metadata.gz: f3266daeaf38ba3f4faef257188f1a4e8cb06dad0ec451aba60aa285eec5b380c1e247569c072de8b5394df39c67b5813288ab24f50cfa7635c381bc105c37b1
7
+ data.tar.gz: 91291529747a1d3f6b6182f633411e23c7df07214238f4fa44352666da0430c5451ac742c0f31575b3286dc9dc0f48e8745c2c3b846916f4d603f7f328df8e10
@@ -3,27 +3,27 @@ require_relative "middleware/publishing_platform_header_sniffer"
3
3
  module PublishingPlatformApi
4
4
  class Railtie < Rails::Railtie
5
5
  initializer "publishing_platform_api.initialize_publishing_platform_request_id_sniffer" do |app|
6
- Rails.logger.debug "Using middleware PublishingPlatformApi::PublishingPlatformHeaderSniffer to sniff for PublishingPlatform-Request-Id header"
6
+ Rails.logger.debug "Using middleware PublishingPlatformApi::PublishingPlatformHeaderSniffer to sniff for Publishing-Platform-Request-Id header"
7
7
  app.middleware.use PublishingPlatformApi::PublishingPlatformHeaderSniffer, "HTTP_PUBLISHING_PLATFORM_REQUEST_ID"
8
8
  end
9
9
 
10
10
  initializer "publishing_platform_api.initialize_publishing_platform_original_url_sniffer" do |app|
11
- Rails.logger.debug "Using middleware PublishingPlatformApi::PublishingPlatformHeaderSniffer to sniff for PublishingPlatform-Original-Url header"
11
+ Rails.logger.debug "Using middleware PublishingPlatformApi::PublishingPlatformHeaderSniffer to sniff for Publishing-Platform-Original-Url header"
12
12
  app.middleware.use PublishingPlatformApi::PublishingPlatformHeaderSniffer, "HTTP_PUBLISHING_PLATFORM_ORIGINAL_URL"
13
13
  end
14
14
 
15
15
  initializer "publishing_platform_api.initialize_publishing_platform_authenticated_user_sniffer" do |app|
16
- Rails.logger.debug "Using middleware PublishingPlatformApi::PublishingPlatformHeaderSniffer to sniff for X-PublishingPlatform-Authenticated-User header"
16
+ Rails.logger.debug "Using middleware PublishingPlatformApi::PublishingPlatformHeaderSniffer to sniff for X-Publishing-Platform-Authenticated-User header"
17
17
  app.middleware.use PublishingPlatformApi::PublishingPlatformHeaderSniffer, "HTTP_X_PUBLISHING_PLATFORM_AUTHENTICATED_USER"
18
18
  end
19
19
 
20
20
  initializer "publishing_platform_api.initialize_publishing_platform_authenticated_user_organisation_sniffer" do |app|
21
- Rails.logger.debug "Using middleware PublishingPlatformApi::PublishingPlatformHeaderSniffer to sniff for X-PublishingPlatform-Authenticated-User-Organisation header"
21
+ Rails.logger.debug "Using middleware PublishingPlatformApi::PublishingPlatformHeaderSniffer to sniff for X-Publishing-Platform-Authenticated-User-Organisation header"
22
22
  app.middleware.use PublishingPlatformApi::PublishingPlatformHeaderSniffer, "HTTP_X_PUBLISHING_PLATFORM_AUTHENTICATED_USER_ORGANISATION"
23
23
  end
24
24
 
25
25
  initializer "publishing_platform_api.initialize_publishing_platform_content_id_sniffer" do |app|
26
- Rails.logger.debug "Using middleware PublishingPlatformApi::PublishingPlatformHeaderSniffer to sniff for PublishingPlatform-Auth-Bypass-Id header"
26
+ Rails.logger.debug "Using middleware PublishingPlatformApi::PublishingPlatformHeaderSniffer to sniff for Publishing-Platform-Auth-Bypass-Id header"
27
27
  app.middleware.use PublishingPlatformApi::PublishingPlatformHeaderSniffer, "HTTP_PUBLISHING_PLATFORM_AUTH_BYPASS_ID"
28
28
  end
29
29
  end
@@ -0,0 +1,63 @@
1
+ require_relative "base"
2
+
3
+ class PublishingPlatformApi::Router < PublishingPlatformApi::Base
4
+ ### Backends
5
+
6
+ def get_backend(id)
7
+ get_json("#{endpoint}/backends/#{CGI.escape(id)}")
8
+ end
9
+
10
+ def add_backend(id, url)
11
+ put_json("#{endpoint}/backends/#{CGI.escape(id)}", backend: { backend_url: url })
12
+ end
13
+
14
+ def delete_backend(id)
15
+ delete_json("#{endpoint}/backends/#{CGI.escape(id)}")
16
+ end
17
+
18
+ ### Routes
19
+
20
+ def get_route(path)
21
+ get_json("#{endpoint}/routes?incoming_path=#{CGI.escape(path)}")
22
+ end
23
+
24
+ def add_route(path, type, backend_id)
25
+ put_json(
26
+ "#{endpoint}/routes",
27
+ route: {
28
+ incoming_path: path,
29
+ route_type: type,
30
+ handler: "backend",
31
+ backend_id:,
32
+ },
33
+ )
34
+ end
35
+
36
+ def add_redirect_route(path, type, destination, redirect_type = "permanent", options = {})
37
+ put_json(
38
+ "#{endpoint}/routes",
39
+ route: {
40
+ incoming_path: path,
41
+ route_type: type,
42
+ handler: "redirect",
43
+ redirect_to: destination,
44
+ redirect_type:,
45
+ segments_mode: options[:segments_mode],
46
+ },
47
+ )
48
+ end
49
+
50
+ def add_gone_route(path, type)
51
+ put_json(
52
+ "#{endpoint}/routes",
53
+ route: { incoming_path: path, route_type: type, handler: "gone" },
54
+ )
55
+ end
56
+
57
+ def delete_route(path, hard_delete: false)
58
+ url = "#{endpoint}/routes?incoming_path=#{CGI.escape(path)}"
59
+ url += "&hard_delete=true" if hard_delete
60
+
61
+ delete_json(url)
62
+ end
63
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PublishingPlatformApi
4
- VERSION = "0.5.0"
4
+ VERSION = "0.6.0"
5
5
  end
@@ -1,11 +1,25 @@
1
1
  require "addressable"
2
2
  require "publishing_platform_location"
3
3
  require "time"
4
- require "publishing_platform_api/publishing_api"
5
4
  require "publishing_platform_api/content_store"
5
+ require "publishing_platform_api/publishing_api"
6
+ require "publishing_platform_api/router"
6
7
 
7
8
  # @api documented
8
9
  module PublishingPlatformApi
10
+ # Creates a PublishingPlatformApi::ContentStore adapter
11
+ #
12
+ # This will set a bearer token if a CONTENT_STORE_BEARER_TOKEN environment
13
+ # variable is set
14
+ #
15
+ # @return [PublishingPlatformApi::ContentStore]
16
+ def self.content_store(options = {})
17
+ PublishingPlatformApi::ContentStore.new(
18
+ PublishingPlatformLocation.find("content-store"),
19
+ { bearer_token: ENV["CONTENT_STORE_BEARER_TOKEN"] }.merge(options),
20
+ )
21
+ end
22
+
9
23
  # Creates a PublishingPlatformApi::PublishingApi adapter
10
24
  #
11
25
  # This will set a bearer token if a PUBLISHING_API_BEARER_TOKEN environment
@@ -19,16 +33,16 @@ module PublishingPlatformApi
19
33
  )
20
34
  end
21
35
 
22
- # Creates a PublishingPlatformApi::ContentStore adapter
36
+ # Creates a PublishingPlatformApi::Router adapter for communicating with Router API
23
37
  #
24
- # This will set a bearer token if a CONTENT_STORE_BEARER_TOKEN environment
38
+ # This will set a bearer token if a ROUTER_API_BEARER_TOKEN environment
25
39
  # variable is set
26
40
  #
27
- # @return [PublishingPlatformApi::ContentStore]
28
- def self.content_store(options = {})
29
- PublishingPlatformApi::ContentStore.new(
30
- PublishingPlatformLocation.find("content-store"),
31
- { bearer_token: ENV["CONTENT_STORE_BEARER_TOKEN"] }.merge(options),
41
+ # @return [PublishingPlatformApi::Router]
42
+ def self.router(options = {})
43
+ PublishingPlatformApi::Router.new(
44
+ PublishingPlatformLocation.find("router-api"),
45
+ { bearer_token: ENV["ROUTER_API_BEARER_TOKEN"] }.merge(options),
32
46
  )
33
47
  end
34
48
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: publishing_platform_api_adapters
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Publishing Platform
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-08-05 00:00:00.000000000 Z
11
+ date: 2024-08-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
@@ -113,6 +113,7 @@ files:
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
+ - lib/publishing_platform_api/router.rb
116
117
  - lib/publishing_platform_api/version.rb
117
118
  - lib/publishing_platform_api_adapters.rb
118
119
  homepage: