echonest-ruby-api 0.0.5 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- echonest-ruby-api (0.0.4)
4
+ echonest-ruby-api (0.0.5)
5
5
  httparty
6
6
  multi_json
7
7
 
data/Guardfile CHANGED
@@ -5,5 +5,4 @@ guard 'rspec', :cli => "--color --format documentation" do
5
5
  watch(%r{^spec/.+_spec\.rb$})
6
6
  watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
7
7
  watch('spec/spec_helper.rb') { "spec" }
8
- end
9
-
8
+ end
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
- # echonest-ruby-api [![Code Climate](https://codeclimate.com/github/maxehmookau/echonest-ruby-api.png)](https://codeclimate.com/github/maxehmookau/echonest-ruby-api)
1
+ # echonest-ruby-api
2
+ [![Code Climate](https://codeclimate.com/github/maxehmookau/echonest-ruby-api.png)](https://codeclimate.com/github/maxehmookau/echonest-ruby-api)
2
3
  [![Build Status](https://travis-ci.org/maxehmookau/echonest-ruby-api.png)](https://travis-ci.org/maxehmookau/echonest-ruby-api)
3
4
  [![Dependency Status](https://gemnasium.com/maxehmookau/echonest-ruby-api.png)](https://gemnasium.com/maxehmookau/echonest-ruby-api)
4
- TODO: Everything. (also, come up with a cool name)
5
5
 
6
6
  ## Installation
7
7
 
@@ -17,7 +17,6 @@ Or install it yourself as:
17
17
 
18
18
  $ gem install echonest-ruby-api
19
19
 
20
- *That said, probably don't do any of that, since nothing works yet...*
21
20
 
22
21
  ## Usage
23
22
 
@@ -25,18 +24,46 @@ Require the gem in your file:
25
24
 
26
25
  require 'echonest-ruby-api'
27
26
 
27
+ ### Artist
28
+
29
+
28
30
  Create an instance of an object
29
31
 
30
- a = Echonest::Artist.new('Weezer', 'YOUR-API-KEY')
32
+ artist = Echonest::Artist.new('Weezer', 'YOUR-API-KEY')
33
+
34
+ Then you have access to a bunch of methods:
35
+
36
+ artist.name
37
+ artist.biographies
38
+ artist.blogs
39
+ artist.familiarity
40
+ artist.hotttnesss
41
+ artist.images
42
+ artist.songs
43
+
44
+ ### Song
45
+
46
+ Create an instance of the Song module.
47
+
48
+ song = Echonest::Song.new('YOUR-API-KEY')
49
+
50
+ Then you have access to the song/search endpoint:
51
+ *(this is where it gets clever)*
52
+
53
+ params = { mood: "sad^.5", results: 10, min_tempo: 130, max_tempo: 150 }
54
+ song.search(params)
55
+
56
+ See the full list of params [here](http://developer.echonest.com/docs/v4/song.html#search)
57
+
58
+ You can even **identify** a song simply from its fingerprint!
31
59
 
32
- Find out some stuff!
60
+ Firstly generate an [Echoprint](http://echoprint.me/) code. You'll need to run and compile this for whatever platform you're using. [echonest/echoprint-codegen](https://github.com/echonest/echoprint-codegen) Then just pass the generated code to the `song.identify` method.
33
61
 
34
- a.blogs(results: 20)
35
- a.biographies
62
+ song.idenfity(YOUR_ECHOPRINT_CODE)
36
63
 
37
- Calls will return the first result unless setting the `results` option.
64
+ Checkout `spec/song_spec.rb` for an example code.
38
65
 
39
- *Any valid option for echonest API calls will work as normal*
66
+ Note that this calls the song/identify API endpoint and does *not* support other Echoprint servers.
40
67
 
41
68
  ## Contributing
42
69
 
@@ -1,5 +1,6 @@
1
1
  require "echonest-ruby-api/version"
2
- require_relative 'artist'
2
+ require 'echonest-ruby-api/artist'
3
+ require 'echonest-ruby-api/song'
3
4
 
4
5
  module Echonest
5
6
 
@@ -1,8 +1,8 @@
1
1
  require "rubygems"
2
2
  require "bundler/setup"
3
- require 'httparty'
4
- require 'multi_json'
5
3
  require_relative 'base'
4
+ require_relative 'blog'
5
+ require_relative 'biography'
6
6
 
7
7
  module Echonest
8
8
 
@@ -17,19 +17,6 @@ module Echonest
17
17
  @name
18
18
  end
19
19
 
20
- def entity_name
21
- self.class.to_s.split('::').last.downcase
22
- end
23
-
24
- def get_response(options = {})
25
- get(endpoint, options)
26
- end
27
-
28
- def endpoint
29
- calling_method = caller[1].split('`').last[0..-2]
30
- "#{ entity_name }/#{ calling_method }"
31
- end
32
-
33
20
  def biographies(options = { results: 1 })
34
21
  response = get_response(results: options[:results], name: @name)
35
22
  biographies = []
@@ -1,6 +1,5 @@
1
- require 'artist'
2
- require 'biography'
3
- require 'blog'
1
+ require 'httparty'
2
+ require 'multi_json'
4
3
 
5
4
  module Echonest
6
5
  class Base
@@ -11,6 +10,19 @@ module Echonest
11
10
  @base_uri = "http://developer.echonest.com/api/v4/"
12
11
  end
13
12
 
13
+ def get_response(options = {})
14
+ get(endpoint, options)
15
+ end
16
+
17
+ def entity_name
18
+ self.class.to_s.split('::').last.downcase
19
+ end
20
+
21
+ def endpoint
22
+ calling_method = caller[1].split('`').last[0..-2]
23
+ "#{ entity_name }/#{ calling_method }"
24
+ end
25
+
14
26
  # Gets the base URI for all API calls
15
27
  #
16
28
  # Returns a String
@@ -43,6 +55,7 @@ module Echonest
43
55
  options.each do |key, value|
44
56
  query_string << "#{ key }=#{ value }&"
45
57
  end
58
+ #puts "#{ Base.base_uri }#{ endpoint }?api_key=#{ @api_key }&format=json&#{ query_string }"
46
59
  response = HTTParty.get("#{ Base.base_uri }#{ endpoint }?api_key=#{ @api_key }&format=json&#{ query_string }")
47
60
  json = MultiJson.load(response.body, symbolize_keys: true)
48
61
  response_code = json[:response][:status][:code]
@@ -0,0 +1,34 @@
1
+ require "rubygems"
2
+ require "bundler/setup"
3
+ require 'httparty'
4
+ require 'multi_json'
5
+ require_relative 'base'
6
+
7
+ module Echonest
8
+ class Song < Echonest::Base
9
+
10
+ def initialize(api_key)
11
+ @api_key = api_key
12
+ end
13
+
14
+ def search(options = {})
15
+ defaults = { api_key: @api_key }
16
+ response = get_response(options)
17
+ songs = []
18
+ response[:songs].each do |song|
19
+ songs << song
20
+ end
21
+ end
22
+
23
+ def identify(code)
24
+ raise ArgumentError, 'Not a valid Echoprint or ENFMP fingerprint' if code.empty?
25
+ response = get_response(code: code)
26
+ results = []
27
+ response[:songs].each do |song|
28
+ results << { score: song[:score], title: song[:title], artist_name: song[:artist_name] }
29
+ end
30
+ results
31
+ end
32
+
33
+ end
34
+ end
@@ -1,3 +1,3 @@
1
1
  module Echonest
2
- VERSION = "0.0.5"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -1,5 +1,4 @@
1
1
  require 'spec_helper'
2
- require 'base'
3
2
 
4
3
  describe Echonest::Artist do
5
4
 
@@ -0,0 +1,56 @@
1
+ require 'spec_helper'
2
+
3
+ describe Echonest::Song do
4
+
5
+ it 'should initialize correct' do
6
+ a = Echonest::Song.new('abc234')
7
+ a.should be_a Echonest::Song
8
+ end
9
+
10
+ describe '#search' do
11
+
12
+ it 'should return an array of tracks' do
13
+ a = Echonest::Song.new('BNOAEBT3IZYZI6WXI')
14
+ options = { title: 'Hello' }
15
+ a.search(options).should be_a Array
16
+ end
17
+
18
+ it 'should have the expected parameters' do
19
+ a = Echonest::Song.new('BNOAEBT3IZYZI6WXI')
20
+ options = { title: 'Hello' }
21
+ a.search(options).each do |song|
22
+ song.keys.should include :id, :artist_id, :artist_name, :title
23
+ end
24
+ end
25
+
26
+ it 'should happily find slow songs' do
27
+ a = Echonest::Song.new('BNOAEBT3IZYZI6WXI')
28
+ options = { max_tempo: 60 }
29
+ a.search(options).each do |song|
30
+ song.keys.should include :id, :artist_id, :artist_name, :title
31
+ end
32
+ end
33
+
34
+ # TODO: Write some comprehensive tests to make sure this breaks
35
+ # if the API ever changes.
36
+ # http://developer.echonest.com/docs/v4/song.html#search
37
+
38
+ end
39
+
40
+ describe '#identify' do
41
+
42
+ it 'should identify billie jean with ease' do
43
+ a = Echonest::Song.new('BNOAEBT3IZYZI6WXI')
44
+ result = a.identify('eJxVlIuNwzAMQ1fxCDL133-xo1rnGqNAEcWy_ERa2aKeZmW9ustWVYrXrl5bthn_laFkzguNWpklEmoTB74JKYZSPlbJ0sy9fQrsrbEaO9W3bsbaWOoK7IhkHFaf_ag2d75oOQSZczbz5CKA7XgTIBIXASvFi0A3W8pMUZ7FZTWTVbujCcADlQ_f_WbdRNJ2vDUwSF0EZmFvAku_CVy440fgiIvArWZZWoJ7GWd-CVTYC5FCFI8GQdECdROE20UQfLoIUmhLC7IiByF1gzbAs3tsSKctyC76MPJlHRsZ5qhSQhu_CJFcKtW4EMrHSIrpTGLFqsdItj1H9JYHQYN7W2nkC6GDPjZTAzL9dx0fS4M1FoROHh9YhLHWdRchQSd_CLTpOHkQQP3xQsA2-sLOUD7CzxU0GmHVdIxh46Oide0NrNEmjghG44Ax_k2AoDHsiV6WsiD6OFm8y-0Lyt8haDBBzeMlAnTuuGYIB4WA2lEPAWbdeOabgFN6TQMs6ctLA5fHyKMBB0veGrjPfP00IAlWNm9n7hEh5PiYYBGKQDP-x4F0CL8HkhoQnRWN997JyEpnHFR7EhLPQMZmgXS68hsHktEVErranvSSR2VwfJhQCnkuwhBUcINNY-xu1pmw3PmBqU9-8xu0kiF1ngOa8vwBSSzzNw==')
45
+ result.should be_a Array
46
+ result.first[:artist_name].should eql 'Michael Jackson'
47
+ end
48
+
49
+ it 'should raise ArgumentError if the code is blank' do
50
+ a = Echonest::Song.new('BNOAEBT3IZYZI6WXI')
51
+ expect { a.identify() }.to raise_error(ArgumentError)
52
+ end
53
+
54
+ end
55
+
56
+ end
@@ -1,6 +1,6 @@
1
1
  require 'rubygems'
2
2
  require 'bundler/setup'
3
-
3
+ require_relative '../lib/echonest-ruby-api/base.rb'
4
4
  require 'echonest-ruby-api'
5
5
 
6
6
  RSpec.configure do |config|
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: echonest-ruby-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-10 00:00:00.000000000 Z
12
+ date: 2013-02-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: httparty
@@ -125,18 +125,22 @@ files:
125
125
  - doc/js/jquery.js
126
126
  - doc/method_list.html
127
127
  - doc/top-level-namespace.html
128
+ - echonest-ruby-api-0.0.5.gem
128
129
  - echonest-ruby-api.gemspec
129
- - lib/artist.rb
130
- - lib/base.rb
131
- - lib/biography.rb
132
- - lib/blog.rb
133
130
  - lib/echonest-ruby-api.rb
131
+ - lib/echonest-ruby-api/artist.rb
132
+ - lib/echonest-ruby-api/base.rb
133
+ - lib/echonest-ruby-api/biography.rb
134
+ - lib/echonest-ruby-api/blog.rb
135
+ - lib/echonest-ruby-api/song.rb
134
136
  - lib/echonest-ruby-api/version.rb
135
137
  - pkg/echonest-ruby-api-0.0.1.gem
136
138
  - pkg/echonest-ruby-api-0.0.3.gem
137
139
  - pkg/echonest-ruby-api-0.0.4.gem
140
+ - pkg/echonest-ruby-api-0.0.5.gem
138
141
  - spec/artist_spec.rb
139
142
  - spec/base_spec.rb
143
+ - spec/song_spec.rb
140
144
  - spec/spec_helper.rb
141
145
  - tmp/rspec_guard_result
142
146
  homepage: https://github.com/maxehmookau/echonest-ruby-api
@@ -166,5 +170,6 @@ summary: A gem to get hold of some echonest stuff!
166
170
  test_files:
167
171
  - spec/artist_spec.rb
168
172
  - spec/base_spec.rb
173
+ - spec/song_spec.rb
169
174
  - spec/spec_helper.rb
170
175
  has_rdoc: