firstfm 0.6.0 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION.yml +1 -1
- data/firstfm.gemspec +6 -3
- data/lib/firstfm/artist.rb +2 -1
- data/lib/firstfm/user.rb +21 -0
- data/lib/firstfm.rb +1 -0
- data/test/fixtures/user_artists.xml +29 -0
- data/test/test_user.rb +19 -0
- metadata +7 -4
data/VERSION.yml
CHANGED
data/firstfm.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "firstfm"
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.7.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Aleksandr Lossenko"]
|
12
|
-
s.date = "2013-
|
12
|
+
s.date = "2013-07-14"
|
13
13
|
s.description = "Firstfm is a ruby wrapper for the Last.fm APIs ( http://www.last.fm/api ). My main focus is to import events from Last.FM, but with time I will try to add support for all API methods."
|
14
14
|
s.email = "aleksandr.lossenko@gmail.com"
|
15
15
|
s.extra_rdoc_files = [
|
@@ -33,6 +33,7 @@ Gem::Specification.new do |s|
|
|
33
33
|
"lib/firstfm/image.rb",
|
34
34
|
"lib/firstfm/location.rb",
|
35
35
|
"lib/firstfm/track.rb",
|
36
|
+
"lib/firstfm/user.rb",
|
36
37
|
"lib/firstfm/venue.rb",
|
37
38
|
"test/fixtures/artist.xml",
|
38
39
|
"test/fixtures/artists.xml",
|
@@ -46,18 +47,20 @@ Gem::Specification.new do |s|
|
|
46
47
|
"test/fixtures/get_images.xml",
|
47
48
|
"test/fixtures/top_tracks.xml",
|
48
49
|
"test/fixtures/tracks.xml",
|
50
|
+
"test/fixtures/user_artists.xml",
|
49
51
|
"test/fixtures/venue.xml",
|
50
52
|
"test/fixtures/venues.xml",
|
51
53
|
"test/helper.rb",
|
52
54
|
"test/test_artist.rb",
|
53
55
|
"test/test_geo.rb",
|
54
56
|
"test/test_track.rb",
|
57
|
+
"test/test_user.rb",
|
55
58
|
"test/test_venue.rb"
|
56
59
|
]
|
57
60
|
s.homepage = "http://github.com/egze/firstfm"
|
58
61
|
s.licenses = ["MIT"]
|
59
62
|
s.require_paths = ["lib"]
|
60
|
-
s.rubygems_version = "1.8.
|
63
|
+
s.rubygems_version = "1.8.25"
|
61
64
|
s.summary = "A ruby wrapper for the Last.fm APIs"
|
62
65
|
|
63
66
|
if s.respond_to? :specification_version then
|
data/lib/firstfm/artist.rb
CHANGED
@@ -2,7 +2,7 @@ module Firstfm
|
|
2
2
|
|
3
3
|
class Artist
|
4
4
|
|
5
|
-
attr_accessor :name, :mbid, :url, :listeners, :streamable, :images
|
5
|
+
attr_accessor :name, :mbid, :url, :listeners, :streamable, :images, :playcount
|
6
6
|
|
7
7
|
include HTTParty
|
8
8
|
base_uri 'ws.audioscrobbler.com'
|
@@ -88,6 +88,7 @@ module Firstfm
|
|
88
88
|
artist.listeners = hash["listeners"].to_i
|
89
89
|
artist.streamable = hash["streamable"] == "1"
|
90
90
|
artist.images = hash["image"]
|
91
|
+
artist.playcount = hash["playcount"].to_i
|
91
92
|
end
|
92
93
|
end
|
93
94
|
|
data/lib/firstfm/user.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
module Firstfm
|
2
|
+
|
3
|
+
class User
|
4
|
+
|
5
|
+
include HTTParty
|
6
|
+
base_uri 'ws.audioscrobbler.com'
|
7
|
+
format :xml
|
8
|
+
|
9
|
+
def self.get_top_artists(user, period = "overall", page = 1, limit = 50)
|
10
|
+
response = get("/2.0/", {query: {method: 'user.getTopArtists', user: user, period: period, page: page, limit: limit, api_key: Firstfm.config.api_key}})
|
11
|
+
artists_array = (response and response["lfm"] and response["lfm"]["topartists"] and response["lfm"]["topartists"]["artist"]) || []
|
12
|
+
artists = Artist.init_from_array(artists_array)
|
13
|
+
WillPaginate::Collection.create(page, limit) do |pager|
|
14
|
+
pager.replace artists
|
15
|
+
pager.total_entries = response['lfm']['topartists']['total'].to_i rescue 0
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
data/lib/firstfm.rb
CHANGED
@@ -0,0 +1,29 @@
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
2
|
+
<lfm status="ok">
|
3
|
+
<topartists user="RJ" type="overall" page="1" perPage="50" totalPages="115" total="5702">
|
4
|
+
<artist rank="1">
|
5
|
+
<name>Dream Theater</name>
|
6
|
+
<playcount>1797</playcount>
|
7
|
+
<mbid>28503ab7-8bf2-4666-a7bd-2644bfc7cb1d</mbid>
|
8
|
+
<url>http://www.last.fm/music/Dream+Theater</url>
|
9
|
+
<streamable>1</streamable>
|
10
|
+
<image size="small">http://userserve-ak.last.fm/serve/34/5623420.jpg</image>
|
11
|
+
<image size="medium">http://userserve-ak.last.fm/serve/64/5623420.jpg</image>
|
12
|
+
<image size="large">http://userserve-ak.last.fm/serve/126/5623420.jpg</image>
|
13
|
+
<image size="extralarge">http://userserve-ak.last.fm/serve/252/5623420.jpg</image>
|
14
|
+
<image size="mega">http://userserve-ak.last.fm/serve/500/5623420/Dream+Theater+dt.jpg</image>
|
15
|
+
</artist>
|
16
|
+
<artist rank="2">
|
17
|
+
<name>Dire Straits</name>
|
18
|
+
<playcount>1498</playcount>
|
19
|
+
<mbid>614e3804-7d34-41ba-857f-811bad7c2b7a</mbid>
|
20
|
+
<url>http://www.last.fm/music/Dire+Straits</url>
|
21
|
+
<streamable>1</streamable>
|
22
|
+
<image size="small">http://userserve-ak.last.fm/serve/34/12048127.jpg</image>
|
23
|
+
<image size="medium">http://userserve-ak.last.fm/serve/64/12048127.jpg</image>
|
24
|
+
<image size="large">http://userserve-ak.last.fm/serve/126/12048127.jpg</image>
|
25
|
+
<image size="extralarge">http://userserve-ak.last.fm/serve/252/12048127.jpg</image>
|
26
|
+
<image size="mega">http://userserve-ak.last.fm/serve/500/12048127/Dire+Straits+expresso+love.jpg</image>
|
27
|
+
</artist>
|
28
|
+
</topartists>
|
29
|
+
</lfm>
|
data/test/test_user.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestUser < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def test_should_get_top_artists
|
6
|
+
FakeWeb.register_uri(:get, %r|http://ws.audioscrobbler.com/|, :body => File.read(File.dirname(__FILE__) + "/fixtures/user_artists.xml"))
|
7
|
+
artists = Firstfm::User.get_top_artists("RJ")
|
8
|
+
assert_equal 2, artists.size
|
9
|
+
assert_equal 5702, artists.total_entries
|
10
|
+
artist = artists.first
|
11
|
+
assert_equal "Dream Theater", artist.name
|
12
|
+
assert_equal 1797, artist.playcount
|
13
|
+
assert_equal "http://www.last.fm/music/Dream+Theater", artist.url
|
14
|
+
assert_equal "28503ab7-8bf2-4666-a7bd-2644bfc7cb1d", artist.mbid
|
15
|
+
assert artist.streamable
|
16
|
+
assert_equal 5, artist.images.size
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: firstfm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-07-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: httparty
|
@@ -165,6 +165,7 @@ files:
|
|
165
165
|
- lib/firstfm/image.rb
|
166
166
|
- lib/firstfm/location.rb
|
167
167
|
- lib/firstfm/track.rb
|
168
|
+
- lib/firstfm/user.rb
|
168
169
|
- lib/firstfm/venue.rb
|
169
170
|
- test/fixtures/artist.xml
|
170
171
|
- test/fixtures/artists.xml
|
@@ -178,12 +179,14 @@ files:
|
|
178
179
|
- test/fixtures/get_images.xml
|
179
180
|
- test/fixtures/top_tracks.xml
|
180
181
|
- test/fixtures/tracks.xml
|
182
|
+
- test/fixtures/user_artists.xml
|
181
183
|
- test/fixtures/venue.xml
|
182
184
|
- test/fixtures/venues.xml
|
183
185
|
- test/helper.rb
|
184
186
|
- test/test_artist.rb
|
185
187
|
- test/test_geo.rb
|
186
188
|
- test/test_track.rb
|
189
|
+
- test/test_user.rb
|
187
190
|
- test/test_venue.rb
|
188
191
|
homepage: http://github.com/egze/firstfm
|
189
192
|
licenses:
|
@@ -200,7 +203,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
200
203
|
version: '0'
|
201
204
|
segments:
|
202
205
|
- 0
|
203
|
-
hash:
|
206
|
+
hash: -964110322330808442
|
204
207
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
205
208
|
none: false
|
206
209
|
requirements:
|
@@ -209,7 +212,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
209
212
|
version: '0'
|
210
213
|
requirements: []
|
211
214
|
rubyforge_project:
|
212
|
-
rubygems_version: 1.8.
|
215
|
+
rubygems_version: 1.8.25
|
213
216
|
signing_key:
|
214
217
|
specification_version: 3
|
215
218
|
summary: A ruby wrapper for the Last.fm APIs
|