Class: ActiveSP::Site::Service

Inherits:
Object
  • Object
show all
Defined in:
lib/activesp/site.rb

Instance Method Summary collapse

Constructor Details

#initialize(site, name) ⇒ Service

Returns a new instance of Service.



279
280
281
282
283
284
285
286
287
288
289
290
291
292
# File 'lib/activesp/site.rb', line 279

def initialize(site, name)
  @site, @name = site, name
  @client = Savon::Client.new(::File.join(URI.escape(site.url), "_vti_bin", name + ".asmx?WSDL"))
  if site.connection.
    case site.connection.auth_type
    when :ntlm
      @client.request.ntlm_auth(site.connection., site.connection.password)
    when :basic
      @client.request.basic_auth(site.connection., site.connection.password)
    else
      raise ArgumentError, "Unknown authentication type #{site.connection.auth_type.inspect}"
    end
  end
end

Instance Method Details

#call(m, *args) ⇒ Object



294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
# File 'lib/activesp/site.rb', line 294

def call(m, *args)
  t1 = Time.now
  if Hash === args[-1]
    body = args.pop
  end
  @client.send(m, *args) do |soap|
    if body
      soap.body = body.inject({}) { |h, (k, v)| h["wsdl:#{k}"] = v ; h }
    end
    yield soap if block_given?
  end
rescue Savon::SOAPFault => e
  if e.error_code == 0x80004005
    raise AccessDenied, "access denied"
  else
    raise e
  end
ensure
  t2 = Time.now
  puts "SP - time: %.3fs, site: %s, service: %s, method: %s, body: %s" % [t2 - t1, @site.url, @name, m, body.inspect] if @site.connection.trace
end