module TinyerpRuby::Poster

Public Class Methods

call(connection, service, params) click to toggle source
# File lib/tinyerp_ruby/poster.rb, line 10
def call(connection, service, params)
  @connection = connection
  webservice = Savon.client(wsdl: @connection.base_url, convert_request_keys_to: :none, filters: [:token])
  response = webservice.call(service, message: formatted_params(params))
  parse service, response
end

Private Class Methods

formatted_params(params) click to toggle source
# File lib/tinyerp_ruby/poster.rb, line 18
def formatted_params(params)
  params = params.first
  param_value = params.last.kind_of?(Hash) ? params.last.to_json : params.last

  formatted = { token: @connection.api_key }
  formatted.delete(:formato)
  formatted.merge!({params.first => param_value})
  formatted.merge!({formato: 'json'})
  formatted
end
parse(service, response) click to toggle source
# File lib/tinyerp_ruby/poster.rb, line 29
def parse(service, response)
  node = [service.to_s, "response"].join("_").to_sym
  body = response.body[node][:return]
  parsed = JSON.parse body, symbolize_names: true
  parsed[:retorno]
rescue
  {status: 'Erro'}
end