Class: Bandcamp::Getter

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

Instance Method Summary collapse

Constructor Details

#initialize(request) ⇒ Getter

Returns a new instance of Getter.



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

def initialize request
  @request = request
end

Instance Method Details

#album(album_id) ⇒ Object



28
29
30
31
# File 'lib/bandcamp/getter.rb', line 28

def album album_id
  response = @request.album album_id
  response.nil? ? nil : Album.new(response)
end

#band(name) ⇒ Object



42
43
44
45
# File 'lib/bandcamp/getter.rb', line 42

def band name
  response = @request.band name
  response.nil? ? nil : Band.new(response)
end

#search(band_name) ⇒ Object



33
34
35
36
37
38
39
40
# File 'lib/bandcamp/getter.rb', line 33

def search band_name
  response = @request.search band_name
  if response.nil?
    []
  else
    response.collect{|band_json| Band.new band_json}
  end
end

#track(track_id) ⇒ Object



13
14
15
16
# File 'lib/bandcamp/getter.rb', line 13

def track track_id
  response = @request.track track_id
  response.nil? ? nil : Track.new(response)
end

#tracks(*tracks) ⇒ Object



18
19
20
21
22
23
24
25
26
# File 'lib/bandcamp/getter.rb', line 18

def tracks *tracks
  track_list = tracks.join(',')
  response = @request.track track_list
  if response.nil?
    []
  else
    response.collect{|key,val| Track.new val}
  end
end

#url(address) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/bandcamp/getter.rb', line 47

def url address
  response = @request.url address
  return nil if response.nil?
  case
  when response.has_key?("album_id")
    album(response["album_id"])
  when response.has_key?("track_id")
    track(response["track_id"])
  when (response.keys.length == 1) && response.has_key?("band_id")
    band(response["band_id"])
  end
end