lastfm 0.0.1

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/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.sw?
2
+ .DS_Store
3
+ coverage
4
+ rdoc
5
+ pkg
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 youpy
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,69 @@
1
+ = ruby-lastfm
2
+
3
+ A Ruby interface for Last.fm Web Services v2.0
4
+
5
+ == Synopsis
6
+
7
+ require 'lastfm'
8
+
9
+ lastfm = Lastfm.new(api_key, api_secret)
10
+ token = lastfm.auth.get_token
11
+
12
+ # open 'http://www.last.fm/api/auth/?api_key=xxxxxxxxxxx&token=xxxxxxxx' and grant the application
13
+
14
+ lastfm.session = lastfm.auth.get_session(token)
15
+
16
+ lastfm.track.love('Hujiko Pro', 'acid acid 7riddim')
17
+
18
+ == Supported API Methods
19
+
20
+ It supports methods which require {authentication}[http://www.last.fm/api/authentication].
21
+
22
+ === Auth
23
+
24
+ * auth.getToken
25
+ * auth.getSession
26
+
27
+ === Track
28
+
29
+ * track.addTags
30
+ * track.ban
31
+ * track.getInfo
32
+ * track.getSimilar
33
+ * track.getTags
34
+ * track.getTopFans
35
+ * track.getTopTags
36
+ * track.love
37
+ * track.removeTag
38
+ * track.search
39
+ * track.share
40
+
41
+ == Installation
42
+
43
+ === Archive Installation
44
+
45
+ rake install
46
+
47
+ === Gem Installation
48
+
49
+ gem update --system
50
+ gem install gemcutter
51
+ gem tumble
52
+ gem install lastfm
53
+
54
+ == Features/Problems
55
+
56
+ == Note on Patches/Pull Requests
57
+
58
+ * Fork the project.
59
+ * Make your feature addition or bug fix.
60
+ * Add tests for it. This is important so I don't break it in a
61
+ future version unintentionally.
62
+ * Commit, do not mess with rakefile, version, or history.
63
+ (if you want to have your own version, that is fine but
64
+ bump version in a commit by itself I can ignore when I pull)
65
+ * Send me a pull request. Bonus points for topic branches.
66
+
67
+ == Copyright
68
+
69
+ Copyright (c) 2010 youpy. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,46 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "lastfm"
8
+ gem.summary = %Q{A Ruby interface for Last.fm Web Services}
9
+ gem.description = %Q{A ruby interface for Last.fm web services version 2.0}
10
+ gem.email = "youpy@buycheapviagraonlinenow.com"
11
+ gem.homepage = "http://github.com/youpy/ruby-lastfm"
12
+ gem.authors = ["youpy"]
13
+ gem.add_development_dependency "rspec"
14
+ gem.add_dependency "httparty"
15
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
16
+ end
17
+ Jeweler::GemcutterTasks.new
18
+ rescue LoadError
19
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
20
+ end
21
+
22
+ require 'spec/rake/spectask'
23
+ Spec::Rake::SpecTask.new(:spec) do |spec|
24
+ spec.libs << 'lib' << 'spec'
25
+ spec.spec_files = FileList['spec/**/*_spec.rb']
26
+ end
27
+
28
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
29
+ spec.libs << 'lib' << 'spec'
30
+ spec.pattern = 'spec/**/*_spec.rb'
31
+ spec.rcov = true
32
+ end
33
+
34
+ task :spec => :check_dependencies
35
+
36
+ task :default => :spec
37
+
38
+ require 'rake/rdoctask'
39
+ Rake::RDocTask.new do |rdoc|
40
+ version = File.read('VERSION')
41
+
42
+ rdoc.rdoc_dir = 'rdoc'
43
+ rdoc.title = "lastfm #{version}"
44
+ rdoc.rdoc_files.include('README*')
45
+ rdoc.rdoc_files.include('lib/**/*.rb')
46
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
data/lastfm.gemspec ADDED
@@ -0,0 +1,64 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{lastfm}
8
+ s.version = "0.0.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["youpy"]
12
+ s.date = %q{2010-01-11}
13
+ s.description = %q{A ruby interface for Last.fm web services version 2.0}
14
+ s.email = %q{youpy@buycheapviagraonlinenow.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".gitignore",
22
+ "LICENSE",
23
+ "README.rdoc",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "lastfm.gemspec",
27
+ "lib/lastfm.rb",
28
+ "lib/lastfm/method_category.rb",
29
+ "lib/lastfm/method_category/auth.rb",
30
+ "lib/lastfm/method_category/track.rb",
31
+ "lib/lastfm/response.rb",
32
+ "spec/lastfm_spec.rb",
33
+ "spec/method_category_spec.rb",
34
+ "spec/response_spec.rb",
35
+ "spec/spec_helper.rb"
36
+ ]
37
+ s.homepage = %q{http://github.com/youpy/ruby-lastfm}
38
+ s.rdoc_options = ["--charset=UTF-8"]
39
+ s.require_paths = ["lib"]
40
+ s.rubygems_version = %q{1.3.5}
41
+ s.summary = %q{A Ruby interface for Last.fm Web Services}
42
+ s.test_files = [
43
+ "spec/lastfm_spec.rb",
44
+ "spec/method_category_spec.rb",
45
+ "spec/response_spec.rb",
46
+ "spec/spec_helper.rb"
47
+ ]
48
+
49
+ if s.respond_to? :specification_version then
50
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
51
+ s.specification_version = 3
52
+
53
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
54
+ s.add_development_dependency(%q<rspec>, [">= 0"])
55
+ s.add_runtime_dependency(%q<httparty>, [">= 0"])
56
+ else
57
+ s.add_dependency(%q<rspec>, [">= 0"])
58
+ s.add_dependency(%q<httparty>, [">= 0"])
59
+ end
60
+ else
61
+ s.add_dependency(%q<rspec>, [">= 0"])
62
+ s.add_dependency(%q<httparty>, [">= 0"])
63
+ end
64
+ end
data/lib/lastfm.rb ADDED
@@ -0,0 +1,63 @@
1
+ require 'lastfm/response'
2
+ require 'lastfm/method_category'
3
+
4
+ require 'lastfm/method_category/auth'
5
+ require 'lastfm/method_category/track'
6
+
7
+ require 'rubygems'
8
+ require 'digest/md5'
9
+ require 'httparty'
10
+
11
+ class Lastfm
12
+ API_ROOT = 'http://ws.audioscrobbler.com/2.0'
13
+
14
+ include HTTParty
15
+ base_uri API_ROOT
16
+
17
+ attr_accessor :session
18
+
19
+ class Error < StandardError; end
20
+ class ApiError < Error; end
21
+
22
+ def initialize(api_key, api_secret)
23
+ @api_key = api_key
24
+ @api_secret = api_secret
25
+ end
26
+
27
+ def auth
28
+ Auth.new(self)
29
+ end
30
+
31
+ def track
32
+ Track.new(self)
33
+ end
34
+
35
+ def request(method, params = {}, http_method = :get, with_signature = false, with_session = false)
36
+ params[:method] = method
37
+ params[:api_key] = @api_key
38
+
39
+ # http://www.lastfm.jp/group/Last.fm+Web+Services/forum/21604/_/497978
40
+ #params[:format] = format
41
+
42
+ params.update(:sk => @session) if with_session
43
+ params.update(:api_sig => Digest::MD5.hexdigest(build_method_signature(params))) if with_signature
44
+ params.update(:format => 'json')
45
+
46
+ response = Response.new(self.class.send(http_method, '/', (http_method == :post ? :body : :query) => params).body)
47
+ unless response.success?
48
+ raise ApiError.new(response.message)
49
+ end
50
+
51
+ response
52
+ end
53
+
54
+ private
55
+
56
+ def build_method_signature(params)
57
+ params.to_a.sort_by do |param|
58
+ param.first.to_s
59
+ end.inject('') do |result, param|
60
+ result + param.join('')
61
+ end + @api_secret
62
+ end
63
+ end
@@ -0,0 +1,26 @@
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
@@ -0,0 +1,11 @@
1
+ class Lastfm
2
+ class Auth < MethodCategory
3
+ def get_token
4
+ request_for_authentication('getToken')['token']
5
+ end
6
+
7
+ def get_session(token)
8
+ request_for_authentication('getSession', { :token => token })['session']['key']
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,87 @@
1
+ class Lastfm
2
+ class Track < MethodCategory
3
+ def add_tags(artist, track, tags)
4
+ write_request('addTags', {
5
+ :artist => artist,
6
+ :track => track,
7
+ :tags => tags
8
+ })
9
+ end
10
+
11
+ def ban(artist, track)
12
+ write_request('ban', {
13
+ :artist => artist,
14
+ :track => track,
15
+ })
16
+ end
17
+
18
+ def get_info(artist, track, username = nil)
19
+ request('getInfo', {
20
+ :artist => artist,
21
+ :track => track,
22
+ :username => username
23
+ })
24
+ end
25
+
26
+ def get_similar(artist, track)
27
+ request('getSimilar', {
28
+ :artist => artist,
29
+ :track => track,
30
+ })
31
+ end
32
+
33
+ def get_tags(artist, track)
34
+ request_with_authentication('getTags', {
35
+ :artist => artist,
36
+ :track => track,
37
+ })
38
+ end
39
+
40
+ def get_top_fans(artist, track)
41
+ request('getTopFans', {
42
+ :artist => artist,
43
+ :track => track,
44
+ })
45
+ end
46
+
47
+ def get_top_tags(artist, track)
48
+ request('getTopTags', {
49
+ :artist => artist,
50
+ :track => track,
51
+ })
52
+ end
53
+
54
+ def love(artist, track)
55
+ write_request('love', {
56
+ :artist => artist,
57
+ :track => track,
58
+ })
59
+ end
60
+
61
+ def remove_tag(artist, track, tag)
62
+ write_request('removeTag', {
63
+ :artist => artist,
64
+ :track => track,
65
+ :tag => tag
66
+ })
67
+ end
68
+
69
+ def search(artist, track, limit = nil, page = nil)
70
+ request('search', {
71
+ :artist => artist,
72
+ :track => track,
73
+ :limit => limit,
74
+ :page => page
75
+ })
76
+ end
77
+
78
+ def share(artist, track, recipient, message = nil)
79
+ write_request('share', {
80
+ :artist => artist,
81
+ :track => track,
82
+ :recipient => recipient,
83
+ :message => message
84
+ })
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,34 @@
1
+ require 'rubygems'
2
+ require 'json'
3
+
4
+ class Lastfm
5
+ class Response
6
+ def initialize(body)
7
+ # API returns XML response when no child node?
8
+ if body == '<?xml version="1.0" encoding="utf-8"?>
9
+ <lfm status="ok">
10
+ </lfm>
11
+ '
12
+ @parsed_body = {}
13
+ else
14
+ @parsed_body = JSON.parse(body)
15
+ end
16
+ end
17
+
18
+ def [](key)
19
+ @parsed_body[key]
20
+ end
21
+
22
+ def success?
23
+ !self['error']
24
+ end
25
+
26
+ def message
27
+ self['message']
28
+ end
29
+
30
+ def error
31
+ self['error']
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,245 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "Lastfm" do
4
+ before do
5
+ @lastfm = Lastfm.new('xxx', 'yyy')
6
+ end
7
+
8
+ it 'should have base_uri' do
9
+ Lastfm.base_uri.should eql('http://ws.audioscrobbler.com/2.0')
10
+ end
11
+
12
+ describe '.new' do
13
+ it 'should instantiate' do
14
+ @lastfm.should be_an_instance_of(Lastfm)
15
+ end
16
+ end
17
+
18
+ describe '#request' do
19
+ it 'should post' do
20
+ mock_response = mock(HTTParty::Response)
21
+ @lastfm.class.should_receive(:post).with('/', :body => {
22
+ :foo => 'bar',
23
+ :method => 'xxx.yyy',
24
+ :api_key => 'xxx',
25
+ :format => 'json'
26
+ }).and_return(mock_response)
27
+ mock_response.should_receive(:body).and_return('{ "bar": "baz" }')
28
+ @lastfm.request('xxx.yyy', { :foo => 'bar' }, :post, false, false)['bar'].should eql('baz')
29
+ end
30
+
31
+ it 'should post with signature' do
32
+ mock_response = mock(HTTParty::Response)
33
+ @lastfm.class.should_receive(:post).with('/', :body => {
34
+ :foo => 'bar',
35
+ :method => 'xxx.yyy',
36
+ :api_key => 'xxx',
37
+ :api_sig => Digest::MD5.hexdigest('api_keyxxxfoobarmethodxxx.yyyyyy'),
38
+ :format => 'json'
39
+ }).and_return(mock_response)
40
+ mock_response.should_receive(:body).and_return('{ "bar": "baz" }')
41
+ @lastfm.request('xxx.yyy', { :foo => 'bar' }, :post, true, false)['bar'].should eql('baz')
42
+ end
43
+
44
+ it 'should post with signature and session (request with authentication)' do
45
+ mock_response = mock(HTTParty::Response)
46
+ @lastfm.session = 'abcdef'
47
+ @lastfm.class.should_receive(:post).with('/', :body => {
48
+ :foo => 'bar',
49
+ :method => 'xxx.yyy',
50
+ :api_key => 'xxx',
51
+ :api_sig => Digest::MD5.hexdigest('api_keyxxxfoobarmethodxxx.yyyskabcdefyyy'),
52
+ :sk => 'abcdef',
53
+ :format => 'json'
54
+ }).and_return(mock_response)
55
+ mock_response.should_receive(:body).and_return('{ "bar": "baz" }')
56
+
57
+ @lastfm.request('xxx.yyy', { :foo => 'bar' }, :post, true, true)['bar'].should eql('baz')
58
+ end
59
+
60
+ it 'should get' do
61
+ mock_response = mock(HTTParty::Response)
62
+ @lastfm.class.should_receive(:get).with('/', :query => {
63
+ :foo => 'bar',
64
+ :method => 'xxx.yyy',
65
+ :api_key => 'xxx',
66
+ :format => 'json'
67
+ }).and_return(mock_response)
68
+ mock_response.should_receive(:body).and_return('{ "bar": "baz" }')
69
+
70
+ @lastfm.request('xxx.yyy', { :foo => 'bar' }, :get, false, false)['bar'].should eql('baz')
71
+ end
72
+
73
+ it 'should get with signature (request for authentication)' do
74
+ mock_response = mock(HTTParty::Response)
75
+ @lastfm.class.should_receive(:get).with('/', :query => {
76
+ :foo => 'bar',
77
+ :method => 'xxx.yyy',
78
+ :api_key => 'xxx',
79
+ :api_sig => Digest::MD5.hexdigest('api_keyxxxfoobarmethodxxx.yyyyyy'),
80
+ :format => 'json'
81
+ }).and_return(mock_response)
82
+ mock_response.should_receive(:body).and_return('{ "bar": "baz" }')
83
+
84
+ @lastfm.request('xxx.yyy', { :foo => 'bar' }, :get, true, false)['bar'].should eql('baz')
85
+ end
86
+
87
+ it 'should get with signature and session' do
88
+ mock_response = mock(HTTParty::Response)
89
+ @lastfm.session = 'abcdef'
90
+ @lastfm.class.should_receive(:get).with('/', :query => {
91
+ :foo => 'bar',
92
+ :method => 'xxx.yyy',
93
+ :api_key => 'xxx',
94
+ :api_sig => Digest::MD5.hexdigest('api_keyxxxfoobarmethodxxx.yyyskabcdefyyy'),
95
+ :sk => 'abcdef',
96
+ :format => 'json'
97
+ }).and_return(mock_response)
98
+ mock_response.should_receive(:body).and_return('{ "bar": "baz" }')
99
+
100
+ @lastfm.request('xxx.yyy', { :foo => 'bar' }, :get, true, true)['bar'].should eql('baz')
101
+ end
102
+
103
+ it 'should raise an error if an api error is ocuured' do
104
+ mock_response = mock(HTTParty::Response)
105
+ mock_response.should_receive(:body).and_return('{"message": "Invalid Method - No method with that name in this package", "error": 3}')
106
+ @lastfm.class.should_receive(:post).and_return(mock_response)
107
+
108
+ lambda {
109
+ @lastfm.request('xxx.yyy', { :foo => 'bar' }, :post)
110
+ }.should raise_error(Lastfm::ApiError, 'Invalid Method - No method with that name in this package')
111
+ end
112
+ end
113
+
114
+ describe '#auth' do
115
+ it 'should return an instance of Lastfm::Auth' do
116
+ @lastfm.auth.should be_an_instance_of(Lastfm::Auth)
117
+ end
118
+
119
+ it 'should get token' do
120
+ @lastfm.should_receive(:request).
121
+ with('auth.getToken', {}, :get, true).
122
+ and_return({ 'token' => 'xxxyyyzzz' })
123
+ @lastfm.auth.get_token.should eql('xxxyyyzzz')
124
+ end
125
+
126
+ it 'should get session' do
127
+ @lastfm.should_receive(:request).
128
+ with('auth.getSession', { :token => 'xxxyyyzzz' }, :get, true).
129
+ and_return({ 'session' => { 'key' => 'zzzyyyxxx' }})
130
+ @lastfm.auth.get_session('xxxyyyzzz').should eql('zzzyyyxxx')
131
+ end
132
+ end
133
+
134
+ describe '#track' do
135
+ it 'should return an instance of Lastfm::Track' do
136
+ @lastfm.track.should be_an_instance_of(Lastfm::Track)
137
+ end
138
+
139
+ it 'should add tags' do
140
+ @lastfm.should_receive(:request).with('track.addTags', {
141
+ :artist => 'foo artist',
142
+ :track => 'foo track',
143
+ :tags => 'aaa,bbb,ccc'
144
+ }, :post, true, true).and_return({})
145
+
146
+ @lastfm.track.add_tags('foo artist', 'foo track', 'aaa,bbb,ccc')
147
+ end
148
+
149
+ it 'should ban' do
150
+ @lastfm.should_receive(:request).with('track.ban', {
151
+ :artist => 'foo artist',
152
+ :track => 'foo track',
153
+ }, :post, true, true).and_return({})
154
+
155
+ @lastfm.track.ban('foo artist', 'foo track')
156
+ end
157
+
158
+ it 'should get info' do
159
+ @lastfm.should_receive(:request).with('track.getInfo', {
160
+ :artist => 'foo artist',
161
+ :track => 'foo track',
162
+ :username => 'youpy',
163
+ }).and_return({})
164
+
165
+ @lastfm.track.get_info('foo artist', 'foo track', 'youpy')
166
+ end
167
+
168
+ it 'should get similar' do
169
+ @lastfm.should_receive(:request).with('track.getSimilar', {
170
+ :artist => 'foo artist',
171
+ :track => 'foo track',
172
+ }).and_return({})
173
+
174
+ @lastfm.track.get_similar('foo artist', 'foo track')
175
+ end
176
+
177
+ it 'should get tags' do
178
+ @lastfm.should_receive(:request).with('track.getTags', {
179
+ :artist => 'foo artist',
180
+ :track => 'foo track',
181
+ }, :get, true, true).and_return({})
182
+
183
+ @lastfm.track.get_tags('foo artist', 'foo track')
184
+ end
185
+
186
+ it 'should get top fans' do
187
+ @lastfm.should_receive(:request).with('track.getTopFans', {
188
+ :artist => 'foo artist',
189
+ :track => 'foo track',
190
+ }).and_return({})
191
+
192
+ @lastfm.track.get_top_fans('foo artist', 'foo track')
193
+ end
194
+
195
+ it 'should get top tags' do
196
+ @lastfm.should_receive(:request).with('track.getTopTags', {
197
+ :artist => 'foo artist',
198
+ :track => 'foo track',
199
+ }).and_return({})
200
+
201
+ @lastfm.track.get_top_tags('foo artist', 'foo track')
202
+ end
203
+
204
+ it 'should love' do
205
+ @lastfm.should_receive(:request).with('track.love', {
206
+ :artist => 'foo artist',
207
+ :track => 'foo track',
208
+ }, :post, true, true).and_return({})
209
+
210
+ @lastfm.track.love('foo artist', 'foo track')
211
+ end
212
+
213
+ it 'should remove tag' do
214
+ @lastfm.should_receive(:request).with('track.removeTag', {
215
+ :artist => 'foo artist',
216
+ :track => 'foo track',
217
+ :tag => 'aaa'
218
+ }, :post, true, true).and_return({})
219
+
220
+ @lastfm.track.remove_tag('foo artist', 'foo track', 'aaa')
221
+ end
222
+
223
+ it 'should search' do
224
+ @lastfm.should_receive(:request).with('track.search', {
225
+ :artist => 'foo artist',
226
+ :track => 'foo track',
227
+ :limit => 10,
228
+ :page => 3,
229
+ }).and_return({})
230
+
231
+ @lastfm.track.search('foo artist', 'foo track', 10, 3)
232
+ end
233
+
234
+ it 'should share' do
235
+ @lastfm.should_receive(:request).with('track.share', {
236
+ :artist => 'foo artist',
237
+ :track => 'foo track',
238
+ :message => 'this is a message',
239
+ :recipient => 'foo@example.com',
240
+ }, :post, true, true).and_return({})
241
+
242
+ @lastfm.track.share('foo artist', 'foo track', 'foo@example.com', 'this is a message')
243
+ end
244
+ end
245
+ end
@@ -0,0 +1,11 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe 'Lastfm::MethodCategory' do
4
+ before do
5
+ @lastfm = Lastfm.new('xxx', 'yyy')
6
+ end
7
+
8
+ it 'should have instance of Lastfm' do
9
+ Lastfm::MethodCategory.new(@lastfm).instance_eval { @lastfm }.should equal(@lastfm)
10
+ end
11
+ end
@@ -0,0 +1,48 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "Lastfm::Response" do
4
+ describe '.new' do
5
+ it 'should instantiate' do
6
+ Lastfm::Response.new('{ "foo": "bar" }').should be_an_instance_of(Lastfm::Response)
7
+ end
8
+ end
9
+
10
+ describe 'success' do
11
+ before do
12
+ @response = Lastfm::Response.new('{ "foo": "bar" }')
13
+ end
14
+
15
+ it 'should be success' do
16
+ @response.should be_success
17
+ end
18
+
19
+ it 'should parse response body as json' do
20
+ @response['foo'].should eql('bar')
21
+ 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
+ end
30
+
31
+ describe 'failure' do
32
+ before do
33
+ @response = Lastfm::Response.new('{"message": "Invalid Method - No method with that name in this package", "error": 3}')
34
+ end
35
+
36
+ it 'should not be success' do
37
+ @response.should_not be_success
38
+ end
39
+
40
+ it 'should have message' do
41
+ @response.message.should eql('Invalid Method - No method with that name in this package')
42
+ end
43
+
44
+ it 'should have error number' do
45
+ @response.error.should eql(3)
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,9 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'lastfm'
4
+ require 'spec'
5
+ require 'spec/autorun'
6
+
7
+ Spec::Runner.configure do |config|
8
+
9
+ end
metadata ADDED
@@ -0,0 +1,93 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lastfm
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - youpy
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-01-11 00:00:00 +09:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rspec
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: httparty
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: "0"
34
+ version:
35
+ description: A ruby interface for Last.fm web services version 2.0
36
+ email: youpy@buycheapviagraonlinenow.com
37
+ executables: []
38
+
39
+ extensions: []
40
+
41
+ extra_rdoc_files:
42
+ - LICENSE
43
+ - README.rdoc
44
+ files:
45
+ - .document
46
+ - .gitignore
47
+ - LICENSE
48
+ - README.rdoc
49
+ - Rakefile
50
+ - VERSION
51
+ - lastfm.gemspec
52
+ - lib/lastfm.rb
53
+ - lib/lastfm/method_category.rb
54
+ - lib/lastfm/method_category/auth.rb
55
+ - lib/lastfm/method_category/track.rb
56
+ - lib/lastfm/response.rb
57
+ - spec/lastfm_spec.rb
58
+ - spec/method_category_spec.rb
59
+ - spec/response_spec.rb
60
+ - spec/spec_helper.rb
61
+ has_rdoc: true
62
+ homepage: http://github.com/youpy/ruby-lastfm
63
+ licenses: []
64
+
65
+ post_install_message:
66
+ rdoc_options:
67
+ - --charset=UTF-8
68
+ require_paths:
69
+ - lib
70
+ required_ruby_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: "0"
75
+ version:
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: "0"
81
+ version:
82
+ requirements: []
83
+
84
+ rubyforge_project:
85
+ rubygems_version: 1.3.5
86
+ signing_key:
87
+ specification_version: 3
88
+ summary: A Ruby interface for Last.fm Web Services
89
+ test_files:
90
+ - spec/lastfm_spec.rb
91
+ - spec/method_category_spec.rb
92
+ - spec/response_spec.rb
93
+ - spec/spec_helper.rb