Class: ApiBucket::Itunes::Client

Inherits:
Object
  • Object
show all
Includes:
Http
Defined in:
lib/api_bucket/itunes/client.rb,
lib/api_bucket/itunes/client/http.rb

Defined Under Namespace

Modules: Http

Constant Summary collapse

REQUEST_URL =
'http://itunes.apple.com/search'
REQUEST_URL_ITEM =
'http://itunes.apple.com/lookup'

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Base::Client::Http

#prepare_query, #send_request

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.



27
28
29
30
31
# File 'lib/api_bucket/itunes/client.rb', line 27

def initialize(options={})
  options = ApiBucket::Itunes.options.merge(options)
  self.country = options[:country] || 'JP'
  self.limit   = options[:limit]   || 20
end

Instance Attribute Details

#countryObject

Returns the value of attribute country.



7
8
9
# File 'lib/api_bucket/itunes/client.rb', line 7

def country
  @country
end

#limitObject

Returns the value of attribute limit.



7
8
9
# File 'lib/api_bucket/itunes/client.rb', line 7

def limit
  @limit
end

Instance Method Details

#categoriesObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/api_bucket/itunes/client.rb', line 12

def categories
  {
    all:        'All',
    movie:      'Movie',
    podcast:    'Podcast',
    music:      'Music',
    musicVideo: 'MusicVideo',
    audiobook:  'Audiobook',
    shortFilm:  'ShortFilm',
    tvShow:     'TvShow',
    software:   'Software',
    ebook:      'Ebook',
  }
end

#lookup(id, params = {}) ⇒ Object

lookup



51
52
53
54
55
56
57
58
59
# File 'lib/api_bucket/itunes/client.rb', line 51

def lookup(id, params={})
  options = {
    country: self.country,
    id:      id,
  }
  options.merge!(params)

  ApiBucket::Itunes::Response.new(send_request(options, REQUEST_URL_ITEM))
end

#search(keywords, params = {}) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/api_bucket/itunes/client.rb', line 33

def search(keywords, params={})
  options = {
    limit:   self.limit,
    country: self.country,
    media:   params[:search_index],
    term:    keywords,
  }
  options.merge!(params)

  # delete no needed keys
  options.delete(:keywords)
  options.delete(:search_index)
  options[:media] = 'all' if options[:media].nil?

  ApiBucket::Itunes::Response.new(send_request(options, REQUEST_URL))
end