claudiob-lastfm 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
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,65 @@
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{claudiob-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/method_category/user.rb",
32
+ "lib/lastfm/response.rb",
33
+ "spec/lastfm_spec.rb",
34
+ "spec/method_category_spec.rb",
35
+ "spec/response_spec.rb",
36
+ "spec/spec_helper.rb"
37
+ ]
38
+ s.homepage = %q{http://github.com/youpy/ruby-lastfm}
39
+ s.rdoc_options = ["--charset=UTF-8"]
40
+ s.require_paths = ["lib"]
41
+ s.rubygems_version = %q{1.3.5}
42
+ s.summary = %q{A Ruby interface for Last.fm Web Services}
43
+ s.test_files = [
44
+ "spec/lastfm_spec.rb",
45
+ "spec/method_category_spec.rb",
46
+ "spec/response_spec.rb",
47
+ "spec/spec_helper.rb"
48
+ ]
49
+
50
+ if s.respond_to? :specification_version then
51
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
52
+ s.specification_version = 3
53
+
54
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
55
+ s.add_development_dependency(%q<rspec>, [">= 0"])
56
+ s.add_runtime_dependency(%q<httparty>, [">= 0"])
57
+ else
58
+ s.add_dependency(%q<rspec>, [">= 0"])
59
+ s.add_dependency(%q<httparty>, [">= 0"])
60
+ end
61
+ else
62
+ s.add_dependency(%q<rspec>, [">= 0"])
63
+ s.add_dependency(%q<httparty>, [">= 0"])
64
+ end
65
+ end
data/lib/lastfm.rb ADDED
@@ -0,0 +1,68 @@
1
+ require 'lastfm/response'
2
+ require 'lastfm/method_category'
3
+
4
+ require 'lastfm/method_category/auth'
5
+ require 'lastfm/method_category/track'
6
+ require 'lastfm/method_category/user'
7
+
8
+ require 'rubygems'
9
+ require 'digest/md5'
10
+ require 'httparty'
11
+
12
+ class Lastfm
13
+ API_ROOT = 'http://ws.audioscrobbler.com/2.0'
14
+
15
+ include HTTParty
16
+ base_uri API_ROOT
17
+
18
+ attr_accessor :session
19
+
20
+ class Error < StandardError; end
21
+ class ApiError < Error; end
22
+
23
+ def initialize(api_key, api_secret)
24
+ @api_key = api_key
25
+ @api_secret = api_secret
26
+ end
27
+
28
+ def auth
29
+ Auth.new(self)
30
+ end
31
+
32
+ def track
33
+ Track.new(self)
34
+ end
35
+
36
+ def user
37
+ User.new(self)
38
+ end
39
+
40
+ def request(method, params = {}, http_method = :get, with_signature = false, with_session = false)
41
+ params[:method] = method
42
+ params[:api_key] = @api_key
43
+
44
+ # http://www.lastfm.jp/group/Last.fm+Web+Services/forum/21604/_/497978
45
+ #params[:format] = format
46
+
47
+ params.update(:sk => @session) if with_session
48
+ params.update(:api_sig => Digest::MD5.hexdigest(build_method_signature(params))) if with_signature
49
+ params.update(:format => 'json')
50
+
51
+ response = Response.new(self.class.send(http_method, '/', (http_method == :post ? :body : :query) => params).body)
52
+ unless response.success?
53
+ raise ApiError.new(response.message)
54
+ end
55
+
56
+ response
57
+ end
58
+
59
+ private
60
+
61
+ def build_method_signature(params)
62
+ params.to_a.sort_by do |param|
63
+ param.first.to_s
64
+ end.inject('') do |result, param|
65
+ result + param.join('')
66
+ end + @api_secret
67
+ end
68
+ 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,22 @@
1
+ class Lastfm
2
+ class User < MethodCategory
3
+ def get_info(user)
4
+ request('getInfo', {
5
+ :user => user
6
+ })
7
+ end
8
+
9
+ def get_loved_tracks(user)
10
+ request('getLovedTracks', {
11
+ :user => user
12
+ })
13
+ end
14
+
15
+ def get_recent_tracks(user)
16
+ request('getRecentTracks', {
17
+ :user => user
18
+ })
19
+ end
20
+
21
+ end
22
+ 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,114 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: claudiob-lastfm
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - youpy
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-01-11 00:00:00 +01:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: rspec
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
33
+ type: :development
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: httparty
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ hash: 3
44
+ segments:
45
+ - 0
46
+ version: "0"
47
+ type: :runtime
48
+ version_requirements: *id002
49
+ description: A ruby interface for Last.fm web services version 2.0
50
+ email: youpy@buycheapviagraonlinenow.com
51
+ executables: []
52
+
53
+ extensions: []
54
+
55
+ extra_rdoc_files:
56
+ - LICENSE
57
+ - README.rdoc
58
+ files:
59
+ - .document
60
+ - .gitignore
61
+ - LICENSE
62
+ - README.rdoc
63
+ - Rakefile
64
+ - VERSION
65
+ - lastfm.gemspec
66
+ - lib/lastfm.rb
67
+ - lib/lastfm/method_category.rb
68
+ - lib/lastfm/method_category/auth.rb
69
+ - lib/lastfm/method_category/track.rb
70
+ - lib/lastfm/method_category/user.rb
71
+ - lib/lastfm/response.rb
72
+ - spec/lastfm_spec.rb
73
+ - spec/method_category_spec.rb
74
+ - spec/response_spec.rb
75
+ - spec/spec_helper.rb
76
+ has_rdoc: true
77
+ homepage: http://github.com/youpy/ruby-lastfm
78
+ licenses: []
79
+
80
+ post_install_message:
81
+ rdoc_options:
82
+ - --charset=UTF-8
83
+ require_paths:
84
+ - lib
85
+ required_ruby_version: !ruby/object:Gem::Requirement
86
+ none: false
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ hash: 3
91
+ segments:
92
+ - 0
93
+ version: "0"
94
+ required_rubygems_version: !ruby/object:Gem::Requirement
95
+ none: false
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ hash: 3
100
+ segments:
101
+ - 0
102
+ version: "0"
103
+ requirements: []
104
+
105
+ rubyforge_project:
106
+ rubygems_version: 1.3.7
107
+ signing_key:
108
+ specification_version: 3
109
+ summary: A Ruby interface for Last.fm Web Services
110
+ test_files:
111
+ - spec/lastfm_spec.rb
112
+ - spec/method_category_spec.rb
113
+ - spec/response_spec.rb
114
+ - spec/spec_helper.rb