musix_match 0.1.8 → 0.1.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,19 @@
1
+ module MusixMatch
2
+ module API
3
+ class Feedback < Base
4
+ class InvalidFeedbackTypeException < Exception; end
5
+
6
+ VALID_TYPES = %w(wrong_attribution bad_characters lines_too_long wrong_verses wrong_formatting)
7
+
8
+ def post_feedback(track_id, lyrics_id, feedback)
9
+ raise InvalidFeedbackTypeException.new("Invalid feedback type. Try one of the following: #{VALID_TYPES.join(", ")}") unless VALID_TYPES.include?(feedback.to_s)
10
+ response = get('track.lyrics.feedback.post', {:track_id => track_id, :lyrics_id => lyrics_id, :feedback => feedback})
11
+ FeedbackResult.new(response)
12
+ end
13
+
14
+ def self.post_feedback(track_id, lyrics_id, feedback)
15
+ Feedback.new.post_feedback(track_id, lyrics_id, feedback)
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,21 @@
1
+ module MusixMatch
2
+ class FeedbackResult
3
+ attr_reader :status_code, :execute_time
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
+ end
14
+
15
+ def parse_response_header(response)
16
+ [:status_code, :execute_time].each do |key|
17
+ instance_variable_set "@#{key}", response['message']['header'][key.to_s]
18
+ end
19
+ end
20
+ end
21
+ end
data/lib/musix_match.rb CHANGED
@@ -18,8 +18,10 @@ musix_match_path = File.dirname(__FILE__)
18
18
  'api/search',
19
19
  'lyrics_find_result',
20
20
  'track_find_result',
21
+ 'feedback_result',
21
22
  'api/finder',
22
23
  'api/track_chart',
24
+ 'api/feedback',
23
25
  'models/track',
24
26
  'instant_lyrics'].each do |lib|
25
27
  require musix_match_path + '/musix_match/' + lib
@@ -49,5 +51,9 @@ module MusixMatch
49
51
  def self.i_m_feeling_lucky(q)
50
52
  result = MusixMatch::InstantLyrics::Search.search(q)
51
53
  result.found? ? result.lyrics.lyrics_body : 'Lyrics not found'
52
- end
54
+ end
55
+
56
+ def self.post_feedback(*args)
57
+ API::Feedback.post_feedback(*args)
58
+ end
53
59
  end
@@ -2,12 +2,12 @@ require 'spec_helper'
2
2
 
3
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
 
@@ -0,0 +1,39 @@
1
+ require 'spec_helper'
2
+
3
+ describe MusixMatch::API::Feedback do
4
+ it "should raise an exception for bad feedback type" do
5
+ lambda do
6
+ MusixMatch::API::Feedback.post_feedback(1, 1, "invalid-feedback-type")
7
+ end.should raise_error(MusixMatch::API::Feedback::InvalidFeedbackTypeException)
8
+ end
9
+
10
+ it "should call get with track.lyrics.feedback.post" do
11
+ track_id = 1
12
+ lyrics_id = 1
13
+ feedback_type = 'wrong_attribution'
14
+ feedback = MusixMatch::API::Feedback.new
15
+ feedback.should_receive(:get).with('track.lyrics.feedback.post', {:track_id => track_id, :lyrics_id => lyrics_id, :feedback => feedback_type}).and_return(load_fixture('track.lyrics.feedback.post'))
16
+ feedback.post_feedback(track_id, lyrics_id, feedback_type)
17
+ end
18
+
19
+ it "should initialize a new Feedback object" do
20
+ track_id = 1
21
+ lyrics_id = 1
22
+ feedback_type = 'wrong_attribution'
23
+ feedback = mock(MusixMatch::API::Feedback)
24
+ MusixMatch::API::Feedback.should_receive(:new).and_return(feedback)
25
+ feedback.should_receive(:post_feedback).with(track_id, lyrics_id, feedback_type)
26
+ MusixMatch::API::Feedback.post_feedback(track_id, lyrics_id, feedback_type)
27
+ end
28
+
29
+ it "should initialize a FeedbackResult" do
30
+ track_id = 1
31
+ lyrics_id = 1
32
+ feedback_type = 'wrong_attribution'
33
+ feedback = MusixMatch::API::Feedback.new
34
+ feedback_response = load_fixture('track.lyrics.feedback.post')
35
+ feedback.should_receive(:get).with('track.lyrics.feedback.post', {:track_id => track_id, :lyrics_id => lyrics_id, :feedback => feedback_type}).and_return(feedback_response)
36
+ MusixMatch::FeedbackResult.should_receive(:new).with(feedback_response)
37
+ feedback.post_feedback(track_id, lyrics_id, feedback_type)
38
+ end
39
+ end
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+
3
+ describe MusixMatch::FeedbackResult do
4
+ it 'should set status_code' do
5
+ response = load_fixture('track.lyrics.feedback.post')
6
+ result = MusixMatch::FeedbackResult.new(response)
7
+ result.status_code.should == 200
8
+ end
9
+
10
+ it 'should set execute_time' do
11
+ response = load_fixture('track.lyrics.feedback.post')
12
+ result = MusixMatch::FeedbackResult.new(response)
13
+ result.execute_time.should == 0.137812137604
14
+ end
15
+ end
@@ -41,4 +41,12 @@ describe MusixMatch do
41
41
  MusixMatch::InstantLyrics::Search.should_receive(:search).with(q).and_return(result)
42
42
  MusixMatch.i_m_feeling_lucky(q)
43
43
  end
44
+
45
+ it "should call post_feedback on Feedback" do
46
+ track_id = 1
47
+ lyrics_id = 1
48
+ feedback_type = 'wrong_attribution'
49
+ MusixMatch::API::Feedback.should_receive(:post_feedback).with(track_id, lyrics_id, feedback_type)
50
+ MusixMatch.post_feedback(track_id, lyrics_id, feedback_type)
51
+ end
44
52
  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: 11
4
+ hash: 9
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 8
10
- version: 0.1.8
9
+ - 9
10
+ version: 0.1.9
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-17 00:00:00 -05:00
18
+ date: 2010-11-27 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -63,9 +63,11 @@ files:
63
63
  - Rakefile
64
64
  - lib/musix_match.rb
65
65
  - lib/musix_match/api/base.rb
66
+ - lib/musix_match/api/feedback.rb
66
67
  - lib/musix_match/api/finder.rb
67
68
  - lib/musix_match/api/search.rb
68
69
  - lib/musix_match/api/track_chart.rb
70
+ - lib/musix_match/feedback_result.rb
69
71
  - lib/musix_match/instant_lyrics.rb
70
72
  - lib/musix_match/lyrics_find_result.rb
71
73
  - lib/musix_match/lyrics_search_result.rb
@@ -76,9 +78,11 @@ files:
76
78
  - lib/musix_match/track_find_result.rb
77
79
  - lib/musix_match/track_search_result.rb
78
80
  - spec/api/base_spec.rb
81
+ - spec/api/feedback_spec.rb
79
82
  - spec/api/finder_spec.rb
80
83
  - spec/api/search_spec.rb
81
84
  - spec/api/track_chart_spec.rb
85
+ - spec/feedback_result_spec.rb
82
86
  - spec/lyrics_find_result_spec.rb
83
87
  - spec/lyrics_search_result_spec.rb
84
88
  - spec/models/lyrics_spec.rb
@@ -124,9 +128,11 @@ specification_version: 3
124
128
  summary: API wrapper for musixmatch.com API's
125
129
  test_files:
126
130
  - spec/api/base_spec.rb
131
+ - spec/api/feedback_spec.rb
127
132
  - spec/api/finder_spec.rb
128
133
  - spec/api/search_spec.rb
129
134
  - spec/api/track_chart_spec.rb
135
+ - spec/feedback_result_spec.rb
130
136
  - spec/lyrics_find_result_spec.rb
131
137
  - spec/lyrics_search_result_spec.rb
132
138
  - spec/models/lyrics_spec.rb