Class: SpotTracks::Feed

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

Constant Summary collapse

HOST =
'http://ws.audioscrobbler.com'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(username) ⇒ Feed

Returns a new instance of Feed.



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

def initialize(username)
  @username = username
end

Instance Attribute Details

#usernameObject (readonly)

Returns the value of attribute username.



5
6
7
# File 'lib/spot_tracks/feed.rb', line 5

def username
  @username
end

Instance Method Details

#titleObject



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

def title
  client.title
end

#to_jsonObject



27
28
29
30
31
32
33
# File 'lib/spot_tracks/feed.rb', line 27

def to_json
  {
    title: title,
    url: url,
    tracks: tracks.map(&:to_h)
  }.to_json
end

#tracksObject



21
22
23
24
25
# File 'lib/spot_tracks/feed.rb', line 21

def tracks
  client.entries.map do |entry|
    SpotTracks::Track.search entry.title
  end.compact
end

#urlObject



17
18
19
# File 'lib/spot_tracks/feed.rb', line 17

def url
  client.url
end