bandsintown 0.1.2 → 0.1.4

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.
@@ -1,3 +1,12 @@
1
+ == 0.1.4 2010-03-02
2
+ * Added Events - On Sale Soon API method (Bandsintown::Event.on_sale_soon)
3
+ * Corrected some typos in Bandsintown::Event spec
4
+
5
+ == 0.1.3 2010-01-28
6
+ * Added Artists - Get API method (Bandsintown::Artist.get)
7
+ * Added Bandsintown::Artist#on_tour? method
8
+ * Updated readme and documentation for Bandsintown::Artist.get and Bandsintown::Artist#on_tour?
9
+
1
10
  == 0.1.2 2009-11-11
2
11
  * updated Bandsintown::Artist class with support for mbid / music brainz id and additional documentation
3
12
 
@@ -39,6 +39,27 @@ For more information visit http://www.bandsintown.com/api/requests.
39
39
  })
40
40
  events = artist.events
41
41
 
42
+ === Find basic information about an artist without requesting event data
43
+
44
+ artist = Bandsintown::Artist.get({
45
+ :name => "Raekwon"
46
+ })
47
+ artist.upcoming_events_count
48
+ => 5
49
+ artist.on_tour?
50
+ => true
51
+
52
+ === Find basic information about an artist without requesting event data, using mbid
53
+
54
+ # 4e954b02-fae2-4bd7-9547-e055a6ac0527 => mbid for Raekwon
55
+ artist = Bandsintown::Artist.get({
56
+ :mbid => "4e954b02-fae2-4bd7-9547-e055a6ac0527"
57
+ })
58
+ artist.upcoming_events_count
59
+ => 5
60
+ artist.on_tour?
61
+ => true
62
+
42
63
  === Find events this week around Boston, MA
43
64
 
44
65
  events = Bandsintown::Event.search({
@@ -75,10 +96,17 @@ For more information visit http://www.bandsintown.com/api/requests.
75
96
  :location => 'Boston, MA'
76
97
  })
77
98
 
78
- === find events added/updated/deleted within the last day
99
+ === Find events added/updated/deleted within the last day
79
100
 
80
101
  events = Bandsintown::Event.daily
81
102
 
103
+ === Find events going on sale in the next week within 10 miles of Boston, MA
104
+
105
+ events = Bandsintown::Event.on_sale_soon({
106
+ :location => "Boston, MA",
107
+ :radius => 10
108
+ })
109
+
82
110
  == Links
83
111
 
84
112
  * RDoc[http://bandsintown.rubyforge.org/rdoc]
data/Rakefile CHANGED
@@ -1,4 +1,4 @@
1
- %w[rubygems rake rake/clean fileutils newgem rubigen hoe].each { |f| require f }
1
+ %w[rubygems rake rake/clean fileutils newgem rubigen].each { |f| require f }
2
2
  require File.dirname(__FILE__) + '/lib/bandsintown'
3
3
 
4
4
  # Generate all the Rake tasks
@@ -14,7 +14,7 @@ require 'bandsintown/event'
14
14
  require 'bandsintown/venue'
15
15
 
16
16
  module Bandsintown
17
- VERSION = '0.1.2'
17
+ VERSION = '0.1.4'
18
18
  class APIError < StandardError; end
19
19
  class << self
20
20
  # All Bandsintown API requests require an app_id parameter for identification.
@@ -1,7 +1,7 @@
1
1
  module Bandsintown
2
2
  class Artist < Base
3
3
 
4
- attr_accessor :name, :bandsintown_url, :mbid, :events
4
+ attr_accessor :name, :bandsintown_url, :mbid, :events, :upcoming_events_count
5
5
 
6
6
  def initialize(options = {})
7
7
  @name = options[:name]
@@ -40,6 +40,47 @@ module Bandsintown
40
40
  "mbid_#{@mbid}"
41
41
  end
42
42
  end
43
+
44
+ #Returns true if there is at least 1 upcoming event for the artist, or false if there are 0 upcoming events for the artist.
45
+ #Should only be used for artists requested using Bandsintown::Artist.get, or with events already loaded, otherwise an error will be raised.
46
+ #====example:
47
+ # # using .get method
48
+ # artist = Bandsintown::Artist.get(:name => "Little Brother")
49
+ # artist_on_tour = artist.on_tour?
50
+ #
51
+ # # using .initialize and .events methods
52
+ # artist = Bandsintown::Artist.get(:name => "Little Brother")
53
+ # events = artist.events
54
+ # artist_on_tour = artist.on_tour?
55
+ #
56
+ def on_tour?
57
+ (@upcoming_events_count || @events.size) > 0
58
+ end
59
+
60
+ #Returns a Bandsintown::Artist object with basic information for a single artist, including the number of upcoming events.
61
+ #Useful in determining if an artist is on tour without requesting the event data.
62
+ #See http://www.bandsintown.com/api/requests#artists-get for more information.
63
+ #Can be used with either artist name or mbid (music brainz id).
64
+ #====example:
65
+ # # using artist name
66
+ # artist = Bandsintown::Artist.get(:name => "Little Brother")
67
+ #
68
+ # # using mbid for Little Brother
69
+ # artist = Bandsintown::Artist.get(:mbid => "b929c0c9-5de0-4d87-8eb9-365ad1725629")
70
+ #
71
+ def self.get(options = {})
72
+ request_url = Bandsintown::Artist.new(options).api_name
73
+ build_from_json(request_and_parse(request_url))
74
+ end
75
+
76
+ def self.build_from_json(json_hash)
77
+ artist = Bandsintown::Artist.new({})
78
+ artist.name = json_hash['name']
79
+ artist.mbid = json_hash['mbid']
80
+ artist.bandsintown_url = json_hash['url']
81
+ artist.upcoming_events_count = json_hash['upcoming_events_count']
82
+ artist
83
+ end
43
84
 
44
85
  def self.resource_path
45
86
  "artists"
@@ -79,6 +79,27 @@ module Bandsintown
79
79
  events
80
80
  end
81
81
 
82
+ #Returns an array of Bandsintown::Event objects going on sale in the next week, and matching the options passed.
83
+ #See http://www.bandsintown.com/api/requests#on-sale-soon for more information.
84
+ #====options:
85
+ #:location, :radius, and :date options are supported. See the Bandsintown::Event.search documentation for accepted formats.
86
+ #
87
+ #====notes:
88
+ #If :location is given without :radius, a default radius of 25 miles will be used.
89
+ #
90
+ #====examples:
91
+ #All upcoming concerts within 10 miles of Boston, MA, with tickets going on sale in the next week:
92
+ # Bandsintown::Event.on_sale_soon(:location => "Boston, MA", :radius => 10)
93
+ #
94
+ #All concerts happening between Mar 01 2010 and Mar 15 2010 within 25 miles of London, UK, with tickets going on sale in the next week:
95
+ # Bandsintown::Event.on_sale_soon(:location => "London, UK", :start_date => "2010-03-01", :end_date => "2010-03-15")
96
+ #
97
+ def self.on_sale_soon(options = {})
98
+ events = []
99
+ self.request_and_parse("on_sale_soon", options).each { |event| events << Bandsintown::Event.build_from_json(event) }
100
+ events
101
+ end
102
+
82
103
  def self.resource_path
83
104
  "events"
84
105
  end
@@ -24,6 +24,10 @@ describe Bandsintown::Artist do
24
24
  @artist.should respond_to(:mbid)
25
25
  @artist.should respond_to(:mbid=)
26
26
  end
27
+ it "should have an attr_accessor for @upcoming_events_count" do
28
+ @artist.should respond_to(:upcoming_events_count)
29
+ @artist.should respond_to(:upcoming_events_count=)
30
+ end
27
31
  end
28
32
 
29
33
  describe ".initialize(options = {})" do
@@ -140,4 +144,80 @@ describe Bandsintown::Artist do
140
144
  Bandsintown::Artist.new(:mbid => '1234').api_name.should == 'mbid_1234'
141
145
  end
142
146
  end
147
+
148
+ describe ".get(options = {})" do
149
+ before(:each) do
150
+ @options = { :name => "Pete Rock" }
151
+ @artist = Bandsintown::Artist.new(@options)
152
+ Bandsintown::Artist.stub!(:request_and_parse).and_return('json')
153
+ Bandsintown::Artist.stub!(:build_from_json).and_return('built artist')
154
+ end
155
+ it "should initialize a Bandsintown::Artist from options" do
156
+ Bandsintown::Artist.should_receive(:new).with(@options).and_return(@artist)
157
+ Bandsintown::Artist.get(@options)
158
+ end
159
+ it "should request and parse a call to the BIT artists - get API method using api_name" do
160
+ Bandsintown::Artist.should_receive(:request_and_parse).with(@artist.api_name).and_return('json')
161
+ Bandsintown::Artist.get(@options)
162
+ end
163
+ it "should return the result of Bandsintown::Artist.build_from_json with the response data" do
164
+ Bandsintown::Artist.should_receive(:build_from_json).with('json').and_return('built artist')
165
+ Bandsintown::Artist.get(@options).should == 'built artist'
166
+ end
167
+ end
168
+
169
+ describe ".build_from_json(json_hash)" do
170
+ before(:each) do
171
+ @name = "Pete Rock"
172
+ @bandsintown_url = "http://www.bandsintown.com/PeteRock"
173
+ @mbid = "39a973f2-0785-4ef6-90d9-551378864f89"
174
+ @upcoming_events_count = 7
175
+ @json_hash = {
176
+ "name" => @name,
177
+ "url" => @bandsintown_url,
178
+ "mbid" => @mbid,
179
+ "upcoming_events_count" => @upcoming_events_count
180
+ }
181
+ @artist = Bandsintown::Artist.build_from_json(@json_hash)
182
+ end
183
+ it "should return an instance of Bandsintown::Artist" do
184
+ @artist.should be_instance_of(Bandsintown::Artist)
185
+ end
186
+ it "should set the name" do
187
+ @artist.name.should == @name
188
+ end
189
+ it "should set the mbid" do
190
+ @artist.mbid.should == @mbid
191
+ end
192
+ it "should set the bandsintown_url" do
193
+ @artist.bandsintown_url.should == @bandsintown_url
194
+ end
195
+ it "should set the upcoming events count" do
196
+ @artist.upcoming_events_count.should == @upcoming_events_count
197
+ end
198
+ end
199
+
200
+ describe "#on_tour?" do
201
+ it "should return true if @upcoming_events_count is greater than 0" do
202
+ @artist.upcoming_events_count = 1
203
+ @artist.should be_on_tour
204
+ end
205
+ it "should return false if @upcoming_events_count is 0" do
206
+ @artist.upcoming_events_count = 0
207
+ @artist.should_not be_on_tour
208
+ end
209
+ it "should raise an error if both @upcoming_events_count and @events are nil" do
210
+ lambda { @artist.on_tour? }.should raise_error
211
+ end
212
+ describe "when @upcoming_events_count is nil" do
213
+ it "should return true if @events is not empty (.events only returns upcoming events)" do
214
+ @artist.events = [mock(Bandsintown::Event)]
215
+ @artist.should be_on_tour
216
+ end
217
+ it "should return false if @events is empty" do
218
+ @artist.events = []
219
+ @artist.should_not be_on_tour
220
+ end
221
+ end
222
+ end
143
223
  end
@@ -8,8 +8,10 @@ describe Bandsintown::Event do
8
8
  end
9
9
  end
10
10
 
11
- describe ".search(args = {})" do
12
- @args = { :location => "Boston, MA", :date => "2009-01-01" }
11
+ describe ".search(options = {})" do
12
+ before(:each) do
13
+ @args = { :location => "Boston, MA", :date => "2009-01-01" }
14
+ end
13
15
  it "should request and parse a call to the BIT events search api method" do
14
16
  Bandsintown::Event.should_receive(:request_and_parse).with("search", @args).and_return([])
15
17
  Bandsintown::Event.search(@args)
@@ -25,8 +27,10 @@ describe Bandsintown::Event do
25
27
  end
26
28
  end
27
29
 
28
- describe ".recommended(args = {})" do
29
- @args = { :location => "Boston, MA", :date => "2009-01-01" }
30
+ describe ".recommended(options = {})" do
31
+ before(:each) do
32
+ @args = { :location => "Boston, MA", :date => "2009-01-01" }
33
+ end
30
34
  it "should request and parse a call to the BIT recommended events api method" do
31
35
  Bandsintown::Event.should_receive(:request_and_parse).with("recommended", @args).and_return([])
32
36
  Bandsintown::Event.recommended(@args)
@@ -55,6 +59,22 @@ describe Bandsintown::Event do
55
59
  end
56
60
  end
57
61
 
62
+ describe ".on_sale_soon(options = {})" do
63
+ before(:each) do
64
+ @args = { :location => "Boston, MA", :radius => 50, :date => "2010-03-02" }
65
+ end
66
+ it "should request and parse a call to the BIT on sale soon api method" do
67
+ Bandsintown::Event.should_receive(:request_and_parse).with("on_sale_soon", @args).and_return([])
68
+ Bandsintown::Event.on_sale_soon(@args)
69
+ end
70
+ it "should return an array of Bandsintown::Events built from the response" do
71
+ event = mock(Bandsintown::Event)
72
+ Bandsintown::Event.stub!(:request_and_parse).and_return(['event json'])
73
+ Bandsintown::Event.should_receive(:build_from_json).with('event json').and_return(event)
74
+ Bandsintown::Event.daily.should == [event]
75
+ end
76
+ end
77
+
58
78
  describe ".build_from_json(json_hash)" do
59
79
  before(:each) do
60
80
  @event_id = 745089
@@ -34,7 +34,7 @@
34
34
  <div class="sidebar">
35
35
  <div id="version" class="clickable" onclick='document.location = "http://rubyforge.org/projects/bandsintown"; return false'>
36
36
  <p>Get Version</p>
37
- <a href="http://rubyforge.org/projects/bandsintown" class="numbers">0.1.2</a>
37
+ <a href="http://rubyforge.org/projects/bandsintown" class="numbers">0.1.4</a>
38
38
  </div>
39
39
  </div>
40
40
  <h2>Description</h2>
@@ -66,6 +66,27 @@
66
66
  <span class="punct">})</span>
67
67
  <span class="ident">events</span> <span class="punct">=</span> <span class="ident">artist</span><span class="punct">.</span><span class="ident">events</span>
68
68
  </pre></p>
69
+ <h3>Find basic information about an artist without requesting event data</h3>
70
+ <p><pre class='syntax'>
71
+ <span class="ident">artist</span> <span class="punct">=</span> <span class="constant">Bandsintown</span><span class="punct">::</span><span class="constant">Artist</span><span class="punct">.</span><span class="ident">get</span><span class="punct">({</span>
72
+ <span class="symbol">:name</span> <span class="punct">=&gt;</span> <span class="punct">&quot;</span><span class="string">Raekwon</span><span class="punct">&quot;</span>
73
+ <span class="punct">})</span>
74
+ <span class="ident">artist</span><span class="punct">.</span><span class="ident">upcoming_events_count</span>
75
+ <span class="punct">=&gt;</span> <span class="number">5</span>
76
+ <span class="ident">artist</span><span class="punct">.</span><span class="ident">on_tour?</span>
77
+ <span class="punct">=&gt;</span> <span class="constant">true</span>
78
+ </pre></p>
79
+ <h3>Find basic information about an artist without requesting event data, using mbid</h3>
80
+ <p><pre class='syntax'>
81
+ <span class="comment"># 4e954b02-fae2-4bd7-9547-e055a6ac0527 =&gt; mbid for Raekwon</span>
82
+ <span class="ident">artist</span> <span class="punct">=</span> <span class="constant">Bandsintown</span><span class="punct">::</span><span class="constant">Artist</span><span class="punct">.</span><span class="ident">get</span><span class="punct">({</span>
83
+ <span class="symbol">:mbid</span> <span class="punct">=&gt;</span> <span class="punct">&quot;</span><span class="string">4e954b02-fae2-4bd7-9547-e055a6ac0527</span><span class="punct">&quot;</span>
84
+ <span class="punct">})</span>
85
+ <span class="ident">artist</span><span class="punct">.</span><span class="ident">upcoming_events_count</span>
86
+ <span class="punct">=&gt;</span> <span class="number">5</span>
87
+ <span class="ident">artist</span><span class="punct">.</span><span class="ident">on_tour?</span>
88
+ <span class="punct">=&gt;</span> <span class="constant">true</span>
89
+ </pre></p>
69
90
  <h3>Find events this week around Boston, MA</h3>
70
91
  <p><pre class='syntax'>
71
92
  <span class="ident">events</span> <span class="punct">=</span> <span class="constant">Bandsintown</span><span class="punct">::</span><span class="constant">Event</span><span class="punct">.</span><span class="ident">search</span><span class="punct">({</span>
@@ -106,6 +127,13 @@
106
127
  <p><pre class='syntax'>
107
128
  <span class="ident">events</span> <span class="punct">=</span> <span class="constant">Bandsintown</span><span class="punct">::</span><span class="constant">Event</span><span class="punct">.</span><span class="ident">daily</span>
108
129
  </pre></p>
130
+ <h3>Find events going on sale in the next week within 10 miles of Boston, MA</h3>
131
+ <p><pre class='syntax'>
132
+ <span class="ident">events</span> <span class="punct">=</span> <span class="constant">Bandsintown</span><span class="punct">::</span><span class="constant">Event</span><span class="punct">.</span><span class="ident">on_sale_soon</span><span class="punct">({</span>
133
+ <span class="symbol">:location</span> <span class="punct">=&gt;</span> <span class="punct">&quot;</span><span class="string">Boston, MA</span><span class="punct">&quot;,</span>
134
+ <span class="symbol">:radius</span> <span class="punct">=&gt;</span> <span class="number">10</span>
135
+ <span class="punct">})</span>
136
+ </pre></p>
109
137
  <h2>Source</h2>
110
138
  <pre>git clone git://github.com/bandsintown/bandsintown.git</pre>
111
139
  <h2>Links</h2>
@@ -45,6 +45,31 @@ artist = Bandsintown::Artist.new({
45
45
  events = artist.events
46
46
  </pre>
47
47
 
48
+ h3. Find basic information about an artist without requesting event data
49
+
50
+ <pre syntax="ruby">
51
+ artist = Bandsintown::Artist.get({
52
+ :name => "Raekwon"
53
+ })
54
+ artist.upcoming_events_count
55
+ => 5
56
+ artist.on_tour?
57
+ => true
58
+ </pre>
59
+
60
+ h3. Find basic information about an artist without requesting event data, using mbid
61
+
62
+ <pre syntax="ruby">
63
+ # 4e954b02-fae2-4bd7-9547-e055a6ac0527 => mbid for Raekwon
64
+ artist = Bandsintown::Artist.get({
65
+ :mbid => "4e954b02-fae2-4bd7-9547-e055a6ac0527"
66
+ })
67
+ artist.upcoming_events_count
68
+ => 5
69
+ artist.on_tour?
70
+ => true
71
+ </pre>
72
+
48
73
  h3. Find events this week around Boston, MA
49
74
 
50
75
  <pre syntax="ruby">
@@ -95,6 +120,15 @@ h3. Find events added/updated/deleted within the last day
95
120
  events = Bandsintown::Event.daily
96
121
  </pre>
97
122
 
123
+ h3. Find events going on sale in the next week within 10 miles of Boston, MA
124
+
125
+ <pre syntax="ruby">
126
+ events = Bandsintown::Event.on_sale_soon({
127
+ :location => "Boston, MA",
128
+ :radius => 10
129
+ })
130
+ </pre>
131
+
98
132
  h2. Source
99
133
 
100
134
  <pre>git clone git://github.com/bandsintown/bandsintown.git</pre>
metadata CHANGED
@@ -1,7 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bandsintown
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 4
9
+ version: 0.1.4
5
10
  platform: ruby
6
11
  authors:
7
12
  - Mike Costanza
@@ -9,49 +14,65 @@ autorequire:
9
14
  bindir: bin
10
15
  cert_chain: []
11
16
 
12
- date: 2009-11-12 00:00:00 -05:00
17
+ date: 2010-03-03 00:00:00 -08:00
13
18
  default_executable:
14
19
  dependencies:
15
20
  - !ruby/object:Gem::Dependency
16
21
  name: activesupport
17
- type: :runtime
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
20
24
  requirements:
21
25
  - - ">="
22
26
  - !ruby/object:Gem::Version
27
+ segments:
28
+ - 2
29
+ - 0
30
+ - 2
23
31
  version: 2.0.2
24
- version:
32
+ type: :runtime
33
+ version_requirements: *id001
25
34
  - !ruby/object:Gem::Dependency
26
35
  name: json
27
- type: :runtime
28
- version_requirement:
29
- version_requirements: !ruby/object:Gem::Requirement
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
30
38
  requirements:
31
39
  - - ">="
32
40
  - !ruby/object:Gem::Version
41
+ segments:
42
+ - 1
43
+ - 1
44
+ - 3
33
45
  version: 1.1.3
34
- version:
46
+ type: :runtime
47
+ version_requirements: *id002
35
48
  - !ruby/object:Gem::Dependency
36
49
  name: newgem
37
- type: :development
38
- version_requirement:
39
- version_requirements: !ruby/object:Gem::Requirement
50
+ prerelease: false
51
+ requirement: &id003 !ruby/object:Gem::Requirement
40
52
  requirements:
41
53
  - - ">="
42
54
  - !ruby/object:Gem::Version
43
- version: 1.5.2
44
- version:
55
+ segments:
56
+ - 1
57
+ - 4
58
+ - 1
59
+ version: 1.4.1
60
+ type: :development
61
+ version_requirements: *id003
45
62
  - !ruby/object:Gem::Dependency
46
63
  name: hoe
47
- type: :development
48
- version_requirement:
49
- version_requirements: !ruby/object:Gem::Requirement
64
+ prerelease: false
65
+ requirement: &id004 !ruby/object:Gem::Requirement
50
66
  requirements:
51
67
  - - ">="
52
68
  - !ruby/object:Gem::Version
53
- version: 2.3.3
54
- version:
69
+ segments:
70
+ - 1
71
+ - 8
72
+ - 0
73
+ version: 1.8.0
74
+ type: :development
75
+ version_requirements: *id004
55
76
  description: |-
56
77
  Bandsintown.com API gem
57
78
 
@@ -69,6 +90,7 @@ extensions: []
69
90
  extra_rdoc_files:
70
91
  - History.txt
71
92
  - Manifest.txt
93
+ - README.rdoc
72
94
  - website/index.txt
73
95
  files:
74
96
  - History.txt
@@ -112,18 +134,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
112
134
  requirements:
113
135
  - - ">="
114
136
  - !ruby/object:Gem::Version
137
+ segments:
138
+ - 0
115
139
  version: "0"
116
- version:
117
140
  required_rubygems_version: !ruby/object:Gem::Requirement
118
141
  requirements:
119
142
  - - ">="
120
143
  - !ruby/object:Gem::Version
144
+ segments:
145
+ - 0
121
146
  version: "0"
122
- version:
123
147
  requirements: []
124
148
 
125
149
  rubyforge_project: bandsintown
126
- rubygems_version: 1.3.5
150
+ rubygems_version: 1.3.6
127
151
  signing_key:
128
152
  specification_version: 3
129
153
  summary: Bandsintown.com API gem A Ruby library for accessing the Bandsintown API