facturapi_ruby 1.2.0 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/facturapi_ruby/configuration.rb +2 -1
- data/lib/facturapi_ruby/http_client.rb +36 -26
- data/lib/facturapi_ruby/invoices.rb +14 -0
- data/lib/facturapi_ruby/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b58fed997b3fb3da051f518146bc46b1aa982b874f771e0890870b8578dabb61
|
4
|
+
data.tar.gz: a6ad129cffa87123e86e36e7b38a53c99e9e30ba3a5b024d77c530e21847ec7f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f7f2b0e62be8433c3cd944fa693829fe0ff495901cc38a8ef73dd8e0d27689f4f8d7b022ae71877a15972dd4d2f628f96655e90e68ec69cb0b6f31440cb65989
|
7
|
+
data.tar.gz: b7d7e814f06a68fbc3a3b779e9dda13d5869183570ce1c72e3a011a281473300d9f86178b6389a4719bbbdf9e5e3108885754d896fa2104009107d41752a3348
|
@@ -17,38 +17,50 @@ module FacturapiRuby
|
|
17
17
|
BASE_URL = 'https://www.facturapi.io/v1'
|
18
18
|
|
19
19
|
def get_file(options)
|
20
|
-
|
21
|
-
|
22
|
-
http = Net::HTTP.new(uri.host, uri.port)
|
23
|
-
http.use_ssl = true
|
24
|
-
request = Net::HTTP::Get.new(uri.request_uri)
|
25
|
-
request.basic_auth(FacturapiRuby.configuration.api_key, '')
|
20
|
+
response = request(Net::HTTP::Get, options)
|
26
21
|
|
27
|
-
response = http.request(request)
|
28
22
|
file = Tempfile.open(['my', options[:file_ext]])
|
29
23
|
file.binmode
|
30
24
|
file.write(response.body)
|
31
25
|
|
32
|
-
if response.code
|
26
|
+
if response.code.start_with? '20'
|
33
27
|
file
|
34
28
|
else
|
35
29
|
raise FacturapiRubyError.new(JSON.parse(response.body))
|
36
30
|
end
|
37
31
|
end
|
38
32
|
|
33
|
+
def get(options)
|
34
|
+
response = request(Net::HTTP::Get, options)
|
35
|
+
|
36
|
+
json_response(response)
|
37
|
+
end
|
38
|
+
|
39
39
|
def post(options)
|
40
|
-
|
40
|
+
response = request(Net::HTTP::Post, options) do |request|
|
41
|
+
request.body = options[:api_options].to_json
|
42
|
+
end
|
43
|
+
|
44
|
+
json_response(response)
|
45
|
+
end
|
41
46
|
|
42
|
-
|
43
|
-
|
47
|
+
def put(options)
|
48
|
+
response = request(Net::HTTP::Put, options) do |request|
|
49
|
+
request.body = options[:api_options].to_json
|
50
|
+
end
|
44
51
|
|
45
|
-
|
46
|
-
|
47
|
-
request.basic_auth(FacturapiRuby.configuration.api_key, '')
|
52
|
+
json_response(response)
|
53
|
+
end
|
48
54
|
|
49
|
-
|
55
|
+
def delete(options)
|
56
|
+
response = request(Net::HTTP::Delete, options)
|
50
57
|
|
51
|
-
response
|
58
|
+
json_response(response)
|
59
|
+
end
|
60
|
+
|
61
|
+
private
|
62
|
+
|
63
|
+
def json_response(response)
|
52
64
|
if response.code.start_with? '20'
|
53
65
|
JSON.parse(response.body)
|
54
66
|
else
|
@@ -56,24 +68,22 @@ module FacturapiRuby
|
|
56
68
|
end
|
57
69
|
end
|
58
70
|
|
59
|
-
def
|
71
|
+
def request(request_method, options)
|
60
72
|
uri = URI(BASE_URL + options[:endpoint])
|
61
73
|
|
62
74
|
http = Net::HTTP.new(uri.host, uri.port)
|
63
75
|
http.use_ssl = true
|
64
76
|
|
65
|
-
request =
|
66
|
-
request.body = options[:api_options].to_json
|
77
|
+
request = request_method.new(uri.request_uri, 'Content-Type' => 'application/json')
|
78
|
+
# request.body = options[:api_options].to_json
|
79
|
+
|
80
|
+
yield(request) if block_given?
|
81
|
+
|
67
82
|
request.basic_auth(FacturapiRuby.configuration.api_key, '')
|
68
83
|
|
69
|
-
http.set_debug_output($stdout)
|
84
|
+
http.set_debug_output($stdout) if FacturapiRuby.configuration.debug_output
|
70
85
|
|
71
|
-
|
72
|
-
if response.code.start_with? '20'
|
73
|
-
JSON.parse(response.body)
|
74
|
-
else
|
75
|
-
raise FacturapiRubyError.new(JSON.parse(response.body))
|
76
|
-
end
|
86
|
+
http.request(request)
|
77
87
|
end
|
78
88
|
end
|
79
89
|
end
|
@@ -9,6 +9,20 @@ module FacturapiRuby
|
|
9
9
|
api_options: options
|
10
10
|
)
|
11
11
|
end
|
12
|
+
|
13
|
+
def cancel(invoice_id, options={})
|
14
|
+
HttpClient.delete(
|
15
|
+
endpoint: "/invoices/#{invoice_id}",
|
16
|
+
api_options: options
|
17
|
+
)
|
18
|
+
end
|
19
|
+
|
20
|
+
def get(invoice_id, options={})
|
21
|
+
HttpClient.get(
|
22
|
+
endpoint: "/invoices/#{invoice_id}",
|
23
|
+
api_options: options
|
24
|
+
)
|
25
|
+
end
|
12
26
|
end
|
13
27
|
end
|
14
28
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: facturapi_ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Diego Llamas Velasco
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-02-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|