Class: ViafirmaApi::Client
- Inherits:
-
Object
- Object
- ViafirmaApi::Client
- Defined in:
- lib/viafirma-api/client.rb
Class Method Summary collapse
Instance Method Summary collapse
- #call(*args) ⇒ Object
-
#initialize(credentials) ⇒ Client
constructor
A new instance of Client.
- #parse_response(response) ⇒ Object
Constructor Details
#initialize(credentials) ⇒ Client
Returns a new instance of Client.
6 7 8 9 |
# File 'lib/viafirma-api/client.rb', line 6 def initialize(credentials) validate(credentials) @client = Savon.client(adapter: :net_http, wsdl: self.class.wsdl(credentials), basic_auth: [credentials[:user], credentials[:apikey]]) end |
Class Method Details
.wsdl(credentials) ⇒ Object
11 12 13 |
# File 'lib/viafirma-api/client.rb', line 11 def self.wsdl(credentials) "http://#{credentials[:server]}:#{credentials[:port] || 80}/inbox/serviceWS?wsdl" end |
Instance Method Details
#call(*args) ⇒ Object
15 16 17 18 |
# File 'lib/viafirma-api/client.rb', line 15 def call(*args) response = @client.call(*args) parse_response(response.body) end |
#parse_response(response) ⇒ Object
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/viafirma-api/client.rb', line 20 def parse_response(response) response_key = response.keys.detect{|k,v| k.to_s.end_with?('_response')} data = response[response_key][:return] if data[:error] raise "#{data[:response_code]}: #{data[:message]}" else data end end |