nfe-io 0.2.5 → 0.3.0
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/README.md +1 -5
- data/lib/nfe/api_operations/download.rb +24 -0
- data/lib/nfe/api_resource.rb +47 -13
- data/lib/nfe/service_invoice.rb +1 -0
- data/lib/nfe/version.rb +1 -1
- data/lib/nfe.rb +1 -0
- data/nfe.gemspec +1 -0
- metadata +17 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 96f9666241489f3f8c683779eb2c69b806d3b4e1
|
4
|
+
data.tar.gz: 46acc434314f5de1ed39b59ce3b3cf495fb003a4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d6acd8114623cf0ff33bf264b72b5bff1d694ac55ea4b25887b7912e152b5864a549217a4639694bcd6613de2eb34f224b106a5017a7e5e4373a9e4a9da92916
|
7
|
+
data.tar.gz: 9987a01436c78325ba87edd229270e1dda2c5cfb0dcfbec40bc3e69e6ca303b394e8b50ea183b1280132cf3a3f84db26c5a18ec0b01bbaedd1c4cc17fd1d5a50
|
data/README.md
CHANGED
@@ -80,10 +80,6 @@ git commit -m'Bump version 0.2.4'
|
|
80
80
|
```bash
|
81
81
|
git tag 0.2.4
|
82
82
|
```
|
83
|
-
- Executar gem build
|
84
|
-
```bash
|
85
|
-
gem build nfe.gemspec
|
86
|
-
```
|
87
83
|
- Executar gem build, repare que um novo arquivo será criado, com a versão do pacote alterada acima
|
88
84
|
```bash
|
89
85
|
gem build nfe.gemspec
|
@@ -97,4 +93,4 @@ gem push nfe-io-0.2.4.gem
|
|
97
93
|
|
98
94
|
Originalmente criado pela equipe da [Pluga](https://github.com/PlugaDotCo).
|
99
95
|
|
100
|
-
Esta gem é open source sob os termos da [Licença MIT](http://opensource.org/licenses/MIT).
|
96
|
+
Esta gem é open source sob os termos da [Licença MIT](http://opensource.org/licenses/MIT).
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'byebug'
|
2
|
+
|
3
|
+
module Nfe
|
4
|
+
module ApiOperations
|
5
|
+
module Download
|
6
|
+
def download(nfe_id, file_format)
|
7
|
+
if file_format != :pdf && file_format != :xml
|
8
|
+
rcode = '422'
|
9
|
+
message = 'Invalid file format. Only :pdf or :xml are supported'
|
10
|
+
formatted = { error: message }
|
11
|
+
raise NfeError.new(rcode, formatted, formatted, message)
|
12
|
+
else
|
13
|
+
url = "#{self.url}/#{nfe_id}/#{file_format}"
|
14
|
+
method = :get
|
15
|
+
api_request_file(url, method)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.included(base)
|
20
|
+
base.extend(Download)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/lib/nfe/api_resource.rb
CHANGED
@@ -20,20 +20,22 @@ module Nfe
|
|
20
20
|
params = nil
|
21
21
|
end
|
22
22
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
}).execute
|
23
|
+
payload = (params != nil) ? params.to_json : ''
|
24
|
+
request = RestClient::Request.new(
|
25
|
+
method: method,
|
26
|
+
url: url,
|
27
|
+
payload: payload,
|
28
|
+
headers: {
|
29
|
+
content_type: 'application/json',
|
30
|
+
accept: 'application/json',
|
31
|
+
authorization: api_key,
|
32
|
+
user_agent: Nfe.configuration.user_agent
|
33
|
+
})
|
35
34
|
|
35
|
+
begin
|
36
|
+
response = request.execute
|
36
37
|
rescue RestClient::ExceptionWithResponse => e
|
38
|
+
# byebug
|
37
39
|
if rcode = e.http_code and rbody = e.http_body
|
38
40
|
rbody = JSON.parse(rbody)
|
39
41
|
rbody = Util.symbolize_names(rbody)
|
@@ -45,11 +47,43 @@ module Nfe
|
|
45
47
|
rescue RestClient::Exception => e
|
46
48
|
raise e
|
47
49
|
end
|
48
|
-
JSON.parse(response.
|
50
|
+
JSON.parse(response.to_s)
|
49
51
|
end
|
50
52
|
|
51
53
|
def self.included(base)
|
52
54
|
base.extend(ApiResource)
|
53
55
|
end
|
56
|
+
|
57
|
+
def api_request_file(url, method, params=nil)
|
58
|
+
api_key = Nfe.access_keys
|
59
|
+
url = "#{Nfe.configuration.url}#{url}?api_key=#{api_key}"
|
60
|
+
|
61
|
+
request = RestClient::Request.new(
|
62
|
+
method: method,
|
63
|
+
url: url,
|
64
|
+
headers: {
|
65
|
+
user_agent: Nfe.configuration.user_agent
|
66
|
+
}
|
67
|
+
)
|
68
|
+
|
69
|
+
begin
|
70
|
+
response = request.execute
|
71
|
+
rescue RestClient::ExceptionWithResponse => e
|
72
|
+
# byebug
|
73
|
+
if rcode = e.http_code and rbody = e.http_body
|
74
|
+
rbody = JSON.parse(rbody)
|
75
|
+
rbody = Util.symbolize_names(rbody)
|
76
|
+
|
77
|
+
raise NfeError.new(rcode, rbody, rbody, rbody[:message])
|
78
|
+
else
|
79
|
+
raise e
|
80
|
+
end
|
81
|
+
rescue RestClient::Exception => e
|
82
|
+
raise e
|
83
|
+
end
|
84
|
+
|
85
|
+
response
|
86
|
+
end
|
87
|
+
|
54
88
|
end
|
55
89
|
end
|
data/lib/nfe/service_invoice.rb
CHANGED
data/lib/nfe/version.rb
CHANGED
data/lib/nfe.rb
CHANGED
data/nfe.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nfe-io
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ricardo Caldeira
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-06-
|
11
|
+
date: 2017-06-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - '>='
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: byebug
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
69
83
|
description: Nfe.io's ruby gem
|
70
84
|
email:
|
71
85
|
- ricardo.nezz@gmail.com
|
@@ -88,6 +102,7 @@ files:
|
|
88
102
|
- lib/nfe.rb
|
89
103
|
- lib/nfe/api_operations/create.rb
|
90
104
|
- lib/nfe/api_operations/delete.rb
|
105
|
+
- lib/nfe/api_operations/download.rb
|
91
106
|
- lib/nfe/api_operations/list.rb
|
92
107
|
- lib/nfe/api_operations/retrieve.rb
|
93
108
|
- lib/nfe/api_operations/update.rb
|