omie-client 0.1.2 → 0.1.7
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 +4 -4
- data/.gitlab-ci.yml +11 -0
- data/.rubocop.yml +25 -0
- data/Gemfile +4 -2
- data/Gemfile.lock +20 -2
- data/README.md +40 -0
- data/Rakefile +5 -3
- data/bin/console +4 -3
- data/lib/omie.rb +3 -0
- data/lib/omie/base_resource.rb +19 -1
- data/lib/omie/company.rb +54 -22
- data/lib/omie/product.rb +174 -0
- data/lib/omie/tax_recommendation.rb +18 -0
- data/lib/omie/version.rb +1 -1
- data/omie-client.gemspec +25 -20
- metadata +41 -23
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 94419cf21c98a1561abc447b6b2573dff8000e5803eee8fbf8fe900f0c84e0f3
|
4
|
+
data.tar.gz: e6c9f7a717722a8defa94da9b70012f52eb867b204fc3c01cc21da31ee9044c5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b494ee1e588966d557a3be0eeb43d6b1a9a858c736946a82e23a589a3a66182821a3826aa86b1dc1bd4101bf11b625f0de8b86367ae50608fe96c351f4a35be5
|
7
|
+
data.tar.gz: c83fd3c1f491968b12ba0336e6b233c2480c7c0574209f6ae0d87720ab4a1f8e459cc179739334958a3488d3f73301f3e5fbc6a4c9ca8f42aae4892ecb7584ea
|
data/.gitlab-ci.yml
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
AllCops:
|
2
|
+
TargetRubyVersion: 2.3.*
|
3
|
+
Exclude:
|
4
|
+
- 'bin/*'
|
5
|
+
- 'lib/tasks/*.rake'
|
6
|
+
|
7
|
+
Metrics/MethodLength:
|
8
|
+
Max: 20
|
9
|
+
|
10
|
+
Metrics/BlockLength:
|
11
|
+
Exclude:
|
12
|
+
- "spec/**/*"
|
13
|
+
|
14
|
+
Lint/AmbiguousBlockAssociation:
|
15
|
+
Exclude:
|
16
|
+
- "spec/**/*"
|
17
|
+
|
18
|
+
Style/HashEachMethods:
|
19
|
+
Enabled: true
|
20
|
+
|
21
|
+
Style/HashTransformKeys:
|
22
|
+
Enabled: true
|
23
|
+
|
24
|
+
Style/HashTransformValues:
|
25
|
+
Enabled: true
|
data/Gemfile
CHANGED
@@ -1,6 +1,8 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
source 'https://rubygems.org'
|
4
|
+
|
5
|
+
git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
|
4
6
|
|
5
7
|
# Specify your gem's dependencies in omie-client.gemspec
|
6
8
|
gemspec
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
omie-client (0.1.
|
4
|
+
omie-client (0.1.6)
|
5
5
|
activesupport (>= 5.0)
|
6
6
|
rest-client (>= 2.0)
|
7
7
|
|
@@ -13,6 +13,7 @@ GEM
|
|
13
13
|
i18n (>= 0.7, < 2)
|
14
14
|
minitest (~> 5.1)
|
15
15
|
tzinfo (~> 1.1)
|
16
|
+
ast (2.4.0)
|
16
17
|
concurrent-ruby (1.1.5)
|
17
18
|
cpf_cnpj (0.5.0)
|
18
19
|
diff-lcs (1.3)
|
@@ -25,17 +26,23 @@ GEM
|
|
25
26
|
domain_name (~> 0.5)
|
26
27
|
i18n (1.8.2)
|
27
28
|
concurrent-ruby (~> 1.0)
|
29
|
+
jaro_winkler (1.5.4)
|
28
30
|
mime-types (3.3.1)
|
29
31
|
mime-types-data (~> 3.2015)
|
30
32
|
mime-types-data (3.2019.1009)
|
31
33
|
minitest (5.14.0)
|
32
34
|
netrc (0.11.0)
|
35
|
+
parallel (1.19.1)
|
36
|
+
parser (2.7.0.4)
|
37
|
+
ast (~> 2.4.0)
|
38
|
+
rainbow (3.0.0)
|
33
39
|
rake (10.5.0)
|
34
40
|
rest-client (2.1.0)
|
35
41
|
http-accept (>= 1.7.0, < 2.0)
|
36
42
|
http-cookie (>= 1.0.2, < 2.0)
|
37
43
|
mime-types (>= 1.16, < 4.0)
|
38
44
|
netrc (~> 0.8)
|
45
|
+
rexml (3.2.4)
|
39
46
|
rspec (3.9.0)
|
40
47
|
rspec-core (~> 3.9.0)
|
41
48
|
rspec-expectations (~> 3.9.0)
|
@@ -49,12 +56,22 @@ GEM
|
|
49
56
|
diff-lcs (>= 1.2.0, < 2.0)
|
50
57
|
rspec-support (~> 3.9.0)
|
51
58
|
rspec-support (3.9.2)
|
59
|
+
rubocop (0.80.1)
|
60
|
+
jaro_winkler (~> 1.5.1)
|
61
|
+
parallel (~> 1.10)
|
62
|
+
parser (>= 2.7.0.1)
|
63
|
+
rainbow (>= 2.2.2, < 4.0)
|
64
|
+
rexml
|
65
|
+
ruby-progressbar (~> 1.7)
|
66
|
+
unicode-display_width (>= 1.4.0, < 1.7)
|
67
|
+
ruby-progressbar (1.10.1)
|
52
68
|
thread_safe (0.3.6)
|
53
69
|
tzinfo (1.2.6)
|
54
70
|
thread_safe (~> 0.1)
|
55
71
|
unf (0.1.4)
|
56
72
|
unf_ext
|
57
|
-
unf_ext (0.0.7.
|
73
|
+
unf_ext (0.0.7.7)
|
74
|
+
unicode-display_width (1.6.1)
|
58
75
|
|
59
76
|
PLATFORMS
|
60
77
|
ruby
|
@@ -66,6 +83,7 @@ DEPENDENCIES
|
|
66
83
|
omie-client!
|
67
84
|
rake (~> 10.0)
|
68
85
|
rspec (~> 3.0)
|
86
|
+
rubocop (~> 0.80.1)
|
69
87
|
|
70
88
|
BUNDLED WITH
|
71
89
|
1.16.6
|
data/README.md
CHANGED
@@ -99,6 +99,46 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
99
99
|
Bug reports and pull requests are welcome. If you want to add a new resource
|
100
100
|
from the API, please open an issue first to avoid duplicated work.
|
101
101
|
|
102
|
+
### Building and Testing Locally
|
103
|
+
|
104
|
+
To properly test if the gem is working properly, you can install it locally:
|
105
|
+
```sh
|
106
|
+
gem build omie-client.gemspec
|
107
|
+
gem install ./omie-client-x.y.z.gem
|
108
|
+
```
|
109
|
+
The `x.y.z` represents the version described in [lib/omie/version.rb](lib/omie/version.rb)
|
110
|
+
|
111
|
+
You can make some smoke test to check if everything is ok, especially because
|
112
|
+
this gem interacts with Omie API, requiring some integration tests that
|
113
|
+
is not covered by the existing unit tests.
|
114
|
+
* Open irb:
|
115
|
+
```sh
|
116
|
+
irb
|
117
|
+
```
|
118
|
+
|
119
|
+
```ruby
|
120
|
+
require 'omie'
|
121
|
+
=> true
|
122
|
+
Omie::VERSION
|
123
|
+
=> "x.y.z"
|
124
|
+
# Default credentials provided by Omie API for tests
|
125
|
+
Omie.app_key = '1560731700'
|
126
|
+
Omie.app_secret = '226dcf372489bb45ceede61bfd98f0f1'
|
127
|
+
|
128
|
+
Omie::Company.list
|
129
|
+
Omie::Product.list
|
130
|
+
```
|
131
|
+
|
132
|
+
If everything is working fine and you have the proper credentials to upload
|
133
|
+
the new version, run:
|
134
|
+
|
135
|
+
```sh
|
136
|
+
gem push omie-client-x.y.z.gem
|
137
|
+
Pushing gem to RubyGems.org...
|
138
|
+
Successfully registered gem: omie-client (x.y.z)
|
139
|
+
```
|
140
|
+
> You may need to authenticate at rubygems first => https://guides.rubygems.org/make-your-own-gem/
|
141
|
+
|
102
142
|
## License
|
103
143
|
|
104
144
|
See the [LICENSE](LICENSE) file.
|
data/Rakefile
CHANGED
data/bin/console
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
|
-
require
|
4
|
-
require
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'omie/client'
|
5
6
|
|
6
7
|
# You can add fixtures and/or initialization code here to make experimenting
|
7
8
|
# with your gem easier. You can also use a different console, if you like.
|
@@ -10,5 +11,5 @@ require "omie/client"
|
|
10
11
|
# require "pry"
|
11
12
|
# Pry.start
|
12
13
|
|
13
|
-
require
|
14
|
+
require 'irb'
|
14
15
|
IRB.start(__FILE__)
|
data/lib/omie.rb
CHANGED
@@ -2,11 +2,14 @@
|
|
2
2
|
|
3
3
|
require_relative 'omie/base_resource'
|
4
4
|
require_relative 'omie/company'
|
5
|
+
require_relative 'omie/tax_recommendation'
|
6
|
+
require_relative 'omie/product'
|
5
7
|
require_relative 'omie/connection'
|
6
8
|
require_relative 'omie/error'
|
7
9
|
require_relative 'omie/info'
|
8
10
|
require_relative 'omie/version'
|
9
11
|
|
12
|
+
# High level namespace for Omie Client lib
|
10
13
|
module Omie
|
11
14
|
cattr_accessor :app_key, :app_secret
|
12
15
|
end
|
data/lib/omie/base_resource.rb
CHANGED
@@ -11,7 +11,15 @@ module Omie
|
|
11
11
|
# values
|
12
12
|
def initialize(args = {})
|
13
13
|
args.each do |key, value|
|
14
|
-
|
14
|
+
key_s = key.to_sym
|
15
|
+
has_internal_const = self.class.const_defined?('INTERNAL_MODELS')
|
16
|
+
if has_internal_const && self.class::INTERNAL_MODELS.key?(key_s)
|
17
|
+
klass = self.class::INTERNAL_MODELS[key_s]
|
18
|
+
instance = klass.new(value)
|
19
|
+
send("#{key}=", instance)
|
20
|
+
elsif respond_to?(key_s)
|
21
|
+
send("#{key}=", value)
|
22
|
+
end
|
15
23
|
end
|
16
24
|
end
|
17
25
|
|
@@ -21,5 +29,15 @@ module Omie
|
|
21
29
|
send("#{key}=", value) if respond_to?(key)
|
22
30
|
end
|
23
31
|
end
|
32
|
+
|
33
|
+
def self.request(uri, call, params)
|
34
|
+
Omie::Connection.request(uri, call, params)
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.request_and_initialize(uri, call, params)
|
38
|
+
response = request(uri, call, params)
|
39
|
+
|
40
|
+
new(response)
|
41
|
+
end
|
24
42
|
end
|
25
43
|
end
|
data/lib/omie/company.rb
CHANGED
@@ -13,13 +13,14 @@ module Omie
|
|
13
13
|
# Attributes' names are equal to the Portuguese names described in the API
|
14
14
|
# documentation.
|
15
15
|
class Company < Omie::BaseResource
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
16
|
+
CALLS = {
|
17
|
+
list: 'ListarClientes',
|
18
|
+
create: 'IncluirCliente',
|
19
|
+
update: 'AlterarCliente',
|
20
|
+
find: 'ConsultarCliente',
|
21
|
+
delete: 'ExcluirCliente',
|
22
|
+
upsert: 'UpsertCliente',
|
23
|
+
associate: 'AssociarCodIntCliente'
|
23
24
|
}.freeze
|
24
25
|
|
25
26
|
URI = '/v1/geral/clientes/'
|
@@ -43,8 +44,7 @@ module Omie
|
|
43
44
|
# @raise [Omie::RequestError]
|
44
45
|
# in case of failed requests due to failed validations
|
45
46
|
def self.create(params = {})
|
46
|
-
|
47
|
-
Omie::Company.new(response)
|
47
|
+
request_and_initialize(URI, CALLS[:create], params)
|
48
48
|
end
|
49
49
|
|
50
50
|
# Updates an existing company using the
|
@@ -64,8 +64,7 @@ module Omie
|
|
64
64
|
# in case of failed requests due to failed validations or when the
|
65
65
|
# company was not found.
|
66
66
|
def self.update(params = {})
|
67
|
-
|
68
|
-
Omie::Company.new(response)
|
67
|
+
request_and_initialize(URI, CALLS[:update], params)
|
69
68
|
end
|
70
69
|
|
71
70
|
# Search for a company using the
|
@@ -83,8 +82,7 @@ module Omie
|
|
83
82
|
# @return [nil]
|
84
83
|
# in case of no company found
|
85
84
|
def self.find(params)
|
86
|
-
|
87
|
-
Omie::Company.new(response)
|
85
|
+
request_and_initialize(URI, CALLS[:find], params)
|
88
86
|
rescue Omie::RequestError
|
89
87
|
nil
|
90
88
|
end
|
@@ -95,21 +93,47 @@ module Omie
|
|
95
93
|
# records.
|
96
94
|
#
|
97
95
|
# @!scope class
|
98
|
-
# @param
|
99
|
-
# the
|
100
|
-
#
|
101
|
-
# the number of items per page (max: 50).
|
96
|
+
# @param [Hash] options
|
97
|
+
# The options param follows the same structure described by
|
98
|
+
# https://app.omie.com.br/api/v1/geral/clientes/#clientes_list_request
|
102
99
|
# @return [Array<Omie::Company>]
|
103
100
|
# the list of found companies
|
104
|
-
def self.list(
|
105
|
-
|
101
|
+
def self.list(options = {})
|
102
|
+
default = {
|
103
|
+
pagina: 1, registros_por_pagina: 50,
|
104
|
+
apenas_importado_api: 'N'
|
105
|
+
}
|
106
|
+
|
107
|
+
default.each do |k, v|
|
108
|
+
options[k] = v unless options.key?(k)
|
109
|
+
end
|
106
110
|
|
107
|
-
response =
|
111
|
+
response = request(URI, CALLS[:list], options)
|
108
112
|
response['clientes_cadastro'].map { |client| Omie::Company.new(client) }
|
109
113
|
rescue Omie::RequestError
|
110
114
|
[]
|
111
115
|
end
|
112
116
|
|
117
|
+
# Associate the local entry with an existing entry at Omie
|
118
|
+
# {https://app.omie.com.br/api/v1/geral/clientes/#AssociarCodIntCliente
|
119
|
+
# AssociarCodIntCliente}. Omie will find the existing entry through the
|
120
|
+
# {#codigo_cliente_omie} and updates its {#codigo_cliente_integracao}
|
121
|
+
#
|
122
|
+
# @!scope class
|
123
|
+
# @param codigo_cliente_omie [String]
|
124
|
+
# The id of the existing entry at Omie
|
125
|
+
# @param codigo_cliente_integracao [String]
|
126
|
+
# The integration id to be used by the existing entry - usually a local
|
127
|
+
# id.
|
128
|
+
def self.associate(codigo_cliente_omie, codigo_cliente_integracao)
|
129
|
+
params = {
|
130
|
+
codigo_cliente_integracao: codigo_cliente_integracao,
|
131
|
+
codigo_cliente_omie: codigo_cliente_omie
|
132
|
+
}
|
133
|
+
|
134
|
+
request(URI, CALLS[:associate], params)
|
135
|
+
end
|
136
|
+
|
113
137
|
# Get method for tags attribute.
|
114
138
|
#
|
115
139
|
# @return [Array<Hash>]
|
@@ -160,9 +184,9 @@ module Omie
|
|
160
184
|
# the company itself updated
|
161
185
|
def save
|
162
186
|
company = if saved?
|
163
|
-
Omie::Company.update(as_json.except(
|
187
|
+
Omie::Company.update(as_json.except('tag_values'))
|
164
188
|
else
|
165
|
-
Omie::Company.create(as_json.except(
|
189
|
+
Omie::Company.create(as_json.except('tag_values'))
|
166
190
|
end
|
167
191
|
|
168
192
|
self.codigo_cliente_omie = company.codigo_cliente_omie if company
|
@@ -176,5 +200,13 @@ module Omie
|
|
176
200
|
def saved?
|
177
201
|
!codigo_cliente_omie.blank?
|
178
202
|
end
|
203
|
+
|
204
|
+
# Updates the omie entry with the local id for integration purposes.
|
205
|
+
#
|
206
|
+
# @return [Boolean]
|
207
|
+
def associate_entry
|
208
|
+
Omie::Company.associate(codigo_cliente_omie, codigo_cliente_integracao)
|
209
|
+
true
|
210
|
+
end
|
179
211
|
end
|
180
212
|
end
|
data/lib/omie/product.rb
ADDED
@@ -0,0 +1,174 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Omie
|
4
|
+
# This class abstracts the product resource from Omie (Ref: Produto)
|
5
|
+
# It aims at providing abstractions to the endpoints described in
|
6
|
+
# {https://app.omie.com.br/api/v1/geral/produtos/}.
|
7
|
+
#
|
8
|
+
# The class methods of Omie::Product usually performs requests to Omie API and
|
9
|
+
# manipulate product objects that contain the returned values.
|
10
|
+
# Attributes' names are equal to the Portuguese names described in the API
|
11
|
+
# documentation.
|
12
|
+
class Product < Omie::BaseResource
|
13
|
+
CALLS = {
|
14
|
+
list: 'ListarProdutos',
|
15
|
+
create: 'IncluirProduto',
|
16
|
+
update: 'AlterarProduto',
|
17
|
+
find: 'ConsultarProduto',
|
18
|
+
delete: 'ExcluirProduto',
|
19
|
+
simple: 'UpsertProduto',
|
20
|
+
associate: 'AssociarCodIntProduto'
|
21
|
+
}.freeze
|
22
|
+
|
23
|
+
INTERNAL_MODELS = {
|
24
|
+
recomendacoes_fiscais: Omie::TaxRecommendation
|
25
|
+
}.freeze
|
26
|
+
|
27
|
+
URI = '/v1/geral/produtos/'
|
28
|
+
|
29
|
+
attr_accessor :ncm, :valor_unitario, :unidade, :descricao_status
|
30
|
+
attr_accessor :codigo_produto_integracao, :codigo_produto, :descricao
|
31
|
+
attr_accessor :codigo, :tipoItem # They do not keep the same name style =(
|
32
|
+
attr_accessor :recomendacoes_fiscais # {Omie::TaxRecommendation}
|
33
|
+
|
34
|
+
# Record a new product using the
|
35
|
+
# {https://app.omie.com.br/api/v1/geral/produtos/#IncluirProduto
|
36
|
+
# IncluirProduto} call and returns an instance of Omie::Product
|
37
|
+
# with the data from the created product.
|
38
|
+
#
|
39
|
+
# @!scope class
|
40
|
+
# @param params [Hash]
|
41
|
+
# a hash containing the data to be recorded in the product based on
|
42
|
+
# the available attributes of this class
|
43
|
+
# @return [Omie::Product]
|
44
|
+
# the created product
|
45
|
+
# @raise [Omie::RequestError]
|
46
|
+
# in case of failed requests due to failed validations
|
47
|
+
def self.create(params = {})
|
48
|
+
request_and_initialize(URI, CALLS[:create], params)
|
49
|
+
end
|
50
|
+
|
51
|
+
# Update an existing product using the
|
52
|
+
# {https://app.omie.com.br/api/v1/geral/produtos/#AlterarProduto
|
53
|
+
# AlterarProduto} call and returns an instance of the updated product.
|
54
|
+
# Omie will use either the {#codigo_produto_integracao} or the
|
55
|
+
# {#codigo_produto} to identify the entry to be changed. It will
|
56
|
+
# change only the informed attributes in params.
|
57
|
+
#
|
58
|
+
# @!scope class
|
59
|
+
# @param params [Hash]
|
60
|
+
# a hash containing the search attribute to locate the product and
|
61
|
+
# the attributes/values to be updated.
|
62
|
+
# @return [Omie::Product]
|
63
|
+
# the updated product
|
64
|
+
# @raise [Omie::RequestError]
|
65
|
+
# in case of failed requests due to failed validations or when the
|
66
|
+
# product was not found.
|
67
|
+
def self.update(params = {})
|
68
|
+
request_and_initialize(URI, CALLS[:update], params)
|
69
|
+
end
|
70
|
+
|
71
|
+
# Search for a product using the
|
72
|
+
# {https://app.omie.com.br/api/v1/geral/produtos/#ConsultarProduto
|
73
|
+
# ConsultarProduto} call and returns an instance of the found product
|
74
|
+
# or nil otherwise.
|
75
|
+
# One may use either the {#codigo_cliente_omie} or
|
76
|
+
# {#codigo_cliente_integracao} to search for product
|
77
|
+
#
|
78
|
+
# @!scope class
|
79
|
+
# @param params [Hash]
|
80
|
+
# a hash containing the search attribute to locate the product
|
81
|
+
# @return [Omie::Product]
|
82
|
+
# the found product
|
83
|
+
# @return [nil]
|
84
|
+
# in case of no product found
|
85
|
+
def self.find(params)
|
86
|
+
request_and_initialize(URI, CALLS[:find], params)
|
87
|
+
rescue Omie::RequestError
|
88
|
+
nil
|
89
|
+
end
|
90
|
+
|
91
|
+
# Get a paginated list of companies recorded in Omie by using the
|
92
|
+
# {https://app.omie.com.br/api/v1/geral/produtos/#ListarProdutos
|
93
|
+
# Listarprodutos}. You may change the params to get other pages of
|
94
|
+
# records.
|
95
|
+
#
|
96
|
+
# @!scope class
|
97
|
+
# @param [Hash] options
|
98
|
+
# The options param follows the same structure described by
|
99
|
+
# https://app.omie.com.br/api/v1/geral/produtos/#produto_servico_list_request
|
100
|
+
# @return [Array<Omie::Product>]
|
101
|
+
# the list of found companies
|
102
|
+
def self.list(options = {})
|
103
|
+
default = {
|
104
|
+
pagina: 1, registros_por_pagina: 50,
|
105
|
+
apenas_importado_api: 'N', filtrar_apenas_omiepdv: 'N'
|
106
|
+
}
|
107
|
+
|
108
|
+
default.each do |k, v|
|
109
|
+
options[k] = v unless options.key?(k)
|
110
|
+
end
|
111
|
+
|
112
|
+
response = request(URI, CALLS[:list], options)
|
113
|
+
response['produto_servico_cadastro'].map do |product|
|
114
|
+
Omie::Product.new(product)
|
115
|
+
end
|
116
|
+
rescue Omie::RequestError
|
117
|
+
[]
|
118
|
+
end
|
119
|
+
|
120
|
+
# Associate the local entry with an existing entry at Omie
|
121
|
+
# {https://app.omie.com.br/api/v1/geral/clientes/#AssociarCodIntProduto
|
122
|
+
# AssociarCodIntProduto}. Omie will find the existing entry through the
|
123
|
+
# {#codigo_produto} and updates its {#codigo_produto_integracao}
|
124
|
+
#
|
125
|
+
# @!scope class
|
126
|
+
# @param codigo_produto [String]
|
127
|
+
# The id of the existing entry at Omie
|
128
|
+
# @param codigo_produto_integracao [String]
|
129
|
+
# The integration id to be used by the existing entry - usually a local
|
130
|
+
# id.
|
131
|
+
def self.associate(codigo_produto, codigo_produto_integracao)
|
132
|
+
params = {
|
133
|
+
codigo_produto: codigo_produto,
|
134
|
+
codigo_produto_integracao: codigo_produto_integracao
|
135
|
+
}
|
136
|
+
|
137
|
+
request(URI, CALLS[:associate], params)
|
138
|
+
end
|
139
|
+
|
140
|
+
# Save the product.
|
141
|
+
#
|
142
|
+
# If the product is new a record is created on Omie, otherwise
|
143
|
+
# the existing record gets updated.
|
144
|
+
#
|
145
|
+
# @return [Omie::Product]
|
146
|
+
# the product itself updated
|
147
|
+
def save
|
148
|
+
product = if saved?
|
149
|
+
Omie::Product.update(as_json)
|
150
|
+
else
|
151
|
+
Omie::Product.create(as_json)
|
152
|
+
end
|
153
|
+
|
154
|
+
self.codigo_produto = product.codigo_produto if product
|
155
|
+
product
|
156
|
+
end
|
157
|
+
|
158
|
+
# Check whether the object has a related record on Omie based on the
|
159
|
+
# {#codigo_produto} attribute
|
160
|
+
#
|
161
|
+
# @return [Boolean]
|
162
|
+
def saved?
|
163
|
+
!codigo_produto.blank?
|
164
|
+
end
|
165
|
+
|
166
|
+
# Updates the omie entry with the local id for integration purposes.
|
167
|
+
#
|
168
|
+
# @return [Boolean]
|
169
|
+
def associate_entry
|
170
|
+
Omie::Product.associate(codigo_produto, codigo_produto_integracao)
|
171
|
+
true
|
172
|
+
end
|
173
|
+
end
|
174
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Omie
|
4
|
+
# This class abstracts tax recommendations related to the Product resource
|
5
|
+
# from Omie (Ref: Produto). It works as an embedded object inside Product
|
6
|
+
# payload. Take a look at this link for more details:
|
7
|
+
# {https://app.omie.com.br/api/v1/geral/produtos/}.
|
8
|
+
#
|
9
|
+
# Different from traditional resources that inherit from {Omie::BaseResource},
|
10
|
+
# internal objects does nothing but declares attributes that will comprise
|
11
|
+
# a higher level resource's payload. They usually does not have specific
|
12
|
+
# endpoints.
|
13
|
+
class TaxRecommendation < Omie::BaseResource
|
14
|
+
attr_accessor :origem_mercadoria, :id_preco_tabelado, :id_cest,
|
15
|
+
:cupom_fiscal, :market_place, :indicador_escala,
|
16
|
+
:cnpj_fabricante
|
17
|
+
end
|
18
|
+
end
|
data/lib/omie/version.rb
CHANGED
data/omie-client.gemspec
CHANGED
@@ -1,37 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
|
2
|
-
lib = File.expand_path(
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
3
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require
|
5
|
+
require 'omie/version'
|
5
6
|
|
6
7
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name =
|
8
|
+
spec.name = 'omie-client'
|
8
9
|
spec.version = Omie::VERSION
|
9
|
-
spec.authors = [
|
10
|
-
spec.email = [
|
10
|
+
spec.authors = ['Peerdustry']
|
11
|
+
spec.email = ['contato@peerdustry.com']
|
11
12
|
|
12
|
-
spec.summary =
|
13
|
-
spec.description =
|
14
|
-
spec.homepage =
|
15
|
-
spec.license =
|
13
|
+
spec.summary = 'A Ruby client for Omie ERP API'
|
14
|
+
spec.description = 'A Ruby client for Omie ERP API'
|
15
|
+
spec.homepage = 'https://gitlab.com/peerdustry/floss/omie-client'
|
16
|
+
spec.license = 'MIT'
|
16
17
|
|
17
18
|
# Specify which files should be added to the gem when it is released.
|
18
|
-
# The `git ls-files -z` loads the files in the RubyGem that have been added
|
19
|
-
|
20
|
-
|
19
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added
|
20
|
+
# into git.
|
21
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
22
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
23
|
+
f.match(%r{^(test|spec|features)/})
|
24
|
+
end
|
21
25
|
end
|
22
|
-
spec.bindir =
|
26
|
+
spec.bindir = 'exe'
|
23
27
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
24
|
-
spec.require_paths = [
|
25
|
-
spec.required_ruby_version =
|
28
|
+
spec.require_paths = ['lib']
|
29
|
+
spec.required_ruby_version = '>= 2.3'
|
26
30
|
|
27
31
|
# development dependencies
|
28
|
-
spec.add_development_dependency
|
29
|
-
spec.add_development_dependency "rake", "~> 10.0"
|
30
|
-
spec.add_development_dependency "rspec", "~> 3.0"
|
31
|
-
spec.add_development_dependency 'factory_bot', '>= 5.0'
|
32
|
+
spec.add_development_dependency 'bundler', '~> 1.16'
|
32
33
|
spec.add_development_dependency 'cpf_cnpj', '~> 0.5'
|
34
|
+
spec.add_development_dependency 'factory_bot', '>= 5.0'
|
35
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
36
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
37
|
+
spec.add_development_dependency 'rubocop', '~> 0.80.1'
|
33
38
|
|
34
39
|
# development dependencies
|
35
|
-
spec.add_dependency 'rest-client', '>= 2.0'
|
36
40
|
spec.add_dependency 'activesupport', '>= 5.0'
|
41
|
+
spec.add_dependency 'rest-client', '>= 2.0'
|
37
42
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: omie-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peerdustry
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-05-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -25,89 +25,103 @@ dependencies:
|
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.16'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: cpf_cnpj
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '0.5'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '0.5'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: factory_bot
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '5.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '5.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
44
58
|
requirements:
|
45
59
|
- - "~>"
|
46
60
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
61
|
+
version: '10.0'
|
48
62
|
type: :development
|
49
63
|
prerelease: false
|
50
64
|
version_requirements: !ruby/object:Gem::Requirement
|
51
65
|
requirements:
|
52
66
|
- - "~>"
|
53
67
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
68
|
+
version: '10.0'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
70
|
+
name: rspec
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
58
72
|
requirements:
|
59
|
-
- - "
|
73
|
+
- - "~>"
|
60
74
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
75
|
+
version: '3.0'
|
62
76
|
type: :development
|
63
77
|
prerelease: false
|
64
78
|
version_requirements: !ruby/object:Gem::Requirement
|
65
79
|
requirements:
|
66
|
-
- - "
|
80
|
+
- - "~>"
|
67
81
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
82
|
+
version: '3.0'
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
84
|
+
name: rubocop
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|
72
86
|
requirements:
|
73
87
|
- - "~>"
|
74
88
|
- !ruby/object:Gem::Version
|
75
|
-
version:
|
89
|
+
version: 0.80.1
|
76
90
|
type: :development
|
77
91
|
prerelease: false
|
78
92
|
version_requirements: !ruby/object:Gem::Requirement
|
79
93
|
requirements:
|
80
94
|
- - "~>"
|
81
95
|
- !ruby/object:Gem::Version
|
82
|
-
version:
|
96
|
+
version: 0.80.1
|
83
97
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
98
|
+
name: activesupport
|
85
99
|
requirement: !ruby/object:Gem::Requirement
|
86
100
|
requirements:
|
87
101
|
- - ">="
|
88
102
|
- !ruby/object:Gem::Version
|
89
|
-
version: '
|
103
|
+
version: '5.0'
|
90
104
|
type: :runtime
|
91
105
|
prerelease: false
|
92
106
|
version_requirements: !ruby/object:Gem::Requirement
|
93
107
|
requirements:
|
94
108
|
- - ">="
|
95
109
|
- !ruby/object:Gem::Version
|
96
|
-
version: '
|
110
|
+
version: '5.0'
|
97
111
|
- !ruby/object:Gem::Dependency
|
98
|
-
name:
|
112
|
+
name: rest-client
|
99
113
|
requirement: !ruby/object:Gem::Requirement
|
100
114
|
requirements:
|
101
115
|
- - ">="
|
102
116
|
- !ruby/object:Gem::Version
|
103
|
-
version: '
|
117
|
+
version: '2.0'
|
104
118
|
type: :runtime
|
105
119
|
prerelease: false
|
106
120
|
version_requirements: !ruby/object:Gem::Requirement
|
107
121
|
requirements:
|
108
122
|
- - ">="
|
109
123
|
- !ruby/object:Gem::Version
|
110
|
-
version: '
|
124
|
+
version: '2.0'
|
111
125
|
description: A Ruby client for Omie ERP API
|
112
126
|
email:
|
113
127
|
- contato@peerdustry.com
|
@@ -116,7 +130,9 @@ extensions: []
|
|
116
130
|
extra_rdoc_files: []
|
117
131
|
files:
|
118
132
|
- ".gitignore"
|
133
|
+
- ".gitlab-ci.yml"
|
119
134
|
- ".rspec"
|
135
|
+
- ".rubocop.yml"
|
120
136
|
- Gemfile
|
121
137
|
- Gemfile.lock
|
122
138
|
- LICENSE
|
@@ -130,6 +146,8 @@ files:
|
|
130
146
|
- lib/omie/connection.rb
|
131
147
|
- lib/omie/error.rb
|
132
148
|
- lib/omie/info.rb
|
149
|
+
- lib/omie/product.rb
|
150
|
+
- lib/omie/tax_recommendation.rb
|
133
151
|
- lib/omie/version.rb
|
134
152
|
- omie-client.gemspec
|
135
153
|
homepage: https://gitlab.com/peerdustry/floss/omie-client
|
@@ -144,7 +162,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
144
162
|
requirements:
|
145
163
|
- - ">="
|
146
164
|
- !ruby/object:Gem::Version
|
147
|
-
version: 2.
|
165
|
+
version: '2.3'
|
148
166
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
149
167
|
requirements:
|
150
168
|
- - ">="
|