Skip to content

Commit

Permalink
Merge pull request youpy#42 from morion4000/master
Browse files Browse the repository at this point in the history
Added a new method category: chart and a new method: get_hyped_artists
  • Loading branch information
youpy committed Nov 18, 2012
2 parents f134563 + fc40501 commit ff7c538
Show file tree
Hide file tree
Showing 5 changed files with 165 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.rdoc
Expand Up @@ -100,6 +100,10 @@ It supports methods which require {authentication}[http://www.last.fm/api/authen
* {library.getArtists}[http://www.lastfm.jp/api/show?service=322]
* {library.getTracks}[http://www.last.fm/api/show/library.getTracks]

=== Chart

* {chart.getHypedArtists}[http://www.lastfm.jp/api/show/chart.getHypedArtists]

== Installation

=== Archive Installation
Expand Down
5 changes: 5 additions & 0 deletions lib/lastfm.rb
Expand Up @@ -16,6 +16,7 @@
require 'lastfm/method_category/tasteometer'
require 'lastfm/method_category/track'
require 'lastfm/method_category/user'
require 'lastfm/method_category/chart'

class Lastfm
API_ROOT = 'http://ws.audioscrobbler.com/2.0'
Expand Down Expand Up @@ -80,6 +81,10 @@ def user
MethodCategory::User.new(self)
end

def chart
MethodCategory::Chart.new(self)
end

def request(method, params = {}, http_method = :get, with_signature = false, with_session = false)
params[:method] = method
params[:api_key] = @api_key
Expand Down
9 changes: 9 additions & 0 deletions lib/lastfm/method_category/chart.rb
@@ -0,0 +1,9 @@
class Lastfm
module MethodCategory
class Chart < Base
regular_method :get_hyped_artists, [], [[:page, nil], [:limit, nil]] do |response|
response.xml['artists']['artist']
end
end
end
end
126 changes: 126 additions & 0 deletions spec/fixtures/chart_get_hyped_artists.xml
@@ -0,0 +1,126 @@

<?xml version="1.0" encoding="utf-8"?>
<lfm status="ok">
<artists page="3" perPage="10" totalPages="50" total="500">
<artist>
<name>Noonie Bao</name>
<percentagechange>240</percentagechange>
<mbid></mbid>
<url>http://www.last.fm/music/Noonie+Bao</url>
<streamable>0</streamable>
<image size="small">http://userserve-ak.last.fm/serve/34/83515811.jpg</image>
<image size="medium">http://userserve-ak.last.fm/serve/64/83515811.jpg</image>
<image size="large">http://userserve-ak.last.fm/serve/126/83515811.jpg</image>
<image size="extralarge">http://userserve-ak.last.fm/serve/252/83515811.jpg</image>
<image size="mega">http://userserve-ak.last.fm/serve/_/83515811/Noonie+Bao+Noonie_Bao_photo_by_Morgan_Nor.jpg</image>
</artist>
<artist>
<name>Let The Sky Fall</name>
<percentagechange>238</percentagechange>
<mbid></mbid>
<url>http://www.last.fm/music/Let+The+Sky+Fall</url>
<streamable>0</streamable>
<image size="small">http://userserve-ak.last.fm/serve/34/83252315.jpg</image>
<image size="medium">http://userserve-ak.last.fm/serve/64/83252315.jpg</image>
<image size="large">http://userserve-ak.last.fm/serve/126/83252315.jpg</image>
<image size="extralarge">http://userserve-ak.last.fm/serve/252/83252315.jpg</image>
<image size="mega">http://userserve-ak.last.fm/serve/500/83252315/Let+The+Sky+Fall+SKYFALLUKPOSTER_650.jpg</image>
</artist>
<artist>
<name>Early Graves</name>
<percentagechange>231</percentagechange>
<mbid>ddacb291-52ff-40a8-8cce-0ddfa535ce4a</mbid>
<url>http://www.last.fm/music/Early+Graves</url>
<streamable>1</streamable>
<image size="small">http://userserve-ak.last.fm/serve/34/37235129.jpg</image>
<image size="medium">http://userserve-ak.last.fm/serve/64/37235129.jpg</image>
<image size="large">http://userserve-ak.last.fm/serve/126/37235129.jpg</image>
<image size="extralarge">http://userserve-ak.last.fm/serve/252/37235129.jpg</image>
<image size="mega">http://userserve-ak.last.fm/serve/_/37235129/Early+Graves.jpg</image>
</artist>
<artist>
<name>Concrete Knives</name>
<percentagechange>229</percentagechange>
<mbid>75296680-d93b-43ea-b8ac-8695262e4b1d</mbid>
<url>http://www.last.fm/music/Concrete+Knives</url>
<streamable>0</streamable>
<image size="small">http://userserve-ak.last.fm/serve/34/60292433.jpg</image>
<image size="medium">http://userserve-ak.last.fm/serve/64/60292433.jpg</image>
<image size="large">http://userserve-ak.last.fm/serve/126/60292433.jpg</image>
<image size="extralarge">http://userserve-ak.last.fm/serve/252/60292433.jpg</image>
<image size="mega">http://userserve-ak.last.fm/serve/500/60292433/Concrete+Knives+Live++la+Cave+aux+potes+Roubai.jpg</image>
</artist>
<artist>
<name>The Soft Moon</name>
<percentagechange>226</percentagechange>
<mbid>93eba14e-f85c-4d39-8412-5e4018c89d75</mbid>
<url>http://www.last.fm/music/The+Soft+Moon</url>
<streamable>1</streamable>
<image size="small">http://userserve-ak.last.fm/serve/34/64608131.jpg</image>
<image size="medium">http://userserve-ak.last.fm/serve/64/64608131.jpg</image>
<image size="large">http://userserve-ak.last.fm/serve/126/64608131.jpg</image>
<image size="extralarge">http://userserve-ak.last.fm/serve/252/64608131.jpg</image>
<image size="mega">http://userserve-ak.last.fm/serve/500/64608131/The+Soft+Moon+259306_10150195557771316_15967.jpg</image>
</artist>
<artist>
<name>Daley</name>
<percentagechange>215</percentagechange>
<mbid>baca710e-7df7-40e1-8d39-464543e5dc3d</mbid>
<url>http://www.last.fm/music/Daley</url>
<streamable>1</streamable>
<image size="small">http://userserve-ak.last.fm/serve/34/72621822.png</image>
<image size="medium">http://userserve-ak.last.fm/serve/64/72621822.png</image>
<image size="large">http://userserve-ak.last.fm/serve/126/72621822.png</image>
<image size="extralarge">http://userserve-ak.last.fm/serve/252/72621822.png</image>
<image size="mega">http://userserve-ak.last.fm/serve/500/72621822/Daley+PNG.png</image>
</artist>
<artist>
<name>Kyla La Grange</name>
<percentagechange>213</percentagechange>
<mbid>082e714f-be12-4890-ae83-6203bd9c7d2a</mbid>
<url>http://www.last.fm/music/Kyla+La+Grange</url>
<streamable>1</streamable>
<image size="small">http://userserve-ak.last.fm/serve/34/70951258.png</image>
<image size="medium">http://userserve-ak.last.fm/serve/64/70951258.png</image>
<image size="large">http://userserve-ak.last.fm/serve/126/70951258.png</image>
<image size="extralarge">http://userserve-ak.last.fm/serve/252/70951258.png</image>
<image size="mega">http://userserve-ak.last.fm/serve/500/70951258/Kyla+La+Grange+788778top.png</image>
</artist>
<artist>
<name>Sticky Fingers</name>
<percentagechange>212</percentagechange>
<mbid>7be0c0eb-7ae6-496d-a190-27cebf8b9905</mbid>
<url>http://www.last.fm/music/Sticky+Fingers</url>
<streamable>1</streamable>
<image size="small">http://userserve-ak.last.fm/serve/34/45590739.jpg</image>
<image size="medium">http://userserve-ak.last.fm/serve/64/45590739.jpg</image>
<image size="large">http://userserve-ak.last.fm/serve/126/45590739.jpg</image>
<image size="extralarge">http://userserve-ak.last.fm/serve/252/45590739.jpg</image>
<image size="mega">http://userserve-ak.last.fm/serve/_/45590739/Sticky+Fingers++on+the+road.jpg</image>
</artist>
<artist>
<name>Jackie Chain</name>
<percentagechange>211</percentagechange>
<mbid>2c9e6509-0a3b-498c-8c10-7d9b61f99d18</mbid>
<url>http://www.last.fm/music/Jackie+Chain</url>
<streamable>1</streamable>
<image size="small">http://userserve-ak.last.fm/serve/34/71569556.png</image>
<image size="medium">http://userserve-ak.last.fm/serve/64/71569556.png</image>
<image size="large">http://userserve-ak.last.fm/serve/126/71569556.png</image>
<image size="extralarge">http://userserve-ak.last.fm/serve/252/71569556.png</image>
<image size="mega">http://userserve-ak.last.fm/serve/500/71569556/Jackie+Chain.png</image>
</artist>
<artist>
<name>Stubborn Heart</name>
<percentagechange>206</percentagechange>
<mbid>5b78aa72-7b9a-4aad-a928-de83123221d9</mbid>
<url>http://www.last.fm/music/Stubborn+Heart</url>
<streamable>0</streamable>
<image size="small">http://userserve-ak.last.fm/serve/34/83532481.jpg</image>
<image size="medium">http://userserve-ak.last.fm/serve/64/83532481.jpg</image>
<image size="large">http://userserve-ak.last.fm/serve/126/83532481.jpg</image>
<image size="extralarge">http://userserve-ak.last.fm/serve/252/83532481.jpg</image>
<image size="mega">http://userserve-ak.last.fm/serve/_/83532481/Stubborn+Heart.jpg</image>
</artist>
</artists>
</lfm>
21 changes: 21 additions & 0 deletions spec/method_specs/chart_spec.rb
@@ -0,0 +1,21 @@
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')

describe '#chart' do
before { init_lastfm }

it 'should return an instance of Lastfm::Chart' do
@lastfm.chart.should be_an_instance_of(Lastfm::MethodCategory::Chart)
end

describe '#get_hyped_artists' do
it 'should get hyped artists' do
@lastfm.should_receive(:request).with('chart.getHypedArtists', {
:limit => 10,
:page => 3
}).and_return(make_response('chart_get_hyped_artists'))

hyped_artists = @lastfm.chart.get_hyped_artists(:limit => 10, :page => 3)
hyped_artists.size.should > 1
end
end
end

0 comments on commit ff7c538

Please sign in to comment.