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



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
225
226
227
228
229
230
231
232
# File 'lib/vindicia.rb', line 186

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



182
183
184
# File 'lib/vindicia.rb', line 182

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

#nameObject



234
235
236
# File 'lib/vindicia.rb', line 234

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

#soapObject



238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
# File 'lib/vindicia.rb', line 238

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