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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ca87b5dcc40d9731b77114fb38f73680a26f85d5
4
- data.tar.gz: b38d619dbc26ccff7cb8e44c79407bb5a09a7ff9
3
+ metadata.gz: 96f9666241489f3f8c683779eb2c69b806d3b4e1
4
+ data.tar.gz: 46acc434314f5de1ed39b59ce3b3cf495fb003a4
5
5
  SHA512:
6
- metadata.gz: 3539cd808e0137bdda3abdae152fe29373a196207d4bb2bb2bf7b5bea85aa3e349129dd394d0124a5ad5f8d0788470c5ba9754e0e772be8fd6dbb1b2cb26278e
7
- data.tar.gz: 9cc619dad566bd9cb8b700554d5ffe60f5cd3179cd18412c47719104ba1215d4f692cc9e4d39577da82b174d833763f79c28a428133fd6536cd5928ab2ecb8d9
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
@@ -20,20 +20,22 @@ module Nfe
20
20
  params = nil
21
21
  end
22
22
 
23
- begin
24
- payload = params.to_json
25
- response = RestClient::Request.new(
26
- method: method,
27
- url: url,
28
- payload: payload,
29
- headers: {
30
- content_type: 'application/json',
31
- accept: '*/*',
32
- authorization: api_key,
33
- user_agent: Nfe.configuration.user_agent
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.to_str)
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
@@ -6,6 +6,7 @@ module Nfe
6
6
  include ApiOperations::Retrieve
7
7
  include ApiOperations::Delete
8
8
  include ApiOperations::Update
9
+ include ApiOperations::Download
9
10
 
10
11
  def self.company_id(company_id)
11
12
  @company_id = company_id
data/lib/nfe/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Nfe
2
- VERSION = "0.2.5"
2
+ VERSION = "0.3.0"
3
3
  end
data/lib/nfe.rb CHANGED
@@ -9,6 +9,7 @@ require "nfe/api_operations/delete"
9
9
  require "nfe/api_operations/list"
10
10
  require "nfe/api_operations/retrieve"
11
11
  require "nfe/api_operations/update"
12
+ require "nfe/api_operations/download"
12
13
 
13
14
  require "nfe/nfe_object"
14
15
  require "nfe/service_invoice"
data/nfe.gemspec CHANGED
@@ -32,4 +32,5 @@ Gem::Specification.new do |spec|
32
32
  spec.add_development_dependency "bundler", "~> 1.10"
33
33
  spec.add_development_dependency "rake", "~> 10.0"
34
34
  spec.add_development_dependency "rspec"
35
+ spec.add_development_dependency "byebug"
35
36
  end
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.2.5
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-07 00:00:00.000000000 Z
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