class ClearSaleClearId::Server

Attributes

entity_code[RW]
savon_client[RW]
service_url[RW]
wsdl_url[RW]

Public Class Methods

new( service_url: ENV.fetch('CS_SERVICE_URL'), wsdl_url: ENV.fetch('CS_WSDL_URL'), entity_code: ENV.fetch('CS_ENTITY_CODE'), savon_client: nil ) click to toggle source
# File lib/clear_sale_clear_id/server.rb, line 7
def initialize(
  service_url: ENV.fetch('CS_SERVICE_URL'),
  wsdl_url: ENV.fetch('CS_WSDL_URL'),
  entity_code: ENV.fetch('CS_ENTITY_CODE'),
  savon_client: nil
)
  self.service_url = service_url
  self.wsdl_url = wsdl_url
  self.entity_code = entity_code
  self.savon_client = savon_client || Savon.client(wsdl: wsdl_url)
end

Public Instance Methods

submit_info(order) click to toggle source
# File lib/clear_sale_clear_id/server.rb, line 19
def submit_info(order)
  request_body = order.to_xml

  response = savon_client.call(
    :submit_info, message: {
      'entityCode' => self.entity_code,
      'xmlDados' => request_body
    }
  )
  response_body = response.body

  Response::PackageStatus.new(
    request_body,
    extract_response_xml('submit_info', response_body)
  )
end

Private Instance Methods

extract_response_xml(method, response) click to toggle source
# File lib/clear_sale_clear_id/server.rb, line 38
def extract_response_xml(method, response)
  results = response.fetch(:"#{method.snakecase}_response", {})
  results.fetch(:"#{method.snakecase}_result", {})
end