class EbayTrader::SessionID

Request a session ID from the eBay API.

@see developer.ebay.com/DevZone/XML/docs/Reference/eBay/GetSessionID.html @see developer.ebay.com/DevZone/XML/docs/HowTo/Tokens/GettingTokens.html @see developer.ebay.com/DevZone/guides/ebayfeatures/Basics/Tokens-MultipleUsers.html

Constants

CALL_NAME

Attributes

ru_name[R]

The application RuName defined in {Configuration#ru_name}, unless over-ridden in {#initialize} args. @return [String] the RuName for this call. @see developer.ebay.com/DevZone/account/appsettings/Consent/

Public Class Methods

new(args = {}) click to toggle source

Construct a GetSessionID eBay API call. @param [Hash] args a hash of optional arguments. @option args [String] :ru_name Override the default RuName,

which should be defined in {Configuration#ru_name}.
Calls superclass method EbayTrader::Request::new
# File lib/ebay_trader/session_id.rb, line 29
def initialize(args = {})
  @ru_name = (args[:ru_name] || EbayTrader.configuration.ru_name).freeze

  super(CALL_NAME, args) do
    RuName ru_name
  end
end

Public Instance Methods

id() click to toggle source

Get the session ID returned by the API call. @return [String] the session ID.

# File lib/ebay_trader/session_id.rb, line 40
def id
  response_hash[:session_id]
end
sign_in_url(ruparams = {}) click to toggle source

Get the URL through which a user must sign in using this session ID. @param [Hash] ruparams eBay appends this data to the AcceptURL and RejectURL.

In a typical rails app this might include the user's model primary key.

@return [String] the sign-in URL.

# File lib/ebay_trader/session_id.rb, line 49
def sign_in_url(ruparams = {})
  url = []
  url << EbayTrader.configuration.production? ? 'https://signin.ebay.com' : 'https://signin.sandbox.ebay.com'
  url << '/ws/eBayISAPI.dll?SignIn'
  url << "&runame=#{url_encode ru_name}"
  url << "&SessID=#{url_encode id}"
  if ruparams && ruparams.is_a?(Hash) && !ruparams.empty?
    params = []
    ruparams.each_pair { |key, value| params << "#{key}=#{value}" }
    url << "&ruparams=#{url_encode(params.join('&'))}"
  end
  url.join
end

Private Instance Methods

url_decode(string) click to toggle source
# File lib/ebay_trader/session_id.rb, line 70
def url_decode(string)
  CGI.unescape string
end
url_encode(string) click to toggle source
# File lib/ebay_trader/session_id.rb, line 66
def url_encode(string)
  CGI.escape string
end