Class: TntMercurio::Service::WebService

Inherits:
Object
  • Object
show all
Defined in:
lib/tnt_mercurio/service/web_service.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeWebService

Returns a new instance of WebService.



10
11
12
13
14
15
16
17
18
# File 'lib/tnt_mercurio/service/web_service.rb', line 10

def initialize
  @savon_client = Savon.client(
    wsdl: ::TntMercurio::Service::Configuracao::URL,
    convert_request_keys_to: :lower_camelcase,
    namespace_identifier: :ser,
    namespaces: { "xmlns:ser" => "http://service.calculoFrete.mercurio.com",
                  "xmlns:mod" => "http://model.vendas.lms.mercurio.com" },
  )
end

Instance Attribute Details

#savon_clientObject (readonly)

Returns the value of attribute savon_client.



8
9
10
# File 'lib/tnt_mercurio/service/web_service.rb', line 8

def savon_client
  @savon_client
end

Instance Method Details

#request(parametros = {}) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/tnt_mercurio/service/web_service.rb', line 20

def request(parametros = {})
  # Monta os parâmetros
  params = helper.build_request_calculo_frete(parametros)

  # Faz a requisição para o wsdl
  begin
    retorno = @savon_client.call(:calcula_frete, message: params)
    # Coverte a resposta
    resposta = retorno.to_array.first unless retorno.blank?
  rescue Savon::SOAPFault => error
    return helper.build_response_calculo_frete({error: error.to_hash[:fault][:faultstring]})
  end

  # Verifica se a resposta veio correta ou se deu problema
  if resposta.blank?
    return {error: true}
  else
    return resposta
  end
end