nova-api 1.0.0 → 1.1.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: b970fbc5e4e4fee3d3d4e1338421306d7e85abaea9679188715b58be18f4b20a
4
- data.tar.gz: 38c83a6a84d1092aace8f0bf8d96164a5889a28a0d70748fc5de3e2ce1975a61
3
+ metadata.gz: d410fdaa147a6cd242a39c66045adc47398f59f175b93c760d53f041c3d101a6
4
+ data.tar.gz: 3d9d057da1e97fb373b299599fa2bce0dd51419f97b0bde30996d4ef3a1e8147
5
5
  SHA512:
6
- metadata.gz: ac1b74bf1ef47745dfb9d4f2b33b675ab7332d4ab514b66c54e902252a79083c1f77fcd3296159297eb89b895af547813db7898b7a17072cf3389523dd59ef47
7
- data.tar.gz: 86c8cecd0efa2ea4a171739b4cf9d2d97a2426784623db651e7bd3f0bdad6040a0ae8d0da01d5d1a61dd47546f831767129e2f98d334d4e2c337ec2b5128a771
6
+ metadata.gz: 46f13e1baa522137120e1431cd3fd4ccd5ff9a98f729eb518b4ab190998303c06c4f4ae7b8712f08f8d63678245f582cc8d0fbf3aedb6ccee84762630dac1b15
7
+ data.tar.gz: 19a9131c280fadc21a7ddef76119ce680211e84cf0227e7dc87eaa956c2636ed468167ad8cd08cddd1bb72e1cf77245294d3f11f852d8a0fa6f8d0683b1e8d8a
data/CHANGELOG.md CHANGED
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [1.1.0] - 2023-09-22
9
+
10
+ ### Added
11
+
12
+ - Webhooks endpoint
13
+
8
14
  ## [1.0.0] - 2023-07-11
9
15
 
10
16
  ### Added
@@ -95,7 +101,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
95
101
 
96
102
  - Apportionment related stuff
97
103
 
98
- [unreleased]: https://github.com/coyosoftware/nova-api/compare/1.0.0...HEAD
104
+ [unreleased]: https://github.com/coyosoftware/nova-api/compare/1.1.0...HEAD
105
+ [1.1.0]: https://github.com/coyosoftware/nova-api/releases/tag/1.1.0
99
106
  [1.0.0]: https://github.com/coyosoftware/nova-api/releases/tag/1.0.0
100
107
  [0.8.0]: https://github.com/coyosoftware/nova-api/releases/tag/0.8.0
101
108
  [0.7.0]: https://github.com/coyosoftware/nova-api/releases/tag/0.7.0
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- nova-api (1.0.0)
4
+ nova-api (1.1.0)
5
5
  dry-struct (~> 1.6)
6
6
  dry-types (~> 1.7)
7
7
  httparty (~> 0.1)
@@ -0,0 +1,75 @@
1
+ module Nova
2
+ module API
3
+ module Resource
4
+ class Webhook < Nova::API::Base
5
+ ALLOWED_ATTRIBUTES = %i[events url]
6
+
7
+ attribute? :id, Dry::Types['coercible.integer'].optional
8
+ attribute :events, Dry::Types['strict.array'].of(Dry::Types['coercible.string'])
9
+ attribute :url, Dry::Types['coercible.string']
10
+
11
+ def self.endpoint
12
+ '/api/webhooks'
13
+ end
14
+
15
+ def self.create(parameters)
16
+ model = new parameters
17
+
18
+ model.attributes.delete(:id)
19
+
20
+ model.save
21
+ end
22
+
23
+ def self.update(id, parameters)
24
+ model = new parameters.merge(id: id)
25
+
26
+ model.update
27
+ end
28
+
29
+ def self.destroy(id)
30
+ model = initialize_empty_model_with_id(self, id, events: [])
31
+
32
+ model.destroy
33
+ end
34
+
35
+ def self.restore(id)
36
+ model = initialize_empty_model_with_id(self, id, events: [])
37
+
38
+ model.restore
39
+ end
40
+
41
+ def endpoint
42
+ protect_operation_from_missing_value
43
+
44
+ "/api/webhooks/#{id}"
45
+ end
46
+
47
+ def save
48
+ if id.nil?
49
+ do_post(self.class.endpoint, allowed_attributes)
50
+ else
51
+ do_patch("#{endpoint}", allowed_attributes)
52
+ end
53
+ end
54
+
55
+ def update
56
+ protect_operation_from_missing_value
57
+
58
+ do_patch("#{endpoint}", allowed_attributes)
59
+ end
60
+
61
+ def destroy
62
+ protect_operation_from_missing_value
63
+
64
+ do_delete("#{endpoint}")
65
+ end
66
+
67
+ def restore
68
+ protect_operation_from_missing_value
69
+
70
+ do_patch("#{endpoint}/restore", {})
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end
@@ -30,13 +30,13 @@ module Nova
30
30
  protected
31
31
 
32
32
  def self.initialize_empty_model_with_id(klass, id, additional_attributes = {})
33
- data = klass.schema.type.keys.map do |field|
34
- name = field.name
35
-
36
- value_for_field(name, additional_attributes[name], field)
33
+ values = Hash.new.tap do |hash|
34
+ klass.schema.type.keys.each do |field|
35
+ hash[field.name] = value_for_field(additional_attributes[field.name], field)
36
+ end
37
37
  end
38
38
 
39
- klass.new(Hash[*data.flatten].merge(id: id))
39
+ klass.new(values.merge(id: id))
40
40
  end
41
41
 
42
42
  private
@@ -49,12 +49,12 @@ module Nova
49
49
  value.respond_to?(:allowed_attributes) ? value.allowed_attributes : value
50
50
  end
51
51
 
52
- def self.value_for_field(name, override_value, field)
53
- return [name, override_value] if override_value
52
+ def self.value_for_field(override_value, field)
53
+ return override_value if override_value
54
54
 
55
55
  type = field.type
56
56
 
57
- type.optional? ? [name, nil] : [name, generate_valid_value_for(type)]
57
+ type.optional? ? nil : generate_valid_value_for(type)
58
58
  end
59
59
 
60
60
  def self.generate_valid_value_for(type)
@@ -1,5 +1,5 @@
1
1
  module Nova
2
2
  module API
3
- VERSION = "1.0.0"
3
+ VERSION = "1.1.0"
4
4
  end
5
5
  end
data/lib/nova/api.rb CHANGED
@@ -30,6 +30,8 @@ require "nova/api/resource/write_off"
30
30
 
31
31
  require "nova/api/resource/permission"
32
32
 
33
+ require "nova/api/resource/webhook"
34
+
33
35
  require "nova/api/resource/response/current_asset_statement"
34
36
 
35
37
  require "nova/api/search_params/apportionment"
@@ -111,6 +113,10 @@ module Nova
111
113
  def third_parties
112
114
  Nova::API::Resource::ThirdParty
113
115
  end
116
+
117
+ def webhooks
118
+ Nova::API::Resource::Webhook
119
+ end
114
120
  end
115
121
  end
116
122
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nova-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Coyô Software
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-07-17 00:00:00.000000000 Z
11
+ date: 2023-09-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -191,6 +191,7 @@ files:
191
191
  - lib/nova/api/resource/receivable.rb
192
192
  - lib/nova/api/resource/response/current_asset_statement.rb
193
193
  - lib/nova/api/resource/third_party.rb
194
+ - lib/nova/api/resource/webhook.rb
194
195
  - lib/nova/api/resource/write_off.rb
195
196
  - lib/nova/api/response.rb
196
197
  - lib/nova/api/search_params/apportionment.rb
@@ -225,7 +226,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
225
226
  - !ruby/object:Gem::Version
226
227
  version: '0'
227
228
  requirements: []
228
- rubygems_version: 3.4.10
229
+ rubygems_version: 3.4.19
229
230
  signing_key:
230
231
  specification_version: 4
231
232
  summary: Nova.Money API gem