youpy-ruby-echonest 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -1,10 +1,9 @@
1
1
  = echonest
2
2
 
3
- An Ruby interface for Echo Nest Developer API
3
+ A Ruby interface for Echo Nest Developer API
4
4
 
5
5
  == Description
6
6
 
7
-
8
7
  == Installation
9
8
 
10
9
  === Archive Installation
@@ -13,21 +12,25 @@ An Ruby interface for Echo Nest Developer API
13
12
 
14
13
  === Gem Installation
15
14
 
16
- gem install youpy-echonest
17
-
15
+ gem sources -a http://gems.github.com/
16
+ gem install youpy-ruby-echonest
18
17
 
19
18
  == Features/Problems
20
19
 
20
+ Supports only API for Track http://developer.echonest.com/pages/overview
21
21
 
22
22
  == Synopsis
23
23
 
24
+ require 'rubygems'
25
+ require 'echonest'
26
+
24
27
  filename = 'foo.mp3'
25
28
  echonest = Echonest('YOUR_API_KEY')
26
29
  echonest.get_beats(filename)
27
30
 
28
31
  == Thanks
29
32
 
30
- koyachi for original idea <http://gist.github.com/87086>
33
+ {koyachi}[http://github.com/koyachi] for original idea http://gist.github.com/87086
31
34
 
32
35
  == Copyright
33
36
 
data/lib/echonest/api.rb CHANGED
@@ -1,4 +1,3 @@
1
- require 'ostruct'
2
1
  require 'digest/md5'
3
2
 
4
3
  module Echonest
@@ -14,14 +14,14 @@ module Echonest
14
14
  url.query = query(args)
15
15
  end
16
16
 
17
- req = Net::HTTP::Get.new(url.request_uri)
17
+ req = make_request(url, 'get')
18
18
 
19
19
  request(req, url)
20
20
  end
21
21
 
22
22
  def post(resource, args = nil)
23
23
  url = url(resource.to_s)
24
- req = Net::HTTP::Post.new(url.request_uri)
24
+ req = make_request(url, 'post')
25
25
 
26
26
  if args
27
27
  data = post_data(args)
@@ -74,5 +74,16 @@ module Echonest
74
74
  def query(params)
75
75
  params.map { |k,v| "%s=%s" % [CGI.escape(k.to_s), CGI.escape(v.to_s)] }.join("&")
76
76
  end
77
+
78
+ def make_request(uri, method)
79
+ req = (method == 'post' ? Net::HTTP::Post : Net::HTTP::Get).new(uri.request_uri)
80
+ req['User-Agent'] = user_agent
81
+
82
+ req
83
+ end
84
+
85
+ def user_agent
86
+ '%s/%s' % ['ruby-echonest', VERSION]
87
+ end
77
88
  end
78
89
  end
@@ -1,3 +1,3 @@
1
1
  module Echonest
2
- VERSION = '0.0.1'
2
+ VERSION = '0.0.2'
3
3
  end
@@ -0,0 +1,19 @@
1
+ $:.unshift File.dirname(__FILE__)
2
+
3
+ require 'spec_helper'
4
+ require "echonest"
5
+
6
+ include SpecHelper
7
+
8
+ describe Echonest::Connection do
9
+ before do
10
+ @connection = Echonest::Connection.new(Echonest::Api::URL)
11
+ end
12
+
13
+ it "should make http request with user agent" do
14
+ req = @connection.make_request(URI('http://example.com/xxx'), 'get')
15
+
16
+ req.method.should eql('GET')
17
+ req['User-Agent'].should eql('ruby-echonest/' + Echonest::VERSION)
18
+ end
19
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: youpy-ruby-echonest
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - youpy
@@ -27,6 +27,7 @@ files:
27
27
  - ChangeLog
28
28
  - Rakefile
29
29
  - spec/api_spec.rb
30
+ - spec/connection_spec.rb
30
31
  - spec/echonest_spec.rb
31
32
  - spec/fixtures
32
33
  - spec/fixtures/get_bars.xml