Class: HTTPItunesGetRequest
- Inherits:
-
Object
- Object
- HTTPItunesGetRequest
- Defined in:
- lib/HTTPItunesGetRequest.rb
Instance Attribute Summary collapse
-
#base_url ⇒ Object
readonly
Returns the value of attribute base_url.
-
#country ⇒ Object
Returns the value of attribute country.
-
#entity ⇒ Object
Returns the value of attribute entity.
-
#item_id ⇒ Object
Returns the value of attribute item_id.
-
#limit ⇒ Object
Returns the value of attribute limit.
-
#name ⇒ Object
Returns the value of attribute name.
Instance Method Summary collapse
- #getItemInfos ⇒ Object
-
#initialize ⇒ HTTPItunesGetRequest
constructor
A new instance of HTTPItunesGetRequest.
Constructor Details
#initialize ⇒ HTTPItunesGetRequest
Returns a new instance of HTTPItunesGetRequest.
15 16 17 18 19 |
# File 'lib/HTTPItunesGetRequest.rb', line 15 def initialize @base_url="https://itunes.apple.com/" @method= "lookup?" @limit="200" end |
Instance Attribute Details
#base_url ⇒ Object (readonly)
Returns the value of attribute base_url.
8 9 10 |
# File 'lib/HTTPItunesGetRequest.rb', line 8 def base_url @base_url end |
#country ⇒ Object
Returns the value of attribute country.
10 11 12 |
# File 'lib/HTTPItunesGetRequest.rb', line 10 def country @country end |
#entity ⇒ Object
Returns the value of attribute entity.
11 12 13 |
# File 'lib/HTTPItunesGetRequest.rb', line 11 def entity @entity end |
#item_id ⇒ Object
Returns the value of attribute item_id.
9 10 11 |
# File 'lib/HTTPItunesGetRequest.rb', line 9 def item_id @item_id end |
#limit ⇒ Object
Returns the value of attribute limit.
13 14 15 |
# File 'lib/HTTPItunesGetRequest.rb', line 13 def limit @limit end |
#name ⇒ Object
Returns the value of attribute name.
12 13 14 |
# File 'lib/HTTPItunesGetRequest.rb', line 12 def name @name end |
Instance Method Details
#getItemInfos ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/HTTPItunesGetRequest.rb', line 21 def getItemInfos begin raise "Itemid and name is empty" if @item_id.empty? && @name.empty? @method = name.length ==0 ? "lookup?" : "search?" full_url=@base_url + @method + (name.length ==0 ? "id=#{@item_id}" : "term=#{@name}") + "&country=#{@country}" + "&entity=#{@entity}" + "&limit=#{@limit}"; puts full_url uri=URI(full_url); puts "start request ....." res=Net::HTTP.get_response(uri) response_body=res.body json_body = JSON.parse response_body; puts "request OK !" if res.code == "200" return json_body rescue Exception => e puts e end end |