Class: EbayTrader::SessionID

Inherits:
Request
  • Object
show all
Defined in:
lib/ebay_trader/session_id.rb

Overview

Request a session ID from the eBay API.

Constant Summary collapse

CALL_NAME =
'GetSessionID'

Constants inherited from Request

Request::XMLNS

Instance Attribute Summary collapse

Attributes inherited from Request

#auth_token, #call_name, #ebay_site_id, #http_response_code, #http_timeout, #known_arrays, #message_id, #response_hash, #response_time, #skip_type_casting, #xml_request, #xml_response, #xml_tab_width

Instance Method Summary collapse

Methods inherited from Request

#deep_find, #errors, #errors_and_warnings, #failure?, #has_errors?, #has_errors_or_warnings?, #has_warnings?, #partial_failure?, #success?, #timestamp, #to_json_s, #to_s, #warnings

Constructor Details

#initialize(args = {}) ⇒ SessionID

Construct a GetSessionID eBay API call.

Parameters:

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

    a hash of optional arguments.

Options Hash (args):



29
30
31
32
33
34
35
# 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

Instance Attribute Details

#ru_nameString (readonly)

The application RuName defined in Configuration#ru_name, unless over-ridden in #initialize args.

Returns:

  • (String)

    the RuName for this call.

See Also:



22
23
24
# File 'lib/ebay_trader/session_id.rb', line 22

def ru_name
  @ru_name
end

Instance Method Details

#idString

Get the session ID returned by the API call.

Returns:

  • (String)

    the session ID.



40
41
42
# File 'lib/ebay_trader/session_id.rb', line 40

def id
  response_hash[:session_id]
end

#sign_in_url(ruparams = {}) ⇒ String

Get the URL through which a user must sign in using this session ID.

Parameters:

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

    eBay appends this data to the AcceptURL and RejectURL. In a typical rails app this might include the user’s model primary key.

Returns:

  • (String)

    the sign-in URL.



49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/ebay_trader/session_id.rb', line 49

def (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