lastfm 0.0.1 → 0.1.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/.rspec +2 -0
- data/README.rdoc +4 -0
- data/Rakefile +7 -12
- data/VERSION +1 -1
- data/lastfm.gemspec +29 -9
- data/lib/lastfm.rb +10 -5
- data/lib/lastfm/method_category/artist.rb +9 -0
- data/lib/lastfm/method_category/auth.rb +8 -6
- data/lib/lastfm/method_category/base.rb +58 -0
- data/lib/lastfm/method_category/track.rb +25 -83
- data/lib/lastfm/response.rb +7 -17
- data/lib/lastfm/util.rb +18 -0
- data/spec/fixtures/artist_get_events.xml +57 -0
- data/spec/fixtures/ng.xml +3 -0
- data/spec/fixtures/ok.xml +128 -0
- data/spec/fixtures/track_get_info.xml +111 -0
- data/spec/fixtures/track_get_info_force_array.xml +89 -0
- data/spec/fixtures/track_get_similar.xml +5095 -0
- data/spec/fixtures/track_get_tags.xml +13 -0
- data/spec/fixtures/track_get_top_fans.xml +28 -0
- data/spec/fixtures/track_get_top_tags.xml +15 -0
- data/spec/fixtures/track_search.xml +35 -0
- data/spec/lastfm_spec.rb +137 -57
- data/spec/method_category_spec.rb +1 -1
- data/spec/response_spec.rb +13 -14
- data/spec/spec_helper.rb +12 -6
- metadata +63 -13
- data/lib/lastfm/method_category.rb +0 -26
data/spec/response_spec.rb
CHANGED
@@ -1,36 +1,35 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
2
|
|
3
3
|
describe "Lastfm::Response" do
|
4
|
+
before do
|
5
|
+
@ok = open(fixture('ok.xml')).read
|
6
|
+
@ng = open(fixture('ng.xml')).read
|
7
|
+
end
|
8
|
+
|
4
9
|
describe '.new' do
|
5
10
|
it 'should instantiate' do
|
6
|
-
Lastfm::Response.new(
|
11
|
+
Lastfm::Response.new(@ok).should be_an_instance_of(Lastfm::Response)
|
7
12
|
end
|
8
13
|
end
|
9
14
|
|
10
15
|
describe 'success' do
|
11
16
|
before do
|
12
|
-
@response = Lastfm::Response.new(
|
17
|
+
@response = Lastfm::Response.new(@ok)
|
13
18
|
end
|
14
19
|
|
15
20
|
it 'should be success' do
|
16
21
|
@response.should be_success
|
17
22
|
end
|
18
23
|
|
19
|
-
it 'should parse response body as
|
20
|
-
@response
|
24
|
+
it 'should parse response body as xml' do
|
25
|
+
xml = @response.xml
|
26
|
+
xml['similartracks']['track'].size.should eql(7)
|
21
27
|
end
|
22
|
-
|
23
|
-
it 'should ignore unexpected xml response' do
|
24
|
-
Lastfm::Response.new('<?xml version="1.0" encoding="utf-8"?>
|
25
|
-
<lfm status="ok">
|
26
|
-
</lfm>
|
27
|
-
').should be_success
|
28
|
-
end
|
29
28
|
end
|
30
29
|
|
31
30
|
describe 'failure' do
|
32
31
|
before do
|
33
|
-
@response = Lastfm::Response.new(
|
32
|
+
@response = Lastfm::Response.new(@ng)
|
34
33
|
end
|
35
34
|
|
36
35
|
it 'should not be success' do
|
@@ -38,11 +37,11 @@ describe "Lastfm::Response" do
|
|
38
37
|
end
|
39
38
|
|
40
39
|
it 'should have message' do
|
41
|
-
@response.message.should eql('Invalid
|
40
|
+
@response.message.should eql('Invalid API key - You must be granted a valid key by last.fm')
|
42
41
|
end
|
43
42
|
|
44
43
|
it 'should have error number' do
|
45
|
-
@response.error.should eql(
|
44
|
+
@response.error.should eql(10)
|
46
45
|
end
|
47
46
|
end
|
48
47
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,9 +1,15 @@
|
|
1
|
-
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
2
|
-
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
3
1
|
require 'lastfm'
|
4
|
-
require 'spec'
|
5
|
-
require 'spec/autorun'
|
6
2
|
|
7
|
-
|
8
|
-
|
3
|
+
RSpec.configure do |config|
|
4
|
+
def fixture(filename)
|
5
|
+
File.dirname(__FILE__) + '/fixtures/' + filename
|
6
|
+
end
|
7
|
+
|
8
|
+
def make_response(xml_filename_or_string)
|
9
|
+
if xml_filename_or_string !~ /</
|
10
|
+
xml_filename_or_string = open(fixture(xml_filename_or_string + '.xml')).read
|
11
|
+
end
|
12
|
+
|
13
|
+
Lastfm::Response.new(xml_filename_or_string)
|
14
|
+
end
|
9
15
|
end
|
metadata
CHANGED
@@ -1,7 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lastfm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
version: 0.1.0
|
5
10
|
platform: ruby
|
6
11
|
authors:
|
7
12
|
- youpy
|
@@ -9,29 +14,59 @@ autorequire:
|
|
9
14
|
bindir: bin
|
10
15
|
cert_chain: []
|
11
16
|
|
12
|
-
date: 2010-
|
17
|
+
date: 2010-11-18 00:00:00 +09:00
|
13
18
|
default_executable:
|
14
19
|
dependencies:
|
15
20
|
- !ruby/object:Gem::Dependency
|
16
21
|
name: rspec
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 2
|
29
|
+
- 0
|
30
|
+
- 0
|
31
|
+
version: 2.0.0
|
17
32
|
type: :development
|
18
|
-
|
19
|
-
|
33
|
+
version_requirements: *id001
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
name: httparty
|
36
|
+
prerelease: false
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
20
38
|
requirements:
|
21
39
|
- - ">="
|
22
40
|
- !ruby/object:Gem::Version
|
41
|
+
segments:
|
42
|
+
- 0
|
23
43
|
version: "0"
|
24
|
-
|
44
|
+
type: :runtime
|
45
|
+
version_requirements: *id002
|
25
46
|
- !ruby/object:Gem::Dependency
|
26
|
-
name:
|
47
|
+
name: xml-simple
|
48
|
+
prerelease: false
|
49
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
segments:
|
54
|
+
- 0
|
55
|
+
version: "0"
|
27
56
|
type: :runtime
|
28
|
-
|
29
|
-
|
57
|
+
version_requirements: *id003
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: activesupport
|
60
|
+
prerelease: false
|
61
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
30
62
|
requirements:
|
31
63
|
- - ">="
|
32
64
|
- !ruby/object:Gem::Version
|
65
|
+
segments:
|
66
|
+
- 0
|
33
67
|
version: "0"
|
34
|
-
|
68
|
+
type: :runtime
|
69
|
+
version_requirements: *id004
|
35
70
|
description: A ruby interface for Last.fm web services version 2.0
|
36
71
|
email: youpy@buycheapviagraonlinenow.com
|
37
72
|
executables: []
|
@@ -44,16 +79,29 @@ extra_rdoc_files:
|
|
44
79
|
files:
|
45
80
|
- .document
|
46
81
|
- .gitignore
|
82
|
+
- .rspec
|
47
83
|
- LICENSE
|
48
84
|
- README.rdoc
|
49
85
|
- Rakefile
|
50
86
|
- VERSION
|
51
87
|
- lastfm.gemspec
|
52
88
|
- lib/lastfm.rb
|
53
|
-
- lib/lastfm/method_category.rb
|
89
|
+
- lib/lastfm/method_category/artist.rb
|
54
90
|
- lib/lastfm/method_category/auth.rb
|
91
|
+
- lib/lastfm/method_category/base.rb
|
55
92
|
- lib/lastfm/method_category/track.rb
|
56
93
|
- lib/lastfm/response.rb
|
94
|
+
- lib/lastfm/util.rb
|
95
|
+
- spec/fixtures/artist_get_events.xml
|
96
|
+
- spec/fixtures/ng.xml
|
97
|
+
- spec/fixtures/ok.xml
|
98
|
+
- spec/fixtures/track_get_info.xml
|
99
|
+
- spec/fixtures/track_get_info_force_array.xml
|
100
|
+
- spec/fixtures/track_get_similar.xml
|
101
|
+
- spec/fixtures/track_get_tags.xml
|
102
|
+
- spec/fixtures/track_get_top_fans.xml
|
103
|
+
- spec/fixtures/track_get_top_tags.xml
|
104
|
+
- spec/fixtures/track_search.xml
|
57
105
|
- spec/lastfm_spec.rb
|
58
106
|
- spec/method_category_spec.rb
|
59
107
|
- spec/response_spec.rb
|
@@ -71,18 +119,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
71
119
|
requirements:
|
72
120
|
- - ">="
|
73
121
|
- !ruby/object:Gem::Version
|
122
|
+
segments:
|
123
|
+
- 0
|
74
124
|
version: "0"
|
75
|
-
version:
|
76
125
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
77
126
|
requirements:
|
78
127
|
- - ">="
|
79
128
|
- !ruby/object:Gem::Version
|
129
|
+
segments:
|
130
|
+
- 0
|
80
131
|
version: "0"
|
81
|
-
version:
|
82
132
|
requirements: []
|
83
133
|
|
84
134
|
rubyforge_project:
|
85
|
-
rubygems_version: 1.3.
|
135
|
+
rubygems_version: 1.3.6
|
86
136
|
signing_key:
|
87
137
|
specification_version: 3
|
88
138
|
summary: A Ruby interface for Last.fm Web Services
|
@@ -1,26 +0,0 @@
|
|
1
|
-
class Lastfm
|
2
|
-
class MethodCategory
|
3
|
-
def initialize(lastfm)
|
4
|
-
@lastfm = lastfm
|
5
|
-
end
|
6
|
-
|
7
|
-
def write_request(method, params = {})
|
8
|
-
request(method, params, :post, true, true)
|
9
|
-
end
|
10
|
-
|
11
|
-
def request_with_authentication(method, params = {})
|
12
|
-
request(method, params, :get, true, true)
|
13
|
-
end
|
14
|
-
|
15
|
-
def request_for_authentication(method, params = {})
|
16
|
-
request(method, params, :get, true)
|
17
|
-
end
|
18
|
-
|
19
|
-
def request(*args)
|
20
|
-
method, *rest = args
|
21
|
-
method = [self.class.name.split(/::/).last.downcase, method].join('.')
|
22
|
-
|
23
|
-
@lastfm.request(method, *rest)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|