Class: Afipws::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/afipws/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(savon_options) ⇒ Client

Returns a new instance of Client.



3
4
5
# File 'lib/afipws/client.rb', line 3

def initialize savon_options
  @client = Savon.client savon_options.reverse_merge(soap_version: 2)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_sym, *args) ⇒ Object



24
25
26
# File 'lib/afipws/client.rb', line 24

def method_missing method_sym, *args
  request method_sym, *args
end

Instance Method Details

#operationsObject



20
21
22
# File 'lib/afipws/client.rb', line 20

def operations
  @client.operations
end

#raw_request(action, body = nil) ⇒ Object



16
17
18
# File 'lib/afipws/client.rb', line 16

def raw_request action, body = nil
  @client.call action, message: body
end

#request(action, body = nil) ⇒ Object



7
8
9
10
11
12
13
14
# File 'lib/afipws/client.rb', line 7

def request action, body = nil
  response = raw_request(action, body).to_hash[:"#{action}_response"][:"#{action}_result"]
  if response[:errors]
    raise WSError, Array.wrap(response[:errors][:err])
  else
    response
  end
end