Module: Ebay::Requestable

Included in:
Browse, Finding, Merchandising, Oauth::ClientCredentialsGrant, Shopping
Defined in:
lib/ebay/requestable.rb

Overview

Adds an HTTP client and ability to switch to the eBay Sandbox environment

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#endpointString (readonly)

Returns:

  • (String)


41
42
43
# File 'lib/ebay/requestable.rb', line 41

def endpoint
  @endpoint ||= self.class.endpoint
end

#headersHash

Returns:

  • (Hash)


23
24
25
# File 'lib/ebay/requestable.rb', line 23

def headers
  @headers
end

#httpHTTP::Client

Returns:

  • (HTTP::Client)


35
36
37
# File 'lib/ebay/requestable.rb', line 35

def http
  @http ||= HTTP::Client.new
end

Instance Method Details

#market_id=(market_id) ⇒ Object

Sets the eBay Market

Parameters:

  • (String)


28
29
30
31
# File 'lib/ebay/requestable.rb', line 28

def market_id=(market_id)
  @headers ||= {}
  @headers['X-EBAY-SOA-GLOBAL-ID'] = market_id
end

#persistent(timeout: 5) ⇒ self

Flags request as persistent

Parameters:

  • timeout (Integer) (defaults to: 5)

Returns:

  • (self)


57
58
59
60
# File 'lib/ebay/requestable.rb', line 57

def persistent(timeout: 5)
  self.http = http.persistent(endpoint, timeout: timeout)
  self
end

#sandboxself

Switches to the eBay Sandbox environment

Returns:

  • (self)


48
49
50
51
# File 'lib/ebay/requestable.rb', line 48

def sandbox
  @endpoint = endpoint.sub('ebay', 'sandbox.ebay')
  self
end

#use(*features) ⇒ self

Turns on HTTP features

Parameters:

  • features

Returns:

  • (self)


74
75
76
77
78
79
# File 'lib/ebay/requestable.rb', line 74

%i[timeout via through use].each do |method_name|
  define_method(method_name) do |*args, &block|
    self.http = http.send(method_name, *args, &block)
    self
  end
end

#via(*proxy) ⇒ self

Makes a request through an HTTP proxy

Parameters:

  • proxy (Array)

Returns:

  • (self)

Raises:

  • (HTTP::Request::Error)

    if HTTP proxy is invalid



74
75
76
77
78
79
# File 'lib/ebay/requestable.rb', line 74

%i[timeout via through use].each do |method_name|
  define_method(method_name) do |*args, &block|
    self.http = http.send(method_name, *args, &block)
    self
  end
end