Module: FacturapiRuby::HttpClient
- Defined in:
- lib/facturapi_ruby/http_client.rb
Constant Summary collapse
- BASE_URL =
'https://www.facturapi.io'
Class Method Summary collapse
- .delete(options) ⇒ Object
- .get(options) ⇒ Object
- .get_file(options) ⇒ Object
- .post(options) ⇒ Object
- .put(options) ⇒ Object
Class Method Details
.delete(options) ⇒ Object
55 56 57 58 59 |
# File 'lib/facturapi_ruby/http_client.rb', line 55 def delete() response = request(Net::HTTP::Delete, ) json_response(response) end |
.get(options) ⇒ Object
33 34 35 36 37 |
# File 'lib/facturapi_ruby/http_client.rb', line 33 def get() response = request(Net::HTTP::Get, ) json_response(response) end |
.get_file(options) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/facturapi_ruby/http_client.rb', line 19 def get_file() response = request(Net::HTTP::Get, ) file = Tempfile.open(['my', [:file_ext]]) file.binmode file.write(response.body) if response.code.start_with? '20' file else raise FacturapiRubyError.new(JSON.parse(response.body)) end end |
.post(options) ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/facturapi_ruby/http_client.rb', line 39 def post() response = request(Net::HTTP::Post, ) do |request| request.body = [:api_options].to_json end json_response(response) end |
.put(options) ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/facturapi_ruby/http_client.rb', line 47 def put() response = request(Net::HTTP::Put, ) do |request| request.body = [:api_options].to_json end json_response(response) end |