Class: EbayClient::Api

Inherits:
ActiveSupport::ProxyObject
  • Object
show all
Defined in:
lib/ebay_client/api.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(configuration) ⇒ Api

Returns a new instance of Api.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/ebay_client/api.rb', line 8

def initialize(configuration)
  @configuration = configuration
  @endpoint = ::EbayClient::Endpoint.new configuration
  @namespace = :urn
  @header = ::EbayClient::Header.new configuration, namespace
  @logger = (defined?(Rails) && Rails.respond_to?(:logger) ? Rails.logger : ::Logger.new(::STDOUT))
  @client = ::Savon.client(
    :wsdl => configuration.wsdl_file,
    :read_timeout => configuration.http_read_timeout,
    :namespaces => {'xmlns:urn' => 'urn:ebay:apis:eBLBaseComponents'},
    :convert_request_keys_to => :camelcase,
    :log => true,
    :logger => @logger,
    :log_level => configuration.savon_log_level,
  )
  @calls = 0

  create_methods if configuration.preload?
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object (protected)



76
77
78
79
80
81
82
# File 'lib/ebay_client/api.rb', line 76

def method_missing(name, *args, &block)
  if name.to_s[-1, 1] == '!'
    dispatch! name[0..-2], args.first
  else
    dispatch name, args.first
  end
end

Instance Attribute Details

#callsObject (readonly)

Returns the value of attribute calls.



6
7
8
# File 'lib/ebay_client/api.rb', line 6

def calls
  @calls
end

#clientObject (readonly)

Returns the value of attribute client.



6
7
8
# File 'lib/ebay_client/api.rb', line 6

def client
  @client
end

#configurationObject (readonly)

Returns the value of attribute configuration.



6
7
8
# File 'lib/ebay_client/api.rb', line 6

def configuration
  @configuration
end

#endpointObject (readonly)

Returns the value of attribute endpoint.



6
7
8
# File 'lib/ebay_client/api.rb', line 6

def endpoint
  @endpoint
end

#headerObject (readonly)

Returns the value of attribute header.



6
7
8
# File 'lib/ebay_client/api.rb', line 6

def header
  @header
end

#namespaceObject (readonly)

Returns the value of attribute namespace.



6
7
8
# File 'lib/ebay_client/api.rb', line 6

def namespace
  @namespace
end

Instance Method Details

#dispatch(name, body, fail_on_error = false) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/ebay_client/api.rb', line 28

def dispatch(name, body, fail_on_error = false)
  request = ::EbayClient::Request.new self, name, body
  response = nil

  @calls += 1
  begin
    response = request.execute
    response.raise_failure if fail_on_error && response.failure?
  rescue ::EbayClient::Response::Exception => e
    if e.code == '218050'
      @configuration.next_key!
      response = request.execute
    else
      @logger.error e.to_s unless @logger.nil? || !@logger.respond_to?(:error)
      raise e
    end
  end
  response
end

#dispatch!(name, body) ⇒ Object



48
49
50
# File 'lib/ebay_client/api.rb', line 48

def dispatch!(name, body)
  dispatch(name, body, true).payload
end

#inspectObject Also known as: to_s



52
53
54
# File 'lib/ebay_client/api.rb', line 52

def inspect
  "<EbayClient::Api>"
end