musix_match 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/LICENSE +21 -0
- data/README.rdoc +96 -0
- data/Rakefile +28 -0
- data/lib/musix_match/api/base.rb +42 -0
- data/lib/musix_match/api/finder.rb +23 -0
- data/lib/musix_match/api/search.rb +23 -0
- data/lib/musix_match/lyrics_find_result.rb +28 -0
- data/lib/musix_match/lyrics_search_result.rb +35 -0
- data/lib/musix_match/models/lyrics.rb +9 -0
- data/lib/musix_match/models/model.rb +37 -0
- data/lib/musix_match/models/track.rb +9 -0
- data/lib/musix_match/track_find_result.rb +28 -0
- data/lib/musix_match/track_search_result.rb +35 -0
- data/lib/musix_match.rb +42 -0
- data/spec/finder_spec.rb +39 -0
- data/spec/lyrics_spec.rb +51 -0
- data/spec/musix_match_spec.rb +27 -0
- data/spec/search_spec.rb +39 -0
- data/spec/spec_helper.rb +1 -0
- data/spec/track_spec.rb +69 -0
- metadata +122 -0
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
== MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2010, Andrea Franz - (http://gravityblast.com)
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
= Musix Match
|
2
|
+
|
3
|
+
_ _
|
4
|
+
| | _ _ | |
|
5
|
+
| | | | | | | |
|
6
|
+
| | _ _ | | | | _ _ | |
|
7
|
+
| || || || | MusixMatch is wrapper for the musixmatch.com API's. | || || || |
|
8
|
+
| || || || | With this library you can search for lyrics and tracks | || || || |
|
9
|
+
| | || || | using the http://musixmatch.com service. | | || || |
|
10
|
+
| | | |
|
11
|
+
| | | |
|
12
|
+
\ / \ /
|
13
|
+
---------- ----------
|
14
|
+
|
15
|
+
== Installation
|
16
|
+
|
17
|
+
gem install musix_match
|
18
|
+
|
19
|
+
== Usage
|
20
|
+
|
21
|
+
require 'musix_match'
|
22
|
+
|
23
|
+
MusixMatch::API::Base.api_key = 'YOUR_API_KEY'
|
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
|
+
* format: desired output format
|
40
|
+
* page: requested page of results
|
41
|
+
* page_size: desired number of items per result page
|
42
|
+
|
43
|
+
=== Getting lyrics
|
44
|
+
|
45
|
+
response = MusixMatch.get_lyrics(lyrics_id)
|
46
|
+
if response.status_code == 200 && lyrics = response.lyrics
|
47
|
+
puts lyrics.lyrics_body
|
48
|
+
end
|
49
|
+
|
50
|
+
=== Track search
|
51
|
+
|
52
|
+
response = MusixMatch.search_track(:q_artist => 'Pantera')
|
53
|
+
if response.status_code == 200
|
54
|
+
response.each do |track|
|
55
|
+
puts "#{track.track_id}: #{track.track_name} (#{track.artist_name})"
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
=== Getting track
|
60
|
+
|
61
|
+
response = MusixMatch.get_track(track_id)
|
62
|
+
if response.status_code == 200 && track = response.track
|
63
|
+
puts "#{track.track_name} (#{track.artist_name})"
|
64
|
+
puts "Lyrics id: #{track.lyrics_id}"
|
65
|
+
end
|
66
|
+
|
67
|
+
== Lyrics
|
68
|
+
|
69
|
+
The Lyrics object has the following attributes:
|
70
|
+
|
71
|
+
* lyrics_id
|
72
|
+
* lyrics_body
|
73
|
+
* track_name
|
74
|
+
* artist_name
|
75
|
+
|
76
|
+
== Track
|
77
|
+
|
78
|
+
The track object has the following attributes:
|
79
|
+
|
80
|
+
* track_id
|
81
|
+
* track_mbid
|
82
|
+
* lyrics_id
|
83
|
+
* track_name
|
84
|
+
* artist_id
|
85
|
+
* artist_mbid
|
86
|
+
* artist_name
|
87
|
+
|
88
|
+
== Links
|
89
|
+
|
90
|
+
* Repository: git://github.com/pilu/musix_match.git
|
91
|
+
* Musixmatch site: {musixmatch.com}[http://musixmatch.com]
|
92
|
+
* Musixmatch API: {developer.musixmatch.com}[http://developer.musixmatch.com]
|
93
|
+
|
94
|
+
== Author
|
95
|
+
|
96
|
+
Andrea Franz - {http://gravityblast.com}[http://gravityblast.com]
|
data/Rakefile
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'json'
|
3
|
+
require 'spec/rake/spectask'
|
4
|
+
|
5
|
+
Spec::Rake::SpecTask.new do |t|
|
6
|
+
t.spec_files = FileList['spec/**/*_spec.rb']
|
7
|
+
end
|
8
|
+
|
9
|
+
task :default => :spec
|
10
|
+
|
11
|
+
begin
|
12
|
+
require 'jeweler'
|
13
|
+
Jeweler::Tasks.new do |gemspec|
|
14
|
+
gemspec.name = "musix_match"
|
15
|
+
gemspec.summary = "API wrapper for musixmatch.com API's"
|
16
|
+
gemspec.description = "API wrapper for musixmatch.com API's"
|
17
|
+
gemspec.email = "andrea@gravityblast.com"
|
18
|
+
gemspec.homepage = "http://github.com/pilu/musix_match"
|
19
|
+
gemspec.authors = ["Andrea Franz"]
|
20
|
+
gemspec.files = FileList['LICENSE', 'README.rdoc', 'Rakefile', 'lib/**/*.rb', 'spec/**/*.rb']
|
21
|
+
gemspec.add_dependency('json')
|
22
|
+
gemspec.add_dependency('httparty', '>= 0.6.1')
|
23
|
+
gemspec.extra_rdoc_files = ['README.rdoc', 'LICENSE']
|
24
|
+
gemspec.rdoc_options = ['--main=README.rdoc', '--charset=UTF-8']
|
25
|
+
end
|
26
|
+
rescue LoadError
|
27
|
+
puts "Jeweler not available. Install it with: gem install jeweler"
|
28
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module MusixMatch
|
2
|
+
module API
|
3
|
+
class APIKeyNotSpecifiedException < Exception; end
|
4
|
+
|
5
|
+
class Base
|
6
|
+
API_URL = 'http://api.musixmatch.com/ws/1.0'
|
7
|
+
|
8
|
+
def self.api_key=(value)
|
9
|
+
@@api_key = value
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.api_key
|
13
|
+
class_variable_defined?("@@api_key") ? @@api_key : nil
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.url_for(method, params={})
|
17
|
+
params.merge!({ :apikey => api_key })
|
18
|
+
url_params = params.collect{|k, v| "#{k}=#{v}"}.join('&')
|
19
|
+
URI.escape("#{API_URL}/#{method}?#{url_params}")
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.get(method, params={})
|
23
|
+
raise APIKeyNotSpecifiedException.new('You must specify the API key. MusixMatch::API::Base.api_key = "YOUR_API_KEY"') if api_key.nil?
|
24
|
+
response = HTTParty.get(url_for(method, params))
|
25
|
+
case response.parsed_response
|
26
|
+
when Hash
|
27
|
+
response.parsed_response
|
28
|
+
when String
|
29
|
+
JSON.parse(response.parsed_response)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def api_key
|
34
|
+
self.class.api_key
|
35
|
+
end
|
36
|
+
|
37
|
+
def get(method, params={})
|
38
|
+
self.class.get(method, params)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module MusixMatch
|
2
|
+
module API
|
3
|
+
class Finder < Base
|
4
|
+
def find_lyrics(lyrics_id)
|
5
|
+
response = get('lyrics.get', {:lyrics_id => lyrics_id})
|
6
|
+
LyricsFindResult.new(response)
|
7
|
+
end
|
8
|
+
|
9
|
+
def find_track(track_id)
|
10
|
+
response = get('track.get', {:track_id => track_id})
|
11
|
+
TrackFindResult.new(response)
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.find_lyrics(lyrics_id)
|
15
|
+
Finder.new.find_lyrics(lyrics_id)
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.find_track(track_id)
|
19
|
+
Finder.new.find_track(track_id)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module MusixMatch
|
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
|
+
|
9
|
+
def search_track(options={})
|
10
|
+
response = get('track.search', options)
|
11
|
+
TrackSearchResult.new(response)
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.search_lyrics(options={})
|
15
|
+
Search.new.search_lyrics(options)
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.search_track(options={})
|
19
|
+
Search.new.search_track(options)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module MusixMatch
|
2
|
+
class LyricsFindResult
|
3
|
+
attr_reader :status_code, :execute_time, :lyrics
|
4
|
+
|
5
|
+
def initialize(response)
|
6
|
+
parse_response(response)
|
7
|
+
end
|
8
|
+
|
9
|
+
protected
|
10
|
+
|
11
|
+
def parse_response(response)
|
12
|
+
parse_response_header(response)
|
13
|
+
parse_response_body(response)
|
14
|
+
end
|
15
|
+
|
16
|
+
def parse_response_header(response)
|
17
|
+
[:status_code, :execute_time].each do |key|
|
18
|
+
instance_variable_set "@#{key}", response['message']['header'][key.to_s]
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def parse_response_body(response)
|
23
|
+
if status_code == 200
|
24
|
+
@lyrics = Models::Lyrics.new(response['message']['body']['lyrics_list']['lyrics'])
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module MusixMatch
|
2
|
+
class LyricsSearchResult
|
3
|
+
attr_reader :status_code, :execute_time, :available
|
4
|
+
|
5
|
+
def initialize(response)
|
6
|
+
@lyrics_list = []
|
7
|
+
parse_response(response)
|
8
|
+
end
|
9
|
+
|
10
|
+
def each
|
11
|
+
@lyrics_list.each do |lyrics|
|
12
|
+
yield lyrics
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
protected
|
17
|
+
|
18
|
+
def parse_response(response)
|
19
|
+
parse_response_header(response)
|
20
|
+
parse_response_body(response)
|
21
|
+
end
|
22
|
+
|
23
|
+
def parse_response_header(response)
|
24
|
+
[:status_code, :execute_time, :available].each do |key|
|
25
|
+
instance_variable_set "@#{key}", response['message']['header'][key.to_s]
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def parse_response_body(response)
|
30
|
+
response['message']['body']['lyrics_list'].each do |obj|
|
31
|
+
@lyrics_list << Models::Lyrics.new(obj['lyrics'])
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module MusixMatch
|
2
|
+
module Models
|
3
|
+
module Model
|
4
|
+
def self.included(base)
|
5
|
+
base.send(:extend, ClassMethods)
|
6
|
+
ModelBuilder.build_constructor(self)
|
7
|
+
end
|
8
|
+
|
9
|
+
module ClassMethods
|
10
|
+
def model_with_attributes(*attributes)
|
11
|
+
attr_accessor(*attributes)
|
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
|
18
|
+
|
19
|
+
def get(item_id)
|
20
|
+
API::Finder.send("find_#{self.name.split('::').last.downcase}", item_id)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
module ModelBuilder
|
26
|
+
def self.build_constructor(base, *attributes)
|
27
|
+
initialize_method = Proc.new do |*params|
|
28
|
+
model_params = params.first || {}
|
29
|
+
attributes.each do |attribute|
|
30
|
+
instance_variable_set("@#{attribute}", model_params.delete(attribute.to_s))
|
31
|
+
end
|
32
|
+
end
|
33
|
+
base.send(:define_method, :initialize, &initialize_method)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module MusixMatch
|
2
|
+
class TrackFindResult
|
3
|
+
attr_reader :status_code, :execute_time, :track
|
4
|
+
|
5
|
+
def initialize(response)
|
6
|
+
parse_response(response)
|
7
|
+
end
|
8
|
+
|
9
|
+
protected
|
10
|
+
|
11
|
+
def parse_response(response)
|
12
|
+
parse_response_header(response)
|
13
|
+
parse_response_body(response)
|
14
|
+
end
|
15
|
+
|
16
|
+
def parse_response_header(response)
|
17
|
+
[:status_code, :execute_time].each do |key|
|
18
|
+
instance_variable_set "@#{key}", response['message']['header'][key.to_s]
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def parse_response_body(response)
|
23
|
+
if status_code == 200
|
24
|
+
@track = Models::Track.new(response['message']['body']['track_list']['track'])
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module MusixMatch
|
2
|
+
class TrackSearchResult
|
3
|
+
attr_reader :status_code, :execute_time, :available
|
4
|
+
|
5
|
+
def initialize(response)
|
6
|
+
@track_list = []
|
7
|
+
parse_response(response)
|
8
|
+
end
|
9
|
+
|
10
|
+
def each
|
11
|
+
@track_list.each do |lyrics|
|
12
|
+
yield lyrics
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
protected
|
17
|
+
|
18
|
+
def parse_response(response)
|
19
|
+
parse_response_header(response)
|
20
|
+
parse_response_body(response)
|
21
|
+
end
|
22
|
+
|
23
|
+
def parse_response_header(response)
|
24
|
+
[:status_code, :execute_time, :available].each do |key|
|
25
|
+
instance_variable_set "@#{key}", response['message']['header'][key.to_s]
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def parse_response_body(response)
|
30
|
+
response['message']['body']['track_list'].each do |obj|
|
31
|
+
@track_list << Models::Track.new(obj['track'])
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/lib/musix_match.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'uri'
|
2
|
+
|
3
|
+
gem_libs = %w(json httparty)
|
4
|
+
begin
|
5
|
+
gem_libs.each{|lib| require lib}
|
6
|
+
rescue LoadError
|
7
|
+
require 'rubygems'
|
8
|
+
gem_libs.each{|lib| require lib}
|
9
|
+
end
|
10
|
+
|
11
|
+
musix_match_path = File.dirname(__FILE__)
|
12
|
+
|
13
|
+
['api/base',
|
14
|
+
'models/model',
|
15
|
+
'models/lyrics',
|
16
|
+
'lyrics_search_result',
|
17
|
+
'track_search_result',
|
18
|
+
'api/search',
|
19
|
+
'lyrics_find_result',
|
20
|
+
'track_find_result',
|
21
|
+
'api/finder',
|
22
|
+
'models/track'].each do |lib|
|
23
|
+
require musix_match_path + '/musix_match/' + lib
|
24
|
+
end
|
25
|
+
|
26
|
+
module MusixMatch
|
27
|
+
def self.get_lyrics(*args)
|
28
|
+
Models::Lyrics.get(*args)
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.search_lyrics(*args)
|
32
|
+
Models::Lyrics.search(*args)
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.get_track(*args)
|
36
|
+
Models::Track.get(*args)
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.search_track(*args)
|
40
|
+
Models::Track.search(*args)
|
41
|
+
end
|
42
|
+
end
|
data/spec/finder_spec.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Finder' do
|
4
|
+
|
5
|
+
lyrics_find_response = {'message' => {'body' => {'lyrics_list' => {'lyrics' => {}}}, 'header' => { 'status_code' => 200, 'execute_time' => 1 }}}
|
6
|
+
track_find_response = {'message' => {'body' => {'track_list' => {'track' => {}} }, 'header' => { 'status_code' => 200, 'execute_time' => 1 }}}
|
7
|
+
|
8
|
+
it "should initialize a new Finder object and call find_lyrics" do
|
9
|
+
finder = mock(MusixMatch::API::Finder)
|
10
|
+
MusixMatch::API::Finder.should_receive(:new).and_return(finder)
|
11
|
+
lyrics_id = 1
|
12
|
+
finder.should_receive(:find_lyrics).with(lyrics_id)
|
13
|
+
MusixMatch::API::Finder.find_lyrics(lyrics_id)
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should call get with lyrics.get and initialize a LyricsFindResult object" do
|
17
|
+
finder = MusixMatch::API::Finder.new
|
18
|
+
lyrics_id = 1
|
19
|
+
finder.should_receive(:get).with('lyrics.get', :lyrics_id => lyrics_id).and_return(lyrics_find_response)
|
20
|
+
MusixMatch::LyricsFindResult.should_receive(:new).with(lyrics_find_response)
|
21
|
+
finder.find_lyrics(lyrics_id)
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should initialize a new Finder object and call find_track" do
|
25
|
+
finder = mock(MusixMatch::API::Finder)
|
26
|
+
MusixMatch::API::Finder.should_receive(:new).and_return(finder)
|
27
|
+
track_id = 1
|
28
|
+
finder.should_receive(:find_track).with(track_id)
|
29
|
+
MusixMatch::API::Finder.find_track(track_id)
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should call get with track.get and initialize a TrackFinderResult" do
|
33
|
+
finder = MusixMatch::API::Finder.new
|
34
|
+
track_id = 1
|
35
|
+
finder.should_receive(:get).with('track.get', :track_id => track_id).and_return(track_find_response)
|
36
|
+
MusixMatch::TrackFindResult.should_receive(:new).with(track_find_response)
|
37
|
+
finder.find_track(track_id)
|
38
|
+
end
|
39
|
+
end
|
data/spec/lyrics_spec.rb
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe '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
|
+
|
10
|
+
it 'should call find_lyrics on Finder class' do
|
11
|
+
lyrics_id = 1
|
12
|
+
MusixMatch::API::Finder.should_receive(:find_lyrics).with(lyrics_id)
|
13
|
+
MusixMatch::Models::Lyrics.get(lyrics_id)
|
14
|
+
end
|
15
|
+
|
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
|
+
|
21
|
+
it 'should have the get class method' do
|
22
|
+
MusixMatch::Models::Lyrics.should respond_to(:get)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
context 'when initialized' do
|
27
|
+
it 'should set lyrics_id' do
|
28
|
+
lyrics_id = 1
|
29
|
+
lyrics = MusixMatch::Models::Lyrics.new('lyrics_id' => lyrics_id)
|
30
|
+
lyrics.lyrics_id.should == lyrics_id
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'should set lyrics_body' do
|
34
|
+
lyrics_body = "lyrics body"
|
35
|
+
lyrics = MusixMatch::Models::Lyrics.new('lyrics_body' => lyrics_body)
|
36
|
+
lyrics.lyrics_body.should == lyrics_body
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'should set track_name' do
|
40
|
+
track_name = "track name"
|
41
|
+
lyrics = MusixMatch::Models::Lyrics.new('track_name' => track_name)
|
42
|
+
lyrics.track_name.should == track_name
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'should set artist_name' do
|
46
|
+
artist_name = "artist name"
|
47
|
+
lyrics = MusixMatch::Models::Lyrics.new('artist_name' => artist_name)
|
48
|
+
lyrics.artist_name.should == artist_name
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'MusixMatch' do
|
4
|
+
it "should call get on Lyrics" do
|
5
|
+
lyrics_id = 1
|
6
|
+
MusixMatch::Models::Lyrics.should_receive(:get).with(lyrics_id)
|
7
|
+
MusixMatch.get_lyrics(lyrics_id)
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should call get on Track" do
|
11
|
+
track_id = 1
|
12
|
+
MusixMatch::Models::Track.should_receive(:get).with(track_id)
|
13
|
+
MusixMatch.get_track(track_id)
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should call search on Lyrics" do
|
17
|
+
params = { :q_artist => 'artist name' }
|
18
|
+
MusixMatch::Models::Lyrics.should_receive(:search).with(params)
|
19
|
+
MusixMatch.search_lyrics(params)
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should call search on Track" do
|
23
|
+
params = { :q_artist => 'artist name' }
|
24
|
+
MusixMatch::Models::Track.should_receive(:search).with(params)
|
25
|
+
MusixMatch.search_track(params)
|
26
|
+
end
|
27
|
+
end
|
data/spec/search_spec.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Search' do
|
4
|
+
|
5
|
+
lyrics_search_response = {'message' => {'body' => {'lyrics_list' => []}, 'header' => { 'status_code' => 200, 'execute_time' => 1, 'available' => 10 }}}
|
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
|
23
|
+
|
24
|
+
it "should initialize a new Search object and call search_track" do
|
25
|
+
search = mock(MusixMatch::API::Search)
|
26
|
+
MusixMatch::API::Search.should_receive(:new).and_return(search)
|
27
|
+
options = { :q_artist => 'artist name' }
|
28
|
+
search.should_receive(:search_track).with(options)
|
29
|
+
MusixMatch::API::Search.search_track(options)
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should call get with track.search and initialize a TrackSearchResult" do
|
33
|
+
search = MusixMatch::API::Search.new
|
34
|
+
options = { :q_artist => 'artist name' }
|
35
|
+
search.should_receive(:get).with('track.search', options).and_return(track_search_response)
|
36
|
+
MusixMatch::TrackSearchResult.should_receive(:new).with(track_search_response)
|
37
|
+
search.search_track(options)
|
38
|
+
end
|
39
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../lib/musix_match'
|
data/spec/track_spec.rb
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Track' do
|
4
|
+
it 'should call search_track on Search class' do
|
5
|
+
params = { :q_artist => 'artist name' }
|
6
|
+
MusixMatch::API::Search.should_receive(:search_track).with(params)
|
7
|
+
MusixMatch::Models::Track.search(params)
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'should call find_track on Finder class' do
|
11
|
+
track_id = 1
|
12
|
+
MusixMatch::API::Finder.should_receive(:find_track).with(track_id)
|
13
|
+
MusixMatch::Models::Track.get(track_id)
|
14
|
+
end
|
15
|
+
|
16
|
+
context 'when created' do
|
17
|
+
it 'should have the search class method' do
|
18
|
+
MusixMatch::Models::Track.should respond_to(:search)
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'should have the get class method' do
|
22
|
+
MusixMatch::Models::Track.should respond_to(:get)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
context 'when initialized' do
|
27
|
+
it 'should set track_id' do
|
28
|
+
track_id = 1
|
29
|
+
track = MusixMatch::Models::Track.new('track_id' => track_id)
|
30
|
+
track.track_id.should == track_id
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'should set track_mbid' do
|
34
|
+
track_mbid = 1
|
35
|
+
track = MusixMatch::Models::Track.new('track_mbid' => track_mbid)
|
36
|
+
track.track_mbid.should == track_mbid
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'should set lyrics_id' do
|
40
|
+
lyrics_id = 1
|
41
|
+
track = MusixMatch::Models::Track.new('lyrics_id' => lyrics_id)
|
42
|
+
track.lyrics_id.should == lyrics_id
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'should set track_name' do
|
46
|
+
track_name = "track name"
|
47
|
+
track = MusixMatch::Models::Track.new('track_name' => track_name)
|
48
|
+
track.track_name.should == track_name
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'should set artist_id' do
|
52
|
+
artist_id = 1
|
53
|
+
track = MusixMatch::Models::Track.new('artist_id' => artist_id)
|
54
|
+
track.artist_id.should == artist_id
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'should set artist_mbid' do
|
58
|
+
artist_mbid = 1
|
59
|
+
track = MusixMatch::Models::Track.new('artist_mbid' => artist_mbid)
|
60
|
+
track.artist_mbid.should == artist_mbid
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'should set artist_name' do
|
64
|
+
artist_name = "artist name"
|
65
|
+
track = MusixMatch::Models::Track.new('artist_name' => artist_name)
|
66
|
+
track.artist_name.should == artist_name
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
metadata
ADDED
@@ -0,0 +1,122 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: musix_match
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Andrea Franz
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-09-20 00:00:00 +02:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: json
|
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: :runtime
|
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: 5
|
44
|
+
segments:
|
45
|
+
- 0
|
46
|
+
- 6
|
47
|
+
- 1
|
48
|
+
version: 0.6.1
|
49
|
+
type: :runtime
|
50
|
+
version_requirements: *id002
|
51
|
+
description: API wrapper for musixmatch.com API's
|
52
|
+
email: andrea@gravityblast.com
|
53
|
+
executables: []
|
54
|
+
|
55
|
+
extensions: []
|
56
|
+
|
57
|
+
extra_rdoc_files:
|
58
|
+
- LICENSE
|
59
|
+
- README.rdoc
|
60
|
+
files:
|
61
|
+
- LICENSE
|
62
|
+
- README.rdoc
|
63
|
+
- Rakefile
|
64
|
+
- lib/musix_match.rb
|
65
|
+
- lib/musix_match/api/base.rb
|
66
|
+
- lib/musix_match/api/finder.rb
|
67
|
+
- lib/musix_match/api/search.rb
|
68
|
+
- lib/musix_match/lyrics_find_result.rb
|
69
|
+
- lib/musix_match/lyrics_search_result.rb
|
70
|
+
- lib/musix_match/models/lyrics.rb
|
71
|
+
- lib/musix_match/models/model.rb
|
72
|
+
- lib/musix_match/models/track.rb
|
73
|
+
- lib/musix_match/track_find_result.rb
|
74
|
+
- lib/musix_match/track_search_result.rb
|
75
|
+
- spec/finder_spec.rb
|
76
|
+
- spec/lyrics_spec.rb
|
77
|
+
- spec/musix_match_spec.rb
|
78
|
+
- spec/search_spec.rb
|
79
|
+
- spec/spec_helper.rb
|
80
|
+
- spec/track_spec.rb
|
81
|
+
has_rdoc: true
|
82
|
+
homepage: http://github.com/pilu/musix_match
|
83
|
+
licenses: []
|
84
|
+
|
85
|
+
post_install_message:
|
86
|
+
rdoc_options:
|
87
|
+
- --main=README.rdoc
|
88
|
+
- --charset=UTF-8
|
89
|
+
require_paths:
|
90
|
+
- lib
|
91
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
92
|
+
none: false
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
hash: 3
|
97
|
+
segments:
|
98
|
+
- 0
|
99
|
+
version: "0"
|
100
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
101
|
+
none: false
|
102
|
+
requirements:
|
103
|
+
- - ">="
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
hash: 3
|
106
|
+
segments:
|
107
|
+
- 0
|
108
|
+
version: "0"
|
109
|
+
requirements: []
|
110
|
+
|
111
|
+
rubyforge_project:
|
112
|
+
rubygems_version: 1.3.7
|
113
|
+
signing_key:
|
114
|
+
specification_version: 3
|
115
|
+
summary: API wrapper for musixmatch.com API's
|
116
|
+
test_files:
|
117
|
+
- spec/finder_spec.rb
|
118
|
+
- spec/lyrics_spec.rb
|
119
|
+
- spec/musix_match_spec.rb
|
120
|
+
- spec/search_spec.rb
|
121
|
+
- spec/spec_helper.rb
|
122
|
+
- spec/track_spec.rb
|