Class: Ebayer::OpenEbay

Inherits:
Object
  • Object
show all
Defined in:
lib/ebayer/get_user_profile.rb

Constant Summary collapse

EBAYOPENURL =
"http://open.api.sandbox.ebay.com/shopping"
RESPONSEENCODING =
"JSON"
APIVERSION =
"721"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(callname, app_id, user_id) ⇒ OpenEbay

Returns a new instance of OpenEbay.



10
11
12
13
14
# File 'lib/ebayer/get_user_profile.rb', line 10

def initialize( callname, app_id, user_id)
  @callname = callname
  @app_id = app_id
  @user_id = user_id
end

Instance Attribute Details

#app_idObject

Returns the value of attribute app_id.



8
9
10
# File 'lib/ebayer/get_user_profile.rb', line 8

def app_id
  @app_id
end

#callnameObject

Returns the value of attribute callname.



8
9
10
# File 'lib/ebayer/get_user_profile.rb', line 8

def callname
  @callname
end

#open_urlObject

Returns the value of attribute open_url.



8
9
10
# File 'lib/ebayer/get_user_profile.rb', line 8

def open_url
  @open_url
end

#responseObject

Returns the value of attribute response.



8
9
10
# File 'lib/ebayer/get_user_profile.rb', line 8

def response
  @response
end

#response_encodingObject

Returns the value of attribute response_encoding.



8
9
10
# File 'lib/ebayer/get_user_profile.rb', line 8

def response_encoding
  @response_encoding
end

#user_idObject

Returns the value of attribute user_id.



8
9
10
# File 'lib/ebayer/get_user_profile.rb', line 8

def user_id
  @user_id
end

Instance Method Details

#request_ebayObject

Placing request to ebay via httparty.



29
30
31
32
33
34
35
36
37
38
# File 'lib/ebayer/get_user_profile.rb', line 29

def request_ebay
  requested_url = self.url_definer
  response = nil 
  begin
  new_response = HTTParty.get(requested_url)
  rescue Timeout::Error
    raise TimeoutError, "Ebay is currently unavailbale. Please try again later"
  end
  @response = self.response_parser(new_response.body)
end

#response_parser(response_content) ⇒ Object

response parsing from string to JSON and mashing it into hash format of access. The rails way!



41
42
43
# File 'lib/ebayer/get_user_profile.rb', line 41

def response_parser(response_content)
  Hashie::Mash.new(JSON(response_content))
end

#url_definerObject

Defineing the url. URL should have all the required elements like following: callname - Name of the method being called

ResponseEncoding - Response format. XML, JSON, Text formats are allowed. For this version lets keep JSON AppId - Appid is generated on ebay. While in production ensure you are using production keys and not sandbox ApiVersion - Version of api you are placing the call.



22
23
24
25
# File 'lib/ebayer/get_user_profile.rb', line 22

def url_definer
  url = EBAYOPENURL+"?callname=#{@callname}&responseencoding=#{RESPONSEENCODING}&appid=#{@app_id}&siteid=0&UserID=#{@user_id}&IncludeSelector=Details&version=#{APIVERSION}"
  return url
end

#user_informationObject

For all those who require just the information and do no require whole response. Just a handy method.



46
47
48
# File 'lib/ebayer/get_user_profile.rb', line 46

def user_information
  self.request_ebay
end