intown 0.1.0

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/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color --format nested
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in tourbus.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Ben Scheirman
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,78 @@
1
+ # Intown
2
+
3
+ A gem to consume the Bandsintown 2.0 API. Supports finding artists by name, MusicBrainz ID, & Facebook Page Id. Supports returning events by artist & optional date range.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'intown'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install intown
18
+
19
+ ## Usage
20
+
21
+ Set your "app_id" configuration before making any calls. In a Rails app, this would go in `config/initializers/intown.rb`.
22
+
23
+ ```ruby
24
+ Intown.configure do |config|
25
+ config.app_id = <YOUR APP ID HERE>
26
+ end
27
+ ```
28
+
29
+ ### Fetching an artist
30
+
31
+ ```ruby
32
+ Intown::Artist.fetch(params)
33
+ ```
34
+
35
+ Params should be one of the following:
36
+
37
+ ```ruby
38
+ {:name => "Radiohead"}
39
+ {:mbid => "<band's MusicBrainz ID>"}
40
+ {:fbid => "<band's Facebook page ID>"}
41
+ ```
42
+
43
+ Returns an object that responds to the API attributes in the [Bandsintown API documentation](http://www.bandsintown.com/api/responses#artist-json)
44
+
45
+ Returns nil if the band cannot be found.
46
+
47
+ ### Fetching events for an artist
48
+
49
+ ```ruby
50
+ Intown::Event.list(params)
51
+ ```
52
+
53
+ Params should identify the artist to search for (see above). Params may also include one of the following date options:
54
+
55
+ ```ruby
56
+ {:upcoming => true} # default: only returns future events
57
+ {:all => true} # returns all events for this artist
58
+ {:date => 3.days.from_now} # returns all events on the specified date
59
+ {:from => 3.days.ago, :to => 5.days.from_now } # returns all events in the date range (inclusive)
60
+ ```
61
+
62
+ Returns an object that responds to the API attributes in the [Bandsintown API documentation](http://www.bandsintown.com/api/responses#event-json)
63
+
64
+ Returns nil if the band does not exist.
65
+
66
+
67
+ ## Contributing
68
+
69
+ 1. Fork it
70
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
71
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
72
+ 4. Write Tests
73
+ 5. Push to the branch (`git push origin my-new-feature`)
74
+ 6. Create new Pull Request
75
+
76
+ ## License
77
+
78
+ This code is provided under the MIT license. See LICENSE.txt for more details.
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/intown.gemspec ADDED
@@ -0,0 +1,27 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'intown/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "intown"
8
+ gem.version = Intown::VERSION
9
+ gem.authors = ["Ben Scheirman"]
10
+ gem.email = ["ben@scheirman.com"]
11
+ gem.description = %q{A client for the Bandsintown API.}
12
+ gem.summary = %q{Supports Bandsintown API version 1.1}
13
+ gem.homepage = "https://github.com/subdigital/intown"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_development_dependency 'rspec', '~> 2.12.0'
21
+ gem.add_development_dependency 'vcr', '~> 2.4.0'
22
+ gem.add_development_dependency 'webmock', '~> 1.9.3'
23
+ gem.add_development_dependency 'pry'
24
+
25
+ gem.add_dependency 'httparty', '~> 0.10.0'
26
+ gem.add_dependency 'hashie', '~> 2.0.0'
27
+ end
@@ -0,0 +1,11 @@
1
+ module Intown
2
+ class Artist < Client
3
+ class << self
4
+ def fetch(params)
5
+ identifier = artist_identifier(params)
6
+ response = get("/artists/#{URI.encode(identifier)}", options)
7
+ process_response(response)
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,62 @@
1
+ require 'httparty'
2
+ require 'json'
3
+ require 'hashie'
4
+
5
+ module Intown
6
+ class Client
7
+ include HTTParty
8
+ API_VERSION = 2.0
9
+ base_uri "https://api.bandsintown.com"
10
+
11
+ class << self
12
+
13
+ def options
14
+ {
15
+ :query => {
16
+ :app_id => Intown.configuration.app_id, :api_version => API_VERSION
17
+ }
18
+ }
19
+ end
20
+
21
+ def process_response(response)
22
+ case response.code
23
+ when 500 then raise Intown::InvalidRequestError, response.body
24
+ when 404 then process_not_found(response)
25
+ else
26
+ json_response = JSON.parse(response.body)
27
+
28
+ if json_response.is_a? Hash
29
+ Hashie::Mash.new(json_response)
30
+ elsif json_response.is_a? Array
31
+ json_response.map {|e| Hashie::Mash.new(e)}
32
+ else
33
+ json_response
34
+ end
35
+ end
36
+ end
37
+
38
+ def process_not_found(response)
39
+ json = JSON.parse(response.body)
40
+ if errors = json['errors']
41
+ raise Intown::InvalidRequestError, "app_id is required for this request" if errors.any? {|e| e =~ /app_id param is required/}
42
+ end
43
+ nil
44
+ end
45
+
46
+ def artist_identifier(params)
47
+ return musicbrainz_identifier(params[:mbid]) if params[:mbid]
48
+ return facebook_identifier(params[:fbid]) if params[:fbid]
49
+ return params[:name] if params[:name]
50
+ raise ArgumentError, "params must contain one of mbid, fbid, or name"
51
+ end
52
+
53
+ def musicbrainz_identifier(mbid)
54
+ "mbid_#{mbid}"
55
+ end
56
+
57
+ def facebook_identifier(fbid)
58
+ "fbid_#{fbid}"
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,16 @@
1
+ module Intown
2
+ class Configuration
3
+ attr_accessor :app_id
4
+ end
5
+
6
+ class << self
7
+ def configure(&block)
8
+ @configuration = Configuration.new
9
+ yield @configuration
10
+ end
11
+
12
+ def configuration
13
+ @configuration ||= Configuration.new
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,4 @@
1
+ module Intown
2
+ IntownError = Class.new(StandardError)
3
+ InvalidRequestError = Class.new(IntownError)
4
+ end
@@ -0,0 +1,25 @@
1
+ module Intown
2
+ class Event < Client
3
+ class << self
4
+ def list(params)
5
+ identifier = artist_identifier(params)
6
+ event_params = options.merge(date_options(params))
7
+ url = "/artists/#{URI.encode(identifier)}/events"
8
+ response = get(url, event_params)
9
+ process_response(response)
10
+ end
11
+
12
+ def date_options(params)
13
+ return {:date => format_date(params[:date])} if params[:date]
14
+ return {:date => "#{format_date(params[:from])},#{format_date(params[:to])}"} if params[:from] && params[:to]
15
+ return {:date => "upcoming"} if params[:upcoming] == true
16
+ return {:date => "all"} if params[:all] == true
17
+ {}
18
+ end
19
+
20
+ def format_date(date)
21
+ date.strftime("%Y-%m-%d")
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,3 @@
1
+ module Intown
2
+ VERSION = "0.1.0"
3
+ end
data/lib/intown.rb ADDED
@@ -0,0 +1,9 @@
1
+ require "intown/version"
2
+ require "intown/configuration"
3
+ require "intown/errors"
4
+ require "intown/client"
5
+ require "intown/artist"
6
+ require "intown/event"
7
+
8
+ module Intown
9
+ end
@@ -0,0 +1,38 @@
1
+ require 'spec_helper'
2
+
3
+ describe Intown::Artist do
4
+
5
+ context "without configuring an app id" do
6
+ before do
7
+ Intown.configure {|c| c.app_id = nil}
8
+ end
9
+ it "should raise an error if the app id param is not set" do
10
+ VCR.use_cassette("fetch_artist_no_app_id_set") do
11
+ expect { Intown::Artist.fetch(:name => "foobar") }.to raise_error Intown::InvalidRequestError
12
+ end
13
+ end
14
+ end
15
+
16
+ context "with an app id configured" do
17
+ before do
18
+ Intown.configure {|c| c.app_id = "test"}
19
+ end
20
+
21
+ it "should return nil for unknown artists" do
22
+ VCR.use_cassette("find_unknown_artist") do
23
+ Intown::Artist.fetch(:name => "Ishouldnotexist").should be_nil
24
+ end
25
+ end
26
+
27
+ it "should be fetched by name" do
28
+ VCR.use_cassette("find_artist_by_name") do
29
+ artist = Intown::Artist.fetch(:name => "My Morning Jacket")
30
+ artist.name.should == "My Morning Jacket"
31
+ artist.upcoming_events_count.should_not be_nil
32
+ artist.image_url.should_not be_nil
33
+ artist.mbid.should_not be_nil
34
+ end
35
+ end
36
+ end
37
+
38
+ end
@@ -0,0 +1,26 @@
1
+ require 'spec_helper'
2
+
3
+ describe Intown::Event do
4
+ before :each do
5
+ Intown.configure do |c|
6
+ c.app_id = "test"
7
+ end
8
+ end
9
+ context "Fetching events for an unknown band" do
10
+ it "should return nil" do
11
+ VCR.use_cassette("fetch events for unknown band") do
12
+ events = Intown::Event.list(:name => "GoobleGobble124")
13
+ events.should be_nil
14
+ end
15
+ end
16
+ end
17
+
18
+ context "Fetching events for an unknown band" do
19
+ it "should return nil" do
20
+ VCR.use_cassette("fetch events for known band") do
21
+ events = Intown::Event.list(:name => "Blame Sally")
22
+ events.length.should >= 0
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,43 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://api.bandsintown.com/artists/foobar?api_version=2.0&app_id=
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers: {}
10
+ response:
11
+ status:
12
+ code: 404
13
+ message: Not Found
14
+ headers:
15
+ Date:
16
+ - Thu, 21 Feb 2013 20:11:49 GMT
17
+ Server:
18
+ - Mongrel 1.1.5
19
+ Content-Length:
20
+ - '40'
21
+ Content-Type:
22
+ - application/json; charset=utf-8
23
+ X-Runtime:
24
+ - '0.02046'
25
+ Status:
26
+ - 404 Not Found
27
+ Cache-Control:
28
+ - no-cache
29
+ Set-Cookie:
30
+ - _session_id=04cd7ac85a121e74bfb474f94f04c501; path=/; expires=Thu, 21 Mar
31
+ 2013 19:11:49 GMT
32
+ Vary:
33
+ - Accept-Encoding
34
+ Connection:
35
+ - close
36
+ body:
37
+ encoding: US-ASCII
38
+ string: ! '{"errors":["app_id param is required"]}
39
+
40
+ '
41
+ http_version:
42
+ recorded_at: Thu, 21 Feb 2013 20:11:49 GMT
43
+ recorded_with: VCR 2.4.0
@@ -0,0 +1,62 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://api.bandsintown.com/artists/Blame%20Sally/events?api_version=2.0&app_id=test
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers: {}
10
+ response:
11
+ status:
12
+ code: 200
13
+ message: OK
14
+ headers:
15
+ Date:
16
+ - Thu, 21 Feb 2013 20:15:44 GMT
17
+ Server:
18
+ - Mongrel 1.1.5
19
+ Etag:
20
+ - ! '"8f78b9ff373c3291535e34a9c28a2d67"'
21
+ Content-Length:
22
+ - '5768'
23
+ Cache-Control:
24
+ - private, max-age=0, must-revalidate
25
+ X-Runtime:
26
+ - '0.06541'
27
+ Status:
28
+ - 200 OK
29
+ Content-Type:
30
+ - application/json; charset=utf-8
31
+ Set-Cookie:
32
+ - _session_id=09b05e580a4b65a836214fc870b5b76b; path=/; expires=Thu, 21 Mar
33
+ 2013 19:15:44 GMT
34
+ Vary:
35
+ - Accept-Encoding
36
+ Connection:
37
+ - close
38
+ body:
39
+ encoding: US-ASCII
40
+ string: ! '[{"ticket_status":"unavailable","ticket_type":null,"ticket_url":null,"formatted_location":"Chico,
41
+ CA","formatted_datetime":"Monday, April 15, 2013 at 7:30pm","facebook_rsvp_url":"http:\/\/www.bandsintown.com\/event\/6216225\/facebook_rsvp?app_id=test&artist=Blame+Sally&came_from=67","artists":[{"mbid":"b30ac2b1-a4fc-45a3-98ff-9087a6a10208","name":"Blame
42
+ Sally","image_url":"http:\/\/www.bandsintown.com\/BlameSally\/photo\/medium.jpg","facebook_tour_dates_url":"http:\/\/bnds.in\/HQt8jZ","thumb_url":"http:\/\/www.bandsintown.com\/BlameSally\/photo\/small.jpg"}],"facebook_share_url":"https:\/\/www.facebook.com\/dialog\/feed?actions=%7B%22link%22%3A%22http%3A%5C%2F%5C%2Fwww.bandsintown.com%5C%2Fevent%5C%2F6216225%5C%2Ffacebook_rsvp%3Fartist%3DBlame%2BSally%26came_from%3D78%22%2C%22name%22%3A%22RSVP%22%7D&app_id=123966167614127&caption=Monday%2C+April+15%2C+2013+at+7%3A30pm&description=%26nbsp%3B&link=http%3A%2F%2Fwww.bandsintown.com%2Fevent%2F6216225%2Ffacebook_rsvp%3Fartist%3DBlame%2BSally%26came_from%3D77&name=Blame+Sally+%40+Sierra+Nevada+Brewing+Co.+in+Chico%2C+CA&picture=https%3A%2F%2Fd12nfv3nknyhzq.cloudfront.net%2FBlameSally%2Fphoto%2Flarge.jpg&properties=%7B%22More+Tour+Dates%22%3A%7B%22text%22%3A%22http%3A%5C%2F%5C%2Fbnds.in%5C%2FIgxMaj%22%2C%22href%22%3A%22http%3A%5C%2F%5C%2Fwww.bandsintown.com%5C%2FBlameSally%5C%2Ffacebookapp%3Fcame_from%3D78%22%7D%7D&redirect_uri=http%3A%2F%2Fwww.bandsintown.com%2Fevent%2F6216225%2Ffacebook_rsvp%3Fartist%3DBlame%2BSally%26came_from%3D102","title":"Blame
43
+ Sally @ Sierra Nevada Brewing Co. in Chico, CA","id":"6216225","description":null,"on_sale_datetime":null,"venue":{"country":"United
44
+ States","name":"Sierra Nevada Brewing Co.","longitude":"-121.8139110","city":"Chico","region":"CA","latitude":"39.7249330"},"datetime":"2013-04-15T19:30:00"},
45
+
46
+ {"ticket_status":"unavailable","ticket_type":null,"ticket_url":null,"formatted_location":"Seattle,
47
+ WA","formatted_datetime":"Friday, April 19, 2013 at 9:00pm","facebook_rsvp_url":"http:\/\/www.bandsintown.com\/event\/6128697\/facebook_rsvp?app_id=test&artist=Blame+Sally&came_from=67","artists":[{"mbid":"b30ac2b1-a4fc-45a3-98ff-9087a6a10208","name":"Blame
48
+ Sally","image_url":"http:\/\/www.bandsintown.com\/BlameSally\/photo\/medium.jpg","facebook_tour_dates_url":"http:\/\/bnds.in\/HQt8jZ","thumb_url":"http:\/\/www.bandsintown.com\/BlameSally\/photo\/small.jpg"}],"facebook_share_url":"https:\/\/www.facebook.com\/dialog\/feed?actions=%7B%22link%22%3A%22http%3A%5C%2F%5C%2Fwww.bandsintown.com%5C%2Fevent%5C%2F6128697%5C%2Ffacebook_rsvp%3Fartist%3DBlame%2BSally%26came_from%3D78%22%2C%22name%22%3A%22RSVP%22%7D&app_id=123966167614127&caption=Friday%2C+April+19%2C+2013+at+9%3A00pm&description=%26nbsp%3B&link=http%3A%2F%2Fwww.bandsintown.com%2Fevent%2F6128697%2Ffacebook_rsvp%3Fartist%3DBlame%2BSally%26came_from%3D77&name=Blame+Sally+%40+The+Triple+Door+in+Seattle%2C+WA&picture=https%3A%2F%2Fd12nfv3nknyhzq.cloudfront.net%2FBlameSally%2Fphoto%2Flarge.jpg&properties=%7B%22More+Tour+Dates%22%3A%7B%22text%22%3A%22http%3A%5C%2F%5C%2Fbnds.in%5C%2FIgxMaj%22%2C%22href%22%3A%22http%3A%5C%2F%5C%2Fwww.bandsintown.com%5C%2FBlameSally%5C%2Ffacebookapp%3Fcame_from%3D78%22%7D%7D&redirect_uri=http%3A%2F%2Fwww.bandsintown.com%2Fevent%2F6128697%2Ffacebook_rsvp%3Fartist%3DBlame%2BSally%26came_from%3D102","title":"Blame
49
+ Sally @ The Triple Door in Seattle, WA","id":"6128697","description":null,"on_sale_datetime":null,"venue":{"country":"United
50
+ States","name":"The Triple Door","longitude":"-122.3379440","city":"Seattle","region":"WA","latitude":"47.6084330"},"datetime":"2013-04-19T21:00:00"},
51
+
52
+ {"ticket_status":"available","ticket_type":"Tickets","ticket_url":"http:\/\/www.bandsintown.com\/event\/5985466\/buy_tickets?app_id=test&artist=Blame+Sally","formatted_location":"San
53
+ Francisco, CA","formatted_datetime":"Saturday, May 11, 2013 at 9:00pm","facebook_rsvp_url":"http:\/\/www.bandsintown.com\/event\/5985466\/facebook_rsvp?app_id=test&artist=Blame+Sally&came_from=67","artists":[{"mbid":"b30ac2b1-a4fc-45a3-98ff-9087a6a10208","name":"Blame
54
+ Sally","image_url":"http:\/\/www.bandsintown.com\/BlameSally\/photo\/medium.jpg","facebook_tour_dates_url":"http:\/\/bnds.in\/HQt8jZ","thumb_url":"http:\/\/www.bandsintown.com\/BlameSally\/photo\/small.jpg"}],"facebook_share_url":"https:\/\/www.facebook.com\/dialog\/feed?actions=%7B%22link%22%3A%22http%3A%5C%2F%5C%2Fwww.bandsintown.com%5C%2Fevent%5C%2F5985466%5C%2Ffacebook_rsvp%3Fartist%3DBlame%2BSally%26came_from%3D78%22%2C%22name%22%3A%22RSVP%22%7D&app_id=123966167614127&caption=Saturday%2C+May+11%2C+2013+at+9%3A00pm&description=%26nbsp%3B&link=http%3A%2F%2Fwww.bandsintown.com%2Fevent%2F5985466%2Ffacebook_rsvp%3Fartist%3DBlame%2BSally%26came_from%3D77&name=Blame+Sally+%40+Great+American+Music+Hall+in+San+Francisco%2C+CA&picture=https%3A%2F%2Fd12nfv3nknyhzq.cloudfront.net%2FBlameSally%2Fphoto%2Flarge.jpg&properties=%7B%22Tickets%22%3A%7B%22text%22%3A%22http%3A%5C%2F%5C%2Fbnds.in%5C%2FUNp0bR%22%2C%22href%22%3A%22http%3A%5C%2F%5C%2Fwww.bandsintown.com%5C%2Fevent%5C%2F5985466%5C%2Fbuy_tickets%3Faffil_code%3Dfb_19907696684%26artist%3DBlame%2BSally%22%7D%2C%22More+Tour+Dates%22%3A%7B%22text%22%3A%22http%3A%5C%2F%5C%2Fbnds.in%5C%2FIgxMaj%22%2C%22href%22%3A%22http%3A%5C%2F%5C%2Fwww.bandsintown.com%5C%2FBlameSally%5C%2Ffacebookapp%3Fcame_from%3D78%22%7D%7D&redirect_uri=http%3A%2F%2Fwww.bandsintown.com%2Fevent%2F5985466%2Ffacebook_rsvp%3Fartist%3DBlame%2BSally%26came_from%3D102","title":"Blame
55
+ Sally @ Great American Music Hall in San Francisco, CA","id":"5985466","description":null,"on_sale_datetime":null,"venue":{"country":"United
56
+ States","name":"Great American Music Hall","longitude":"-122.4205960","city":"San
57
+ Francisco","region":"CA","latitude":"37.7943790"},"datetime":"2013-05-11T21:00:00"}]
58
+
59
+ '
60
+ http_version:
61
+ recorded_at: Thu, 21 Feb 2013 20:15:44 GMT
62
+ recorded_with: VCR 2.4.0
@@ -0,0 +1,43 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://api.bandsintown.com/artists/GoobleGobble124/events?api_version=2.0&app_id=test
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers: {}
10
+ response:
11
+ status:
12
+ code: 404
13
+ message: Not Found
14
+ headers:
15
+ Date:
16
+ - Thu, 21 Feb 2013 20:11:51 GMT
17
+ Server:
18
+ - Mongrel 1.1.5
19
+ Status:
20
+ - 404 Not Found
21
+ Cache-Control:
22
+ - no-cache
23
+ Content-Type:
24
+ - application/json; charset=utf-8
25
+ Content-Length:
26
+ - '30'
27
+ X-Runtime:
28
+ - '0.00860'
29
+ Set-Cookie:
30
+ - _session_id=5d23778c700fcb71fd14d2061fc20e43; path=/; expires=Thu, 21 Mar
31
+ 2013 19:11:51 GMT
32
+ Vary:
33
+ - Accept-Encoding
34
+ Connection:
35
+ - close
36
+ body:
37
+ encoding: US-ASCII
38
+ string: ! '{"errors":["Unknown Artist"]}
39
+
40
+ '
41
+ http_version:
42
+ recorded_at: Thu, 21 Feb 2013 20:11:51 GMT
43
+ recorded_with: VCR 2.4.0
@@ -0,0 +1,44 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://api.bandsintown.com/artists/My%20Morning%20Jacket?api_version=2.0&app_id=test
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers: {}
10
+ response:
11
+ status:
12
+ code: 200
13
+ message: OK
14
+ headers:
15
+ Date:
16
+ - Thu, 21 Feb 2013 20:11:50 GMT
17
+ Server:
18
+ - Mongrel 1.1.5
19
+ Etag:
20
+ - ! '"f71ae1412f3e37311757d098764b8aad"'
21
+ Cache-Control:
22
+ - private, max-age=0, must-revalidate
23
+ Status:
24
+ - 200 OK
25
+ X-Runtime:
26
+ - '0.04589'
27
+ Content-Length:
28
+ - '310'
29
+ Content-Type:
30
+ - application/json; charset=utf-8
31
+ Set-Cookie:
32
+ - _session_id=b50f066fa543a15f617acfe11a075bb2; path=/; expires=Thu, 21 Mar
33
+ 2013 19:11:50 GMT
34
+ Vary:
35
+ - Accept-Encoding
36
+ Connection:
37
+ - close
38
+ body:
39
+ encoding: US-ASCII
40
+ string: ! '{"mbid":"ea5883b7-68ce-48b3-b115-61746ea53b8c","upcoming_events_count":0,"image_url":"http:\/\/www.bandsintown.com\/MyMorningJacket\/photo\/medium.jpg","thumb_url":"http:\/\/www.bandsintown.com\/MyMorningJacket\/photo\/small.jpg","name":"My
41
+ Morning Jacket","facebook_tour_dates_url":"http:\/\/bnds.in\/zTPiUu"}'
42
+ http_version:
43
+ recorded_at: Thu, 21 Feb 2013 20:11:50 GMT
44
+ recorded_with: VCR 2.4.0
@@ -0,0 +1,43 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://api.bandsintown.com/artists/Ishouldnotexist?api_version=2.0&app_id=test
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers: {}
10
+ response:
11
+ status:
12
+ code: 404
13
+ message: Not Found
14
+ headers:
15
+ Date:
16
+ - Thu, 21 Feb 2013 20:11:50 GMT
17
+ Server:
18
+ - Mongrel 1.1.5
19
+ Content-Type:
20
+ - application/json; charset=utf-8
21
+ X-Runtime:
22
+ - '0.01188'
23
+ Status:
24
+ - 404 Not Found
25
+ Cache-Control:
26
+ - no-cache
27
+ Content-Length:
28
+ - '30'
29
+ Set-Cookie:
30
+ - _session_id=407c1b0ceec22028ba725603afbe8534; path=/; expires=Thu, 21 Mar
31
+ 2013 19:11:50 GMT
32
+ Vary:
33
+ - Accept-Encoding
34
+ Connection:
35
+ - close
36
+ body:
37
+ encoding: US-ASCII
38
+ string: ! '{"errors":["Unknown Artist"]}
39
+
40
+ '
41
+ http_version:
42
+ recorded_at: Thu, 21 Feb 2013 20:11:50 GMT
43
+ recorded_with: VCR 2.4.0
@@ -0,0 +1,44 @@
1
+ require 'spec_helper'
2
+
3
+ describe Intown::Artist do
4
+ let(:response) {
5
+ stub(:code => 200,
6
+ :body => '{
7
+ "upcoming_events_count":0,
8
+ "thumb_url":"http:\/\/www.bandsintown.com\/Nirvana\/photo\/small.jpg",
9
+ "name": "Nirvana",
10
+ "image_url":"http:\/\/www.bandsintown.com\/Nirvana\/photo\/medium.jpg",
11
+ "mbid":"ea5883b7-68ce-48b3-b115-61746ea53b8c",
12
+ "facebook_tour_dates_url":"http:\/\/bnds.in\/zTPiUu"
13
+ }'
14
+ )
15
+ }
16
+
17
+ context "searching by name" do
18
+ it "should put the name in the artist url" do
19
+ Intown::Artist.should_receive(:get).with(/\/artists\/Nirvana/, anything).and_return(response)
20
+ Intown::Artist.fetch(:name => "Nirvana")
21
+ end
22
+ end
23
+
24
+ context "searching by name with spaces" do
25
+ it "should url encode the spaces" do
26
+ Intown::Artist.should_receive(:get).with(/\/artists\/Foo%20Fighters/, anything).and_return(response)
27
+ Intown::Artist.fetch(:name => "Foo Fighters")
28
+ end
29
+ end
30
+
31
+ context "searching by musicbrainz id" do
32
+ it "should format the musicbrainz id in the url" do
33
+ Intown::Artist.should_receive(:get).with(/\/artists\/mbid_1234567890abcd/, anything).and_return(response)
34
+ Intown::Artist.fetch(:mbid => "1234567890abcd")
35
+ end
36
+ end
37
+
38
+ context "searching with invalid params" do
39
+ it "should raise an argument error" do
40
+ expect { Intown::Artist.fetch(:foo_bar => "baz") }.to raise_error ArgumentError
41
+ end
42
+ end
43
+
44
+ end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe Intown::Configuration do
4
+ it "should set an app_id" do
5
+ Intown.configure do |config|
6
+ config.app_id = "my_app"
7
+ end
8
+
9
+ Intown.configuration.app_id.should == "my_app"
10
+ end
11
+ end
@@ -0,0 +1,53 @@
1
+ require 'spec_helper'
2
+
3
+ describe Intown::Event do
4
+ let(:response) {
5
+ stub(:code => 200,
6
+ :body => '{"foo":"bar"}')
7
+ }
8
+
9
+ context "searching by artist id" do
10
+ it "should format the proper artist term in the url" do
11
+ Intown::Event.should_receive(:get).with(/artists\/Radiohead\/events/, anything).and_return(response)
12
+ Intown::Event.list(:name => "Radiohead")
13
+ end
14
+ end
15
+
16
+ context "Searching by date range" do
17
+ before :each do
18
+ Intown::Event.should_receive(:get).with(anything, hash_including(expected_params)).and_return(response)
19
+ end
20
+
21
+ context "single date" do
22
+ let(:expected_params) {{ :date => '2013-03-02' }}
23
+ let(:input_params) {{ :name => "Radiohead", :date => Time.new(2013, 3, 2) }}
24
+ it "should format the date in the url" do
25
+ Intown::Event.list(input_params)
26
+ end
27
+ end
28
+
29
+ context "date range" do
30
+ let(:expected_params) {{ :date => '2013-03-02,2013-03-08' }}
31
+ let(:input_params) {{ :name => "Radiohead", :from => Time.new(2013, 3, 2), :to => Time.new(2013, 3, 8)}}
32
+ it "should format the date range from to/from date params" do
33
+ Intown::Event.list(input_params)
34
+ end
35
+ end
36
+
37
+ context "upcoming" do
38
+ let(:expected_params) {{ :date => 'upcoming' }}
39
+ let(:input_params) {{ :name => "Radiohead", :upcoming => true}}
40
+ it "should set the date parameter to upcoming" do
41
+ Intown::Event.list(input_params)
42
+ end
43
+ end
44
+
45
+ context "all" do
46
+ let(:expected_params) {{ :date => 'all' }}
47
+ let(:input_params) {{ :name => "Radiohead", :all => true}}
48
+ it "should set the date parameter to all" do
49
+ Intown::Event.list(input_params)
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ describe Intown do
4
+ it "should define a version" do
5
+ Intown::VERSION.should_not be_nil
6
+ end
7
+ end
@@ -0,0 +1,14 @@
1
+ lib = File.expand_path('../../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'rubygems'
4
+ require 'intown'
5
+ require 'rspec'
6
+ require 'vcr'
7
+ require 'httparty'
8
+ require 'pry'
9
+
10
+ VCR.configure do |c|
11
+ c.cassette_library_dir = 'spec/fixtures/cassettes'
12
+ c.hook_into :webmock
13
+ c.allow_http_connections_when_no_cassette = true
14
+ end
metadata ADDED
@@ -0,0 +1,180 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: intown
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.1.0
6
+ platform: ruby
7
+ authors:
8
+ - Ben Scheirman
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-02-21 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ prerelease: false
16
+ version_requirements: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ~>
19
+ - !ruby/object:Gem::Version
20
+ version: 2.12.0
21
+ none: false
22
+ type: :development
23
+ name: rspec
24
+ requirement: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - ~>
27
+ - !ruby/object:Gem::Version
28
+ version: 2.12.0
29
+ none: false
30
+ - !ruby/object:Gem::Dependency
31
+ prerelease: false
32
+ version_requirements: !ruby/object:Gem::Requirement
33
+ requirements:
34
+ - - ~>
35
+ - !ruby/object:Gem::Version
36
+ version: 2.4.0
37
+ none: false
38
+ type: :development
39
+ name: vcr
40
+ requirement: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ~>
43
+ - !ruby/object:Gem::Version
44
+ version: 2.4.0
45
+ none: false
46
+ - !ruby/object:Gem::Dependency
47
+ prerelease: false
48
+ version_requirements: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ~>
51
+ - !ruby/object:Gem::Version
52
+ version: 1.9.3
53
+ none: false
54
+ type: :development
55
+ name: webmock
56
+ requirement: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ~>
59
+ - !ruby/object:Gem::Version
60
+ version: 1.9.3
61
+ none: false
62
+ - !ruby/object:Gem::Dependency
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ none: false
70
+ type: :development
71
+ name: pry
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ none: false
78
+ - !ruby/object:Gem::Dependency
79
+ prerelease: false
80
+ version_requirements: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ~>
83
+ - !ruby/object:Gem::Version
84
+ version: 0.10.0
85
+ none: false
86
+ type: :runtime
87
+ name: httparty
88
+ requirement: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ~>
91
+ - !ruby/object:Gem::Version
92
+ version: 0.10.0
93
+ none: false
94
+ - !ruby/object:Gem::Dependency
95
+ prerelease: false
96
+ version_requirements: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ~>
99
+ - !ruby/object:Gem::Version
100
+ version: 2.0.0
101
+ none: false
102
+ type: :runtime
103
+ name: hashie
104
+ requirement: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ~>
107
+ - !ruby/object:Gem::Version
108
+ version: 2.0.0
109
+ none: false
110
+ description: A client for the Bandsintown API.
111
+ email:
112
+ - ben@scheirman.com
113
+ executables: []
114
+ extensions: []
115
+ extra_rdoc_files: []
116
+ files:
117
+ - .gitignore
118
+ - .rspec
119
+ - Gemfile
120
+ - LICENSE.txt
121
+ - README.md
122
+ - Rakefile
123
+ - intown.gemspec
124
+ - lib/intown.rb
125
+ - lib/intown/artist.rb
126
+ - lib/intown/client.rb
127
+ - lib/intown/configuration.rb
128
+ - lib/intown/errors.rb
129
+ - lib/intown/event.rb
130
+ - lib/intown/version.rb
131
+ - spec/acceptance/fetch_artist_by_name_spec.rb
132
+ - spec/acceptance/fetch_events_by_artist_spec.rb
133
+ - spec/fixtures/cassettes/fetch_artist_no_app_id_set.yml
134
+ - spec/fixtures/cassettes/fetch_events_for_known_band.yml
135
+ - spec/fixtures/cassettes/fetch_events_for_unknown_band.yml
136
+ - spec/fixtures/cassettes/find_artist_by_name.yml
137
+ - spec/fixtures/cassettes/find_unknown_artist.yml
138
+ - spec/intown/artist_spec.rb
139
+ - spec/intown/configuration_spec.rb
140
+ - spec/intown/event_spec.rb
141
+ - spec/intown/tourbus_spec.rb
142
+ - spec/spec_helper.rb
143
+ homepage: https://github.com/subdigital/intown
144
+ licenses: []
145
+ post_install_message:
146
+ rdoc_options: []
147
+ require_paths:
148
+ - lib
149
+ required_ruby_version: !ruby/object:Gem::Requirement
150
+ requirements:
151
+ - - ! '>='
152
+ - !ruby/object:Gem::Version
153
+ version: '0'
154
+ none: false
155
+ required_rubygems_version: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ! '>='
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ none: false
161
+ requirements: []
162
+ rubyforge_project:
163
+ rubygems_version: 1.8.25
164
+ signing_key:
165
+ specification_version: 3
166
+ summary: Supports Bandsintown API version 1.1
167
+ test_files:
168
+ - spec/acceptance/fetch_artist_by_name_spec.rb
169
+ - spec/acceptance/fetch_events_by_artist_spec.rb
170
+ - spec/fixtures/cassettes/fetch_artist_no_app_id_set.yml
171
+ - spec/fixtures/cassettes/fetch_events_for_known_band.yml
172
+ - spec/fixtures/cassettes/fetch_events_for_unknown_band.yml
173
+ - spec/fixtures/cassettes/find_artist_by_name.yml
174
+ - spec/fixtures/cassettes/find_unknown_artist.yml
175
+ - spec/intown/artist_spec.rb
176
+ - spec/intown/configuration_spec.rb
177
+ - spec/intown/event_spec.rb
178
+ - spec/intown/tourbus_spec.rb
179
+ - spec/spec_helper.rb
180
+ has_rdoc: