Class: HTTPItunesGetRequest

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeHTTPItunesGetRequest

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_urlObject (readonly)

Returns the value of attribute base_url.



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

def base_url
  @base_url
end

#countryObject

Returns the value of attribute country.



10
11
12
# File 'lib/HTTPItunesGetRequest.rb', line 10

def country
  @country
end

#entityObject

Returns the value of attribute entity.



11
12
13
# File 'lib/HTTPItunesGetRequest.rb', line 11

def entity
  @entity
end

#item_idObject

Returns the value of attribute item_id.



9
10
11
# File 'lib/HTTPItunesGetRequest.rb', line 9

def item_id
  @item_id
end

#limitObject

Returns the value of attribute limit.



13
14
15
# File 'lib/HTTPItunesGetRequest.rb', line 13

def limit
  @limit
end

#nameObject

Returns the value of attribute name.



12
13
14
# File 'lib/HTTPItunesGetRequest.rb', line 12

def name
  @name
end

Instance Method Details

#getItemInfosObject



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