bandcamp_api 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -62,11 +62,12 @@ ape_to_angel = Bandcamp.get.album 2909726980
62
62
  => #<Bandcamp::Album:0x00000001e20c60>
63
63
  ```
64
64
 
65
+ Bands, Albums and Tracks all have a #to_json method that does what you would
66
+ expect a to_json method to do.
67
+
65
68
  ## TODO list
66
69
 
67
- * Making the objects a little smarter. Tracks should be able to tell you what album
68
- they are from and what band did them. Same sort of thing for the other
69
- objects.
70
+ * A nice interface for requesting discographies.
70
71
  * Rails 3 integration so you can use these ojects with partials and form_for.
71
72
  * Duck typing helpers along the lines of [ActiveSupport's
72
73
  #acts_like?](http://apidock.com/rails/Object/acts_like%3F)
@@ -9,7 +9,8 @@ module Bandcamp
9
9
  include Associated
10
10
 
11
11
  def initialize album_hash
12
- to_methods album_hash
12
+ @album_hash = album_hash
13
+ to_methods @album_hash
13
14
  if instance_variable_defined? "@tracks"
14
15
  @tracks = @tracks.map{|track| Track.new(track)}
15
16
  end
@@ -19,5 +20,9 @@ module Bandcamp
19
20
  retrieve_associated :band
20
21
  end
21
22
 
23
+ def to_json
24
+ MultiJson.encode @album_hash
25
+ end
26
+
22
27
  end
23
28
  end
data/lib/bandcamp/band.rb CHANGED
@@ -1,3 +1,4 @@
1
+ require 'multi_json'
1
2
  require 'bandcamp/methodical'
2
3
 
3
4
  module Bandcamp
@@ -5,7 +6,12 @@ module Bandcamp
5
6
  include Methodical
6
7
 
7
8
  def initialize attrs_hash
8
- to_methods attrs_hash
9
+ @attrs_hash = attrs_hash
10
+ to_methods @attrs_hash
11
+ end
12
+
13
+ def to_json
14
+ MultiJson.encode @attrs_hash
9
15
  end
10
16
 
11
17
  end
@@ -6,11 +6,12 @@ require 'bandcamp/associated'
6
6
  module Bandcamp
7
7
  class Track
8
8
 
9
- include Bandcamp::Methodical
10
- include Bandcamp::Associated
9
+ include Methodical
10
+ include Associated
11
11
 
12
12
  def initialize attrs
13
- to_methods attrs
13
+ @attrs_hash = attrs
14
+ to_methods @attrs_hash
14
15
  end
15
16
 
16
17
  def paid?
@@ -29,5 +30,9 @@ module Bandcamp
29
30
  retrieve_associated :album
30
31
  end
31
32
 
33
+ def to_json
34
+ MultiJson.encode @attrs_hash
35
+ end
36
+
32
37
  end
33
38
  end
@@ -1,3 +1,3 @@
1
1
  module Bandcamp
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
data/spec/album_spec.rb CHANGED
@@ -1,3 +1,4 @@
1
+ require 'support/be_json'
1
2
  require 'multi_json'
2
3
  require 'bandcamp/band'
3
4
  require 'bandcamp/album'
@@ -40,5 +41,11 @@ module Bandcamp
40
41
  end
41
42
  end
42
43
 
44
+ describe "#to_json" do
45
+ it "returns json" do
46
+ expect(album.to_json).to be_json
47
+ end
48
+ end
49
+
43
50
  end
44
51
  end
data/spec/band_spec.rb CHANGED
@@ -1,3 +1,4 @@
1
+ require 'support/be_json'
1
2
  require 'bandcamp/band'
2
3
 
3
4
  module Bandcamp
@@ -18,5 +19,10 @@ module Bandcamp
18
19
  end
19
20
  end
20
21
 
22
+ describe "#to_json" do
23
+ it "returns json" do
24
+ expect(band.to_json).to be_json
25
+ end
26
+ end
21
27
  end
22
28
  end
data/spec/spec_helper.rb CHANGED
@@ -1 +1,3 @@
1
1
  $:.unshift(File.expand_path('../lib', File.dirname(__FILE__)))
2
+ $:.unshift(File.expand_path('./spec/support'))
3
+
@@ -0,0 +1,24 @@
1
+ require 'json'
2
+
3
+ RSpec::Matchers.define :be_json do |expected|
4
+ match do |actual|
5
+ begin
6
+ JSON.parse actual
7
+ true
8
+ rescue JSON::ParserError
9
+ false
10
+ end
11
+ end
12
+
13
+ failure_message_for_should do |actual|
14
+ "expected that #{actual} would be JSON"
15
+ end
16
+
17
+ failure_message_for_should_not do |actual|
18
+ "expected that #{actual} would not be JSON"
19
+ end
20
+
21
+ description do
22
+ "be JSON"
23
+ end
24
+ end
data/spec/track_spec.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'spec_helper'
2
+ require 'support/be_json'
2
3
  require 'bandcamp/track'
3
4
  require 'multi_json'
4
5
 
@@ -55,6 +56,13 @@ module Bandcamp
55
56
  expect(track.album).to be_an Album
56
57
  end
57
58
  end
59
+
60
+ describe "#to_json" do
61
+ it "returns json" do
62
+ expect(track.to_json).to be_json
63
+ end
64
+ end
65
+
58
66
  end
59
67
 
60
68
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bandcamp_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-27 00:00:00.000000000 Z
12
+ date: 2013-03-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -88,6 +88,7 @@ files:
88
88
  - spec/methodic_spec.rb
89
89
  - spec/request_spec.rb
90
90
  - spec/spec_helper.rb
91
+ - spec/support/be_json.rb
91
92
  - spec/track_spec.rb
92
93
  homepage:
93
94
  licenses: []
@@ -135,4 +136,5 @@ test_files:
135
136
  - spec/methodic_spec.rb
136
137
  - spec/request_spec.rb
137
138
  - spec/spec_helper.rb
139
+ - spec/support/be_json.rb
138
140
  - spec/track_spec.rb