Class: RepsClient::Client

Inherits:
Object
  • Object
show all
Includes:
CommunityMethods, LeadMethods, PickListMethods
Defined in:
lib/reps_client/client.rb

Overview

RepsClient::Client is the main object for connecting to the remote REPS service.

Instance Method Summary collapse

Methods included from LeadMethods

#save_lead

Methods included from PickListMethods

#get_pick_lists

Methods included from CommunityMethods

#get_communities

Constructor Details

#initialize(options = {}) ⇒ Client

Initializes the client.

By default, the new client instance will take all of its configuration values from the module-level configuration, but these can be overridden at the client-level.

Examples:

Using module-level configuration values

RepsClient.configure do |config|
  config.enterprise_key = 'my_key'
end

client1 = RepsClient::Client.new
client1.enterprise_key
# => "my_key"

client2 = RepsClient::Client.new
client2.enterprise_key
# => "my_key"

Selectively overriding configuration values at the client level

RepsClient.configure do |config|
  config.enterprise_key = 'my_key'
  config.debug = 'true'
end

client1 = RepsClient::Client.new
client1.enterprise_key
# => "my_key"
client1.debug?
# => true

client2 = RepsClient::Client.new(:debug => false)
client2.enterprise_key
# => "my_key"
client2.debug?
# => false

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :username (String)

    The username for authenticating to the web service

  • :password (String)

    The password for authenticating to the web service

  • :enterprise_key (String)

    The enterprise key for authentication to the web service

  • :endpoint (String)

    The address for connecting to the web service

  • :namespace (String)

    The XML namespace to use for requests

  • :debug (true, false)

    true enabled debug logging (defaults to false)

  • :logger (Logger)

    a custom logger instance (defaults to STDOUT)

See Also:



91
92
93
94
95
# File 'lib/reps_client/client.rb', line 91

def initialize(options={})
  self.debug = nil
  self.logger = nil
  options.each { |k,v| self.send("#{k}=", v) if self.respond_to?("#{k}=") }
end

Instance Method Details

#debug=(val) ⇒ Object



32
33
34
35
# File 'lib/reps_client/client.rb', line 32

def debug=(val)
  @debug = val
  Savon.log = self.debug?
end

#debug?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/reps_client/client.rb', line 37

def debug?
  self.debug.to_s == 'true'
end

#logger=(val) ⇒ Object



41
42
43
44
# File 'lib/reps_client/client.rb', line 41

def logger=(val)
  @logger = val
  Savon.logger = self.logger
end

#soap_clientSavon::Client

The raw SOAP client to directly execute requests against the REPS service. Preconfigures all service-wide endpoints, namespace URLs, credentials, etc. This method is provided as a convenience to developers; it should rarely be used directly.

Returns:

  • (Savon::Client)

    the SOAP client



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/reps_client/client.rb', line 103

def soap_client
  Savon::Client.new do
    wsdl.endpoint = self.endpoint.to_s
    wsdl.namespace = self.namespace.to_s
    wsse.credentials self.username, self.password, false

    wsse.timestamp = true

    # We have to override some of the timestamps to force UTC
    # (the reps service cacks on any other timezone)
    wsse.created_at = Time.now.utc
    class << wsse
      define_method(:timestamp, lambda { @timestamp ||= Time.now.utc.xs_datetime })
    end
  end
end