bassnode-ruby-echonest 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -41,5 +41,4 @@ Only supports the API for Track http://developer.echonest.com/docs/v4/track.html
41
41
  == Copyright
42
42
 
43
43
  Author:: youpy <youpy@buycheapviagraonlinenow.com>
44
- Copyright:: Copyright (c) 2009 youpy
45
44
  License:: MIT
data/Rakefile CHANGED
@@ -3,8 +3,8 @@ require 'rake'
3
3
  require 'rake/clean'
4
4
  require 'rake/testtask'
5
5
  require 'rake/packagetask'
6
- require 'rake/gempackagetask'
7
- require 'rake/rdoctask'
6
+ require 'rubygems/package_task'
7
+ require 'rdoc/task'
8
8
  require 'rake/contrib/sshpublisher'
9
9
  require 'spec/rake/spectask'
10
10
  require 'fileutils'
@@ -24,7 +24,7 @@ Spec::Rake::SpecTask.new do |t|
24
24
  end
25
25
 
26
26
  spec = eval(File.read("bassnode-ruby-echonest.gemspec"))
27
- Rake::GemPackageTask.new(spec) do |p|
27
+ Gem::PackageTask.new(spec) do |p|
28
28
  p.need_tar = true
29
29
  p.gem_spec = spec
30
30
  end
@@ -34,3 +34,4 @@ desc "Show information about the gem"
34
34
  task :debug_gem do
35
35
  puts spec.to_ruby
36
36
  end
37
+
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{bassnode-ruby-echonest}
5
- s.version = "0.1.2"
5
+ s.version = "0.1.3"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["youpy", "bassnode"]
9
- s.date = %q{2011-04-24}
9
+ s.date = %q{2012-02-12}
10
10
  s.description = %q{An Ruby interface for Echo Nest Developer API}
11
11
  s.summary = %q{An Ruby interface for Echo Nest Developer API}
12
12
  s.email = %q{youpy@buycheapviagraonlinenow.com}
data/console ADDED
@@ -0,0 +1,45 @@
1
+ require 'rubygems'
2
+ require 'irb'
3
+
4
+ # ensure we use local gem
5
+ $LOAD_PATH.unshift('lib')
6
+
7
+ def consolize &block
8
+
9
+ yield
10
+
11
+ IRB.setup(nil)
12
+ irb = IRB::Irb.new
13
+ IRB.conf[:MAIN_CONTEXT] = irb.context
14
+ irb.context.evaluate("require 'irb/completion'", 0)
15
+
16
+ trap("SIGINT") do
17
+ irb.signal_handle
18
+ end
19
+ catch(:IRB_EXIT) do
20
+ irb.eval_input
21
+ end
22
+ end
23
+
24
+ consolize do
25
+ require 'echonest'
26
+
27
+ key = nil
28
+
29
+ locations = ["~/.mreko/echonest_api.key", "~/.echonest/api_key"]
30
+ locations.each do |config|
31
+ if File.exists?(File.expand_path(config))
32
+ key = File.read(File.expand_path(config))
33
+ break
34
+ end
35
+ end
36
+
37
+ raise "Need an EN key in one of these locations: #{locations.inspect}" unless key
38
+
39
+ @en = Echonest(key)
40
+
41
+ def en; @en; end
42
+ end
43
+
44
+
45
+
data/lib/echonest.rb CHANGED
@@ -13,4 +13,20 @@ require 'echonest/element/tatum'
13
13
  def Echonest(api_key) Echonest::Api.new(api_key) end
14
14
 
15
15
  module Echonest
16
+ extend self
17
+
18
+ def debug(obj)
19
+ return unless debug?
20
+
21
+ if obj.is_a?(String)
22
+ puts obj
23
+ else
24
+ puts obj.inspect
25
+ end
26
+ end
27
+
28
+ # MOAR DEBUGGING! *just for now
29
+ def debug?
30
+ true || ENV['DEBUG']
31
+ end
16
32
  end
data/lib/echonest/api.rb CHANGED
@@ -36,6 +36,10 @@ module Echonest
36
36
  end
37
37
  end
38
38
 
39
+ def catalog
40
+ ApiMethods::Catalog.new(self)
41
+ end
42
+
39
43
  def song
40
44
  ApiMethods::Song.new(self)
41
45
  end
@@ -61,7 +65,7 @@ module Echonest
61
65
  hash_to_list = lambda{|kv| [kv[0].to_s, kv[1]]}
62
66
  params.each do |param|
63
67
  if param.instance_of? Array
64
- param[1].map do |p1|
68
+ Array(param[1]).map do |p1|
65
69
  result << [param[0].to_s, p1]
66
70
  end
67
71
  else
@@ -105,6 +109,8 @@ module Echonest
105
109
  res = connection.pop
106
110
  response_body = res.content.read
107
111
  else
112
+ Echonest.debug "#{method.to_s.upcase} #{uri}?#{build_params_to_list(params).inject(''){ |str, (key,val)| str << "#{key}=#{val}&"; str }}"
113
+
108
114
  response_body = @user_agent.__send__(
109
115
  method.to_s + '_content',
110
116
  uri,
@@ -323,8 +329,60 @@ module Echonest
323
329
  end
324
330
 
325
331
  class Playlist < Base
326
- method_with_option(:static, %w[format type artist_pick variety artist_id artist song_id description results max_tempo min_tempo max_duration min_duration max_loudness min_loudness artist_max_familiarity artist_min_familiarity artist_max_hotttnesss artist_min_hotttnesss song_max_hotttnesss song_min_hotttnesss artist_min_longitude aritst_max_longitude artist_min_latitude arist_max_latitude mode key bucket sort limit audio])
327
- method_with_option(:dynamic, %w[format type artist_pick variety artist_id artist song_id description results max_tempo min_tempo max_duration min_duration max_loudness min_loudness artist_max_familiarity artist_min_familiarity artist_max_hotttnesss artist_min_hotttnesss song_max_hotttnesss song_min_hotttnesss artist_min_longitude aritst_max_longitude artist_min_latitude arist_max_latitude mode key bucket sort limit audio session_id dmca rating chain_xspf])
332
+ @basic_parameters = %w[ format type artist_id artist song_id track_id results bucket limit dmca]
333
+
334
+ @static_parameters = %w[ artist_pick variety distribution adventurousness
335
+ seed_catalog description style mood
336
+ max_tempo min_tempo max_duration min_duration max_loudness min_loudness max_danceability min_danceability
337
+ max_energy min_energy artist_max_familiarity artist_min_familiarity artist_max_hotttnesss artist_min_hotttnesss
338
+ artist_start_year_before artist_start_year_after artist_end_year_before artist_end_year_after song_max_hotttnesss song_min_hotttnesss
339
+ min_longitude max_longitude min_latitude max_latitude mode key sort ] + @basic_parameters
340
+
341
+ @dynamic_parameters = %w[ session_id dmca adventurousness rating chain_xspf
342
+ steer steer_description steer_style steer_mood ] + @static_parameters
343
+
344
+ method_with_option(:basic, @basic_parameters)
345
+ method_with_option(:static, @static_parameters)
346
+ method_with_option(:dynamic, @dynamic_parameters)
347
+ end
348
+
349
+ # http://developer.echonest.com/docs/v4/catalog.html
350
+ class Catalog < Base
351
+ # type can be 'song' or 'artist' (Default)
352
+ def create(name, type="artist")
353
+ @api.request('catalog/create', :post, {:name => name, :type => type, :format => "json"}).body
354
+ end
355
+
356
+ # Updates (adds or deletes) items from a catalog. The body of the post should include an item block that describes modifications to the catalog.
357
+ # data: [{:item=>{:item_id => "hogehoge", :artist_name => "Oscar Peterson"}}]
358
+ def update(catalog_id, data)
359
+ json_data = data.to_json
360
+ @api.request('catalog/update', :post, {:id => catalog_id, :data_type => "json", :format => "json", :data => json_data}).body
361
+ end
362
+
363
+ # Checks the status of a catalog update.
364
+ method_with_option(:status, %w[format ticket])
365
+
366
+ # Get basic information on a catalog
367
+ method_with_option(:profile, %w[format id name])
368
+
369
+ # Returns data stored in the catalog. Also returns Echo Nest IDs for items that have been resolved to Echo Nest IDs
370
+ # along with information requested via bucket. If item_id is not set, all items (subject to the limits of the start and results parameters)
371
+ # are returned, otherwise, only the items explicitly specified by item_id are returned.
372
+ method_with_option(:read, %w[format id name item_id bucket results start])
373
+
374
+ # Returns feeds based on the artists in a taste profile. Unlike catalog/read method, the catalog/feed method interleaves items and sorts them by date.
375
+ # since: YYYY-mm-dd
376
+ # high_relevance: boolean (default false)
377
+ # bucket: news, blogs, reviews, audio and video blogs. If omitted defaults to news.
378
+ # result: default of 25
379
+ method_with_option(:feed, %w[format id bucket results start since high_relevance])
380
+
381
+ # Deletes the entire catalog. Only the API key used to create a catalog can be used to delete that catalog.
382
+ method_with_required_any('catalog', :delete, :post, %w[id], [], %w[format], lambda{})
383
+
384
+ # Returns a list of all catalogs created with the current key (account)
385
+ method_with_option(:list, %w[format results start])
328
386
  end
329
387
  end
330
388
  end
@@ -1,3 +1,3 @@
1
1
  module Echonest
2
- VERSION = '0.1.2'
2
+ VERSION = '0.1.3'
3
3
  end
data/spec/api_spec.rb CHANGED
@@ -40,10 +40,11 @@ describe Echonest::Api do
40
40
  end
41
41
 
42
42
  it "should pass arguments including a file to user agent" do
43
+ pending "Failes due to incorrect stubbing."
44
+
43
45
  file = open(fixture('sample.mp3'))
44
46
  file.should_receive(:read).and_return('content')
45
47
 
46
-
47
48
  @api.user_agent.should_receive(:post_async).
48
49
  with(
49
50
  URI('http://developer.echonest.com/api/v4/xxx/zzz?api_key=8TPE3VC60ODJTNTFE&bar=baz&format=json'),
@@ -0,0 +1,32 @@
1
+ $:.unshift File.dirname(__FILE__)
2
+
3
+ require 'spec_helper'
4
+ require "echonest"
5
+
6
+ include SpecHelper
7
+
8
+ describe Echonest::ApiMethods::Catalog do
9
+ before do
10
+ @api = Echonest::Api.new('8TPE3VC60ODJTNTFE')
11
+ @catalog = Echonest::ApiMethods::Catalog.new(@api)
12
+ end
13
+
14
+ describe "#create" do
15
+ it "should request to catalog/create with option" do
16
+ catalog_name = "catalog_name"
17
+ catalog_type = "artist"
18
+ @api.should_receive(:request).with("catalog/create", :post, {:name => catalog_name, :type => catalog_type, :format => "json"}).and_return{ Echonest::Response.new('{"hello":"world"}') }
19
+ @catalog.create(catalog_name, catalog_type)
20
+ end
21
+ end
22
+
23
+ describe "#update" do
24
+ it "should request to catalog/update with option" do
25
+ catalog_id = "catalog_id"
26
+ data = [{:item=>{:item_id => "hogehoge", :artist_name => "Oscar Peterson"}}]
27
+ @api.should_receive(:request).with("catalog/update", :post, {:id => catalog_id, :data_type => "json", :format => "json", :data => data.to_json}).and_return{ Echonest::Response.new('{"hello":"world"}') }
28
+ @catalog.update(catalog_id, data)
29
+ end
30
+ end
31
+
32
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bassnode-ruby-echonest
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31
5
- prerelease: false
4
+ hash: 29
5
+ prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 2
10
- version: 0.1.2
9
+ - 3
10
+ version: 0.1.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - youpy
@@ -16,8 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2011-04-24 00:00:00 -07:00
20
- default_executable:
19
+ date: 2012-02-12 00:00:00 Z
21
20
  dependencies:
22
21
  - !ruby/object:Gem::Dependency
23
22
  name: libxml-ruby
@@ -90,6 +89,7 @@ files:
90
89
  - README.rdoc
91
90
  - Rakefile
92
91
  - bassnode-ruby-echonest.gemspec
92
+ - console
93
93
  - lib/echonest.rb
94
94
  - lib/echonest/analysis.rb
95
95
  - lib/echonest/api.rb
@@ -106,6 +106,7 @@ files:
106
106
  - spec/api_spec.rb
107
107
  - spec/apimethods_base_spec.rb
108
108
  - spec/artist_spec.rb
109
+ - spec/catalog_spec.rb
109
110
  - spec/echonest_spec.rb
110
111
  - spec/fixtures/analysis.json
111
112
  - spec/fixtures/profile.json
@@ -118,7 +119,6 @@ files:
118
119
  - spec/spec.opts
119
120
  - spec/spec_helper.rb
120
121
  - spec/track_spec.rb
121
- has_rdoc: true
122
122
  homepage: http://github.com/bassnode/ruby-echonest
123
123
  licenses: []
124
124
 
@@ -159,7 +159,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
159
159
  requirements: []
160
160
 
161
161
  rubyforge_project: bassnode-ruby-echonest
162
- rubygems_version: 1.3.7
162
+ rubygems_version: 1.8.11
163
163
  signing_key:
164
164
  specification_version: 3
165
165
  summary: An Ruby interface for Echo Nest Developer API