Class: Cinch::Plugins::Spotify
- Inherits:
-
Object
- Object
- Cinch::Plugins::Spotify
- Includes:
- Cinch::Plugin
- Defined in:
- lib/cinch/plugins/spotify.rb
Instance Method Summary collapse
- #_album(uri) ⇒ Object
- #_artist(uri) ⇒ Object
- #_lookup(spotify_uri) ⇒ Object
- #_track(uri) ⇒ Object
- #execute(m, uri, type) ⇒ Object
- #match_url(m, uri, protocol, sub, type) ⇒ Object
Instance Method Details
#_album(uri) ⇒ Object
39 40 41 42 43 44 |
# File 'lib/cinch/plugins/spotify.rb', line 39 def _album uri json = _lookup uri artist = json['album']['artist'] album = json['album']['name'] "Album: #{album} by #{artist}" end |
#_artist(uri) ⇒ Object
33 34 35 36 37 |
# File 'lib/cinch/plugins/spotify.rb', line 33 def _artist uri json = _lookup uri name = json['artist']['name'] "Artist: #{name}" end |
#_lookup(spotify_uri) ⇒ Object
54 55 56 57 |
# File 'lib/cinch/plugins/spotify.rb', line 54 def _lookup spotify_uri content = Curl::Easy.perform("http://ws.spotify.com/lookup/1/.json?uri=#{spotify_uri}").body_str JSON.parse(content) end |
#_track(uri) ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/cinch/plugins/spotify.rb', line 46 def _track uri json = _lookup uri artist = json['track']['artists'].first['name'] album = json['track']['album']['name'] track = json['track']['name'] "Track: #{track} by #{artist} (#{album})" end |
#execute(m, uri, type) ⇒ Object
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/cinch/plugins/spotify.rb', line 22 def execute m, uri, type msg = case type when /artist/ then _artist uri when /album/ then _album uri when /track/ then _track uri else 'something went wrong' end m.reply("Spotify: #{msg}") end |
#match_url(m, uri, protocol, sub, type) ⇒ Object
18 19 20 |
# File 'lib/cinch/plugins/spotify.rb', line 18 def match_url m, uri, protocol, sub, type execute m, uri, type end |