zaikio-webhooks 0.0.10 → 0.2.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: c1e4bb1dfafbb05d683f49875dfd21bec26c616a4e526e3e2d2c0de5cd2b1871
4
- data.tar.gz: 198c277707f4f25d9a76c69a16f23d15b59b22bf46041748adb1f685ee9e2409
3
+ metadata.gz: b1041992660107d3cd89e5a14f95251a24163adf6a2933e9cad959f1827e1b06
4
+ data.tar.gz: 73a2c6ad3b1eece070faf9aafe0217991cf4b4bb89284c49c05a02f333c2400c
5
5
  SHA512:
6
- metadata.gz: 97c1264c19fce2edd41dcc3055a7ac6f02951b7a8c2806f60bf59c40831af2d40452adf3fcbf489892cfee56523ccd39114a3135f826463332a09b354dbc7624
7
- data.tar.gz: 6993041564dbae221625fc61fa916381d4838958fca8ece7dfea4ca8eb410e4ab06d31e4410dbfad20bd166acbab90fe56d121ae34d19ce5af1ce8b213b31e17
6
+ metadata.gz: 6c987086f8a0dd42f0fc273646f9519fd1a162816339b0056d25f20246202888afce2ff97cbe8ffd2b2ac086cf65f845d69772641b63801f242e45789ffa69ba
7
+ data.tar.gz: 4ac9e4e65fa8abc15e0860bfc980b625948894e31443d8ff1c5573f8956f559a000e746690d5bf4a9a83e659a4bc7ac7af61731caa6fcc4d4b25180042962521
data/README.md CHANGED
@@ -96,7 +96,7 @@ Rails.application.reloader.to_prepare do
96
96
  perform_now: true
97
97
  # Only for a specific client
98
98
  Zaikio::Webhooks.on "directory.machine_added", AddMachineJob,
99
- client_name: :my_app
99
+ client_name: :my_app, options: { custom_keyword_argument_for_job: "value" }
100
100
  end
101
101
  ```
102
102
 
@@ -8,7 +8,7 @@ module Zaikio
8
8
  Zaikio::Webhooks.webhooks_for(params[:client_name], event_params[:name])
9
9
  .each do |job_klass, options|
10
10
  job_klass.public_send(options[:perform_now] ? :perform_now : :perform_later,
11
- Zaikio::Webhooks::Event.new(event_params))
11
+ Zaikio::Webhooks::Event.new(event_params), **options[:options])
12
12
  end
13
13
 
14
14
  head :ok
@@ -31,7 +31,7 @@ module Zaikio
31
31
 
32
32
  def event_params
33
33
  params.permit(:id, :client_name, :name, :subject, :timestamp,
34
- :version, :link, :received_at, payload: {})
34
+ :version, :link, :received_at, payload: {}).to_h
35
35
  end
36
36
  end
37
37
  end
@@ -4,28 +4,35 @@ module Zaikio
4
4
  module Webhooks
5
5
  class Event
6
6
  extend Forwardable
7
- attr_reader :data
8
7
 
9
- def_delegators :data, :id, :name, :version, :payload, :link, :client_name, :to_h
8
+ attr_reader :id, :name, :version, :payload, :link, :client_name, :data
9
+
10
+ def_delegators :data, :to_h
10
11
 
11
12
  def initialize(event_data)
12
- @data = OpenStruct.new(event_data)
13
+ event_data = event_data.to_h.stringify_keys
14
+
15
+ event_data.each do |key, value|
16
+ instance_variable_set("@#{key}", value)
17
+ end
18
+
19
+ @data = event_data
13
20
  end
14
21
 
15
22
  def created_at
16
- DateTime.parse(data.timestamp)
23
+ DateTime.parse(data["timestamp"])
17
24
  end
18
25
 
19
26
  def received_at
20
- DateTime.parse(data.received_at)
27
+ DateTime.parse(data["received_at"])
21
28
  end
22
29
 
23
30
  def subject_id
24
- data.subject.split("/").last
31
+ data["subject"].split("/").last
25
32
  end
26
33
 
27
34
  def subject_type
28
- data.subject.split("/").first == "Org" ? "Organization" : "Person"
35
+ data["subject"].split("/").first == "Org" ? "Organization" : "Person"
29
36
  end
30
37
 
31
38
  def ==(other)
@@ -10,7 +10,7 @@ module Zaikio
10
10
  end
11
11
 
12
12
  def deserialize(data)
13
- Event.new(data)
13
+ Event.new(data.without("_aj_serialized"))
14
14
  end
15
15
  end
16
16
  end
@@ -1,5 +1,5 @@
1
1
  module Zaikio
2
2
  module Webhooks
3
- VERSION = "0.0.10".freeze
3
+ VERSION = "0.2.0".freeze
4
4
  end
5
5
  end
@@ -35,7 +35,7 @@ module Zaikio
35
35
  (@webhooks.dig(client_name.to_s, event_name.to_s) || {})
36
36
  end
37
37
 
38
- def on(event_name, job_klass, client_name: nil, perform_now: false)
38
+ def on(event_name, job_klass, client_name: nil, perform_now: false, options: {})
39
39
  @webhooks ||= {}
40
40
 
41
41
  after_configuration do
@@ -44,7 +44,8 @@ module Zaikio
44
44
  @webhooks[name] ||= {}
45
45
  @webhooks[name][event_name.to_s] ||= {}
46
46
  @webhooks[name][event_name.to_s][job_klass] = {
47
- perform_now: perform_now
47
+ perform_now: perform_now,
48
+ options: options
48
49
  }
49
50
  end
50
51
  end
metadata CHANGED
@@ -1,55 +1,75 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zaikio-webhooks
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.10
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zaikio GmbH
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-03-29 00:00:00.000000000 Z
11
+ date: 2022-08-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionpack
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: '6.0'
20
17
  - - ">="
21
18
  - !ruby/object:Gem::Version
22
19
  version: 6.0.2.2
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '8'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
- - - "~>"
27
+ - - ">="
28
28
  - !ruby/object:Gem::Version
29
- version: '6.0'
29
+ version: 6.0.2.2
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '8'
33
+ - !ruby/object:Gem::Dependency
34
+ name: activejob
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
30
37
  - - ">="
31
38
  - !ruby/object:Gem::Version
32
39
  version: 6.0.2.2
40
+ - - "<"
41
+ - !ruby/object:Gem::Version
42
+ version: '8'
43
+ type: :runtime
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: 6.0.2.2
50
+ - - "<"
51
+ - !ruby/object:Gem::Version
52
+ version: '8'
33
53
  - !ruby/object:Gem::Dependency
34
54
  name: railties
35
55
  requirement: !ruby/object:Gem::Requirement
36
56
  requirements:
37
- - - "~>"
38
- - !ruby/object:Gem::Version
39
- version: '6.0'
40
57
  - - ">="
41
58
  - !ruby/object:Gem::Version
42
59
  version: 6.0.2.2
60
+ - - "<"
61
+ - !ruby/object:Gem::Version
62
+ version: '8'
43
63
  type: :runtime
44
64
  prerelease: false
45
65
  version_requirements: !ruby/object:Gem::Requirement
46
66
  requirements:
47
- - - "~>"
48
- - !ruby/object:Gem::Version
49
- version: '6.0'
50
67
  - - ">="
51
68
  - !ruby/object:Gem::Version
52
69
  version: 6.0.2.2
70
+ - - "<"
71
+ - !ruby/object:Gem::Version
72
+ version: '8'
53
73
  description: Handle incoming Zaikio loom webhooks
54
74
  email:
55
75
  - js@crispymtn.com
@@ -92,7 +112,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
92
112
  - !ruby/object:Gem::Version
93
113
  version: '0'
94
114
  requirements: []
95
- rubygems_version: 3.1.4
115
+ rubygems_version: 3.2.32
96
116
  signing_key:
97
117
  specification_version: 4
98
118
  summary: Handle incoming Zaikio loom webhooks