bandcamp_api 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -8,12 +8,12 @@ To use it you will need to request an API key from them. For details see
8
8
 
9
9
  In your Gemfile
10
10
  ```ruby
11
- gem 'bandcamp', github: "sleepycat/bandcamp"
11
+ gem install bandcamp_api
12
12
  ```
13
13
 
14
14
  ## Getting started:
15
15
  ```ruby
16
- require 'bandcamp'
16
+ require 'bandcamp_api'
17
17
  Bandcamp.config.api_key = "your_api_key"
18
18
  ```
19
19
 
@@ -0,0 +1,24 @@
1
+ module Bandcamp
2
+ module Associated
3
+
4
+ def retrieve_associated thing
5
+ return instance_variable_get("@#{thing}") if instance_variable_defined?("@#{thing}")
6
+ if [:band, :album, :track, :discography].include? thing
7
+ response = get thing
8
+ klass = Bandcamp.const_get "#{thing.capitalize}"
9
+ instance_variable_set("@#{thing}", klass.new(response))
10
+ end
11
+ end
12
+
13
+ def get thing
14
+ request.send(thing.to_sym, self.send("#{thing}_id"))
15
+ end
16
+
17
+ def request
18
+ Bandcamp::Request.new(Bandcamp.config.api_key)
19
+ end
20
+
21
+ private :retrieve_associated, :request, :get
22
+
23
+ end
24
+ end
@@ -1,9 +1,13 @@
1
+ require 'bandcamp/band'
2
+ require 'bandcamp/request'
1
3
  require 'bandcamp/methodical'
4
+ require 'bandcamp/associated'
2
5
 
3
6
  module Bandcamp
4
7
  class Track
5
8
 
6
9
  include Bandcamp::Methodical
10
+ include Bandcamp::Associated
7
11
 
8
12
  def initialize attrs
9
13
  to_methods attrs
@@ -17,5 +21,13 @@ module Bandcamp
17
21
  downloadable == 1 ? true : false
18
22
  end
19
23
 
24
+ def band
25
+ retrieve_associated :band
26
+ end
27
+
28
+ def album
29
+ retrieve_associated :album
30
+ end
31
+
20
32
  end
21
33
  end
@@ -1,3 +1,3 @@
1
1
  module Bandcamp
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -0,0 +1,53 @@
1
+ require 'bandcamp/request'
2
+ require 'bandcamp/band'
3
+ require 'bandcamp/associated'
4
+
5
+ module Bandcamp
6
+
7
+ describe Associated do
8
+
9
+ let(:klass) do
10
+ Class.new do
11
+ include Associated
12
+
13
+ def band_id
14
+ 950934886
15
+ end
16
+
17
+ def band
18
+ retrieve_associated :band
19
+ end
20
+
21
+ end.new
22
+ end
23
+
24
+ let(:faux_request) do
25
+ Class.new do
26
+ def band *args
27
+ {band_id: 950934886}
28
+ end
29
+ end.new
30
+ end
31
+
32
+ it "adds the retrieve_associated method" do
33
+ expect(klass.private_methods).to include :retrieve_associated
34
+ end
35
+
36
+ context "requests associated data from api using _id attributes" do
37
+ context "when band is passed" do
38
+ it "returns a band object" do
39
+ klass.stub(:get).and_return({band_id: 950934886})
40
+ expect(klass.band).to be_a Band
41
+ end
42
+
43
+ it "calls band_id to find the id to request" do
44
+ klass.stub(:request).and_return(faux_request)
45
+ klass.should_receive(:band_id).and_return 950934886
46
+ klass.band
47
+ end
48
+ end
49
+ end
50
+ end
51
+
52
+ end
53
+
data/spec/track_spec.rb CHANGED
@@ -7,7 +7,11 @@ module Bandcamp
7
7
  describe Track do
8
8
 
9
9
  it "includes Bandcamp::Methodical" do
10
- expect(Track.ancestors).to include(Bandcamp::Methodical)
10
+ expect(track.private_methods).to include(:to_methods)
11
+ end
12
+
13
+ it "includes Bandcamp::Associated" do
14
+ expect(track.private_methods).to include(:retrieve_associated)
11
15
  end
12
16
 
13
17
  let(:track_json){ MultiJson.decode(File.read(File.join %w(spec fixtures a_new_day.json))) }
@@ -38,6 +42,19 @@ module Bandcamp
38
42
  end
39
43
  end
40
44
 
45
+ describe "#band" do
46
+ it "returns the associated band object" do
47
+ track.stub(:retrieve_associated).and_return(Band.new(foo: "bar"))
48
+ expect(track.band).to be_a Band
49
+ end
50
+ end
51
+
52
+ describe "#album" do
53
+ it "returns the associated album object" do
54
+ track.stub(:retrieve_associated).and_return(Album.new(foo: "bar"))
55
+ expect(track.album).to be_an Album
56
+ end
57
+ end
41
58
  end
42
59
 
43
60
  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.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -59,6 +59,7 @@ files:
59
59
  - bandcamp_api.gemspec
60
60
  - lib/bandcamp.rb
61
61
  - lib/bandcamp/album.rb
62
+ - lib/bandcamp/associated.rb
62
63
  - lib/bandcamp/band.rb
63
64
  - lib/bandcamp/configuration.rb
64
65
  - lib/bandcamp/getter.rb
@@ -68,6 +69,7 @@ files:
68
69
  - lib/bandcamp/version.rb
69
70
  - lib/bandcamp_api.rb
70
71
  - spec/album_spec.rb
72
+ - spec/associated_spec.rb
71
73
  - spec/band_spec.rb
72
74
  - spec/bandcamp_spec.rb
73
75
  - spec/configuration_spec.rb
@@ -114,6 +116,7 @@ summary: A library for communicating with the Bandcamp.com api and wrapping the
114
116
  types of data to make it easier to work with.
115
117
  test_files:
116
118
  - spec/album_spec.rb
119
+ - spec/associated_spec.rb
117
120
  - spec/band_spec.rb
118
121
  - spec/bandcamp_spec.rb
119
122
  - spec/configuration_spec.rb