Class: Clearsale::Connector
- Inherits:
-
Object
- Object
- Clearsale::Connector
- Defined in:
- lib/clearsale/connector.rb
Constant Summary collapse
- NAMESPACE =
"http://www.clearsale.com.br/integration"
- URLs =
{ "homolog" => 'http://homologacao.clearsale.com.br/integracaov2/service.asmx', "production" => 'https://integracao.clearsale.com.br/service.asmx' }
Class Method Summary collapse
Instance Method Summary collapse
- #append_namespace(namespace, hash) ⇒ Object
- #do_request(method, request) ⇒ Object
- #extract_response_xml(method, response) ⇒ Object
-
#initialize(endpoint_url, proxy = nil) ⇒ Connector
constructor
A new instance of Connector.
Constructor Details
#initialize(endpoint_url, proxy = nil) ⇒ Connector
Returns a new instance of Connector.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/clearsale/connector.rb', line 19 def initialize(endpoint_url, proxy=nil) @token = Clearsale::Config.entity_code namespaces = { 'xmlns:soap' => "http://www.w3.org/2003/05/soap-envelope", 'xmlns:xsd' => "http://www.w3.org/2001/XMLSchema" , 'xmlns:xsi' => "http://www.w3.org/2001/XMLSchema-instance" , 'xmlns:int' => "http://www.clearsale.com.br/integration", } = {:endpoint => endpoint_url, :namespace => NAMESPACE, :namespaces => namespaces, :convert_request_keys_to => :snakecase } [:proxy] = proxy if proxy [:log] = Clearsale::Config.log [:logger] = Clearsale::Config.logger [:read_timeout] = Clearsale::Config.read_timeout if Clearsale::Config.read_timeout.present? [:open_timeout] = Clearsale::Config.open_timeout if Clearsale::Config.open_timeout.present? @client = Savon.client() end |
Class Method Details
Instance Method Details
#append_namespace(namespace, hash) ⇒ Object
57 58 59 |
# File 'lib/clearsale/connector.rb', line 57 def append_namespace(namespace, hash) Hash[hash.map {|key, value| ["#{namespace}:#{key}", value]}] end |
#do_request(method, request) ⇒ Object
41 42 43 44 45 46 47 48 |
# File 'lib/clearsale/connector.rb', line 41 def do_request(method, request) namespaced_request = append_namespace('int', request) arguments = namespaced_request.merge({'int:entityCode' => @token}) response = @client.call(method, :message => arguments, :soap_action => "#{NAMESPACE}/#{method}") extract_response_xml(method, response.to_hash) end |
#extract_response_xml(method, response) ⇒ Object
50 51 52 53 54 55 |
# File 'lib/clearsale/connector.rb', line 50 def extract_response_xml(method, response) results = response.fetch(:"#{method.snakecase}_response", {}) response_xml = results.fetch(:"#{method.snakecase}_result", {}).to_s Nori.new(:parser => :nokogiri, :convert_tags_to => lambda { |tag| tag.snakecase.to_sym }).parse(response_xml.gsub(/^<\?xml.*\?>/, '')) end |