Module: FacturapiRuby::HttpClient

Defined in:
lib/facturapi_ruby/http_client.rb

Constant Summary collapse

BASE_URL =
'https://www.facturapi.io'

Class Method Summary collapse

Class Method Details

.delete(options) ⇒ Object



55
56
57
58
59
# File 'lib/facturapi_ruby/http_client.rb', line 55

def delete(options)
  response = request(Net::HTTP::Delete, options)

  json_response(response)
end

.get(options) ⇒ Object



33
34
35
36
37
# File 'lib/facturapi_ruby/http_client.rb', line 33

def get(options)
  response = request(Net::HTTP::Get, options)

  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(options)
  response = request(Net::HTTP::Get, options)

  file = Tempfile.open(['my', options[: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(options)
  response = request(Net::HTTP::Post, options) do |request|
    request.body = options[: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(options)
  response = request(Net::HTTP::Put, options) do |request|
    request.body = options[:api_options].to_json
  end

  json_response(response)
end