bandsintown 0.1.4 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +8 -0
- data/Manifest.txt +1 -0
- data/README.rdoc +42 -0
- data/Rakefile +2 -1
- data/lib/bandsintown.rb +3 -3
- data/lib/bandsintown/artist.rb +9 -9
- data/lib/bandsintown/base.rb +18 -4
- data/lib/bandsintown/connection.rb +14 -7
- data/lib/bandsintown/event.rb +136 -15
- data/lib/bandsintown/venue.rb +66 -11
- data/spec/bandsintown/artist_spec.rb +2 -2
- data/spec/bandsintown/base_spec.rb +46 -19
- data/spec/bandsintown/connection_spec.rb +78 -55
- data/spec/bandsintown/event/creation_helpers_spec.rb +102 -0
- data/spec/bandsintown/event_spec.rb +93 -16
- data/spec/bandsintown/venue_spec.rb +119 -2
- data/website/index.html +43 -1
- data/website/index.txt +50 -0
- metadata +23 -8
@@ -112,7 +112,7 @@ describe Bandsintown::Artist do
|
|
112
112
|
end
|
113
113
|
it "should request and parse a call to the BIT artist events API method and the artist's api name" do
|
114
114
|
@artist.should_receive(:api_name).and_return('Little%20Brother')
|
115
|
-
Bandsintown::Artist.should_receive(:request_and_parse).with("Little%20Brother/events").and_return([])
|
115
|
+
Bandsintown::Artist.should_receive(:request_and_parse).with(:get, "Little%20Brother/events").and_return([])
|
116
116
|
@artist.events
|
117
117
|
end
|
118
118
|
it "should return an Array of Bandsintown::Event objects built from the response" do
|
@@ -157,7 +157,7 @@ describe Bandsintown::Artist do
|
|
157
157
|
Bandsintown::Artist.get(@options)
|
158
158
|
end
|
159
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')
|
160
|
+
Bandsintown::Artist.should_receive(:request_and_parse).with(:get, @artist.api_name).and_return('json')
|
161
161
|
Bandsintown::Artist.get(@options)
|
162
162
|
end
|
163
163
|
it "should return the result of Bandsintown::Artist.build_from_json with the response data" do
|
@@ -11,21 +11,37 @@ describe Bandsintown::Base do
|
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
|
-
describe ".request(api_method,
|
15
|
-
|
16
|
-
resource_path
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
14
|
+
describe ".request(http_method, api_method, params={})" do
|
15
|
+
before(:each) do
|
16
|
+
Bandsintown::Base.stub!(:resource_path).and_return("events")
|
17
|
+
end
|
18
|
+
it "should make a GET request to the connection url using api_method and params when http_method == :get" do
|
19
|
+
http_method = :get
|
20
|
+
api_method = "search"
|
21
|
+
params = { :arg => "value" }
|
22
|
+
Bandsintown::Base.stub!(:resource_path).and_return("events")
|
23
|
+
Bandsintown::Base.connection.should_receive(:get).with("events", api_method, params).and_return("response")
|
24
|
+
Bandsintown::Base.request(http_method, api_method, params).should == "response"
|
25
|
+
end
|
26
|
+
it "should make a POST request to the connection url using api_method and params when http_method == :post" do
|
27
|
+
http_method = :post
|
28
|
+
api_method = "create"
|
29
|
+
params = { :arg => "value" }
|
30
|
+
Bandsintown::Base.connection.should_receive(:post).with("events", api_method, params).and_return("response")
|
31
|
+
Bandsintown::Base.request(http_method, api_method, params).should == "response"
|
32
|
+
end
|
33
|
+
it "should raise an error if http_method is not :get or :post" do
|
34
|
+
http_method = :delete
|
35
|
+
api_method = "search"
|
36
|
+
params = { :arg => "value" }
|
37
|
+
lambda { Bandsintown::Base.request(http_method, api_method, params) }.should raise_error(ArgumentError, "only :get and :post requests are supported")
|
22
38
|
end
|
23
39
|
end
|
24
40
|
|
25
41
|
describe ".parse(response)" do
|
26
42
|
it "should check the response for errors" do
|
27
43
|
response = "response"
|
28
|
-
parsed
|
44
|
+
parsed = mock("parsed json")
|
29
45
|
JSON.stub!(:parse).and_return(parsed)
|
30
46
|
Bandsintown::Base.should_receive(:check_for_errors).with(parsed)
|
31
47
|
Bandsintown::Base.parse(response)
|
@@ -36,23 +52,23 @@ describe Bandsintown::Base do
|
|
36
52
|
end
|
37
53
|
end
|
38
54
|
|
39
|
-
describe ".request_and_parse(api_method,
|
55
|
+
describe ".request_and_parse(http_method, api_method, params={})" do
|
40
56
|
before(:each) do
|
41
|
-
@
|
42
|
-
@
|
43
|
-
@
|
44
|
-
Bandsintown::Base.stub!(:resource_path).and_return(
|
45
|
-
@response = mock("
|
57
|
+
@http_method = :get
|
58
|
+
@api_method = "search"
|
59
|
+
@params = { :arg => "value" }
|
60
|
+
Bandsintown::Base.stub!(:resource_path).and_return("events")
|
61
|
+
@response = mock("HTTP response body")
|
46
62
|
end
|
47
|
-
it "should make a request" do
|
48
|
-
Bandsintown::Base.should_receive(:request).with(@
|
63
|
+
it "should make a request with the http method, api method, and params" do
|
64
|
+
Bandsintown::Base.should_receive(:request).with(@http_method, @api_method, @params).and_return(@response)
|
49
65
|
Bandsintown::Base.stub!(:parse)
|
50
|
-
Bandsintown::Base.request_and_parse(@
|
66
|
+
Bandsintown::Base.request_and_parse(@http_method, @api_method, @params)
|
51
67
|
end
|
52
68
|
it "should parse the response" do
|
53
69
|
Bandsintown::Base.stub!(:request).and_return(@response)
|
54
70
|
Bandsintown::Base.should_receive(:parse).with(@response)
|
55
|
-
Bandsintown::Base.request_and_parse(@
|
71
|
+
Bandsintown::Base.request_and_parse(@http_method, @api_method, @params)
|
56
72
|
end
|
57
73
|
end
|
58
74
|
|
@@ -67,4 +83,15 @@ describe Bandsintown::Base do
|
|
67
83
|
end
|
68
84
|
end
|
69
85
|
|
86
|
+
|
87
|
+
describe "#to_hash" do
|
88
|
+
it "should return a hash from non-blank instance variables" do
|
89
|
+
class Bandsintown::TestObject < Bandsintown::Base; attr_accessor :one, :two, :three; end
|
90
|
+
test_object = Bandsintown::TestObject.new
|
91
|
+
test_object.one = '1'
|
92
|
+
test_object.two = 2
|
93
|
+
test_object.three = ''
|
94
|
+
test_object.to_hash.should == { :one => '1', :two => 2 }
|
95
|
+
end
|
96
|
+
end
|
70
97
|
end
|
@@ -7,79 +7,102 @@ describe Bandsintown::Connection do
|
|
7
7
|
end
|
8
8
|
|
9
9
|
describe ".initialize(base_url)" do
|
10
|
+
before(:each) do
|
11
|
+
@connection = Bandsintown::Connection.new(@base_url)
|
12
|
+
end
|
10
13
|
it "should set the base_url for the Connection" do
|
11
|
-
|
14
|
+
@connection.base_url.should == @base_url
|
12
15
|
end
|
13
16
|
end
|
14
17
|
|
15
|
-
describe ".
|
18
|
+
describe ".get(resource_path, method_path, params = {})" do
|
16
19
|
before(:each) do
|
17
20
|
@connection = Bandsintown::Connection.new(@base_url)
|
18
|
-
|
19
|
-
@connection.stub!(:open).and_return(@response)
|
21
|
+
RestClient.stub!(:get).and_return("response")
|
20
22
|
@api_resource = "events"
|
21
23
|
@api_method = "search"
|
22
24
|
end
|
23
|
-
it "should
|
24
|
-
|
25
|
-
request_url
|
26
|
-
@connection.should_receive(:
|
27
|
-
|
25
|
+
it "should make a get request to the url constructed with resource path, method path, and encoded params" do
|
26
|
+
params = { :artists => ["Little Brother", "Joe Scudda"], :location => "Boston, MA", :radius => 10 }
|
27
|
+
request_url = "http://api.bandsintown.com/events/search?app_id=YOUR_APP_ID&artists%5B%5D=Little+Brother&artists%5B%5D=Joe+Scudda&format=json&location=Boston%2C+MA&radius=10"
|
28
|
+
@connection.should_receive(:encode).with(params).and_return("app_id=YOUR_APP_ID&artists%5B%5D=Little+Brother&artists%5B%5D=Joe+Scudda&format=json&location=Boston%2C+MA&radius=10")
|
29
|
+
RestClient.should_receive(:get).with(request_url).and_return("response")
|
30
|
+
@connection.get(@api_resource, @api_method, params).should == "response"
|
28
31
|
end
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
@connection.
|
32
|
+
|
33
|
+
it "should return the API error message instead of raising an error if there was a problem with the request (404 response)" do
|
34
|
+
error = RestClient::ResourceNotFound.new; error.response = "error message"
|
35
|
+
RestClient.stub!(:get).and_raise(error)
|
36
|
+
lambda { @connection.get("", "", {}) }.should_not raise_error
|
37
|
+
@connection.get("", "", {}).should == "error message"
|
34
38
|
end
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
39
|
+
end
|
40
|
+
|
41
|
+
describe ".post(resource_path, method_path, body = {})" do
|
42
|
+
before(:each) do
|
43
|
+
@connection = Bandsintown::Connection.new(@base_url)
|
44
|
+
RestClient.stub!(:post).and_return("response")
|
45
|
+
@api_resource = "events"
|
46
|
+
@api_method = "create"
|
47
|
+
@body_params = {
|
48
|
+
:event => {
|
49
|
+
:artists => [{ :name => "Little Brother" }],
|
50
|
+
:datetime => "2010-06-01T19:30:00",
|
51
|
+
:venue => { :id => 123 }
|
52
|
+
}
|
53
|
+
}
|
54
|
+
end
|
55
|
+
it "should make a post request to the url constructed with resource path, method path, default encoded params, body converted to json, and application/json request headers" do
|
56
|
+
expected_url = "http://api.bandsintown.com/events/create?app_id=YOUR_APP_ID&format=json"
|
57
|
+
expected_body = @body_params.to_json
|
58
|
+
expected_headers = { :content_type => :json, :accept => :json }
|
59
|
+
@connection.should_receive(:encode).with({}).and_return("app_id=YOUR_APP_ID&format=json")
|
60
|
+
RestClient.should_receive(:post).with(expected_url, expected_body, expected_headers).and_return("response")
|
61
|
+
@connection.post(@api_resource, @api_method, @body_params).should == "response"
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should return the API error message instead of raising an error if there was a problem with the request (404 response)" do
|
65
|
+
error = RestClient::ResourceNotFound.new; error.response = "error message"
|
66
|
+
RestClient.stub!(:post).and_raise(error)
|
67
|
+
lambda { @connection.post(@api_resource, @api_method, @body_params) }.should_not raise_error
|
68
|
+
@connection.post(@api_resource, @api_method, @body_params).should == "error message"
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
describe ".encode(params={})" do
|
73
|
+
before(:each) do
|
74
|
+
@connection = Bandsintown::Connection.new(@base_url)
|
40
75
|
end
|
41
|
-
it "should
|
42
|
-
|
43
|
-
request_url = "http://api.bandsintown.com/events/search?app_id=YOUR_APP_ID&date=#{Date.today.strftime("%Y-%m-%d")}&format=json"
|
44
|
-
@connection.should_receive(:open).with(request_url).and_return(@response)
|
45
|
-
@connection.request(@api_resource, @api_method, args)
|
76
|
+
it "should return a query param string including :app_id and :format => json without the user having to specify them" do
|
77
|
+
@connection.encode({}).should == "app_id=#{Bandsintown.app_id}&format=json"
|
46
78
|
end
|
47
|
-
it "should
|
48
|
-
|
49
|
-
|
50
|
-
@connection.should_receive(:open).with(request_url).and_return(@response)
|
51
|
-
@connection.request(@api_resource, @api_method, args)
|
79
|
+
it "should convert params[:start_date] and params[:end_date] to a single params[:date] parameter" do
|
80
|
+
params = { :start_date => "2009-01-01", :end_date => "2009-02-01" }
|
81
|
+
@connection.encode(params).should == "app_id=#{Bandsintown.app_id}&date=2009-01-01%2C2009-02-01&format=json"
|
52
82
|
end
|
53
|
-
it "should allow
|
54
|
-
|
55
|
-
|
56
|
-
@connection.should_receive(:open).with(request_url).and_return(@response)
|
57
|
-
@connection.request(@api_resource, @api_method, args)
|
83
|
+
it "should allow :date to be a Time object" do
|
84
|
+
params = { :date => Time.now.beginning_of_day }
|
85
|
+
@connection.encode(params).should == "app_id=#{Bandsintown.app_id}&date=#{Time.now.strftime("%Y-%m-%d")}&format=json"
|
58
86
|
end
|
59
|
-
it "should allow
|
60
|
-
|
61
|
-
|
62
|
-
@connection.should_receive(:open).with(request_url).and_return(@response)
|
63
|
-
@connection.request(@api_resource, @api_method, args)
|
87
|
+
it "should allow :date to be a Date object" do
|
88
|
+
params = { :date => Date.today }
|
89
|
+
@connection.encode(params).should == "app_id=#{Bandsintown.app_id}&date=#{Date.today}&format=json"
|
64
90
|
end
|
65
|
-
it "should allow
|
66
|
-
|
67
|
-
|
68
|
-
@connection.should_receive(:open).with(request_url).and_return(@response)
|
69
|
-
@connection.request(@api_resource, @api_method, args)
|
91
|
+
it "should allow :date to be a String object" do
|
92
|
+
params = { :date => "2009-01-01" }
|
93
|
+
@connection.encode(params).should == "app_id=#{Bandsintown.app_id}&date=2009-01-01&format=json"
|
70
94
|
end
|
71
|
-
it "should
|
72
|
-
|
73
|
-
@connection.
|
74
|
-
|
75
|
-
|
76
|
-
|
95
|
+
it "should allow :start_date and :end_date to be Time objects" do
|
96
|
+
params = { :start_date => 1.week.ago, :end_date => 1.week.from_now }
|
97
|
+
@connection.encode(params).should == "app_id=#{Bandsintown.app_id}&date=#{1.week.ago.strftime("%Y-%m-%d")}%2C#{1.week.from_now.strftime("%Y-%m-%d")}&format=json"
|
98
|
+
end
|
99
|
+
it "should allow :start_date and :end_date to be Date objects" do
|
100
|
+
params = { :start_date => 1.week.ago.to_date, :end_date => 1.week.from_now.to_date }
|
101
|
+
@connection.encode(params).should == "app_id=#{Bandsintown.app_id}&date=#{1.week.ago.strftime("%Y-%m-%d")}%2C#{1.week.from_now.strftime("%Y-%m-%d")}&format=json"
|
77
102
|
end
|
78
|
-
it "should
|
79
|
-
|
80
|
-
@connection.
|
81
|
-
@connection.request(@api_resource, @api_method, {})
|
103
|
+
it "should allow :start_date and :end_date to be String objects" do
|
104
|
+
params = { :start_date => "2009-01-01", :end_date => "2009-02-01" }
|
105
|
+
@connection.encode(params).should == "app_id=#{Bandsintown.app_id}&date=2009-01-01%2C2009-02-01&format=json"
|
82
106
|
end
|
83
107
|
end
|
84
|
-
|
85
108
|
end
|
@@ -0,0 +1,102 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
2
|
+
|
3
|
+
describe Bandsintown::Event::CreationHelpers do
|
4
|
+
before(:each) do
|
5
|
+
class Bandsintown::ExtendedClass; include Bandsintown::Event::CreationHelpers; end
|
6
|
+
end
|
7
|
+
describe ".parse_datetime(datetime)" do
|
8
|
+
it "should return datetime when given a String object" do
|
9
|
+
datetime = "2010-06-01T20:30:00"
|
10
|
+
expected = datetime
|
11
|
+
Bandsintown::ExtendedClass.parse_datetime(datetime).should == expected
|
12
|
+
end
|
13
|
+
it "should return datetime formatted to ISO 8601 if given a Time object" do
|
14
|
+
datetime = Time.parse("2010-06-01 20:30")
|
15
|
+
expected = "2010-06-01T20:30:00"
|
16
|
+
Bandsintown::ExtendedClass.parse_datetime(datetime).should == expected
|
17
|
+
end
|
18
|
+
it "should return datetime formatted to ISO 8601 if given a DateTime object" do
|
19
|
+
datetime = DateTime.parse("2010-06-01 20:30")
|
20
|
+
expected = "2010-06-01T20:30:00"
|
21
|
+
Bandsintown::ExtendedClass.parse_datetime(datetime).should == expected
|
22
|
+
end
|
23
|
+
it "should return datetime formatted to ISO 8601 at 19:00 if given a Date object" do
|
24
|
+
datetime = Date.parse("2010-06-01")
|
25
|
+
expected = "2010-06-01T19:00:00"
|
26
|
+
Bandsintown::ExtendedClass.parse_datetime(datetime).should == expected
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe ".parse_venue(venue_data)" do
|
31
|
+
describe "venue_data given as a hash" do
|
32
|
+
before(:each) do
|
33
|
+
@venue_data = {
|
34
|
+
:name => "Paradise",
|
35
|
+
:address => "967 Commonwealth Ave",
|
36
|
+
:city => "Boston",
|
37
|
+
:region => "MA",
|
38
|
+
:postalcode => "02215",
|
39
|
+
:country => "United States",
|
40
|
+
:latitude => '',
|
41
|
+
:longitude => ''
|
42
|
+
}
|
43
|
+
end
|
44
|
+
it "should return a hash with non-blank location data if venue_data is given as a hash without bandsintown id" do
|
45
|
+
Bandsintown::ExtendedClass.parse_venue(@venue_data).should == {
|
46
|
+
:name => "Paradise",
|
47
|
+
:address => "967 Commonwealth Ave",
|
48
|
+
:city => "Boston",
|
49
|
+
:region => "MA",
|
50
|
+
:postalcode => "02215",
|
51
|
+
:country => "United States"
|
52
|
+
}
|
53
|
+
end
|
54
|
+
it "should return a hash with bandsintown id and no location data if venue_data is given as a hash with bandsintown id" do
|
55
|
+
@venue_data[:bandsintown_id] = 1700
|
56
|
+
Bandsintown::ExtendedClass.parse_venue(@venue_data).should == { :id => 1700 }
|
57
|
+
end
|
58
|
+
end
|
59
|
+
describe "venue_data given as a Bandsintown::Venue" do
|
60
|
+
before(:each) do
|
61
|
+
@venue = Bandsintown::Venue.new(1700)
|
62
|
+
@venue.name = "Paradise"
|
63
|
+
@venue.address = "967 Commonwealth Ave"
|
64
|
+
@venue.city = "Boston"
|
65
|
+
@venue.region = "MA"
|
66
|
+
@venue.country = "United States"
|
67
|
+
end
|
68
|
+
it "should return a hash with non-blank location data if venue_data is given as a Bandsintown::Venue without bandsintown id" do
|
69
|
+
@venue.bandsintown_id = ''
|
70
|
+
Bandsintown::ExtendedClass.parse_venue(@venue).should == {
|
71
|
+
:name => "Paradise",
|
72
|
+
:address => "967 Commonwealth Ave",
|
73
|
+
:city => "Boston",
|
74
|
+
:region => "MA",
|
75
|
+
:country => "United States"
|
76
|
+
}
|
77
|
+
end
|
78
|
+
it "should return a hash with bandsintown id if venue_data is given as a Bandsintown::Venue with bandsintown id" do
|
79
|
+
Bandsintown::ExtendedClass.parse_venue(@venue).should == { :id => 1700 }
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
describe ".parse_artists(artist_data)" do
|
85
|
+
it "should return an array of { :name => name } when given strings" do
|
86
|
+
artist_data = ["Evidence", "Alchemist"]
|
87
|
+
Bandsintown::Event.parse_artists(artist_data).should == [{ :name => "Evidence" }, { :name => "Alchemist" }]
|
88
|
+
end
|
89
|
+
it "should return an array of { :name => name } when given Bandsintown::Artist instances without mbid" do
|
90
|
+
artist_data = [Bandsintown::Artist.new(:name => "Evidence"), Bandsintown::Artist.new(:name => "Alchemist")]
|
91
|
+
Bandsintown::Event.parse_artists(artist_data).should == [{ :name => "Evidence" }, { :name => "Alchemist" }]
|
92
|
+
end
|
93
|
+
it "should return an array of { :mbid => mbid } when given Bandsintown::Artist instance with mbid" do
|
94
|
+
artist_data = [Bandsintown::Artist.new(:mbid => "123"), Bandsintown::Artist.new(:mbid => "456")]
|
95
|
+
Bandsintown::Event.parse_artists(artist_data).should == [{ :mbid => "123" }, { :mbid => "456" }]
|
96
|
+
end
|
97
|
+
it "should work with different data types given" do
|
98
|
+
artist_data = ["Evidence", Bandsintown::Artist.new(:name => "Alchemist"), Bandsintown::Artist.new(:mbid => "123")]
|
99
|
+
Bandsintown::Event.parse_artists(artist_data).should == [{ :name => "Evidence" }, { :name => "Alchemist" }, { :mbid => "123" }]
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
@@ -1,6 +1,9 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../spec_helper.rb'
|
2
2
|
|
3
3
|
describe Bandsintown::Event do
|
4
|
+
it "should include the Bandsintown::Event::CreationHelpers module" do
|
5
|
+
Bandsintown::Event.included_modules.should include(Bandsintown::Event::CreationHelpers)
|
6
|
+
end
|
4
7
|
|
5
8
|
describe ".resource_path" do
|
6
9
|
it "should return the relative path to Event requests" do
|
@@ -13,7 +16,7 @@ describe Bandsintown::Event do
|
|
13
16
|
@args = { :location => "Boston, MA", :date => "2009-01-01" }
|
14
17
|
end
|
15
18
|
it "should request and parse a call to the BIT events search api method" do
|
16
|
-
Bandsintown::Event.should_receive(:request_and_parse).with("search", @args).and_return([])
|
19
|
+
Bandsintown::Event.should_receive(:request_and_parse).with(:get, "search", @args).and_return([])
|
17
20
|
Bandsintown::Event.search(@args)
|
18
21
|
end
|
19
22
|
it "should return an Array of Bandsintown::Event objects built from the response" do
|
@@ -32,7 +35,7 @@ describe Bandsintown::Event do
|
|
32
35
|
@args = { :location => "Boston, MA", :date => "2009-01-01" }
|
33
36
|
end
|
34
37
|
it "should request and parse a call to the BIT recommended events api method" do
|
35
|
-
Bandsintown::Event.should_receive(:request_and_parse).with("recommended", @args).and_return([])
|
38
|
+
Bandsintown::Event.should_receive(:request_and_parse).with(:get, "recommended", @args).and_return([])
|
36
39
|
Bandsintown::Event.recommended(@args)
|
37
40
|
end
|
38
41
|
it "should return an Array of Bandsintown::Event objects built from the response" do
|
@@ -48,7 +51,7 @@ describe Bandsintown::Event do
|
|
48
51
|
|
49
52
|
describe ".daily" do
|
50
53
|
it "should request and parse a call to the BIT daily events api method" do
|
51
|
-
Bandsintown::Event.should_receive(:request_and_parse).with("daily").and_return([])
|
54
|
+
Bandsintown::Event.should_receive(:request_and_parse).with(:get, "daily").and_return([])
|
52
55
|
Bandsintown::Event.daily
|
53
56
|
end
|
54
57
|
it "should return an array of Bandsintown::Events built from the response" do
|
@@ -64,7 +67,7 @@ describe Bandsintown::Event do
|
|
64
67
|
@args = { :location => "Boston, MA", :radius => 50, :date => "2010-03-02" }
|
65
68
|
end
|
66
69
|
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([])
|
70
|
+
Bandsintown::Event.should_receive(:request_and_parse).with(:get, "on_sale_soon", @args).and_return([])
|
68
71
|
Bandsintown::Event.on_sale_soon(@args)
|
69
72
|
end
|
70
73
|
it "should return an array of Bandsintown::Events built from the response" do
|
@@ -111,7 +114,7 @@ describe Bandsintown::Event do
|
|
111
114
|
@built_event = Bandsintown::Event.build_from_json(@event_hash)
|
112
115
|
end
|
113
116
|
it "should return a built Event" do
|
114
|
-
@built_event.
|
117
|
+
@built_event.should be_instance_of(Bandsintown::Event)
|
115
118
|
end
|
116
119
|
it "should set the Event id" do
|
117
120
|
@built_event.bandsintown_id.should == @event_id
|
@@ -139,18 +142,31 @@ describe Bandsintown::Event do
|
|
139
142
|
Bandsintown::Event.build_from_json(@event_hash).on_sale_datetime.should be_nil
|
140
143
|
end
|
141
144
|
it "should set the Event's Venue" do
|
142
|
-
|
143
|
-
Bandsintown::Venue
|
144
|
-
|
145
|
-
|
145
|
+
venue = @built_event.venue
|
146
|
+
venue.should be_instance_of(Bandsintown::Venue)
|
147
|
+
venue.bandsintown_id.should == 327987
|
148
|
+
venue.bandsintown_url.should == "http://www.bandsintown.com/venue/327987"
|
149
|
+
venue.region.should == "MA"
|
150
|
+
venue.city.should == "Boston"
|
151
|
+
venue.name.should == "Paradise Rock Club"
|
152
|
+
venue.country.should == "United States"
|
153
|
+
venue.latitude.should == 42.37
|
154
|
+
venue.longitude.should == 71.03
|
146
155
|
end
|
147
156
|
it "should set the Event's Artists" do
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
157
|
+
artists = @built_event.artists
|
158
|
+
artists.should be_instance_of(Array)
|
159
|
+
artists.size.should == 2
|
160
|
+
|
161
|
+
artists.first.should be_instance_of(Bandsintown::Artist)
|
162
|
+
artists.first.name.should == "Little Brother"
|
163
|
+
artists.first.bandsintown_url.should == "http://www.bandsintown.com/LittleBrother"
|
164
|
+
artists.first.mbid.should == "b929c0c9-5de0-4d87-8eb9-365ad1725629"
|
165
|
+
|
166
|
+
artists.last.should be_instance_of(Bandsintown::Artist)
|
167
|
+
artists.last.name.should == "Joe Scudda"
|
168
|
+
artists.last.bandsintown_url.should == "http://www.bandsintown.com/JoeScudda"
|
169
|
+
artists.last.mbid.should be_nil
|
154
170
|
end
|
155
171
|
end
|
156
172
|
|
@@ -166,4 +182,65 @@ describe Bandsintown::Event do
|
|
166
182
|
event.tickets_available?.should be_false
|
167
183
|
end
|
168
184
|
end
|
169
|
-
|
185
|
+
|
186
|
+
describe ".create(options = {})" do
|
187
|
+
before(:each) do
|
188
|
+
@options = { :artists => [], :venue => {}, :datetime => '' }
|
189
|
+
@response = { "message" => "Event successfully submitted (pending approval)" }
|
190
|
+
Bandsintown::Event.stub!(:request_and_parse).and_return(@response)
|
191
|
+
end
|
192
|
+
it "should request and parse a call to the BIT events - create API mehod" do
|
193
|
+
Bandsintown::Event.should_receive(:request_and_parse).with(:post, "create", anything).and_return(@response)
|
194
|
+
Bandsintown::Event.create(@options)
|
195
|
+
end
|
196
|
+
it "should return the response message if an event was successfully submitted using a non-trusted app_id" do
|
197
|
+
Bandsintown::Event.should_not_receive(:build_from_json)
|
198
|
+
Bandsintown::Event.create(@options).should == @response["message"]
|
199
|
+
end
|
200
|
+
it "should return a Bandsintown::Event build from the response if an event was sucessfully submitted using a trusted app_id" do
|
201
|
+
Bandsintown::Event.stub!(:request_and_parse).and_return({ "event" => "data" })
|
202
|
+
event = mock(Bandsintown::Event)
|
203
|
+
Bandsintown::Event.should_receive(:build_from_json).with("data").and_return(event)
|
204
|
+
Bandsintown::Event.create(@options).should == event
|
205
|
+
end
|
206
|
+
describe "event options" do
|
207
|
+
before(:each) do
|
208
|
+
Bandsintown::Event.stub!(:parse_artists)
|
209
|
+
Bandsintown::Event.stub!(:parse_datetime)
|
210
|
+
Bandsintown::Event.stub!(:parse_venue)
|
211
|
+
end
|
212
|
+
|
213
|
+
it "should parse the artists using parse_artists" do
|
214
|
+
@options = { :artists => ["Evidence", "Alchemist"] }
|
215
|
+
Bandsintown::Event.should_receive(:parse_artists).with(@options[:artists]).and_return('parsed')
|
216
|
+
expected_event_params = { :artists => 'parsed' }
|
217
|
+
Bandsintown::Event.should_receive(:request_and_parse).with(:post, "create", :event => hash_including(expected_event_params))
|
218
|
+
end
|
219
|
+
|
220
|
+
it "should parse the datetime using parse_datetime" do
|
221
|
+
@options = { :datetime => "2010-06-01T20:30:00" }
|
222
|
+
Bandsintown::Event.should_receive(:parse_datetime).with(@options[:datetime]).and_return('parsed')
|
223
|
+
expected_event_params = { :datetime => "parsed" }
|
224
|
+
Bandsintown::Event.should_receive(:request_and_parse).with(:post, "create", :event => hash_including(expected_event_params))
|
225
|
+
end
|
226
|
+
|
227
|
+
it "should parse the on_sale_datetime using parse_datetime" do
|
228
|
+
@options = { :on_sale_datetime => "2010-06-01T20:30:00" }
|
229
|
+
Bandsintown::Event.should_receive(:parse_datetime).with(@options[:on_sale_datetime]).and_return('parsed')
|
230
|
+
expected_event_params = { :on_sale_datetime => "parsed" }
|
231
|
+
Bandsintown::Event.should_receive(:request_and_parse).with(:post, "create", :event => hash_including(expected_event_params))
|
232
|
+
end
|
233
|
+
|
234
|
+
it "should parse the venue using parse_venue" do
|
235
|
+
@options = { :venue => "data" }
|
236
|
+
Bandsintown::Event.should_receive(:parse_venue).with("data").and_return("venue")
|
237
|
+
expected_event_params = { :venue => "venue" }
|
238
|
+
Bandsintown::Event.should_receive(:request_and_parse).with(:post, "create", :event => hash_including(expected_event_params))
|
239
|
+
end
|
240
|
+
|
241
|
+
after(:each) do
|
242
|
+
Bandsintown::Event.create(@options)
|
243
|
+
end
|
244
|
+
end
|
245
|
+
end
|
246
|
+
end
|