nova-api 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,84 @@
1
+ module Nova
2
+ module API
3
+ module Resource
4
+ class FinancialAccount < Nova::API::Base
5
+ ALLOWED_ATTRIBUTES = %i[financial_account_id name]
6
+
7
+ attribute? :id, Dry::Types['coercible.integer'].optional
8
+ attribute :name, Dry::Types['coercible.string']
9
+ attribute? :reason, Dry::Types['coercible.integer'].optional
10
+ attribute? :financial_account_id, Dry::Types['coercible.integer'].optional
11
+ attribute? :financial_account, Dry::Types['coercible.string'].optional
12
+ attribute? :income, Dry::Types['strict.bool'].optional
13
+ attribute? :outcome, Dry::Types['strict.bool'].optional
14
+ attribute? :children, Dry::Types['strict.array'].of(Nova::API::Resource::FinancialAccount).optional
15
+
16
+ def self.endpoint
17
+ '/api/financial_accounts'
18
+ end
19
+
20
+ def self.list
21
+ do_get_search(endpoint, nil)
22
+ end
23
+
24
+ def self.income_accounts
25
+ do_get_search("#{endpoint}/income_accounts", nil)
26
+ end
27
+
28
+ def self.payable_accounts
29
+ do_get_search("#{endpoint}/payable_accounts", nil)
30
+ end
31
+
32
+ def self.receivable_accounts
33
+ do_get_search("#{endpoint}/receivable_accounts", nil)
34
+ end
35
+
36
+ def self.create(parameters)
37
+ model = new parameters
38
+
39
+ model.attributes.delete(:id)
40
+
41
+ model.save
42
+ end
43
+
44
+ def self.update(id, parameters)
45
+ model = new parameters.merge(id: id)
46
+
47
+ model.update
48
+ end
49
+
50
+ def self.destroy(id)
51
+ model = initialize_empty_model_with_id(self, id)
52
+
53
+ model.destroy
54
+ end
55
+
56
+ def endpoint
57
+ protect_operation_from_missing_value
58
+
59
+ "/api/financial_accounts/#{id}"
60
+ end
61
+
62
+ def save
63
+ if id.nil?
64
+ do_post(self.class.endpoint, allowed_attributes)
65
+ else
66
+ do_patch("#{endpoint}", allowed_attributes)
67
+ end
68
+ end
69
+
70
+ def update
71
+ protect_operation_from_missing_value
72
+
73
+ do_patch("#{endpoint}", allowed_attributes)
74
+ end
75
+
76
+ def destroy
77
+ protect_operation_from_missing_value
78
+
79
+ do_delete("#{endpoint}")
80
+ end
81
+ end
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,12 @@
1
+ module Nova
2
+ module API
3
+ module Resource
4
+ module Response
5
+ class CurrentAssetStatement < Nova::API::Utils::BaseStruct
6
+ attribute? :last_statement, Dry::Types['coercible.decimal'].optional
7
+ attribute? :write_offs, Dry::Types['strict.array'].of(Nova::API::Resource::WriteOff).optional
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,97 @@
1
+ module Nova
2
+ module API
3
+ module Resource
4
+ class ThirdParty < Nova::API::Base
5
+ ALLOWED_ATTRIBUTES = %i[trading_name identification address phone social_reason municipal_inscription state_inscription email notes supplier customer retention whatsapp twitter facebook linkedin google instagram site csll pis cofins irpj values_past]
6
+
7
+ attribute? :id, Dry::Types['coercible.integer'].optional
8
+ attribute :trading_name, Dry::Types['coercible.string']
9
+ attribute? :identification, Dry::Types['coercible.string'].optional
10
+ attribute? :address, Dry::Types['coercible.string'].optional
11
+ attribute? :phone, Dry::Types['coercible.string'].optional
12
+ attribute? :social_reason, Dry::Types['coercible.string'].optional
13
+ attribute? :municipal_inscription, Dry::Types['coercible.string'].optional
14
+ attribute? :state_inscription, Dry::Types['coercible.string'].optional
15
+ attribute? :email, Dry::Types['coercible.string'].optional
16
+ attribute? :notes, Dry::Types['coercible.string'].optional
17
+ attribute? :supplier, Dry::Types['strict.bool'].optional
18
+ attribute? :customer, Dry::Types['strict.bool'].optional
19
+ attribute? :retention, Dry::Types['strict.bool'].optional
20
+ attribute? :whatsapp, Dry::Types['coercible.string'].optional
21
+ attribute? :twitter, Dry::Types['coercible.string'].optional
22
+ attribute? :facebook, Dry::Types['coercible.string'].optional
23
+ attribute? :linkedin, Dry::Types['coercible.string'].optional
24
+ attribute? :google, Dry::Types['coercible.string'].optional
25
+ attribute? :instagram, Dry::Types['coercible.string'].optional
26
+ attribute? :site, Dry::Types['coercible.string'].optional
27
+ attribute? :csll, Dry::Types['coercible.decimal'].optional
28
+ attribute? :pis, Dry::Types['coercible.decimal'].optional
29
+ attribute? :cofins, Dry::Types['coercible.decimal'].optional
30
+ attribute? :irpj, Dry::Types['coercible.decimal'].optional
31
+ attribute? :values_past, Dry::Types['coercible.decimal'].optional
32
+
33
+ def self.endpoint
34
+ '/api/third_parties'
35
+ end
36
+
37
+ def self.list(parameters = {})
38
+ do_get_search(endpoint, parameters.to_h)
39
+ end
40
+
41
+ def self.customers(parameters = {})
42
+ do_get_search("/api/customers", parameters.to_h)
43
+ end
44
+
45
+ def self.suppliers(parameters = {})
46
+ do_get_search("/api/suppliers", parameters.to_h)
47
+ end
48
+
49
+ def self.create(parameters)
50
+ model = new parameters
51
+
52
+ model.attributes.delete(:id)
53
+
54
+ model.save
55
+ end
56
+
57
+ def self.update(id, parameters)
58
+ model = new parameters.merge(id: id)
59
+
60
+ model.update
61
+ end
62
+
63
+ def self.destroy(id)
64
+ model = initialize_empty_model_with_id(self, id)
65
+
66
+ model.destroy
67
+ end
68
+
69
+ def endpoint
70
+ protect_operation_from_missing_value
71
+
72
+ "/api/third_parties/#{id}"
73
+ end
74
+
75
+ def save
76
+ if id.nil?
77
+ do_post(self.class.endpoint, allowed_attributes)
78
+ else
79
+ do_patch("#{endpoint}", allowed_attributes)
80
+ end
81
+ end
82
+
83
+ def update
84
+ protect_operation_from_missing_value
85
+
86
+ do_patch("#{endpoint}", allowed_attributes)
87
+ end
88
+
89
+ def destroy
90
+ protect_operation_from_missing_value
91
+
92
+ do_delete("#{endpoint}")
93
+ end
94
+ end
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,14 @@
1
+ module Nova
2
+ module API
3
+ module Resource
4
+ class WriteOff < Nova::API::Base
5
+ ALLOWED_ATTRIBUTES = %i[]
6
+
7
+ attribute? :date, Dry::Types['coercible.string'].constrained(format: DATE_REGEX).optional
8
+ attribute? :value, Dry::Types['coercible.decimal'].optional
9
+ attribute? :financial_account, Nova::API::Resource::FinancialAccount.optional
10
+ attribute? :third_party, Nova::API::Resource::ThirdParty.optional
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,39 @@
1
+ require 'httparty'
2
+ require 'dry-struct'
3
+ require 'dry-types'
4
+
5
+ module Nova
6
+ module API
7
+ class Response < Nova::API::Utils::BaseStruct
8
+ attribute? :record, Dry::Types['nominal.any']
9
+ attribute :errors, Dry::Types['strict.array'].of(Dry::Types['coercible.string'])
10
+ attribute :success, Dry::Types['strict.bool']
11
+
12
+ def self.build(response, object = nil)
13
+ success = response.success?
14
+
15
+ parsed_response = response.parsed_response.to_h
16
+
17
+ record = nil
18
+
19
+ errors = extract_error_from_response('error', parsed_response)
20
+ errors ||= extract_error_from_response('errors', parsed_response)
21
+ errors ||= []
22
+
23
+ if object
24
+ record = object.class.new(object.attributes.merge(parsed_response))
25
+ end
26
+
27
+ new(success: success, errors: errors, record: record)
28
+ end
29
+
30
+ private
31
+
32
+ def self.extract_error_from_response(field, response)
33
+ return unless response.has_key?(field)
34
+
35
+ response[field].is_a?(Array) ? response[field] : [response[field]]
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,10 @@
1
+ module Nova
2
+ module API
3
+ module SearchParams
4
+ class Apportionment < Nova::API::Utils::BaseStruct
5
+ attribute? :q, Dry::Types['coercible.string'].optional
6
+ attribute? :with_inactive, Dry::Types['strict.bool'].optional
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ module Nova
2
+ module API
3
+ module SearchParams
4
+ class CurrentAsset < Nova::API::Utils::BaseStruct
5
+ attribute? :company_id, Dry::Types['coercible.integer'].optional
6
+ attribute? :with_inactive, Dry::Types['strict.bool'].optional
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,12 @@
1
+ module Nova
2
+ module API
3
+ module SearchParams
4
+ class CurrentAssetStatement < Nova::API::Utils::BaseStruct
5
+ attribute :company_id, Dry::Types['coercible.integer']
6
+ attribute :current_asset_id, Dry::Types['coercible.integer']
7
+ attribute :initial_date, Dry::Types['coercible.string'].constrained(format: DATE_REGEX)
8
+ attribute :final_date, Dry::Types['coercible.string'].constrained(format: DATE_REGEX)
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,9 @@
1
+ module Nova
2
+ module API
3
+ module SearchParams
4
+ class ThirdParty < Nova::API::Utils::BaseStruct
5
+ attribute? :q, Dry::Types['coercible.string'].optional
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,14 @@
1
+ require 'dry-struct'
2
+ require 'dry-types'
3
+
4
+ module Nova
5
+ module API
6
+ module Utils
7
+ class BaseStruct < Dry::Struct
8
+ DATE_REGEX = /\A\d{4}-\d{2}-\d{2}\z/
9
+
10
+ transform_keys(&:to_sym)
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,5 @@
1
+ module Nova
2
+ module API
3
+ VERSION = "0.4.0"
4
+ end
5
+ end
@@ -0,0 +1,9 @@
1
+ module Nova
2
+ module API
3
+ class Configuration
4
+ attr_accessor :api_key, :subdomain
5
+ attr_reader :host
6
+ attr_reader :scheme
7
+ end
8
+ end
9
+ end
data/nova-api.gemspec ADDED
@@ -0,0 +1,50 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "nova/api/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "nova-api"
8
+ spec.version = Nova::API::VERSION
9
+ spec.authors = ["Coyô Software"]
10
+ spec.email = ["ti@coyo.com.br"]
11
+
12
+ spec.summary = %q{Nova.Money API gem}
13
+ spec.description = %q{This gem was designed to be used as an easy way to comunicate with the Nova.Money API}
14
+ spec.homepage = "https://app.swaggerhub.com/apis-docs/coyosoftware/Nova.Money/v1"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
21
+
22
+ spec.metadata["homepage_uri"] = spec.homepage
23
+ spec.metadata["source_code_uri"] = "https://github.com/coyosoftware/nova-api"
24
+ spec.metadata["changelog_uri"] = "https://github.com/coyosoftware/nova-api/blob/master/CHANGELOG.md"
25
+ else
26
+ raise "RubyGems 2.0 or newer is required to protect against " \
27
+ "public gem pushes."
28
+ end
29
+
30
+ # Specify which files should be added to the gem when it is released.
31
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
32
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
33
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
34
+ end
35
+ spec.bindir = "exe"
36
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
37
+ spec.require_paths = ["lib"]
38
+
39
+ spec.add_development_dependency "bundler", "~> 1.17"
40
+ spec.add_development_dependency "rake", "~> 10.0"
41
+ spec.add_development_dependency "rspec", "~> 3.0"
42
+ spec.add_development_dependency "simplecov", "~> 0.21"
43
+ spec.add_development_dependency "byebug", "~> 11.1.3"
44
+ spec.add_development_dependency "webmock", "~> 3.11.2"
45
+ spec.add_development_dependency "rspec-dry-struct", "~> 0.1"
46
+
47
+ spec.add_dependency "httparty", "~> 0.1"
48
+ spec.add_dependency "dry-struct", "~> 1.4.0"
49
+ spec.add_dependency "dry-types", "~> 1.5.1"
50
+ end
metadata ADDED
@@ -0,0 +1,224 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nova-api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.4.0
5
+ platform: ruby
6
+ authors:
7
+ - Coyô Software
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2021-03-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.17'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.17'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: simplecov
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.21'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.21'
69
+ - !ruby/object:Gem::Dependency
70
+ name: byebug
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 11.1.3
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 11.1.3
83
+ - !ruby/object:Gem::Dependency
84
+ name: webmock
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 3.11.2
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 3.11.2
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec-dry-struct
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '0.1'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '0.1'
111
+ - !ruby/object:Gem::Dependency
112
+ name: httparty
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '0.1'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '0.1'
125
+ - !ruby/object:Gem::Dependency
126
+ name: dry-struct
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: 1.4.0
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: 1.4.0
139
+ - !ruby/object:Gem::Dependency
140
+ name: dry-types
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: 1.5.1
146
+ type: :runtime
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: 1.5.1
153
+ description: This gem was designed to be used as an easy way to comunicate with the
154
+ Nova.Money API
155
+ email:
156
+ - ti@coyo.com.br
157
+ executables: []
158
+ extensions: []
159
+ extra_rdoc_files: []
160
+ files:
161
+ - ".circleci/config.yml"
162
+ - ".circleci/setup-rubygems.sh"
163
+ - ".gitignore"
164
+ - ".rspec"
165
+ - ".travis.yml"
166
+ - CHANGELOG.md
167
+ - Gemfile
168
+ - Gemfile.lock
169
+ - LICENSE.txt
170
+ - README.md
171
+ - Rakefile
172
+ - bin/console
173
+ - bin/setup
174
+ - lib/nova/api.rb
175
+ - lib/nova/api/base.rb
176
+ - lib/nova/api/list_response.rb
177
+ - lib/nova/api/resource/apportionment.rb
178
+ - lib/nova/api/resource/apportionment_value.rb
179
+ - lib/nova/api/resource/bank.rb
180
+ - lib/nova/api/resource/card.rb
181
+ - lib/nova/api/resource/cash.rb
182
+ - lib/nova/api/resource/company.rb
183
+ - lib/nova/api/resource/current_asset.rb
184
+ - lib/nova/api/resource/financial_account.rb
185
+ - lib/nova/api/resource/response/current_asset_statement.rb
186
+ - lib/nova/api/resource/third_party.rb
187
+ - lib/nova/api/resource/write_off.rb
188
+ - lib/nova/api/response.rb
189
+ - lib/nova/api/search_params/apportionment.rb
190
+ - lib/nova/api/search_params/current_asset.rb
191
+ - lib/nova/api/search_params/current_asset_statement.rb
192
+ - lib/nova/api/search_params/third_party.rb
193
+ - lib/nova/api/utils/base_struct.rb
194
+ - lib/nova/api/version.rb
195
+ - lib/nova/configuration.rb
196
+ - nova-api.gemspec
197
+ homepage: https://app.swaggerhub.com/apis-docs/coyosoftware/Nova.Money/v1
198
+ licenses:
199
+ - MIT
200
+ metadata:
201
+ allowed_push_host: https://rubygems.org
202
+ homepage_uri: https://app.swaggerhub.com/apis-docs/coyosoftware/Nova.Money/v1
203
+ source_code_uri: https://github.com/coyosoftware/nova-api
204
+ changelog_uri: https://github.com/coyosoftware/nova-api/blob/master/CHANGELOG.md
205
+ post_install_message:
206
+ rdoc_options: []
207
+ require_paths:
208
+ - lib
209
+ required_ruby_version: !ruby/object:Gem::Requirement
210
+ requirements:
211
+ - - ">="
212
+ - !ruby/object:Gem::Version
213
+ version: '0'
214
+ required_rubygems_version: !ruby/object:Gem::Requirement
215
+ requirements:
216
+ - - ">="
217
+ - !ruby/object:Gem::Version
218
+ version: '0'
219
+ requirements: []
220
+ rubygems_version: 3.0.3
221
+ signing_key:
222
+ specification_version: 4
223
+ summary: Nova.Money API gem
224
+ test_files: []