musix_match 0.1.3 → 0.1.4

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/README.rdoc CHANGED
@@ -71,6 +71,10 @@ Available options for the search_track methods are:
71
71
  puts "#{track.track_name} (#{track.artist_name})"
72
72
  puts "Lyrics id: #{track.lyrics_id}"
73
73
  end
74
+
75
+ === Are you feeling lucky?
76
+
77
+ puts MusixMatch.i_m_feeling_lucky("Guns'n'Roses - Welcome to the jungle")
74
78
 
75
79
  == Lyrics
76
80
 
@@ -18,14 +18,14 @@ module MusixMatch
18
18
  end
19
19
 
20
20
  def start
21
- lyrics_id = search_lyrics
21
+ lyrics_id = search_track
22
22
  lyrics = find_lyrics(lyrics_id) if lyrics_id
23
23
  Result.new(lyrics)
24
24
  end
25
25
 
26
- def search_lyrics
27
- result = MusixMatch.search_lyrics(:q => @q)
28
- if result.status_code == 200 && lyrics = result.lyrics_list.first
26
+ def search_track
27
+ result = MusixMatch.search_track(:q => @q, :f_has_lyrics => 1)
28
+ if result.status_code == 200 && lyrics = result.track_list.first
29
29
  lyrics.lyrics_id
30
30
  end
31
31
  end
@@ -1,5 +1,5 @@
1
1
  module MusixMatch
2
- class LyricsFindResult
2
+ class LyricsFindResult
3
3
  attr_reader :status_code, :execute_time, :lyrics
4
4
 
5
5
  def initialize(response)
@@ -20,8 +20,8 @@ module MusixMatch
20
20
  end
21
21
 
22
22
  def parse_response_body(response)
23
- if status_code == 200
24
- @lyrics = Models::Lyrics.new(response['message']['body']['lyrics_list']['lyrics'])
23
+ if status_code == 200
24
+ @lyrics = Models::Lyrics.new(response['message']['body']['lyrics_list'].first['lyrics'])
25
25
  end
26
26
  end
27
27
  end
@@ -21,7 +21,7 @@ module MusixMatch
21
21
 
22
22
  def parse_response_body(response)
23
23
  if status_code == 200
24
- @track = Models::Track.new(response['message']['body']['track_list']['track'])
24
+ @track = Models::Track.new(response['message']['body']['track_list'].first['track'])
25
25
  end
26
26
  end
27
27
  end
@@ -1,13 +1,13 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe 'API::Base' do
3
+ describe MusixMatch::API::Base do
4
4
  it "should always use JSON as format" do
5
- expected_url = MusixMatch::API::Base::API_URL + '/lyrics.get?apikey=&format=json'
5
+ expected_url = MusixMatch::API::Base::API_URL + '/lyrics.get?format=json&apikey='
6
6
  MusixMatch::API::Base.url_for('lyrics.get', :format => 'xml').should == expected_url
7
7
  end
8
8
 
9
9
  it "should use JSON as format even if the format key is a string" do
10
- expected_url = MusixMatch::API::Base::API_URL + '/lyrics.get?apikey=&format=json'
10
+ expected_url = MusixMatch::API::Base::API_URL + '/lyrics.get?format=json&apikey='
11
11
  MusixMatch::API::Base.url_for('lyrics.get', 'format' => 'xml').should == expected_url
12
12
  end
13
13
 
@@ -1,9 +1,9 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe 'Finder' do
3
+ describe MusixMatch::API::Finder do
4
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 }}}
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
7
 
8
8
  it "should initialize a new Finder object and call find_lyrics" do
9
9
  finder = mock(MusixMatch::API::Finder)
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe 'Search' do
3
+ describe MusixMatch::API::Search do
4
4
 
5
5
  lyrics_search_response = {'message' => {'body' => {'lyrics_list' => []}, 'header' => { 'status_code' => 200, 'execute_time' => 1, 'available' => 10 }}}
6
6
  track_search_response = {'message' => {'body' => {'track_list' => [] }, 'header' => { 'status_code' => 200, 'execute_time' => 1, 'available' => 10 }}}
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+
3
+ describe MusixMatch::LyricsFindResult do
4
+ it 'should set status_code' do
5
+ response = load_fixture('lyrics.get')
6
+ result = MusixMatch::LyricsFindResult.new(response)
7
+ result.status_code.should == 200
8
+ end
9
+
10
+ it 'should set execute_time' do
11
+ response = load_fixture('lyrics.get')
12
+ result = MusixMatch::LyricsFindResult.new(response)
13
+ result.execute_time.should == 0.025208044052
14
+ end
15
+
16
+ it 'should initialize a new lyrics with the first lyrics of lyrics_list' do
17
+ response = load_fixture('lyrics.get')
18
+ MusixMatch::Models::Lyrics.should_receive(:new).with(response['message']['body']['lyrics_list'].first['lyrics'])
19
+ MusixMatch::LyricsFindResult.new(response)
20
+ end
21
+ end
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe 'Lyrics' do
3
+ describe MusixMatch::Models::Lyrics do
4
4
  it 'should call search_lyrics on Search class' do
5
5
  params = { :q_artist => 'artist name' }
6
6
  MusixMatch::API::Search.should_receive(:search_lyrics).with(params)
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe 'Track' do
3
+ describe MusixMatch::Models::Track do
4
4
  it 'should call search_track on Search class' do
5
5
  params = { :q_artist => 'artist name' }
6
6
  MusixMatch::API::Search.should_receive(:search_track).with(params)
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe 'MusixMatch' do
3
+ describe MusixMatch do
4
4
  it "should call get on Lyrics" do
5
5
  lyrics_id = 1
6
6
  MusixMatch::Models::Lyrics.should_receive(:get).with(lyrics_id)
data/spec/spec_helper.rb CHANGED
@@ -1 +1,9 @@
1
- require File.dirname(__FILE__) + '/../lib/musix_match'
1
+ require File.dirname(__FILE__) + '/../lib/musix_match'
2
+
3
+ Spec::Runner.configure do |config|
4
+ def load_fixture(name)
5
+ File.open(File.dirname(__FILE__) + "/fixtures/#{name}.json") do |file|
6
+ JSON.parse(file.read)
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+
3
+ describe MusixMatch::TrackFindResult do
4
+ it 'should set status_code' do
5
+ response = load_fixture('track.get')
6
+ result = MusixMatch::TrackFindResult.new(response)
7
+ result.status_code.should == 200
8
+ end
9
+
10
+ it 'should set execute_time' do
11
+ response = load_fixture('track.get')
12
+ result = MusixMatch::TrackFindResult.new(response)
13
+ result.execute_time.should == 0.0110709667206
14
+ end
15
+
16
+ it 'should initialize a new track with the first track of track_list' do
17
+ response = load_fixture('track.get')
18
+ MusixMatch::Models::Track.should_receive(:new).with(response['message']['body']['track_list'].first['track'])
19
+ MusixMatch::TrackFindResult.new(response)
20
+ end
21
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: musix_match
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 19
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 3
10
- version: 0.1.3
9
+ - 4
10
+ version: 0.1.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Andrea Franz
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-09-26 00:00:00 +02:00
18
+ date: 2010-09-28 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -73,13 +73,15 @@ files:
73
73
  - lib/musix_match/models/track.rb
74
74
  - lib/musix_match/track_find_result.rb
75
75
  - lib/musix_match/track_search_result.rb
76
- - spec/api_base_spec.rb
77
- - spec/finder_spec.rb
78
- - spec/lyrics_spec.rb
76
+ - spec/api/base_spec.rb
77
+ - spec/api/finder_spec.rb
78
+ - spec/api/search_spec.rb
79
+ - spec/lyrics_find_result_spec.rb
80
+ - spec/models/lyrics_spec.rb
81
+ - spec/models/track_spec.rb
79
82
  - spec/musix_match_spec.rb
80
- - spec/search_spec.rb
81
83
  - spec/spec_helper.rb
82
- - spec/track_spec.rb
84
+ - spec/track_find_result_spec.rb
83
85
  has_rdoc: true
84
86
  homepage: http://github.com/pilu/musix_match
85
87
  licenses: []
@@ -116,10 +118,12 @@ signing_key:
116
118
  specification_version: 3
117
119
  summary: API wrapper for musixmatch.com API's
118
120
  test_files:
119
- - spec/api_base_spec.rb
120
- - spec/finder_spec.rb
121
- - spec/lyrics_spec.rb
121
+ - spec/api/base_spec.rb
122
+ - spec/api/finder_spec.rb
123
+ - spec/api/search_spec.rb
124
+ - spec/lyrics_find_result_spec.rb
125
+ - spec/models/lyrics_spec.rb
126
+ - spec/models/track_spec.rb
122
127
  - spec/musix_match_spec.rb
123
- - spec/search_spec.rb
124
128
  - spec/spec_helper.rb
125
- - spec/track_spec.rb
129
+ - spec/track_find_result_spec.rb