rockstar 0.4.2 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/VERSION +1 -1
- data/examples/scrobble.rb +18 -28
- data/lib/rockstar.rb +6 -3
- data/lib/rockstar/playing.rb +2 -1
- data/lib/rockstar/track.rb +132 -2
- data/rockstar.gemspec +3 -2
- data/test/fixtures/xml/track/updatenowplaying_artist_Carrie_Underwood_sk_tag_track_Before_He_Cheats.xml +10 -0
- data/test/unit/test_track.rb +16 -0
- data/test/unit/test_user.rb +1 -1
- metadata +5 -9
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.5.0
|
data/examples/scrobble.rb
CHANGED
@@ -19,37 +19,27 @@ gets
|
|
19
19
|
|
20
20
|
session = a.session(token)
|
21
21
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
:submission_url => auth.submission_url,
|
32
|
-
:artist => 'Coldplay',
|
33
|
-
:track => 'Viva La Vida',
|
34
|
-
:album => 'Viva La Vida',
|
35
|
-
:time => Time.new,
|
36
|
-
:length => 244,
|
37
|
-
:track_number => 7)
|
38
|
-
scrobble.submit!
|
39
|
-
puts "Rockstar Submission Status: #{scrobble.status}"
|
22
|
+
Rockstar::Track.scrobble(
|
23
|
+
:session_key => session.key,
|
24
|
+
:track => "Viva La Vida",
|
25
|
+
:artist => "Coldplay",
|
26
|
+
:album => "Viva La Vida",
|
27
|
+
:time => Time.new,
|
28
|
+
:length => 244,
|
29
|
+
:track_number => 7
|
30
|
+
)
|
40
31
|
|
41
32
|
# Love the Song :
|
42
33
|
l_status = Rockstar::Track.new('Coldplay', 'Viva La Vida').love(session.key)
|
43
34
|
|
44
35
|
puts "Love track status : #{l_status}"
|
45
36
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
puts "Playing Submission Status: #{playing.status}"
|
37
|
+
Rockstar::Track.updateNowPlaying(
|
38
|
+
:session_key => session.key,
|
39
|
+
:track => "Viva La Vida",
|
40
|
+
:artist => "Coldplay",
|
41
|
+
:album => "Viva La Vida",
|
42
|
+
:time => Time.new,
|
43
|
+
:length => 244,
|
44
|
+
:track_number => 7
|
45
|
+
)
|
data/lib/rockstar.rb
CHANGED
@@ -1,10 +1,13 @@
|
|
1
|
-
%w{cgi rubygems hpricot active_support}.each { |x| require x }
|
2
|
-
|
3
1
|
$: << File.expand_path(File.dirname(__FILE__))
|
4
2
|
|
5
3
|
require 'rubygems'
|
6
|
-
require '
|
4
|
+
require 'cgi'
|
5
|
+
require 'hpricot'
|
6
|
+
require 'active_support'
|
7
|
+
require 'active_support/core_ext/object/blank'
|
8
|
+
require 'active_support/core_ext/string/inflections'
|
7
9
|
require 'time'
|
10
|
+
require 'yaml'
|
8
11
|
|
9
12
|
require 'rockstar/base'
|
10
13
|
require 'rockstar/version'
|
data/lib/rockstar/playing.rb
CHANGED
data/lib/rockstar/track.rb
CHANGED
@@ -33,6 +33,12 @@
|
|
33
33
|
# (2449) mlmjcace
|
34
34
|
# (2302) tiNEey
|
35
35
|
# (2169) ajsbabiegirl
|
36
|
+
|
37
|
+
class BadSessionError < StandardError; end
|
38
|
+
class UnavailableError < StandardError; end
|
39
|
+
class RequestFailedError < StandardError; end
|
40
|
+
|
41
|
+
|
36
42
|
module Rockstar
|
37
43
|
class Track < Base
|
38
44
|
attr_accessor :artist, :artist_mbid, :name, :mbid, :playcount, :rank, :url
|
@@ -77,6 +83,102 @@ module Rockstar
|
|
77
83
|
t.image = t.images['medium']
|
78
84
|
t
|
79
85
|
end
|
86
|
+
|
87
|
+
def love(artist, track, session_key)
|
88
|
+
doc = Hpricot::XML(Track.connection.post("track.love", true, {:track => track, :artist => artist, :sk => session_key}))
|
89
|
+
doc.at("lfm")["status"]
|
90
|
+
end
|
91
|
+
|
92
|
+
# Scrobble a song
|
93
|
+
#
|
94
|
+
# Possible parameters:
|
95
|
+
# session_key (required) : the session key you got during authentification
|
96
|
+
# track (required) : name of the track
|
97
|
+
# artist (required) : name of the artist of the track
|
98
|
+
# time (required) : a time object set to the time the track started playing
|
99
|
+
# album : Name of the album
|
100
|
+
# albumArtist : Name of the album artist if artist differs
|
101
|
+
# trackNumber : Number of the track
|
102
|
+
# mbid : MusicBrainz ID of the track
|
103
|
+
# duration : track length
|
104
|
+
def scrobble(params = {})
|
105
|
+
if params[:session_key].blank? || params[:track].blank? || params[:time].nil? || params[:artist].blank?
|
106
|
+
raise ArgumentError, "Missing required argument"
|
107
|
+
end
|
108
|
+
|
109
|
+
query = {
|
110
|
+
:sk => params[:session_key],
|
111
|
+
"track[0]" => params[:track],
|
112
|
+
"timestamp[0]"=> params[:time].utc.to_i,
|
113
|
+
"artist[0]" => params[:artist]
|
114
|
+
}
|
115
|
+
|
116
|
+
query["album[0]"] = params[:album] if !params[:album].blank?
|
117
|
+
query["albumArtist[0]"] = params[:albumArtist] if !params[:albumArtist].blank?
|
118
|
+
query["trackNumber[0]"] = params[:trackNumber] if !params[:trackNumber].blank?
|
119
|
+
query["mbid[0]"] = params[:mbid] if !params[:mbid].blank?
|
120
|
+
query["duration[0]"] = params[:duration] if !params[:duration].blank?
|
121
|
+
|
122
|
+
doc = Hpricot::XML(Track.connection.post("track.scrobble", true, query))
|
123
|
+
|
124
|
+
if doc.at("lfm")["status"] == "failed"
|
125
|
+
case doc.at("lfm").at("error")["code"].to_i
|
126
|
+
when 9
|
127
|
+
raise BadSessionError, doc.at("lfm").at("error").inner_html
|
128
|
+
when 11, 16
|
129
|
+
raise UnavailableError, doc.at("lfm").at("error").inner_html
|
130
|
+
else
|
131
|
+
raise RequestFailedError, doc.at("lfm").at("error").inner_html
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
doc.at("lfm")["status"]
|
136
|
+
end
|
137
|
+
|
138
|
+
# Update the current playing song
|
139
|
+
#
|
140
|
+
# Possible parameters:
|
141
|
+
# session_key (required) : the session key you got during authentification
|
142
|
+
# track (required) : name of the track
|
143
|
+
# artist (required) : name of the artist of the track
|
144
|
+
# album : Name of the album
|
145
|
+
# albumArtist : Name of the album artist if artist differs
|
146
|
+
# trackNumber : Number of the track
|
147
|
+
# mbid : MusicBrainz ID of the track
|
148
|
+
# duration : track length
|
149
|
+
def updateNowPlaying(params = {})
|
150
|
+
if params[:session_key].blank? || params[:track].blank? || params[:artist].blank?
|
151
|
+
raise ArgumentError, "Missing required argument"
|
152
|
+
end
|
153
|
+
|
154
|
+
query = {
|
155
|
+
:sk => params[:session_key],
|
156
|
+
"track" => params[:track],
|
157
|
+
"artist" => params[:artist]
|
158
|
+
}
|
159
|
+
|
160
|
+
query["album"] = params[:album] if !params[:album].blank?
|
161
|
+
query["albumArtist"] = params[:albumArtist] if !params[:albumArtist].blank?
|
162
|
+
query["trackNumber"] = params[:trackNumber] if !params[:trackNumber].blank?
|
163
|
+
query["mbid"] = params[:mbid] if !params[:mbid].blank?
|
164
|
+
query["duration"] = params[:duration] if !params[:duration].blank?
|
165
|
+
|
166
|
+
doc = Hpricot::XML(Track.connection.post("track.updateNowPlaying", true, query))
|
167
|
+
|
168
|
+
if doc.at("lfm")["status"] == "failed"
|
169
|
+
case doc.at("lfm").at("error")["code"].to_i
|
170
|
+
when 9
|
171
|
+
raise BadSessionError, doc.at("lfm").at("error").inner_html
|
172
|
+
when 11, 16
|
173
|
+
raise UnavailableError, doc.at("lfm").at("error").inner_html
|
174
|
+
else
|
175
|
+
raise RequestFailedError, doc.at("lfm").at("error").inner_html
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
doc.at("lfm")["status"]
|
180
|
+
end
|
181
|
+
|
80
182
|
end
|
81
183
|
|
82
184
|
def initialize(artist, name)
|
@@ -96,8 +198,36 @@ module Rockstar
|
|
96
198
|
|
97
199
|
# The session_key is returned by auth.session.key
|
98
200
|
def love(session_key)
|
99
|
-
|
100
|
-
|
201
|
+
Track.love(@artist, @name, session_key)
|
202
|
+
end
|
203
|
+
|
204
|
+
# scrobble this track
|
205
|
+
# time : a time object set to the time the track started playing
|
206
|
+
# session_key: the session key you got during authentification
|
207
|
+
def scrobble(time, session_key)
|
208
|
+
Track.scrobble({
|
209
|
+
:session_key => session_key,
|
210
|
+
:time => time,
|
211
|
+
:track => @name,
|
212
|
+
:artist => @artist,
|
213
|
+
:album => @album,
|
214
|
+
:mbid => @mbid
|
215
|
+
})
|
216
|
+
end
|
217
|
+
|
218
|
+
# inform last.fm that this track is currently playing
|
219
|
+
# time : a time object set to the time the track started playing
|
220
|
+
# session_key: the session key you got during authentification
|
221
|
+
def updateNowPlaying(time, session_key)
|
222
|
+
Track.updateNowPlaying({
|
223
|
+
:session_key => session_key,
|
224
|
+
:time => time,
|
225
|
+
:track => @name,
|
226
|
+
:artist => @artist,
|
227
|
+
:album => @album,
|
228
|
+
:mbid => @mbid
|
229
|
+
})
|
101
230
|
end
|
231
|
+
|
102
232
|
end
|
103
233
|
end
|
data/rockstar.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{rockstar}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.5.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Bodo Tasche"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-11-23}
|
13
13
|
s.description = %q{This gem is an updated version of jnunemakers scrobbler gem. Rockstar uses v2.0 of the last.fm api.}
|
14
14
|
s.email = %q{bodo@bitboxer.de}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -68,6 +68,7 @@ Gem::Specification.new do |s|
|
|
68
68
|
"test/fixtures/xml/track/gettopfans_artist_Carrie_Underwood_track_Before_He_Cheats.xml",
|
69
69
|
"test/fixtures/xml/track/gettoptags_artist_Carrie_Underwood_track_Before_He_Cheats.xml",
|
70
70
|
"test/fixtures/xml/track/love_artist_Carrie_Underwood_sk_tag_track_Before_He_Cheats.xml",
|
71
|
+
"test/fixtures/xml/track/updatenowplaying_artist_Carrie_Underwood_sk_tag_track_Before_He_Cheats.xml",
|
71
72
|
"test/fixtures/xml/user/getevents_sk_token_user_bodot.xml",
|
72
73
|
"test/fixtures/xml/user/getfriends_user_jnunemaker.xml",
|
73
74
|
"test/fixtures/xml/user/getinfo_user_jnunemaker.xml",
|
@@ -0,0 +1,10 @@
|
|
1
|
+
<?xml version='1.0' encoding='utf-8'?>
|
2
|
+
<lfm status="ok">
|
3
|
+
<nowplaying>
|
4
|
+
<track corrected="0">Test Track</track>
|
5
|
+
<artist corrected="0">Test Artist</artist>
|
6
|
+
<album corrected="0"></album>
|
7
|
+
<albumArtist corrected="0"></albumArtist>
|
8
|
+
<ignoredMessage code="0"></ignoredMessage>
|
9
|
+
</nowplaying>
|
10
|
+
</lfm>
|
data/test/unit/test_track.rb
CHANGED
@@ -41,4 +41,20 @@ class TestTrack < Test::Unit::TestCase
|
|
41
41
|
assert_equal('ok', @track.love("tag"))
|
42
42
|
end
|
43
43
|
|
44
|
+
test 'raise missing parameter error' do
|
45
|
+
assert_raises(ArgumentError) { Rockstar::Track.scrobble() }
|
46
|
+
end
|
47
|
+
|
48
|
+
test 'can scrobble tracks' do
|
49
|
+
assert_equal('ok', @track.scrobble(Time.new(2010,10,10,10,10), 'tag'))
|
50
|
+
end
|
51
|
+
|
52
|
+
test 'raise missing parameter error' do
|
53
|
+
assert_raises(ArgumentError) { Rockstar::Track.updateNowPlaying() }
|
54
|
+
end
|
55
|
+
|
56
|
+
test 'can send current playing track' do
|
57
|
+
assert_equal('ok', @track.updateNowPlaying(Time.new(2010,10,10,10,10), 'tag'))
|
58
|
+
end
|
59
|
+
|
44
60
|
end
|
data/test/unit/test_user.rb
CHANGED
@@ -264,7 +264,7 @@ class TestUser < Test::Unit::TestCase
|
|
264
264
|
assert_equal("2raumwohnung", first.headliners.first)
|
265
265
|
assert_equal(Time.local(2010, 8, 20, 17, 50, 1), first.start_date)
|
266
266
|
assert_equal(Time.local(2010, 8, 22, 17, 50, 1), first.end_date)
|
267
|
-
assert_equal(
|
267
|
+
assert_equal(814, first.description.length)
|
268
268
|
assert_equal(200, first.attendance)
|
269
269
|
assert_equal(0, first.reviews)
|
270
270
|
assert_equal("lastfm:event=1575046", first.tag)
|
metadata
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rockstar
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash: 11
|
5
4
|
prerelease: false
|
6
5
|
segments:
|
7
6
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
7
|
+
- 5
|
8
|
+
- 0
|
9
|
+
version: 0.5.0
|
11
10
|
platform: ruby
|
12
11
|
authors:
|
13
12
|
- Bodo Tasche
|
@@ -15,7 +14,7 @@ autorequire:
|
|
15
14
|
bindir: bin
|
16
15
|
cert_chain: []
|
17
16
|
|
18
|
-
date: 2010-
|
17
|
+
date: 2010-11-23 00:00:00 +01:00
|
19
18
|
default_executable:
|
20
19
|
dependencies:
|
21
20
|
- !ruby/object:Gem::Dependency
|
@@ -26,7 +25,6 @@ dependencies:
|
|
26
25
|
requirements:
|
27
26
|
- - ">="
|
28
27
|
- !ruby/object:Gem::Version
|
29
|
-
hash: 163
|
30
28
|
segments:
|
31
29
|
- 0
|
32
30
|
- 4
|
@@ -42,7 +40,6 @@ dependencies:
|
|
42
40
|
requirements:
|
43
41
|
- - ">="
|
44
42
|
- !ruby/object:Gem::Version
|
45
|
-
hash: 3
|
46
43
|
segments:
|
47
44
|
- 1
|
48
45
|
- 4
|
@@ -111,6 +108,7 @@ files:
|
|
111
108
|
- test/fixtures/xml/track/gettopfans_artist_Carrie_Underwood_track_Before_He_Cheats.xml
|
112
109
|
- test/fixtures/xml/track/gettoptags_artist_Carrie_Underwood_track_Before_He_Cheats.xml
|
113
110
|
- test/fixtures/xml/track/love_artist_Carrie_Underwood_sk_tag_track_Before_He_Cheats.xml
|
111
|
+
- test/fixtures/xml/track/updatenowplaying_artist_Carrie_Underwood_sk_tag_track_Before_He_Cheats.xml
|
114
112
|
- test/fixtures/xml/user/getevents_sk_token_user_bodot.xml
|
115
113
|
- test/fixtures/xml/user/getfriends_user_jnunemaker.xml
|
116
114
|
- test/fixtures/xml/user/getinfo_user_jnunemaker.xml
|
@@ -158,7 +156,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
158
156
|
requirements:
|
159
157
|
- - ">="
|
160
158
|
- !ruby/object:Gem::Version
|
161
|
-
hash: 3
|
162
159
|
segments:
|
163
160
|
- 0
|
164
161
|
version: "0"
|
@@ -167,7 +164,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
167
164
|
requirements:
|
168
165
|
- - ">="
|
169
166
|
- !ruby/object:Gem::Version
|
170
|
-
hash: 3
|
171
167
|
segments:
|
172
168
|
- 0
|
173
169
|
version: "0"
|