Module: Vindicia::SoapClient

Instance Method Summary collapse

Methods included from XMLBuilder

#build_array_xml, #build_tag_xml, #build_xml

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object



178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
# File 'lib/vindicia.rb', line 178

def method_missing(method, *args)
  # TODO: verify that this method _is_ a method callable on the wsdl,
  #       and defer to super if not.
  method = underscore(method.to_s).to_sym # back compatability from camelCase api
  out_vars = nil # set up outside variable

  response = soap.request(:wsdl, method) do |soap, wsdl, http|
    # Don't care about broken SSL when testing
    http.auth.ssl.verify_mode = :none if Vindicia.environment == 'prodtest'

    out_vars = wsdl.arg_list["#{method.to_s.lower_camelcase}_out"]

    soap.namespaces["xmlns:vin"] = Vindicia::NAMESPACE
    soap.body = begin
      xml = Builder::XmlMarkup.new

      key = "#{method.to_s.lower_camelcase}_in"
      wsdl.arg_list[key].zip([Vindicia.auth] + args).each do |arg, data|
        build_xml(xml, arg['name'], arg['type'], data)
      end

      xml.target!
    end
  end

  values = response.to_hash[:"#{method}_response"]
  objs = out_vars.map do |var|
    value = values[underscore(var["name"]).to_sym]
    Vindicia.coerce(var["name"], var["type"], value)
  end

  ret = objs.shift

  return [ret] + objs unless objs.first.is_a? SoapObject

  case objs.size
  when 0
    ret.request_status = ret
    ret
  when 1
    objs.first.request_status = ret
    objs.first
  else
    objs.first.request_status = ret
    objs
  end
end

Instance Method Details

#find(id) ⇒ Object



174
175
176
# File 'lib/vindicia.rb', line 174

def find(id)
  self.send(:"fetch_by_merchant_#{name.downcase}_id", id)
end

#nameObject



226
227
228
# File 'lib/vindicia.rb', line 226

def name
  self.to_s.split('::').last
end

#soapObject



230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
# File 'lib/vindicia.rb', line 230

def soap
  @soap ||= begin
    Savon::Client.new do |wsdl|
      wsdl.document = Vindicia.wsdl(name)
      # Test WSDL files contain production endpoints, must override
      wsdl.endpoint = Vindicia.endpoint

      # Be sure to parse arg lists for revification w/ custom parser
      def wsdl.parser
        @parser ||= begin
          parser = Savon::WSDL::ParserWithArgList.new
          REXML::Document.parse_stream self.document, parser
          parser
        end
      end
    end
  end
end