ruby-echonest 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ source :rubygems
2
+
3
+ gem 'rake', '0.9.2.2'
4
+ gem 'httpclient'
5
+ gem 'hashie'
6
+ gem 'libxml-ruby'
7
+ gem 'jeweler'
8
+
9
+ group :development do
10
+ gem 'rspec', '>= 2.0.0'
11
+ gem 'rdoc'
12
+ end
13
+
data/Gemfile.lock ADDED
@@ -0,0 +1,36 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ diff-lcs (1.1.3)
5
+ git (1.2.5)
6
+ hashie (1.2.0)
7
+ httpclient (2.2.1)
8
+ jeweler (1.6.4)
9
+ bundler (~> 1.0)
10
+ git (>= 1.2.5)
11
+ rake
12
+ json (1.6.3)
13
+ libxml-ruby (2.2.2)
14
+ rake (0.9.2.2)
15
+ rdoc (3.11)
16
+ json (~> 1.4)
17
+ rspec (2.7.0)
18
+ rspec-core (~> 2.7.0)
19
+ rspec-expectations (~> 2.7.0)
20
+ rspec-mocks (~> 2.7.0)
21
+ rspec-core (2.7.1)
22
+ rspec-expectations (2.7.0)
23
+ diff-lcs (~> 1.1.2)
24
+ rspec-mocks (2.7.0)
25
+
26
+ PLATFORMS
27
+ ruby
28
+
29
+ DEPENDENCIES
30
+ hashie
31
+ httpclient
32
+ jeweler
33
+ libxml-ruby
34
+ rake (= 0.9.2.2)
35
+ rdoc
36
+ rspec (>= 2.0.0)
data/Rakefile CHANGED
@@ -1,27 +1,17 @@
1
- require 'rubygems'
2
- require 'rake'
1
+ require 'bundler'
2
+ Bundler.require
3
3
 
4
- begin
5
- $LOAD_PATH.unshift "lib"
6
- require 'echonest'
7
- require 'jeweler'
8
- Jeweler::Tasks.new do |gem|
9
- gem.name = "ruby-echonest"
10
- gem.version = Echonest::VERSION
11
- gem.summary = "An Ruby interface for Echo Nest Developer API"
12
- gem.description = "An Ruby interface for Echo Nest Developer API"
13
- gem.email = "youpy@buycheapviagraonlinenow.com"
14
- gem.homepage = "http://github.com/youpy/ruby-echonest"
15
- gem.authors = ["youpy"]
16
- gem.add_development_dependency "rspec", ">= 2.0.0"
17
- gem.add_dependency "httpclient"
18
- gem.add_dependency "hashie"
19
- gem.add_dependency "libxml-ruby"
20
- # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
21
- end
22
- Jeweler::GemcutterTasks.new
23
- rescue LoadError
24
- puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
4
+ $LOAD_PATH.unshift "lib"
5
+ require 'echonest'
6
+
7
+ Jeweler::Tasks.new do |gem|
8
+ gem.name = "ruby-echonest"
9
+ gem.version = Echonest::VERSION
10
+ gem.summary = "An Ruby interface for Echo Nest Developer API"
11
+ gem.description = "An Ruby interface for Echo Nest Developer API"
12
+ gem.email = "youpy@buycheapviagraonlinenow.com"
13
+ gem.homepage = "http://github.com/youpy/ruby-echonest"
14
+ gem.authors = ["youpy"]
25
15
  end
26
16
 
27
17
  require 'rspec/core/rake_task'
@@ -30,7 +20,6 @@ RSpec::Core::RakeTask.new(:core) do |spec|
30
20
  spec.pattern = 'spec/**/*_spec.rb'
31
21
  end
32
22
 
33
- task :core => :check_dependencies
34
23
  task :default => :core
35
24
 
36
25
  require 'rdoc/task'
data/lib/echonest/api.rb CHANGED
@@ -3,6 +3,7 @@ require 'digest/md5'
3
3
  require 'httpclient'
4
4
  require 'json'
5
5
  require 'fileutils'
6
+ require 'cgi'
6
7
 
7
8
  module Echonest
8
9
  class Api
@@ -15,9 +16,13 @@ module Echonest
15
16
 
16
17
  attr_reader :user_agent
17
18
 
18
- def initialize(api_key)
19
- @api_key = api_key
19
+ def initialize(api_key = nil)
20
+ @api_key = api_key || read_api_key_from_file
20
21
  @user_agent = HTTPClient.new(:agent_name => USER_AGENT)
22
+
23
+ # for big files
24
+ @user_agent.send_timeout = 60 * 30
25
+ @user_agent.receive_timeout = 60 * 10
21
26
  end
22
27
 
23
28
  def track
@@ -35,7 +40,7 @@ module Echonest
35
40
  query = build_params(params).sort_by do |param|
36
41
  param[0].to_s
37
42
  end.inject([]) do |m, param|
38
- m << [URI.encode(param[0].to_s), URI.encode(param[1])].join('=')
43
+ m << [CGI.escape(param[0].to_s), CGI.escape(param[1])].join('=')
39
44
  end.join('&')
40
45
 
41
46
  uri = URI.join(BASE_URL, name.to_s)
@@ -64,6 +69,16 @@ module Echonest
64
69
  rescue HTTPClient::BadResponseError => e
65
70
  raise Error.new('%s: %s' % [name, e.message])
66
71
  end
72
+
73
+ def self.api_key_file
74
+ DIRECTORY + 'api_key'
75
+ end
76
+
77
+ private
78
+
79
+ def read_api_key_from_file
80
+ self.class.api_key_file.read.chomp
81
+ end
67
82
  end
68
83
 
69
84
  module ApiMethods
@@ -1,3 +1,3 @@
1
1
  module Echonest
2
- VERSION = '0.2.0'
2
+ VERSION = '0.3.0'
3
3
  end
data/lib/echonest.rb CHANGED
@@ -12,7 +12,7 @@ require 'echonest/element/tatum'
12
12
 
13
13
  require 'pathname'
14
14
 
15
- def Echonest(api_key) Echonest::Api.new(api_key) end
15
+ def Echonest(api_key = nil) Echonest::Api.new(api_key) end
16
16
 
17
17
  module Echonest
18
18
  DIRECTORY = Pathname.new("~/.echonest").expand_path
data/spec/api_spec.rb CHANGED
@@ -1,12 +1,29 @@
1
1
  $:.unshift File.dirname(__FILE__)
2
2
 
3
3
  require 'spec_helper'
4
+ require 'tempfile'
4
5
 
5
6
  describe Echonest::Api do
6
7
  before do
7
8
  @api = Echonest::Api.new('8TPE3VC60ODJTNTFE')
8
9
  end
9
10
 
11
+ it "should have a filename for api key" do
12
+ Echonest::Api.api_key_file.to_s.should eql(Pathname('~/.echonest/api_key').expand_path.to_s)
13
+ end
14
+
15
+ it "should read api key from file" do
16
+ file = Tempfile.new('api_key')
17
+ file.write('XXXXX')
18
+ file.flush
19
+
20
+ Echonest::Api.should_receive(:api_key_file).and_return(Pathname(file.path))
21
+
22
+ api = Echonest::Api.new
23
+
24
+ api.instance_variable_get('@api_key').should eql('XXXXX')
25
+ end
26
+
10
27
  it "should build parameters" do
11
28
  params = @api.build_params(:id => 'TRXXHTJ1294CD8F3B3')
12
29
  params.keys.size.should eql(3)
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 2
7
+ - 3
8
8
  - 0
9
- version: 0.2.0
9
+ version: 0.3.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - youpy
@@ -14,59 +14,98 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-12-30 00:00:00 +09:00
17
+ date: 2012-01-09 00:00:00 +09:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
- name: rspec
22
21
  prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
22
+ type: :runtime
23
+ name: rake
24
+ version_requirements: &id001 !ruby/object:Gem::Requirement
24
25
  requirements:
25
- - - ">="
26
+ - - "="
26
27
  - !ruby/object:Gem::Version
27
28
  segments:
28
- - 2
29
- - 0
30
29
  - 0
31
- version: 2.0.0
32
- type: :development
33
- version_requirements: *id001
30
+ - 9
31
+ - 2
32
+ - 2
33
+ version: 0.9.2.2
34
+ requirement: *id001
34
35
  - !ruby/object:Gem::Dependency
35
- name: httpclient
36
36
  prerelease: false
37
- requirement: &id002 !ruby/object:Gem::Requirement
37
+ type: :runtime
38
+ name: httpclient
39
+ version_requirements: &id002 !ruby/object:Gem::Requirement
38
40
  requirements:
39
41
  - - ">="
40
42
  - !ruby/object:Gem::Version
41
43
  segments:
42
44
  - 0
43
45
  version: "0"
44
- type: :runtime
45
- version_requirements: *id002
46
+ requirement: *id002
46
47
  - !ruby/object:Gem::Dependency
48
+ prerelease: false
49
+ type: :runtime
47
50
  name: hashie
51
+ version_requirements: &id003 !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ segments:
56
+ - 0
57
+ version: "0"
58
+ requirement: *id003
59
+ - !ruby/object:Gem::Dependency
48
60
  prerelease: false
49
- requirement: &id003 !ruby/object:Gem::Requirement
61
+ type: :runtime
62
+ name: libxml-ruby
63
+ version_requirements: &id004 !ruby/object:Gem::Requirement
50
64
  requirements:
51
65
  - - ">="
52
66
  - !ruby/object:Gem::Version
53
67
  segments:
54
68
  - 0
55
69
  version: "0"
70
+ requirement: *id004
71
+ - !ruby/object:Gem::Dependency
72
+ prerelease: false
56
73
  type: :runtime
57
- version_requirements: *id003
74
+ name: jeweler
75
+ version_requirements: &id005 !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ segments:
80
+ - 0
81
+ version: "0"
82
+ requirement: *id005
58
83
  - !ruby/object:Gem::Dependency
59
- name: libxml-ruby
60
84
  prerelease: false
61
- requirement: &id004 !ruby/object:Gem::Requirement
85
+ type: :development
86
+ name: rspec
87
+ version_requirements: &id006 !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ segments:
92
+ - 2
93
+ - 0
94
+ - 0
95
+ version: 2.0.0
96
+ requirement: *id006
97
+ - !ruby/object:Gem::Dependency
98
+ prerelease: false
99
+ type: :development
100
+ name: rdoc
101
+ version_requirements: &id007 !ruby/object:Gem::Requirement
62
102
  requirements:
63
103
  - - ">="
64
104
  - !ruby/object:Gem::Version
65
105
  segments:
66
106
  - 0
67
107
  version: "0"
68
- type: :runtime
69
- version_requirements: *id004
108
+ requirement: *id007
70
109
  description: An Ruby interface for Echo Nest Developer API
71
110
  email: youpy@buycheapviagraonlinenow.com
72
111
  executables: []
@@ -79,6 +118,8 @@ extra_rdoc_files:
79
118
  files:
80
119
  - .rspec
81
120
  - ChangeLog
121
+ - Gemfile
122
+ - Gemfile.lock
82
123
  - README.rdoc
83
124
  - Rakefile
84
125
  - lib/echonest.rb