Class: Lastgroov
- Inherits:
-
Object
- Object
- Lastgroov
- Defined in:
- lib/lastgroov.rb
Instance Attribute Summary collapse
-
#auth ⇒ Object
Returns the value of attribute auth.
-
#feed ⇒ Object
Returns the value of attribute feed.
-
#groov_user ⇒ Object
Returns the value of attribute groov_user.
-
#tracks ⇒ Object
Returns the value of attribute tracks.
Instance Method Summary collapse
- #authenticate ⇒ Object
-
#initialize(groov_user, user, password, tracks) ⇒ Lastgroov
constructor
A new instance of Lastgroov.
- #parse_rss ⇒ Object
- #scrobble! ⇒ Object
Constructor Details
#initialize(groov_user, user, password, tracks) ⇒ Lastgroov
Returns a new instance of Lastgroov.
9 10 11 12 13 14 |
# File 'lib/lastgroov.rb', line 9 def initialize(groov_user, user, password, tracks) @tracks = tracks - 1 @groov_user = groov_user @auth = Scrobbler::SimpleAuth.new(:user => user, :password => password) end |
Instance Attribute Details
#auth ⇒ Object
Returns the value of attribute auth.
7 8 9 |
# File 'lib/lastgroov.rb', line 7 def auth @auth end |
#feed ⇒ Object
Returns the value of attribute feed.
7 8 9 |
# File 'lib/lastgroov.rb', line 7 def feed @feed end |
#groov_user ⇒ Object
Returns the value of attribute groov_user.
7 8 9 |
# File 'lib/lastgroov.rb', line 7 def groov_user @groov_user end |
#tracks ⇒ Object
Returns the value of attribute tracks.
7 8 9 |
# File 'lib/lastgroov.rb', line 7 def tracks @tracks end |
Instance Method Details
#authenticate ⇒ Object
23 24 25 |
# File 'lib/lastgroov.rb', line 23 def authenticate @auth.handshake! end |
#parse_rss ⇒ Object
16 17 18 19 20 21 |
# File 'lib/lastgroov.rb', line 16 def parse_rss url = "http://api.grooveshark.com/feeds/1.0/users/" url << @groov_user url << "/recent_listens.rss" @feed = Feedzirra::Feed.fetch_and_parse(url) end |
#scrobble! ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/lastgroov.rb', line 27 def scrobble! parse_rss authenticate 0.upto(@tracks) do |n| track, artist = @feed.entries[n].title.split(" - ") time = @feed.entries[n].published scrobbles = Scrobbler::Scrobble.new( :session_id => @auth.session_id, :submission_url => @auth.submission_url, :artist => artist, :track => track, :album => "Unknown", :time => time, :length=> 300, :track_number => n + 1 ) scrobbles.submit! puts "#{@feed.entries[n].title}" puts "Scrobbler Submission Status: #{scrobbles.status}" end end |