nestling 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ script: "bundle exec rake test"
2
+ rvm:
3
+ - 1.8.7
4
+ - 1.9.2
5
+ - 1.9.3
6
+ - jruby
7
+ - ree
@@ -6,10 +6,10 @@ module Nestling
6
6
  USER_AGENT = "Nestling/#{Version::STRING}"
7
7
  DEFAULT_PARAMS = { :format => 'json' }
8
8
 
9
- def initialize(api_key = Nestling.api_key)
9
+ def initialize(api_key = nil)
10
10
  @http = Net::HTTP.new(HOST)
11
- @api_key = api_key
12
- @default_params = { :api_key => api_key }.merge!(DEFAULT_PARAMS)
11
+ @api_key = api_key || Nestling.api_key
12
+ @default_params = { :api_key => @api_key }.merge!(DEFAULT_PARAMS)
13
13
  end
14
14
 
15
15
  def artist(id)
@@ -35,7 +35,7 @@ module Nestling
35
35
  def get(meth, params = {})
36
36
  path = "/api/v4/#{meth}?" << convert_params(params)
37
37
  response, data = @http.get(path, {'User-Agent' => USER_AGENT})
38
- hash = JSON.parse(data)
38
+ hash = MultiJson.decode(data)
39
39
 
40
40
  if (code = hash["response"]["status"]["code"].to_i) != 0
41
41
  raise ERRNO[code], hash["response"]["status"]["message"]
@@ -1,6 +1,8 @@
1
1
  module Nestling
2
2
  class Collection < Array
3
- attr_accessor :results, :start, :session_id, :type
3
+ attr_reader :results, :start, :session_id, :type
4
+
5
+ alias :total :results
4
6
 
5
7
  def initialize(options = {}, *args)
6
8
  options = Nestling::Hash.new(options).symbolize_keys!
@@ -2,7 +2,7 @@ module Nestling
2
2
  module Version
3
3
  MAJOR = 0
4
4
  MINOR = 1
5
- PATCH = 0
5
+ PATCH = 1
6
6
 
7
7
  STRING = [MAJOR, MINOR, PATCH].compact.join('.')
8
8
  end
data/lib/nestling.rb CHANGED
@@ -6,7 +6,7 @@ require 'cgi'
6
6
  require 'date'
7
7
 
8
8
  # gems
9
- require 'json'
9
+ require 'multi_json'
10
10
 
11
11
  # internal
12
12
  require 'nestling/version'
data/nestling.gemspec CHANGED
@@ -17,7 +17,9 @@ Gem::Specification.new do |s|
17
17
  s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
18
18
  s.require_paths = ["lib"]
19
19
 
20
- s.add_dependency "json", "~> 1.5.4"
20
+ s.add_dependency "multi_json", "~> 1.0.3"
21
+ s.add_development_dependency "rake", "~> 0.9"
22
+ s.add_development_dependency "minitest", "~> 2.6.0"
21
23
  s.add_development_dependency "mocha", "~> 0.9.12"
22
24
  end
23
25
 
data/test/helper.rb CHANGED
@@ -8,11 +8,11 @@ def stub_http_get(ret)
8
8
  end
9
9
 
10
10
  def expect_request(resp, req, opts = nil)
11
- resp = JSON.parse(resp)
11
+ resp = MultiJson.decode(resp)
12
12
  if opts
13
- Client.any_instance.expects(:get).with(req, opts).returns(resp)
13
+ Nestling::Client.any_instance.expects(:get).with(req, opts).returns(resp)
14
14
  else
15
- Client.any_instance.expects(:get).with(req, anything).returns(resp)
15
+ Nestling::Client.any_instance.expects(:get).with(req, anything).returns(resp)
16
16
  end
17
17
  end
18
18
 
data/test/test_client.rb CHANGED
@@ -22,13 +22,13 @@ class TestClient < MiniTest::Unit::TestCase
22
22
  def test_default_api_key
23
23
  Nestling.api_key = nil # sanity
24
24
  Nestling.api_key = 'bar'
25
- assert_equal Client.new.api_key, 'bar'
25
+ assert_equal 'bar', Client.new.api_key
26
26
  end
27
27
 
28
28
  def test_default_api_key_through_namespace_module
29
29
  Nestling.api_key = nil # sanity
30
30
  Nestling.api_key = 'baz'
31
- assert_equal Nestling.new.api_key, 'baz'
31
+ assert_equal 'baz', Nestling.new.api_key
32
32
  end
33
33
 
34
34
  def test_artist_returns_artist_object
@@ -68,12 +68,12 @@ class TestClient < MiniTest::Unit::TestCase
68
68
  }
69
69
  EOS
70
70
  stub_http_get response
71
- assert_equal JSON.parse(response), Client.new('foo').get('bar')
71
+ assert_equal MultiJson.decode(response), Client.new('foo').get('bar')
72
72
  end
73
73
 
74
74
  def test_sends_user_agent
75
- Net::HTTP.any_instance.expects(:get)
76
- .with(anything, { 'User-Agent' => Client::USER_AGENT} )
75
+ Net::HTTP.any_instance.expects(:get) \
76
+ .with(anything, { 'User-Agent' => Client::USER_AGENT} ) \
77
77
  .returns([{}, <<-EOS
78
78
  {
79
79
  "response": {
@@ -45,6 +45,13 @@ class TestErrors < MiniTest::Unit::TestCase
45
45
  assert_equal 23, Collection.new(@sym_options_with_total).results
46
46
  end
47
47
 
48
+ def test_collection_has_total_accessor_for_results
49
+ assert_equal 10, Collection.new(@str_options).total
50
+ assert_equal 10, Collection.new(@sym_options).total
51
+ assert_equal 23, Collection.new(@str_options_with_total).total
52
+ assert_equal 23, Collection.new(@sym_options_with_total).total
53
+ end
54
+
48
55
  def test_collection_assigns_start
49
56
  assert_equal 2, Collection.new(@str_options).start
50
57
  assert_equal 2, Collection.new(@sym_options).start
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nestling
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -12,19 +12,41 @@ cert_chain: []
12
12
  date: 2011-09-23 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name: json
16
- requirement: &70365143049080 !ruby/object:Gem::Requirement
15
+ name: multi_json
16
+ requirement: &70331940832920 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
20
20
  - !ruby/object:Gem::Version
21
- version: 1.5.4
21
+ version: 1.0.3
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70365143049080
24
+ version_requirements: *70331940832920
25
+ - !ruby/object:Gem::Dependency
26
+ name: rake
27
+ requirement: &70331940832240 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: '0.9'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *70331940832240
36
+ - !ruby/object:Gem::Dependency
37
+ name: minitest
38
+ requirement: &70331940831560 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: 2.6.0
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70331940831560
25
47
  - !ruby/object:Gem::Dependency
26
48
  name: mocha
27
- requirement: &70365143048260 !ruby/object:Gem::Requirement
49
+ requirement: &70331940830800 !ruby/object:Gem::Requirement
28
50
  none: false
29
51
  requirements:
30
52
  - - ~>
@@ -32,7 +54,7 @@ dependencies:
32
54
  version: 0.9.12
33
55
  type: :development
34
56
  prerelease: false
35
- version_requirements: *70365143048260
57
+ version_requirements: *70331940830800
36
58
  description: Ruby wrapper for the EchoNest API
37
59
  email:
38
60
  - tob@tobiassvensson.co.uk
@@ -41,6 +63,7 @@ extensions: []
41
63
  extra_rdoc_files: []
42
64
  files:
43
65
  - .gitignore
66
+ - .travis.yml
44
67
  - Gemfile
45
68
  - LICENSE
46
69
  - README.md