Class: Ebayer::OpenEbay
- Inherits:
-
Object
- Object
- Ebayer::OpenEbay
- 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
-
#app_id ⇒ Object
Returns the value of attribute app_id.
-
#callname ⇒ Object
Returns the value of attribute callname.
-
#open_url ⇒ Object
Returns the value of attribute open_url.
-
#response ⇒ Object
Returns the value of attribute response.
-
#response_encoding ⇒ Object
Returns the value of attribute response_encoding.
-
#user_id ⇒ Object
Returns the value of attribute user_id.
Instance Method Summary collapse
-
#initialize(callname, app_id, user_id) ⇒ OpenEbay
constructor
A new instance of OpenEbay.
-
#request_ebay ⇒ Object
Placing request to ebay via httparty.
-
#response_parser(response_content) ⇒ Object
response parsing from string to JSON and mashing it into hash format of access.
-
#url_definer ⇒ Object
Defineing the url.
-
#user_information ⇒ Object
For all those who require just the information and do no require whole response.
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_id ⇒ Object
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 |
#callname ⇒ Object
Returns the value of attribute callname.
8 9 10 |
# File 'lib/ebayer/get_user_profile.rb', line 8 def callname @callname end |
#open_url ⇒ Object
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 |
#response ⇒ Object
Returns the value of attribute response.
8 9 10 |
# File 'lib/ebayer/get_user_profile.rb', line 8 def response @response end |
#response_encoding ⇒ Object
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_id ⇒ Object
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_ebay ⇒ Object
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_definer ⇒ Object
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_information ⇒ Object
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 |