intown 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/intown/artist.rb +1 -1
- data/lib/intown/client.rb +11 -1
- data/lib/intown/event.rb +1 -1
- data/lib/intown/version.rb +1 -1
- data/spec/intown/artist_spec.rb +65 -30
- data/spec/intown/{tourbus_spec.rb → intown_spec.rb} +0 -0
- metadata +4 -4
data/lib/intown/artist.rb
CHANGED
data/lib/intown/client.rb
CHANGED
@@ -22,6 +22,7 @@ module Intown
|
|
22
22
|
case response.code
|
23
23
|
when 500 then raise Intown::InvalidRequestError, response.body
|
24
24
|
when 404 then process_not_found(response)
|
25
|
+
when 406 then process_not_acceptable(response)
|
25
26
|
else
|
26
27
|
json_response = JSON.parse(response.body)
|
27
28
|
|
@@ -34,6 +35,10 @@ module Intown
|
|
34
35
|
end
|
35
36
|
end
|
36
37
|
end
|
38
|
+
|
39
|
+
def process_not_acceptable(response)
|
40
|
+
raise Intown::InvalidRequestError, "Bandsintown rejected your request. Please check your input parameters."
|
41
|
+
end
|
37
42
|
|
38
43
|
def process_not_found(response)
|
39
44
|
json = JSON.parse(response.body)
|
@@ -46,9 +51,14 @@ module Intown
|
|
46
51
|
def artist_identifier(params)
|
47
52
|
return musicbrainz_identifier(params[:mbid]) if params[:mbid]
|
48
53
|
return facebook_identifier(params[:fbid]) if params[:fbid]
|
49
|
-
return params[:name] if params[:name]
|
54
|
+
return encode_name(params[:name]) if params[:name]
|
50
55
|
raise ArgumentError, "params must contain one of mbid, fbid, or name"
|
51
56
|
end
|
57
|
+
|
58
|
+
def encode_name(name)
|
59
|
+
# periods & slashes cause the API to blow up
|
60
|
+
URI.encode(name).gsub(/\./, "%2E").gsub(/\//, "%2F")
|
61
|
+
end
|
52
62
|
|
53
63
|
def musicbrainz_identifier(mbid)
|
54
64
|
"mbid_#{mbid}"
|
data/lib/intown/event.rb
CHANGED
@@ -4,7 +4,7 @@ module Intown
|
|
4
4
|
def list(params)
|
5
5
|
identifier = artist_identifier(params)
|
6
6
|
event_params = options.merge(date_options(params))
|
7
|
-
url = "/artists/#{
|
7
|
+
url = "/artists/#{identifier}/events"
|
8
8
|
response = get(url, event_params)
|
9
9
|
process_response(response)
|
10
10
|
end
|
data/lib/intown/version.rb
CHANGED
data/spec/intown/artist_spec.rb
CHANGED
@@ -1,44 +1,79 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Intown::Artist do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
4
|
+
describe "valid response" do
|
5
|
+
let(:response) {
|
6
|
+
stub(:code => 200,
|
7
|
+
:body => '{
|
8
|
+
"upcoming_events_count":0,
|
9
|
+
"thumb_url":"http:\/\/www.bandsintown.com\/Nirvana\/photo\/small.jpg",
|
10
|
+
"name": "Nirvana",
|
11
|
+
"image_url":"http:\/\/www.bandsintown.com\/Nirvana\/photo\/medium.jpg",
|
12
|
+
"mbid":"ea5883b7-68ce-48b3-b115-61746ea53b8c",
|
13
|
+
"facebook_tour_dates_url":"http:\/\/bnds.in\/zTPiUu"
|
14
|
+
}'
|
15
|
+
)
|
16
|
+
}
|
16
17
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
18
|
+
context "searching by name" do
|
19
|
+
it "should put the name in the artist url" do
|
20
|
+
Intown::Artist.should_receive(:get).with(/\/artists\/Nirvana/, anything).and_return(response)
|
21
|
+
Intown::Artist.fetch(:name => "Nirvana")
|
22
|
+
end
|
21
23
|
end
|
22
|
-
end
|
23
24
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
25
|
+
context "searching by name with spaces" do
|
26
|
+
it "should url encode the spaces" do
|
27
|
+
Intown::Artist.should_receive(:get).with(/\/artists\/Foo%20Fighters/, anything).and_return(response)
|
28
|
+
Intown::Artist.fetch(:name => "Foo Fighters")
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
context "searching by name with periods in the name" do
|
33
|
+
it "should URL encode the period" do
|
34
|
+
Intown::Artist.should_receive(:get).with(/\/artists\/Jr%2E%20Doc/, anything).and_return(response)
|
35
|
+
Intown::Artist.fetch(:name => "Jr. Doc")
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
context "searching by name with a /" do
|
40
|
+
it "should encode the slash" do
|
41
|
+
Intown::Artist.should_receive(:get).with(/\/artists\/Is%2FIs/, anything).and_return(response)
|
42
|
+
Intown::Artist.fetch(:name => "Is/Is")
|
43
|
+
end
|
28
44
|
end
|
29
|
-
end
|
30
45
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
46
|
+
context "searching by musicbrainz id" do
|
47
|
+
it "should format the musicbrainz id in the url" do
|
48
|
+
Intown::Artist.should_receive(:get).with(/\/artists\/mbid_1234567890abcd/, anything).and_return(response)
|
49
|
+
Intown::Artist.fetch(:mbid => "1234567890abcd")
|
50
|
+
end
|
35
51
|
end
|
36
|
-
end
|
37
52
|
|
38
|
-
|
39
|
-
|
40
|
-
|
53
|
+
context "searching with invalid params" do
|
54
|
+
it "should raise an argument error" do
|
55
|
+
expect { Intown::Artist.fetch(:foo_bar => "baz") }.to raise_error ArgumentError
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe "invalid response" do
|
61
|
+
let(:status_code) { nil }
|
62
|
+
let(:response_body) { nil }
|
63
|
+
let(:response) {
|
64
|
+
stub(:body => response_body,
|
65
|
+
:code => status_code)
|
66
|
+
}
|
67
|
+
before do
|
68
|
+
Intown::Artist.should_receive(:get).and_return(response)
|
69
|
+
end
|
70
|
+
context "406 Not Acceptable" do
|
71
|
+
let(:status_code) { 406 }
|
72
|
+
it "should raise an invalid request error" do
|
73
|
+
expect { Intown::Artist.fetch(:name => "Jr. Doc") }.to raise_error Intown::InvalidRequestError
|
74
|
+
end
|
41
75
|
end
|
76
|
+
|
42
77
|
end
|
43
78
|
|
44
79
|
end
|
File without changes
|
metadata
CHANGED
@@ -2,14 +2,14 @@
|
|
2
2
|
name: intown
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.1.
|
5
|
+
version: 0.1.3
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Ben Scheirman
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-03-06 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
prerelease: false
|
@@ -138,7 +138,7 @@ files:
|
|
138
138
|
- spec/intown/artist_spec.rb
|
139
139
|
- spec/intown/configuration_spec.rb
|
140
140
|
- spec/intown/event_spec.rb
|
141
|
-
- spec/intown/
|
141
|
+
- spec/intown/intown_spec.rb
|
142
142
|
- spec/spec_helper.rb
|
143
143
|
homepage: https://github.com/subdigital/intown
|
144
144
|
licenses: []
|
@@ -175,6 +175,6 @@ test_files:
|
|
175
175
|
- spec/intown/artist_spec.rb
|
176
176
|
- spec/intown/configuration_spec.rb
|
177
177
|
- spec/intown/event_spec.rb
|
178
|
-
- spec/intown/
|
178
|
+
- spec/intown/intown_spec.rb
|
179
179
|
- spec/spec_helper.rb
|
180
180
|
has_rdoc:
|