Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added track.chart.get api call

  • Loading branch information...
commit 08e1cfd81c14552768ca4c60caba8f2e10fda9f4 1 parent 5f8d00e
@pilu authored
View
7 lib/musix_match.rb
@@ -19,6 +19,7 @@
'lyrics_find_result',
'track_find_result',
'api/finder',
+'api/track_chart',
'models/track',
'instant_lyrics'].each do |lib|
require musix_match_path + '/musix_match/' + lib
@@ -41,8 +42,12 @@ def self.search_track(*args)
Models::Track.search(*args)
end
+ def self.get_track_chart(*args)
+ Models::Track.get_chart(*args)
+ end
+
def self.i_m_feeling_lucky(q)
result = MusixMatch::InstantLyrics::Search.search(q)
result.found? ? result.lyrics.lyrics_body : 'Lyrics not found'
- end
+ end
end
View
14 lib/musix_match/api/track_chart.rb
@@ -0,0 +1,14 @@
+module MusixMatch
+ module API
+ class TrackChart < Base
+ def get_chart(options={})
+ response = get('track.chart.get', options)
+ TrackSearchResult.new(response)
+ end
+
+ def self.get_chart(options={})
+ TrackChart.new.get_chart(options)
+ end
+ end
+ end
+end
View
4 lib/musix_match/models/track.rb
@@ -4,6 +4,10 @@ class Track
include Model
model_with_attributes :track_id, :track_mbid, :lyrics_id, :track_name, :artist_id, :artist_mbid, :artist_name
+
+ def self.get_chart(options={})
+ API::TrackChart.get_chart(options)
+ end
end
end
end
View
4 spec/api/base_spec.rb
@@ -2,12 +2,12 @@
describe MusixMatch::API::Base do
it "should always use JSON as format" do
- expected_url = MusixMatch::API::Base::API_URL + '/lyrics.get?format=json&apikey='
+ expected_url = MusixMatch::API::Base::API_URL + '/lyrics.get?apikey=&format=json'
MusixMatch::API::Base.url_for('lyrics.get', :format => 'xml').should == expected_url
end
it "should use JSON as format even if the format key is a string" do
- expected_url = MusixMatch::API::Base::API_URL + '/lyrics.get?format=json&apikey='
+ expected_url = MusixMatch::API::Base::API_URL + '/lyrics.get?apikey=&format=json'
MusixMatch::API::Base.url_for('lyrics.get', 'format' => 'xml').should == expected_url
end
View
5 spec/api/track_chart_spec.rb
@@ -0,0 +1,5 @@
+require 'spec_helper'
+
+describe MusixMatch::API::Search do
+ it
+end
View
44 spec/fixtures/track.chart.get.json
@@ -0,0 +1,44 @@
+{
+ "message": {
+ "header": {
+ "status_code": 200,
+ "execute_time": 0.137812137604
+ },
+ "body": {
+ "track_list": [{
+ "track": {
+ "track_id": 9113737,
+ "track_mbid": "a426ebab-2000-4e1b-9e4c-bcbe62f69bb4",
+ "lyrics_id": 4261721,
+ "track_name": "Alejandro",
+ "artist_id": 378462,
+ "artist_mbid": "650e7db6-b795-4eb5-a702-5ea2fc46c848",
+ "artist_name": "Lady Gaga"
+ }
+ },
+ {
+ "track": {
+ "track_id": 8241603,
+ "track_mbid": "bf905182-12f5-44b8-8682-d0e11ca527e1",
+ "lyrics_id": 5368250,
+ "track_name": "Cry Cry",
+ "artist_id": 373202,
+ "artist_mbid": "7fcb104f-8b7e-4852-a8a8-928dc5c5a29b",
+ "artist_name": "Oceana"
+ }
+ },
+ {
+ "track": {
+ "track_id": 11328977,
+ "track_mbid": "63ca1c43-9ba9-43b3-8772-950dac6b4713",
+ "lyrics_id": 4271086,
+ "track_name": "Club Can't Handle Me (feat. David Guetta)",
+ "artist_id": 312472,
+ "artist_mbid": "4593d49a-7f67-46ba-9ec0-126bd676286f",
+ "artist_name": "Flo Rida"
+ }
+ }
+ ]
+ }
+ }
+}
View
4 spec/lyrics_search_result_spec.rb
@@ -0,0 +1,4 @@
+require 'spec_helper'
+
+describe MusixMatch::LyricsSearchResult do
+end
View
6 spec/models/track_spec.rb
@@ -13,6 +13,12 @@
MusixMatch::Models::Track.get(track_id)
end
+ it "should call get_chart on TrackChart" do
+ params = { :country => 'it' }
+ MusixMatch::API::TrackChart.should_receive(:get_chart).with(params)
+ MusixMatch::Models::Track.get_chart(params)
+ end
+
context 'when created' do
it 'should have the search class method' do
MusixMatch::Models::Track.should respond_to(:search)
View
6 spec/musix_match_spec.rb
@@ -25,6 +25,12 @@
MusixMatch.search_track(params)
end
+ it "should call get_chart on Track" do
+ params = { :country => 'it' }
+ MusixMatch::Models::Track.should_receive(:get_chart).with(params)
+ MusixMatch.get_track_chart(params)
+ end
+
it "should call search on InstantLyrics::Search" do
q = 'artist name track name'
result = mock(MusixMatch::InstantLyrics::Result)
View
5 spec/track_search_result_spec.rb
@@ -0,0 +1,5 @@
+require 'spec_helper'
+
+describe MusixMatch::TrackSearchResult do
+
+end
Please sign in to comment.
Something went wrong with that request. Please try again.