Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #40 from programble/tasteometer

Add tasteometer.compare
  • Loading branch information...
commit 92457fe7471c60736b8927d296578ec4bf8a04f0 2 parents d576901 + 9a385ad
@youpy authored
View
4 README.rdoc
@@ -52,6 +52,10 @@ It supports methods which require {authentication}[http://www.last.fm/api/authen
* {tag.getTopArtists}[http://www.lastfm.jp/api/show/tag.getTopArtists]
+=== Tasteometer
+
+* {tasteometer.compare}[http://www.lastfm.jp/api/show/tasteometer.compare]
+
=== Track
* {track.addTags}[http://www.lastfm.jp/api/show?service=304]
View
5 lib/lastfm.rb
@@ -13,6 +13,7 @@
require 'lastfm/method_category/geo'
require 'lastfm/method_category/library'
require 'lastfm/method_category/tag'
+require 'lastfm/method_category/tasteometer'
require 'lastfm/method_category/track'
require 'lastfm/method_category/user'
@@ -67,6 +68,10 @@ def tag
MethodCategory::Tag.new(self)
end
+ def tasteometer
+ MethodCategory::Tasteometer.new(self)
+ end
+
def track
MethodCategory::Track.new(self)
end
View
9 lib/lastfm/method_category/tasteometer.rb
@@ -0,0 +1,9 @@
+class Lastfm
+ module MethodCategory
+ class Tasteometer < Base
+ regular_method :compare, [:type1, :type2, :value1, :value2], [[:limit, nil]] do |response|
+ response.xml['comparison']['result']
+ end
+ end
+ end
+end
View
37 spec/fixtures/tasteometer_compare.xml
@@ -0,0 +1,37 @@
+<?xml version="1.0"?>
+<lfm status="ok">
+ <comparison>
+ <result>
+ <score>0.74</score>
+ <artists matches="43">
+ <artist>
+ <name>Radiohead</name>
+ <url>http://www.last.fm/music/Radiohead</url>
+ <image size="large">http://userserve-ak.last.fm/serve/160/169665.gif</image>
+ <image size="medium">http://userserve-ak.last.fm/serve/85/169665.gif</image>
+ <image size="small">http://userserve-ak.last.fm/serve/50/169665.gif</image>
+ </artist>
+ <artist>
+ <name>The Beatles</name>
+ <url>http://www.last.fm/music/The+Beatles</url>
+ <image size="large">http://userserve-ak.last.fm/serve/160/153358.jpg</image>
+ <image size="medium">http://userserve-ak.last.fm/serve/85/153358.jpg</image>
+ <image size="small">http://userserve-ak.last.fm/serve/50/153358.jpg</image>
+ </artist>
+ </artists>
+ </result>
+ <input>
+ <user>
+ <name>jwheare</name>
+ <url>http://www.last.fm/user/jwheare/</url>
+ <image size="large">http://userserve-ak.last.fm/serve/160/857567.png</image>
+ <image size="medium">http://userserve-ak.last.fm/serve/85/857567.png</image>
+ <image size="small">http://userserve-ak.last.fm/serve/50/857567.png</image>
+ </user>
+ <myspace>
+ <url>http://www.myspace.com/mcscrobbler</url>
+ <image>http://x.myspace.com/images/clear.gif</image>
+ </myspace>
+ </input>
+ </comparison>
+</lfm>
View
24 spec/method_specs/tasteometer_spec.rb
@@ -0,0 +1,24 @@
+require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
+
+describe '#tasteometer' do
+ before { init_lastfm }
+
+ it 'should return an instance of Lastfm::Tasteometer' do
+ @lastfm.tasteometer.should be_an_instance_of(Lastfm::MethodCategory::Tasteometer)
+ end
+
+ describe '#compare' do
+ it 'should compare users' do
+ @lastfm.should_receive(:request).with('tasteometer.compare', {
+ :type1 => 'user',
+ :type2 => 'user',
+ :value1 => 'foo',
+ :value2 => 'bar',
+ :limit => nil
+ }).and_return(make_response('tasteometer_compare'))
+ compare = @lastfm.tasteometer.compare(:type1 => 'user', :type2 => 'user', :value1 =>'foo', :value2 => 'bar')
+ compare['score'].should == '0.74'
+ compare['artists']['artist'][1]['name'].should == 'The Beatles'
+ end
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.