echonest-ruby-api 0.0.3

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/.gitignore ADDED
@@ -0,0 +1 @@
1
+ .DS_Store
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in echonest-ruby-api.gemspec
4
+ gemspec
5
+
6
+ gem 'rake'
data/Gemfile.lock ADDED
@@ -0,0 +1,56 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ echonest-ruby-api (0.0.3)
5
+ httparty
6
+ multi_json
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ coderay (1.0.8)
12
+ diff-lcs (1.1.3)
13
+ guard (1.6.2)
14
+ listen (>= 0.6.0)
15
+ lumberjack (>= 1.0.2)
16
+ pry (>= 0.9.10)
17
+ terminal-table (>= 1.4.3)
18
+ thor (>= 0.14.6)
19
+ guard-rspec (2.4.0)
20
+ guard (>= 1.1)
21
+ rspec (~> 2.11)
22
+ httparty (0.10.2)
23
+ multi_json (~> 1.0)
24
+ multi_xml (>= 0.5.2)
25
+ listen (0.7.2)
26
+ lumberjack (1.0.2)
27
+ method_source (0.8.1)
28
+ multi_json (1.5.0)
29
+ multi_xml (0.5.2)
30
+ pry (0.9.10)
31
+ coderay (~> 1.0.5)
32
+ method_source (~> 0.8)
33
+ slop (~> 3.3.1)
34
+ rake (10.0.3)
35
+ rb-fsevent (0.9.3)
36
+ rspec (2.12.0)
37
+ rspec-core (~> 2.12.0)
38
+ rspec-expectations (~> 2.12.0)
39
+ rspec-mocks (~> 2.12.0)
40
+ rspec-core (2.12.0)
41
+ rspec-expectations (2.12.0)
42
+ diff-lcs (~> 1.1.3)
43
+ rspec-mocks (2.12.0)
44
+ slop (3.3.3)
45
+ terminal-table (1.4.5)
46
+ thor (0.16.0)
47
+
48
+ PLATFORMS
49
+ ruby
50
+
51
+ DEPENDENCIES
52
+ echonest-ruby-api!
53
+ guard-rspec
54
+ rake
55
+ rb-fsevent (~> 0.9.1)
56
+ rspec (~> 2.6)
data/Guardfile ADDED
@@ -0,0 +1,9 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard 'rspec', :cli => "--color --format documentation" do
5
+ watch(%r{^spec/.+_spec\.rb$})
6
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
7
+ watch('spec/spec_helper.rb') { "spec" }
8
+ end
9
+
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Max Woolf
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,47 @@
1
+ # echonest-ruby-api [![Code Climate](https://codeclimate.com/github/maxehmookau/echonest-ruby-api.png)](https://codeclimate.com/github/maxehmookau/echonest-ruby-api)
2
+ [![Build Status](https://travis-ci.org/maxehmookau/echonest-ruby-api.png)](https://travis-ci.org/maxehmookau/echonest-ruby-api)
3
+ [![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
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ gem 'echonest-ruby-api'
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install echonest-ruby-api
19
+
20
+ *That said, probably don't do any of that, since nothing works yet...*
21
+
22
+ ## Usage
23
+
24
+ Require the gem in your file:
25
+
26
+ require 'echonest-ruby-api'
27
+
28
+ Create an instance of an object
29
+
30
+ a = Echonest::Artist.new('Weezer', 'YOUR-API-KEY')
31
+
32
+ Find out some stuff!
33
+
34
+ a.blogs(results: 20)
35
+ a.biographies
36
+
37
+ Calls will return the first result unless setting the `results` option.
38
+
39
+ *Any valid option for echonest API calls will work as normal*
40
+
41
+ ## Contributing
42
+
43
+ 1. Fork it
44
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
45
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
46
+ 4. Push to the branch (`git push origin my-new-feature`)
47
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rake'
3
+ require 'rspec/core/rake_task'
4
+
5
+ RSpec::Core::RakeTask.new(:spec)
6
+
7
+ task :default => :spec
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'echonest-ruby-api/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "echonest-ruby-api"
8
+ gem.version = Echonest::VERSION
9
+ gem.authors = ["Max Woolf"]
10
+ gem.email = ["max.woolf@boxuk.com"]
11
+ gem.description = "A gem to get hold of some echonest stuff!"
12
+ gem.summary = "A gem to get hold of some echonest stuff!"
13
+ gem.homepage = "http://maxehmookau.github.com"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+ gem.add_dependency('httparty')
20
+ gem.add_dependency('multi_json')
21
+ gem.add_development_dependency "rspec", "~> 2.6"
22
+ gem.add_development_dependency 'guard-rspec'
23
+ gem.add_development_dependency 'rb-fsevent', '~> 0.9.1'
24
+ end
data/lib/artist.rb ADDED
@@ -0,0 +1,83 @@
1
+ require "rubygems"
2
+ require "bundler/setup"
3
+ require 'httparty'
4
+ require 'multi_json'
5
+ require_relative 'base'
6
+
7
+ module Echonest
8
+
9
+ class Artist < Echonest::Base
10
+
11
+ def initialize(api_key, name = nil)
12
+ @name = name
13
+ @api_key = api_key
14
+ end
15
+
16
+ def name
17
+ @name
18
+ end
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
+ def biographies(options = { results: 1 })
34
+ response = get_response(results: options[:results], name: @name)
35
+ biographies = []
36
+ response[:biographies].each do |b|
37
+ biographies << Biography.new(text: b[:text], site: b[:site], url: b[:url])
38
+ end
39
+ biographies
40
+ end
41
+
42
+ def blogs(options = { results: 1 })
43
+ response = get_response(results: options[:results], name: @name)
44
+ blogs = []
45
+ response[:blogs].each do |b|
46
+ blogs << Blog.new(name: b[:name], site: b[:site], url: b[:url])
47
+ end
48
+ blogs
49
+ end
50
+
51
+ def familiarity
52
+ response = get_response(name: @name)
53
+ response[entity_name.to_sym][__method__.to_sym]
54
+ end
55
+
56
+ def hotttnesss
57
+ response = get_response(name: @name)
58
+ response[entity_name.to_sym][__method__.to_sym]
59
+ end
60
+
61
+ def images
62
+ response = get_response(name: @name)
63
+ images = []
64
+ response[:images].each do |i|
65
+ images << i[:url]
66
+ end
67
+ images
68
+ end
69
+
70
+ def list_genres
71
+ get_response[:genres]
72
+ end
73
+
74
+ def songs
75
+ songs = []
76
+ get_response(name: @name)[:songs].each do |s|
77
+ songs << { s[:id] => s[:title] }
78
+ end
79
+ songs
80
+ end
81
+
82
+ end
83
+ end
data/lib/base.rb ADDED
@@ -0,0 +1,37 @@
1
+ require 'artist'
2
+ require 'biography'
3
+ require 'blog'
4
+ require 'news'
5
+
6
+ module Echonest
7
+ class Base
8
+ class EchonestConnectionError < Exception; end
9
+
10
+ def initialize(api_key)
11
+ @api_key = api_key
12
+ @base_uri = "http://developer.echonest.com/api/v4/"
13
+ end
14
+
15
+ def self.base_uri
16
+ "http://developer.echonest.com/api/v#{ Base.version }/"
17
+ end
18
+
19
+ def self.version
20
+ 4
21
+ end
22
+
23
+ def get(endpoint, options = {})
24
+ query_string = ""
25
+ options.each do |key, value|
26
+ query_string << "#{ key }=#{ value }&"
27
+ end
28
+ response = HTTParty.get("#{ Base.base_uri }#{ endpoint }?api_key=#{ @api_key }&format=json&#{ query_string }")
29
+ json = MultiJson.load(response.body, symbolize_keys: true)
30
+ response_code = json[:response][:status][:code]
31
+
32
+ response_code.eql?(0) ? json[:response] : raise(ArgumentError, "Error code #{ response_code }")
33
+
34
+ end
35
+
36
+ end
37
+ end
data/lib/biography.rb ADDED
@@ -0,0 +1,21 @@
1
+ class Biography
2
+
3
+ def initialize(options = {})
4
+ @text = options[:text]
5
+ @site = options[:site]
6
+ @url = options[:url]
7
+ end
8
+
9
+ def text
10
+ @text
11
+ end
12
+
13
+ def site
14
+ @site
15
+ end
16
+
17
+ def url
18
+ @url
19
+ end
20
+
21
+ end
data/lib/blog.rb ADDED
@@ -0,0 +1,24 @@
1
+ class Blog
2
+ def initialize(options = {})
3
+ @name = options[:name]
4
+ @summary = options[:summary]
5
+ @url = options[:url]
6
+ @date_posted = options[:date_posted]
7
+ end
8
+
9
+ def name
10
+ @name
11
+ end
12
+
13
+ def summary
14
+ @summary
15
+ end
16
+
17
+ def url
18
+ @url
19
+ end
20
+
21
+ def date_posted
22
+ @date_posted
23
+ end
24
+ end
@@ -0,0 +1,26 @@
1
+ class News
2
+
3
+ def initialize(options = {})
4
+ @name = options[:name]
5
+ @url = options[:url]
6
+ @date_posted = options[:date_posted]
7
+ @summary = options[:summary]
8
+ end
9
+
10
+ def name
11
+ @name
12
+ end
13
+
14
+ def url
15
+ @url
16
+ end
17
+
18
+ def date_posted
19
+ @date_posted
20
+ end
21
+
22
+ def summary
23
+ @summary
24
+ end
25
+
26
+ end
@@ -0,0 +1,3 @@
1
+ module Echonest
2
+ VERSION = "0.0.3"
3
+ end
@@ -0,0 +1,6 @@
1
+ require "echonest-ruby-api/version"
2
+ require_relative 'artist'
3
+
4
+ module Echonest
5
+
6
+ end
data/lib/news.rb ADDED
@@ -0,0 +1,4 @@
1
+ module Echonest
2
+ class News
3
+ end
4
+ end
Binary file
Binary file
@@ -0,0 +1,124 @@
1
+ require 'spec_helper'
2
+ require 'base'
3
+
4
+ describe Echonest::Artist do
5
+
6
+ def create_valid_artist
7
+ @a = Echonest::Artist.new('BNOAEBT3IZYZI6WXI', 'Weezer')
8
+ end
9
+
10
+
11
+ it 'should allow an Artist to have a name' do
12
+ a = Echonest::Artist.new('12345', 'Weezer')
13
+ a.name.should eql 'Weezer'
14
+ end
15
+
16
+ describe '#entity_name' do
17
+
18
+ it 'should always return artist' do
19
+ a = Echonest::Artist.new('Weezer', '12345')
20
+ a.entity_name.should eql 'artist'
21
+ end
22
+
23
+ end
24
+
25
+ describe '#biographies' do
26
+
27
+ it 'should download a specified number of biographies' do
28
+ create_valid_artist
29
+ @a.biographies(results: 10).count.should be 10
30
+ end
31
+
32
+ it 'should return one biography by default' do
33
+ create_valid_artist
34
+ @a.biographies.count.should be 1
35
+ end
36
+
37
+ it 'should deal gracefully with an invalid API key' do
38
+ a = Echonest::Artist.new('Weezer', 'THISISNOTAKEY')
39
+ expect { a.biographies }.to raise_error(ArgumentError)
40
+ end
41
+
42
+ end
43
+
44
+ describe '#blogs' do
45
+
46
+ it 'should download a specified number of blogs' do
47
+ create_valid_artist
48
+ @a.blogs(results: 10).count.should be 10
49
+ end
50
+
51
+ it 'should return one blog by default' do
52
+ create_valid_artist
53
+ @a.blogs.count.should be 1
54
+ end
55
+
56
+ end
57
+
58
+ describe '#familiarity' do
59
+
60
+ it 'should allow us to find out how familiar an artist is' do
61
+ create_valid_artist
62
+ @a.familiarity.should be_a Float
63
+ end
64
+
65
+ end
66
+
67
+ describe '#hotttnesss' do
68
+
69
+ it 'should allow us to find out how hotttt an artist is' do
70
+ create_valid_artist
71
+ @a.hotttnesss.should be_a Float
72
+ end
73
+
74
+ end
75
+
76
+ describe '#images' do
77
+
78
+ it 'should allow us to get an array of urls' do
79
+ create_valid_artist
80
+ @a.images.should be_a Array
81
+ end
82
+
83
+ it 'should only return urls in the array' do
84
+ create_valid_artist
85
+ @a.images.each do |i|
86
+ i.should match(/^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$/)
87
+ end
88
+ end
89
+
90
+ end
91
+
92
+ describe '#list_genres' do
93
+
94
+ it 'should return an array of acceptable genres' do
95
+ create_valid_artist
96
+ @a.list_genres.should be_a Array
97
+ end
98
+
99
+ it 'should return an array in the correct format' do
100
+ create_valid_artist
101
+ @a.list_genres.each do |g|
102
+ g[:name].should be_a String
103
+ end
104
+ end
105
+
106
+ end
107
+
108
+ describe '#songs' do
109
+
110
+ it 'should return an Array of a Hash of songs' do
111
+ create_valid_artist
112
+ @a.songs.should be_a Array
113
+ end
114
+
115
+ it 'should return a valid hash for each song' do
116
+ create_valid_artist
117
+ @a.songs.each do |k|
118
+ k.should be_a Hash
119
+ end
120
+ end
121
+
122
+ end
123
+
124
+ end
data/spec/base_spec.rb ADDED
@@ -0,0 +1,5 @@
1
+ require 'spec_helper'
2
+
3
+ describe Echonest::Base do
4
+
5
+ end
@@ -0,0 +1,8 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+
4
+ require 'echonest-ruby-api'
5
+
6
+ RSpec.configure do |config|
7
+
8
+ end
@@ -0,0 +1 @@
1
+
metadata ADDED
@@ -0,0 +1,150 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: echonest-ruby-api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Max Woolf
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-02-09 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: httparty
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: multi_json
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rspec
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: '2.6'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '2.6'
62
+ - !ruby/object:Gem::Dependency
63
+ name: guard-rspec
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: rb-fsevent
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ~>
84
+ - !ruby/object:Gem::Version
85
+ version: 0.9.1
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ~>
92
+ - !ruby/object:Gem::Version
93
+ version: 0.9.1
94
+ description: A gem to get hold of some echonest stuff!
95
+ email:
96
+ - max.woolf@boxuk.com
97
+ executables: []
98
+ extensions: []
99
+ extra_rdoc_files: []
100
+ files:
101
+ - .gitignore
102
+ - Gemfile
103
+ - Gemfile.lock
104
+ - Guardfile
105
+ - LICENSE.txt
106
+ - README.md
107
+ - Rakefile
108
+ - echonest-ruby-api.gemspec
109
+ - lib/artist.rb
110
+ - lib/base.rb
111
+ - lib/biography.rb
112
+ - lib/blog.rb
113
+ - lib/echonest-ruby-api.rb
114
+ - lib/echonest-ruby-api/news.rb
115
+ - lib/echonest-ruby-api/version.rb
116
+ - lib/news.rb
117
+ - pkg/echonest-ruby-api-0.0.1.gem
118
+ - pkg/echonest-ruby-api-0.0.3.gem
119
+ - spec/artist_spec.rb
120
+ - spec/base_spec.rb
121
+ - spec/spec_helper.rb
122
+ - tmp/rspec_guard_result
123
+ homepage: http://maxehmookau.github.com
124
+ licenses: []
125
+ post_install_message:
126
+ rdoc_options: []
127
+ require_paths:
128
+ - lib
129
+ required_ruby_version: !ruby/object:Gem::Requirement
130
+ none: false
131
+ requirements:
132
+ - - ! '>='
133
+ - !ruby/object:Gem::Version
134
+ version: '0'
135
+ required_rubygems_version: !ruby/object:Gem::Requirement
136
+ none: false
137
+ requirements:
138
+ - - ! '>='
139
+ - !ruby/object:Gem::Version
140
+ version: '0'
141
+ requirements: []
142
+ rubyforge_project:
143
+ rubygems_version: 1.8.24
144
+ signing_key:
145
+ specification_version: 3
146
+ summary: A gem to get hold of some echonest stuff!
147
+ test_files:
148
+ - spec/artist_spec.rb
149
+ - spec/base_spec.rb
150
+ - spec/spec_helper.rb