class EbayClient::Api

Attributes

calls[R]
client[R]
configuration[R]
endpoint[R]
header[R]
namespace[R]

Public Class Methods

new(configuration) click to toggle source
# 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

Public Instance Methods

dispatch(name, body, fail_on_error = false) click to toggle source
# 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) click to toggle source
# File lib/ebay_client/api.rb, line 48
def dispatch!(name, body)
  dispatch(name, body, true).payload
end
inspect() click to toggle source
# File lib/ebay_client/api.rb, line 52
def inspect
  "<EbayClient::Api>"
end
Also aliased as: to_s
to_s()
Alias for: inspect

Protected Instance Methods

create_methods() click to toggle source
# File lib/ebay_client/api.rb, line 58
def create_methods
  api_methods = ::Module.new

  client.operations.each do |action|
    name = action.to_s.gsub(/e_bay_/, '_ebay_')

    api_methods.send :define_method, name do |*args|
      dispatch name, args.first
    end

    api_methods.send :define_method, name + '!' do |*args|
      dispatch! name, args.first
    end
  end

  api_methods.send :extend_object, self
end
method_missing(name, *args, &block) click to toggle source
# 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