musix_match 0.1.7 → 0.1.8
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +2 -4
- data/lib/musix_match/api/base.rb +5 -1
- data/spec/api/base_spec.rb +17 -2
- data/spec/api/finder_spec.rb +8 -9
- data/spec/lyrics_find_result_spec.rb +3 -3
- data/spec/spec_helper.rb +1 -1
- metadata +4 -4
data/Rakefile
CHANGED
data/lib/musix_match/api/base.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
module MusixMatch
|
2
2
|
module API
|
3
3
|
class AuthenticationFailedException < Exception; end
|
4
|
+
class APILimitReachedException < Exception; end
|
4
5
|
class APIKeyNotSpecifiedException < Exception; end
|
5
6
|
|
6
7
|
class Base
|
@@ -31,7 +32,10 @@ module MusixMatch
|
|
31
32
|
when String
|
32
33
|
JSON.parse(response.parsed_response)
|
33
34
|
end
|
34
|
-
|
35
|
+
case parsed_response['message']['header']['status_code']
|
36
|
+
when 401 then raise AuthenticationFailedException.new('Authentication failed, probably because of a bad API key')
|
37
|
+
when 402 then raise APILimitReachedException.new('A limit was reached, either you exceeded per hour requests limits or your balance is insufficient')
|
38
|
+
end
|
35
39
|
parsed_response
|
36
40
|
end
|
37
41
|
|
data/spec/api/base_spec.rb
CHANGED
@@ -30,7 +30,7 @@ describe MusixMatch::API::Base do
|
|
30
30
|
result.should == parsed_response
|
31
31
|
end
|
32
32
|
|
33
|
-
it "should raise an error" do
|
33
|
+
it "should raise an error AuthenticationFailedException" do
|
34
34
|
lambda do
|
35
35
|
MusixMatch::API::Base.api_key = 'API_KEY'
|
36
36
|
method = 'lyrics.search'
|
@@ -43,5 +43,20 @@ describe MusixMatch::API::Base do
|
|
43
43
|
result = MusixMatch::API::Base.get(method, params)
|
44
44
|
result.should == parsed_response
|
45
45
|
end.should raise_error(MusixMatch::API::AuthenticationFailedException)
|
46
|
-
end
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should raise an error APIAccessLimitException" do
|
49
|
+
lambda do
|
50
|
+
MusixMatch::API::Base.api_key = 'API_KEY'
|
51
|
+
method = 'lyrics.search'
|
52
|
+
params = {:q_artist => 'artist name'}
|
53
|
+
url = MusixMatch::API::Base.url_for(method, params)
|
54
|
+
response = mock(HTTParty::Response)
|
55
|
+
parsed_response = {'message' => {'header' => {'status_code' => 402}}}
|
56
|
+
response.should_receive(:parsed_response).twice.and_return(parsed_response)
|
57
|
+
HTTParty.should_receive(:get).with(url).and_return(response)
|
58
|
+
result = MusixMatch::API::Base.get(method, params)
|
59
|
+
result.should == parsed_response
|
60
|
+
end.should raise_error(MusixMatch::API::APILimitReachedException)
|
61
|
+
end
|
47
62
|
end
|
data/spec/api/finder_spec.rb
CHANGED
@@ -1,10 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe MusixMatch::API::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
|
-
|
4
|
+
|
8
5
|
it "should initialize a new Finder object and call find_lyrics" do
|
9
6
|
finder = mock(MusixMatch::API::Finder)
|
10
7
|
MusixMatch::API::Finder.should_receive(:new).and_return(finder)
|
@@ -13,12 +10,13 @@ describe MusixMatch::API::Finder do
|
|
13
10
|
MusixMatch::API::Finder.find_lyrics(lyrics_id)
|
14
11
|
end
|
15
12
|
|
16
|
-
it "should call get with lyrics.get and initialize a LyricsFindResult object" do
|
13
|
+
it "should call get with track.lyrics.get and initialize a LyricsFindResult object" do
|
17
14
|
finder = MusixMatch::API::Finder.new
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
15
|
+
track_id = 1
|
16
|
+
track_lyrics_get_response = load_fixture('track.lyrics.get')
|
17
|
+
finder.should_receive(:get).with('track.lyrics.get', :track_id => track_id).and_return(track_lyrics_get_response)
|
18
|
+
MusixMatch::LyricsFindResult.should_receive(:new).with(track_lyrics_get_response)
|
19
|
+
finder.find_lyrics(track_id)
|
22
20
|
end
|
23
21
|
|
24
22
|
it "should initialize a new Finder object and call find_track" do
|
@@ -32,6 +30,7 @@ describe MusixMatch::API::Finder do
|
|
32
30
|
it "should call get with track.get and initialize a TrackFinderResult" do
|
33
31
|
finder = MusixMatch::API::Finder.new
|
34
32
|
track_id = 1
|
33
|
+
track_find_response = load_fixture('track.get')
|
35
34
|
finder.should_receive(:get).with('track.get', :track_id => track_id).and_return(track_find_response)
|
36
35
|
MusixMatch::TrackFindResult.should_receive(:new).with(track_find_response)
|
37
36
|
finder.find_track(track_id)
|
@@ -2,19 +2,19 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe MusixMatch::LyricsFindResult do
|
4
4
|
it 'should set status_code' do
|
5
|
-
response = load_fixture('lyrics.get')
|
5
|
+
response = load_fixture('track.lyrics.get')
|
6
6
|
result = MusixMatch::LyricsFindResult.new(response)
|
7
7
|
result.status_code.should == 200
|
8
8
|
end
|
9
9
|
|
10
10
|
it 'should set execute_time' do
|
11
|
-
response = load_fixture('lyrics.get')
|
11
|
+
response = load_fixture('track.lyrics.get')
|
12
12
|
result = MusixMatch::LyricsFindResult.new(response)
|
13
13
|
result.execute_time.should == 0.025208044052
|
14
14
|
end
|
15
15
|
|
16
16
|
it 'should initialize a new lyrics with the first lyrics of lyrics_list' do
|
17
|
-
response = load_fixture('lyrics.get')
|
17
|
+
response = load_fixture('track.lyrics.get')
|
18
18
|
MusixMatch::Models::Lyrics.should_receive(:new).with(response['message']['body']['lyrics'])
|
19
19
|
MusixMatch::LyricsFindResult.new(response)
|
20
20
|
end
|
data/spec/spec_helper.rb
CHANGED
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:
|
4
|
+
hash: 11
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 8
|
10
|
+
version: 0.1.8
|
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-11-
|
18
|
+
date: 2010-11-17 00:00:00 -05:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|