# ------------------------------------------------------------------- # Copyright (c) 2009-2010 Sem4r sem4ruby@gmail.com # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the # "Software"), to deal in the Software without restriction, including # without limitation the rights to use, copy, modify, merge, publish, # distribute, sublicense, and/or sell copies of the Software, and to # permit persons to whom the Software is furnished to do so, subject to # the following conditions: # # The above copyright notice and this permission notice shall be # included in all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # ------------------------------------------------------------------- module Sem4r class SoapMessageV2010 attr_reader :response attr_reader :counters def initialize(connector, credentials) @connector = connector @credentials = credentials @response = nil @counters = {} @logger = nil end def logger=(logger) @logger= logger end def init(header_namespace, service_namespace) @header_namespace = header_namespace @service_namespace = service_namespace end def body=(soap_body_content) @soap_body_content = soap_body_content end def send(service_url) send_raw(service_url, build_soap_message) end def send_raw(service_url, soap_message) soap_message = soap_message.dup soap_message.gsub!(/{authentication_token}/, @credentials.authentication_token) soap_message.gsub!(/{useragent}/, @credentials.useragent) soap_message.gsub!(/{developer_token}/, @credentials.developer_token) # soap_message.gsub!(/{client_email}/, @credentials.client_email) _send_raw(service_url, soap_message) end private def _send_raw(service_url, soap_message) response_xml = @connector.send(service_url, "", soap_message) # erase namespace so it more simple parsing the xml response_xml.gsub!(/\b(ns\d:|xsi:|s:|soapenv:|env:|soap:)/, "") response_xml.gsub!(/xmlns=["'].*?['"]/, '') @response = Nokogiri::XML::Document.parse(response_xml) # # extract information from header # header = @response.at_xpath("//ResponseHeader") if header @counters = { :operations => header.at_xpath("operations").text.to_i, :response_time => header.at_xpath("responseTime").text.to_i, :units => header.at_xpath("units").text.to_i } end # # check soap fault # fault_el = @response.at_xpath("//Fault") if fault_el fault_string = fault_el.at_xpath('faultstring').text @logger.error("soap error: #{fault_string}") if @logger raise fault_string end self # # # # e7c3b00f339bcaf56b7df47db97efdb7 # 1 # 231 # 1 # # # # # soap:Server # [CampaignError.DUPLICATE_CAMPAIGN_NAME @ operations[0].operand.name] # # # [CampaignError.DUPLICATE_CAMPAIGN_NAME @ operations[0].operand.name] # ApiException # # operations[0].operand.name # # CampaignError # DUPLICATE_CAMPAIGN_NAME # # # # # # end def build_soap_header auth_token = @credentials.authentication_token str = "" if @service_namespace str += "" else str += "" end str +=<<-EOFS #{auth_token} #{@credentials.useragent} #{@credentials.developer_token} EOFS if @credentials.client_email str += "#{@credentials.client_email}" end if @service_namespace str += "" else str += "" end str += "" str end def build_soap_message soap_message = '' soap_message +=<<-EOFS EOFS soap_message end end end