wcc-contentful 1.6.1 → 1.6.2

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: b816aba232400e71ec193b4a60220a111afc356d3d6aa3a10d77f96eacea21df
4
- data.tar.gz: 95b27d0804915ef3effaf67e36e8e4ebcef39aa8001921d4e94a51c699c43a93
3
+ metadata.gz: 201a27cf2440f6857717728bedf9be194bda2ee14ae62f2eadbd8dca11d89d91
4
+ data.tar.gz: ab94d3e9a5bf2f369bc0cec01ede526541b896ac48e8d43bd19ceef5a0bc2994
5
5
  SHA512:
6
- metadata.gz: ac1bcaeb7ddfe4f1f3fa2c34a542d814665e6d1428da89a4d8ae08a59686b5048d2892dc03cd9b3501a268bcf1867787a34ddeaac0b82d5791dadceef1df69e1
7
- data.tar.gz: 7b84baba5cafff0ac07e7f0e557d08389f003918f84d2da7c10a8d7e50f60d45bd6214389b2e545803ed22964c00581920fa9f614b97d6e94a2e6e75abc090bc
6
+ metadata.gz: 9d0773e70c53a008b56ba96e9a352240db14902657c869449d47aefafc0d9889475947eec0c7e4f4b30d56444ea9763d5ab686045a6dd32bc67800ae62f0142a
7
+ data.tar.gz: c75c8423dc83f4e1ab695a5a5e0c18809235d0e1d4cbbaa3d960c9f8a3bb8380aab08d0324e87b45842c28a9eb514b9285cc49b418a5230026ccb3ccfe539509
@@ -32,7 +32,11 @@ module WCC::Contentful
32
32
  next unless config&.management_token.present?
33
33
  next unless config.app_url.present?
34
34
 
35
- WebhookEnableJob.set(wait: 10.seconds).perform_later if Rails.env.production?
35
+ if defined?(WCC::Contentful::WebhookEnableJob)
36
+ WCC::Contentful::WebhookEnableJob.set(wait: 10.seconds).perform_later if Rails.env.production?
37
+ else
38
+ Rails.logger.error 'ActiveJob is not defined, webhook enable job will not run'
39
+ end
36
40
  end
37
41
  end
38
42
 
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'singleton'
4
+ require 'ostruct'
4
5
 
5
6
  module WCC::Contentful::Event
6
7
  extend ActiveSupport::Concern
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'ostruct'
3
4
  require_relative './link'
4
5
  require_relative './sys'
5
6
  require_relative './rich_text'
@@ -2,6 +2,7 @@
2
2
 
3
3
  gem 'typhoeus'
4
4
  require 'typhoeus'
5
+ require 'ostruct'
5
6
 
6
7
  class WCC::Contentful::SimpleClient::TyphoeusAdapter
7
8
  def get(url, params = {}, headers = {})
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'ostruct'
4
+
3
5
  require_relative './attributes'
4
6
 
5
7
  module WCC::Contentful::Test::Double
@@ -2,6 +2,6 @@
2
2
 
3
3
  module WCC
4
4
  module Contentful
5
- VERSION = '1.6.1'
5
+ VERSION = '1.6.2'
6
6
  end
7
7
  end
@@ -0,0 +1,76 @@
1
+ # frozen_string_literal: true
2
+
3
+ module WCC::Contentful
4
+ if defined?(ActiveJob)
5
+ class WebhookEnableJob < ActiveJob::Base
6
+ self.queue_adapter = :async
7
+ queue_as :default
8
+
9
+ def perform(args = {})
10
+ args = default_configuration.merge!(args)
11
+
12
+ client = WCC::Contentful::SimpleClient::Management.new(
13
+ **args
14
+ )
15
+ enable_webhook(client, **args.slice(:receive_url, :webhook_username, :webhook_password))
16
+ end
17
+
18
+ def enable_webhook(client, receive_url:, webhook_username: nil, webhook_password: nil)
19
+ webhook = client.webhook_definitions.items.find { |w| w['url'] == receive_url }
20
+ logger.debug "existing webhook: #{webhook.inspect}" if webhook
21
+ return if webhook
22
+
23
+ body = {
24
+ 'name' => 'WCC::Contentful webhook',
25
+ 'url' => receive_url,
26
+ 'topics' => [
27
+ '*.publish',
28
+ '*.unpublish'
29
+ ],
30
+ 'filters' => webhook_filters
31
+ }
32
+ body['httpBasicUsername'] = webhook_username if webhook_username.present?
33
+ body['httpBasicPassword'] = webhook_password if webhook_password.present?
34
+
35
+ begin
36
+ resp = client.post_webhook_definition(body)
37
+ logger.info "Created webhook: #{resp.raw.dig('sys', 'id')}"
38
+ rescue WCC::Contentful::SimpleClient::ApiError => e
39
+ logger.error "#{e.response.code}: #{e.response.raw}" if e.response
40
+ raise
41
+ end
42
+ end
43
+
44
+ private
45
+
46
+ def default_configuration
47
+ return {} unless config = WCC::Contentful&.configuration
48
+
49
+ {
50
+ management_token: config.management_token,
51
+ space: config.space,
52
+ environment: config.environment,
53
+ connection: config.connection,
54
+ webhook_username: config.webhook_username,
55
+ webhook_password: config.webhook_password,
56
+
57
+ receive_url: URI.join(config.app_url, 'webhook/receive').to_s
58
+ }
59
+ end
60
+
61
+ def webhook_filters
62
+ filters = []
63
+
64
+ if (environment_id = WCC::Contentful.configuration&.environment).present?
65
+ filters << {
66
+ 'equals' => [
67
+ { 'doc' => 'sys.environment.sys.id' },
68
+ environment_id
69
+ ]
70
+ }
71
+ end
72
+ filters
73
+ end
74
+ end
75
+ end
76
+ end
@@ -24,6 +24,7 @@ require 'wcc/contentful/rich_text'
24
24
  require 'wcc/contentful/rich_text_renderer'
25
25
  require 'wcc/contentful/rich_text_renderer_factory'
26
26
  require 'wcc/contentful/sync_engine'
27
+ require 'wcc/contentful/webhook_enable_job'
27
28
  require 'wcc/contentful/events'
28
29
  require 'wcc/contentful/middleware'
29
30
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wcc-contentful
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.1
4
+ version: 1.6.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Watermark Dev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-11-27 00:00:00.000000000 Z
11
+ date: 2024-11-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: byebug
@@ -419,7 +419,6 @@ files:
419
419
  - Rakefile
420
420
  - app/controllers/wcc/contentful/application_controller.rb
421
421
  - app/controllers/wcc/contentful/webhook_controller.rb
422
- - app/jobs/wcc/contentful/webhook_enable_job.rb
423
422
  - config/initializers/mime_types.rb
424
423
  - config/routes.rb
425
424
  - lib/tasks/download_schema.rake
@@ -494,6 +493,7 @@ files:
494
493
  - lib/wcc/contentful/test/double.rb
495
494
  - lib/wcc/contentful/test/factory.rb
496
495
  - lib/wcc/contentful/version.rb
496
+ - lib/wcc/contentful/webhook_enable_job.rb
497
497
  - wcc-contentful.gemspec
498
498
  homepage: https://github.com/watermarkchurch/wcc-contentful/wcc-contentful
499
499
  licenses:
@@ -516,7 +516,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
516
516
  - !ruby/object:Gem::Version
517
517
  version: '0'
518
518
  requirements: []
519
- rubygems_version: 3.4.10
519
+ rubygems_version: 3.5.16
520
520
  signing_key:
521
521
  specification_version: 4
522
522
  summary: '[![Gem Version](https://badge.fury.io/rb/wcc-contentful.svg)](https://rubygems.org/gems/wcc-contentful)
@@ -1,76 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'active_job'
4
-
5
- module WCC::Contentful
6
- class WebhookEnableJob < ActiveJob::Base
7
- self.queue_adapter = :async
8
- queue_as :default
9
-
10
- def perform(args = {})
11
- args = default_configuration.merge!(args)
12
-
13
- client = WCC::Contentful::SimpleClient::Management.new(
14
- **args
15
- )
16
- enable_webhook(client, **args.slice(:receive_url, :webhook_username, :webhook_password))
17
- end
18
-
19
- def enable_webhook(client, receive_url:, webhook_username: nil, webhook_password: nil)
20
- webhook = client.webhook_definitions.items.find { |w| w['url'] == receive_url }
21
- logger.debug "existing webhook: #{webhook.inspect}" if webhook
22
- return if webhook
23
-
24
- body = {
25
- 'name' => 'WCC::Contentful webhook',
26
- 'url' => receive_url,
27
- 'topics' => [
28
- '*.publish',
29
- '*.unpublish'
30
- ],
31
- 'filters' => webhook_filters
32
- }
33
- body['httpBasicUsername'] = webhook_username if webhook_username.present?
34
- body['httpBasicPassword'] = webhook_password if webhook_password.present?
35
-
36
- begin
37
- resp = client.post_webhook_definition(body)
38
- logger.info "Created webhook: #{resp.raw.dig('sys', 'id')}"
39
- rescue WCC::Contentful::SimpleClient::ApiError => e
40
- logger.error "#{e.response.code}: #{e.response.raw}" if e.response
41
- raise
42
- end
43
- end
44
-
45
- private
46
-
47
- def default_configuration
48
- return {} unless config = WCC::Contentful&.configuration
49
-
50
- {
51
- management_token: config.management_token,
52
- space: config.space,
53
- environment: config.environment,
54
- connection: config.connection,
55
- webhook_username: config.webhook_username,
56
- webhook_password: config.webhook_password,
57
-
58
- receive_url: URI.join(config.app_url, 'webhook/receive').to_s
59
- }
60
- end
61
-
62
- def webhook_filters
63
- filters = []
64
-
65
- if (environment_id = WCC::Contentful.configuration&.environment).present?
66
- filters << {
67
- 'equals' => [
68
- { 'doc' => 'sys.environment.sys.id' },
69
- environment_id
70
- ]
71
- }
72
- end
73
- filters
74
- end
75
- end
76
- end