musix_match 0.1.15 → 0.1.16
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +8 -25
- data/lib/musix_match/api/search.rb +1 -10
- data/lib/musix_match/models/model.rb +14 -6
- data/lib/musix_match/models/track.rb +1 -0
- data/spec/api/search_spec.rb +1 -18
- data/spec/models/lyrics_spec.rb +2 -12
- metadata +1 -1
data/README.rdoc
CHANGED
@@ -22,30 +22,6 @@
|
|
22
22
|
|
23
23
|
MusixMatch::API::Base.api_key = 'YOUR_API_KEY'
|
24
24
|
|
25
|
-
=== Lyrics search
|
26
|
-
|
27
|
-
response = MusixMatch.search_lyrics(:q_artist => 'Pantera')
|
28
|
-
if response.status_code == 200
|
29
|
-
response.each do |lyrics|
|
30
|
-
puts "#{lyrics.lyrics_id}: #{lyrics.track_name} (#{lyrics.artist_name})"
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
Available options for the search_lyrics methods are:
|
35
|
-
|
36
|
-
* q: string to be searched in every data field
|
37
|
-
* q_track: string to be searched among tracks titles
|
38
|
-
* q_artist: string to be searched among artists names
|
39
|
-
* page: requested page of results
|
40
|
-
* page_size: desired number of items per result page
|
41
|
-
|
42
|
-
=== Getting lyrics
|
43
|
-
|
44
|
-
response = MusixMatch.get_lyrics(track_id)
|
45
|
-
if response.status_code == 200 && lyrics = response.lyrics
|
46
|
-
puts lyrics.lyrics_body
|
47
|
-
end
|
48
|
-
|
49
25
|
=== Track search
|
50
26
|
|
51
27
|
response = MusixMatch.search_track(:q_artist => 'Pantera')
|
@@ -54,7 +30,7 @@ Available options for the search_lyrics methods are:
|
|
54
30
|
puts "#{track.track_id}: #{track.track_name} (#{track.artist_name})"
|
55
31
|
end
|
56
32
|
end
|
57
|
-
|
33
|
+
|
58
34
|
Available options for the search_track methods are:
|
59
35
|
|
60
36
|
* q: a string that will be searched in every data field
|
@@ -64,6 +40,13 @@ Available options for the search_track methods are:
|
|
64
40
|
* page_size: desired number of items per result page
|
65
41
|
* f_has_lyrics: exclude tracks without an available lyrics
|
66
42
|
|
43
|
+
=== Getting lyrics
|
44
|
+
|
45
|
+
response = MusixMatch.get_lyrics(track_id)
|
46
|
+
if response.status_code == 200 && lyrics = response.lyrics
|
47
|
+
puts lyrics.lyrics_body
|
48
|
+
end
|
49
|
+
|
67
50
|
=== Getting track
|
68
51
|
|
69
52
|
response = MusixMatch.get_track(track_id)
|
@@ -1,20 +1,11 @@
|
|
1
1
|
module MusixMatch
|
2
2
|
module API
|
3
|
-
class Search < Base
|
4
|
-
def search_lyrics(options={})
|
5
|
-
response = get('lyrics.search', options)
|
6
|
-
LyricsSearchResult.new(response)
|
7
|
-
end
|
8
|
-
|
3
|
+
class Search < Base
|
9
4
|
def search_track(options={})
|
10
5
|
response = get('track.search', options)
|
11
6
|
TrackSearchResult.new(response)
|
12
7
|
end
|
13
8
|
|
14
|
-
def self.search_lyrics(options={})
|
15
|
-
Search.new.search_lyrics(options)
|
16
|
-
end
|
17
|
-
|
18
9
|
def self.search_track(options={})
|
19
10
|
Search.new.search_track(options)
|
20
11
|
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
module MusixMatch
|
2
|
-
module Models
|
2
|
+
module Models
|
3
3
|
module Model
|
4
4
|
def self.included(base)
|
5
5
|
base.send(:extend, ClassMethods)
|
@@ -10,11 +10,7 @@ module MusixMatch
|
|
10
10
|
def model_with_attributes(*attributes)
|
11
11
|
attr_accessor(*attributes)
|
12
12
|
ModelBuilder.build_constructor(self, *attributes)
|
13
|
-
end
|
14
|
-
|
15
|
-
def search(options={})
|
16
|
-
API::Search.send("search_#{self.name.split('::').last.downcase}", options)
|
17
|
-
end
|
13
|
+
end
|
18
14
|
|
19
15
|
def get(item_id)
|
20
16
|
API::Finder.send("find_#{self.name.split('::').last.downcase}", item_id)
|
@@ -22,6 +18,18 @@ module MusixMatch
|
|
22
18
|
end
|
23
19
|
end
|
24
20
|
|
21
|
+
module Searcher
|
22
|
+
def self.included(base)
|
23
|
+
base.send(:extend, ClassMethods)
|
24
|
+
end
|
25
|
+
|
26
|
+
module ClassMethods
|
27
|
+
def search(options={})
|
28
|
+
API::Search.send("search_#{self.name.split('::').last.downcase}", options)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
25
33
|
module ModelBuilder
|
26
34
|
def self.build_constructor(base, *attributes)
|
27
35
|
initialize_method = Proc.new do |*params|
|
@@ -2,6 +2,7 @@ module MusixMatch
|
|
2
2
|
module Models
|
3
3
|
class Track
|
4
4
|
include Model
|
5
|
+
include Searcher
|
5
6
|
|
6
7
|
model_with_attributes :track_id, :track_mbid, :track_name, :track_mbid, :track_length, :lyrics_id, :instrumental, :subtitle_id,
|
7
8
|
:artist_id, :artist_mbid, :artist_name, :artist_mbid,
|
data/spec/api/search_spec.rb
CHANGED
@@ -2,24 +2,7 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe MusixMatch::API::Search do
|
4
4
|
|
5
|
-
|
6
|
-
track_search_response = {'message' => {'body' => {'track_list' => [] }, 'header' => { 'status_code' => 200, 'execute_time' => 1, 'available' => 10 }}}
|
7
|
-
|
8
|
-
it "should initialize a new Search object and call search_lyrics" do
|
9
|
-
search = mock(MusixMatch::API::Search)
|
10
|
-
MusixMatch::API::Search.should_receive(:new).and_return(search)
|
11
|
-
options = { :q_artist => 'artist name' }
|
12
|
-
search.should_receive(:search_lyrics).with(options)
|
13
|
-
MusixMatch::API::Search.search_lyrics(options)
|
14
|
-
end
|
15
|
-
|
16
|
-
it "should call get with lyrics.search and initialize a LyricsSearchResult object" do
|
17
|
-
search = MusixMatch::API::Search.new
|
18
|
-
options = { :q_artist => 'artist name' }
|
19
|
-
search.should_receive(:get).with('lyrics.search', options).and_return(lyrics_search_response)
|
20
|
-
MusixMatch::LyricsSearchResult.should_receive(:new).with(lyrics_search_response)
|
21
|
-
search.search_lyrics(options)
|
22
|
-
end
|
5
|
+
track_search_response = {'message' => {'body' => {'track_list' => [] }, 'header' => { 'status_code' => 200, 'execute_time' => 1, 'available' => 10 }}}
|
23
6
|
|
24
7
|
it "should initialize a new Search object and call search_track" do
|
25
8
|
search = mock(MusixMatch::API::Search)
|
data/spec/models/lyrics_spec.rb
CHANGED
@@ -1,23 +1,13 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe MusixMatch::Models::Lyrics do
|
4
|
-
it 'should call search_lyrics on Search class' do
|
5
|
-
params = { :q_artist => 'artist name' }
|
6
|
-
MusixMatch::API::Search.should_receive(:search_lyrics).with(params)
|
7
|
-
MusixMatch::Models::Lyrics.search(params)
|
8
|
-
end
|
9
|
-
|
3
|
+
describe MusixMatch::Models::Lyrics do
|
10
4
|
it 'should call find_lyrics on Finder class' do
|
11
5
|
lyrics_id = 1
|
12
6
|
MusixMatch::API::Finder.should_receive(:find_lyrics).with(lyrics_id)
|
13
7
|
MusixMatch::Models::Lyrics.get(lyrics_id)
|
14
8
|
end
|
15
9
|
|
16
|
-
context 'when created' do
|
17
|
-
it 'should have the search class method' do
|
18
|
-
MusixMatch::Models::Lyrics.should respond_to(:search)
|
19
|
-
end
|
20
|
-
|
10
|
+
context 'when created' do
|
21
11
|
it 'should have the get class method' do
|
22
12
|
MusixMatch::Models::Lyrics.should respond_to(:get)
|
23
13
|
end
|