Class: Facturama::Services::HttpService

Inherits:
Object
  • Object
show all
Defined in:
lib/facturama/services/http_service.rb

Direct Known Subclasses

CrudService

Instance Method Summary collapse

Constructor Details

#initialize(connection_info, uri_resource) ⇒ HttpService

Returns a new instance of HttpService.



9
10
11
12
# File 'lib/facturama/services/http_service.rb', line 9

def initialize(connection_info, uri_resource)
  @connection_info = connection_info
  @uri_resource = uri_resource
end

Instance Method Details

#delete(args = '') ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/facturama/services/http_service.rb', line 59

def delete(args = '')
  res = RestClient::Request.new(
    method: :delete,
    url: url(args),
    user: @connection_info.facturama_user,
    password: @connection_info.facturama_password,
    headers: { accept: :json,
               content_type: :json }
  )

  executor(res)
end

#get(args = '') ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/facturama/services/http_service.rb', line 14

def get(args = '')
  res = RestClient::Request.new(
    method: :get,
    url: url(args),
    user: @connection_info.facturama_user,
    password: @connection_info.facturama_password,
    headers: { accept: :json,
               content_type: :json,
               user_agent: '' }
  )

  executor(res)
end

#post(message, args = '') ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/facturama/services/http_service.rb', line 28

def post(message, args = '')
  json = message.to_json

  res = RestClient::Request.new(
    method: :post,
    url: url(args),
    user: @connection_info.facturama_user,
    password: @connection_info.facturama_password,
    payload: json,
    headers: { content_type: :json }
  )

  executor(res)
end

#put(message, args = '') ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/facturama/services/http_service.rb', line 43

def put(message, args = '')
  json = message.to_json

  res = RestClient::Request.new(
    method: :put,
    url: url(args),
    user: @connection_info.facturama_user,
    password: @connection_info.facturama_password,
    payload: json,
    headers: { accept: :json,
               content_type: :json }
  )

  executor(res)
end