seatgeek 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ .DS_Store
2
+ *.swp
3
+ *.swo
4
+ pkg
5
+ .rvmrc
data/.rdebugrc ADDED
@@ -0,0 +1 @@
1
+ set autoeval
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/.travis.yml ADDED
@@ -0,0 +1,8 @@
1
+ bundler_args: --without no_travis
2
+ language: ruby
3
+ rvm:
4
+ - ree
5
+ - 1.8.7
6
+ - 1.9.2
7
+ gemfile:
8
+ - Gemfile
data/Gemfile ADDED
@@ -0,0 +1,17 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'faraday'
4
+ gem 'multi_json'
5
+ gem 'rake'
6
+ gem 'yajl-ruby'
7
+
8
+ group :test do
9
+ gem 'rspec'
10
+ end
11
+
12
+ group :no_travis do
13
+ gem 'awesome_print'
14
+ RUBY_VERSION =~ /^1\.9/ ? gem('ruby-debug19') : gem('ruby-debug')
15
+ end
16
+
17
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,55 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ seatgeek (0.1.0)
5
+ faraday
6
+ multi_json
7
+ rake
8
+ yajl-ruby
9
+
10
+ GEM
11
+ remote: https://rubygems.org/
12
+ specs:
13
+ archive-tar-minitar (0.5.2)
14
+ awesome_print (1.0.2)
15
+ columnize (0.3.6)
16
+ diff-lcs (1.1.3)
17
+ faraday (0.8.0)
18
+ multipart-post (~> 1.1)
19
+ linecache19 (0.5.12)
20
+ ruby_core_source (>= 0.1.4)
21
+ multi_json (1.3.5)
22
+ multipart-post (1.1.5)
23
+ rake (0.9.2.2)
24
+ rspec (2.10.0)
25
+ rspec-core (~> 2.10.0)
26
+ rspec-expectations (~> 2.10.0)
27
+ rspec-mocks (~> 2.10.0)
28
+ rspec-core (2.10.0)
29
+ rspec-expectations (2.10.0)
30
+ diff-lcs (~> 1.1.3)
31
+ rspec-mocks (2.10.1)
32
+ ruby-debug-base19 (0.11.25)
33
+ columnize (>= 0.3.1)
34
+ linecache19 (>= 0.5.11)
35
+ ruby_core_source (>= 0.1.4)
36
+ ruby-debug19 (0.11.6)
37
+ columnize (>= 0.3.1)
38
+ linecache19 (>= 0.5.11)
39
+ ruby-debug-base19 (>= 0.11.19)
40
+ ruby_core_source (0.1.5)
41
+ archive-tar-minitar (>= 0.5.2)
42
+ yajl-ruby (1.1.0)
43
+
44
+ PLATFORMS
45
+ ruby
46
+
47
+ DEPENDENCIES
48
+ awesome_print
49
+ faraday
50
+ multi_json
51
+ rake
52
+ rspec
53
+ ruby-debug19
54
+ seatgeek!
55
+ yajl-ruby
data/README.markdown ADDED
@@ -0,0 +1,108 @@
1
+ SeatGeek [![Build Status](https://secure.travis-ci.org/bluefocus/seatgeek.png)](http://travis-ci.org/bluefocus/seatgeek)
2
+ ========
3
+ SeatGeek maintains a canonical directory of live events in the United States. The SeatGeek Platform makes it easy to construct applications that help users find and discover events by exposing the wealth of data and powerful search behind SeatGeek.com in an easy-to-consume format.
4
+
5
+ This Gem is designed to be a platform agnostic wrapper around the SeatGeek Platform API. Enjoy it and please let me know about anything really cool which uses it.
6
+
7
+ For more information, including a detailed description of the functionality available, visit [The SeatGeek Platform documentation site](http://platform.seatgeek.com).
8
+
9
+ **Rubies supported**
10
+
11
+ - 1.9.2
12
+ - 1.8.7
13
+ - ree
14
+
15
+ Installation
16
+ ------------
17
+
18
+ **With Bundler**
19
+ In your Gemfile, add the following line
20
+
21
+ gem 'seatgeek', :require => 'seatgeek'
22
+
23
+ **Without Bundler**
24
+
25
+ gem install seatgeek
26
+
27
+ Usage
28
+ -----
29
+ At the moment the interface is very simple. I have some additional features and classes planned (see TODO).
30
+
31
+ NOTE: Unless it is already defined in your application, SG will be defined as a shortcut class to SeatGeek::Connection. Accordingly, you can replace any instance of SeatGeek::Connection with SG (i.e. SG.events)
32
+
33
+ SeatGeek::Connection is where all the meat is.
34
+
35
+ Each of the four endpoints can be accessed with a class method reflecting the endpoint's name.
36
+
37
+ SeatGeek::Connection.events
38
+ SeatGeek::Connection.performers
39
+ SeatGeek::Connection.taxonomies
40
+ SeatGeek::Connection.venues
41
+
42
+ Options can be passed in a hash to these methods and they will be included in the request.
43
+
44
+ #### Examples mirror documentation at http://platform.seatgeek.com ####
45
+ SeatGeek::Connection.events({:id => 801255})
46
+ # => GET http://api.seatgeek.com/2/events/801255
47
+ SeatGeek::Connection.events({:geoip => 98.213.245.205, :range => 12mi})
48
+ # => GET http://api.seatgeek.com/2/events?geoip=98.213.245.205&range=12mi
49
+
50
+ SeatGeek::Connection objects can be instantiated before calls. Any parameters passed into the call to #initialize will be passed along with all requests which are generated by that object.
51
+
52
+ @sg_50_pp = SeatGeek::Connection.new({:per_page => 50})
53
+ @sg_50_pp.events
54
+ # => GET http://api.seatgeek.com/2/events?per_page=50
55
+ @sg_50_pp.events({:page => 2})
56
+ # => GET http://api.seatgeek.com/2/events?per_page=50&page=2
57
+
58
+ There are a number of class level options that can be overridden.
59
+
60
+ - SeatGeek::Connection.adapter - the Faraday adapter to use (default: :net_http)
61
+ - SeatGeek::Connection.logger - a Logger object for logging requests (default: nil)
62
+ - SeatGeek::Connection.protocol - http or https (default: :http)
63
+ - SeatGeek::Connection.response_format - ruby, json, jsonp or xml (default: ruby)
64
+ - SeatGeek::Connection.url - api.seatgeek::Connection.com [Advanced tuning]
65
+ - SeatGeek::Connection.version - 2 [Forward thinking]
66
+
67
+ Example:
68
+
69
+ SeatGeek::Connection.protocol
70
+ # => :http
71
+ SeatGeek::Connection.protocol = :https
72
+ # => :https
73
+ SeatGeek::Connection.events
74
+ # => GET https://api.seatgeek.com/2/events
75
+
76
+ These options can also be overridden during instantiation of a SeatGeek::Connection
77
+
78
+ @secure = SeatGeek::Connection.new({:protocol => :https})
79
+ @secure.events
80
+ # => GET https://api.seatgeek.com/2/events
81
+
82
+ TODO
83
+ ----
84
+ The following are features planned for later release. I'm happy to take requests and, of course, pull requests.
85
+
86
+ **Endpoint Classes**
87
+ SeatGeek::Events / SeatGeek::Performers / SeatGeek::Venues / SeatGeek::Taxonomies
88
+
89
+ **Endpoint #all method**
90
+ This will loop through the list response until it runs out of results.
91
+
92
+ Acknowledgements
93
+ ----------------
94
+
95
+ - [SeatGeek](http://seatgeek.com) for the platform.
96
+
97
+ - [Ticket Evolution](http://ticketevolution.com) for the introduction and paying me to do a lot of this.
98
+
99
+ DISCLAIMER / LEGAL
100
+ ------------------
101
+ Copyright (c) 2012 Dan Matthews / Ticket Evolution ([http://ticketevolution.com](http://ticketevolution.com))
102
+
103
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
104
+
105
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
106
+
107
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
108
+
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec) do |task|
5
+ task.rspec_opts = ["-c", "-f progress", "-r ./spec/spec_helper.rb"]
6
+ task.pattern = './spec/**/*_spec.rb'
7
+ end
8
+
9
+ task :default => :spec
@@ -0,0 +1,33 @@
1
+ require 'forwardable'
2
+
3
+ module Faraday
4
+ class Response::VerboseLogger < Response::Middleware
5
+ extend Forwardable
6
+
7
+ def initialize(app, logger)
8
+ super(app)
9
+ @logger = logger
10
+ end
11
+
12
+ def_delegators :@logger, :debug, :info, :warn, :error, :fatal
13
+
14
+ def call(env)
15
+ info "#{env[:method]} #{env[:url].to_s}"
16
+ debug('request headers') { dump_headers env[:request_headers] }
17
+ debug('request body') { env[:body] }
18
+ super
19
+ end
20
+
21
+ def on_complete(env)
22
+ info('Status') { env[:status].to_s }
23
+ debug('response headers') { dump_headers env[:response_headers] }
24
+ debug('response body') { env[:body] }
25
+ end
26
+
27
+ private
28
+
29
+ def dump_headers(headers)
30
+ headers.map { |k, v| "#{k}: #{v.inspect}" }.join("\n")
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,125 @@
1
+ require 'faraday'
2
+
3
+ module SeatGeek
4
+ class Connection
5
+ class << self; self; end.class_eval do
6
+ def adapter; @@adapter ||= :net_http; end
7
+ def adapter=(input); @@adapter = input; end
8
+
9
+ def events(*args); new.events(*args); end
10
+
11
+ def logger; @@logger ||= nil; end
12
+ def logger=(input); @@logger = input; end
13
+
14
+ def options
15
+ {
16
+ :adapter => adapter,
17
+ :logger => logger,
18
+ :protocol => protocol,
19
+ :response_format => response_format,
20
+ :url => url,
21
+ :version => version
22
+ }
23
+ end
24
+
25
+ def performers(*args); new.performers(*args); end
26
+
27
+ def protocol; @@protocol ||= :http; end
28
+ def protocol=(input); @@protocol = input; end
29
+
30
+ def response_format; @@response_format ||= :ruby; end
31
+ def response_format=(input); @@response_format = input; end
32
+
33
+ def taxonomies(*args); new.taxonomies(*args); end
34
+
35
+ def url; @@url ||= "api.seatgeek.com"; end
36
+ def url=(input); @@url = input; end
37
+
38
+ def venues(*args); new.venues(*args); end
39
+
40
+ def version; @@version ||= 2; end
41
+ def version=(input); @@version = input; end
42
+ end
43
+
44
+ def initialize(options = {})
45
+ @options = self.class.options.merge({}.tap do |opts|
46
+ options.each do |k, v|
47
+ opts[k.to_sym] = v
48
+ end
49
+ end)
50
+ end
51
+
52
+ def events(params = {})
53
+ request('/events', params)
54
+ end
55
+
56
+ def handle_response(response)
57
+ if response_format == :ruby and response.status == 200
58
+ MultiJson.decode(response.body)
59
+ else
60
+ {:status => response.status, :body => response.body}
61
+ end
62
+ end
63
+
64
+ # Ruby 1.8.7 / ree compatibility
65
+ def id
66
+ @options[:id]
67
+ end
68
+
69
+ def performers(params = {})
70
+ request('/performers', params)
71
+ end
72
+
73
+ def request(url, params)
74
+ handle_response(Faraday.new(*builder(url, params.clone)) do |build|
75
+ build.adapter adapter
76
+ build.use Faraday::Response::VerboseLogger, logger if logger.present?
77
+ end.get)
78
+ end
79
+
80
+ def response_format
81
+ @options[:response_format].to_sym
82
+ end
83
+
84
+ def taxonomies(params = {})
85
+ request('/taxonomies', params)
86
+ end
87
+
88
+ def uri(path)
89
+ "#{protocol}://#{url}/#{version}#{path}"
90
+ end
91
+
92
+ def venues(params = {})
93
+ request('/venues', params)
94
+ end
95
+
96
+ private
97
+
98
+ def method_missing(method, *params)
99
+ @options.keys.include?(method.to_sym) && params.first.nil? ? @options[method.to_sym] : super
100
+ end
101
+
102
+ def builder(uri_segment, params)
103
+ return [
104
+ uri([].tap do |part|
105
+ part << "/events"
106
+ part << "/#{params.delete(:id)}" unless params[:id].nil?
107
+ end.join),
108
+ {
109
+ :params => custom_options.merge((
110
+ [:jsonp, :xml].include?(response_format) ? \
111
+ params.merge(:format => response_format) : params))
112
+ }
113
+ ]
114
+ end
115
+
116
+ def custom_options
117
+ @custom_options ||= {}.tap do |opts|
118
+ ignore = self.class.options.keys
119
+ @options.each do |k, v|
120
+ opts[k] = v unless ignore.include?(k)
121
+ end
122
+ end
123
+ end
124
+ end
125
+ end
@@ -0,0 +1,3 @@
1
+ module SeatGeek
2
+ VERSION = "0.1.0"
3
+ end
data/lib/seatgeek.rb ADDED
@@ -0,0 +1,13 @@
1
+ require 'logger'
2
+ require 'multi_json'
3
+ require 'yajl'
4
+
5
+ MultiJson.engine = :yajl
6
+
7
+ module SeatGeek
8
+ end
9
+
10
+ require 'seat_geek/connection'
11
+ require 'seat_geek/version'
12
+
13
+ require 'faraday/response/verbose_logger'
data/seatgeek.gemspec ADDED
@@ -0,0 +1,28 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require 'seat_geek/version'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "seatgeek"
7
+ s.version = SeatGeek::VERSION
8
+ s.authors = ["Dan Matthews"]
9
+ s.email = ["dan@bluefoc.us"]
10
+ s.homepage = "http://platform.seatgeek.com"
11
+ s.summary = "A Ruby wrapper for the SeatGeek Platform API."
12
+ s.description = "This gem provides Ruby functionality around the SeatGeek Platform API (http://platform.seatgeek.com). It is designed to be framework agnostic and was originally developed for use in my day job at Ticket Evolution."
13
+
14
+ s.rubyforge_project = "seatgeek"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ s.add_dependency "faraday"
22
+ s.add_dependency "multi_json"
23
+ s.add_dependency "rake"
24
+ s.add_dependency "yajl-ruby"
25
+
26
+ s.add_development_dependency "rspec"
27
+ end
28
+
@@ -0,0 +1,283 @@
1
+ require 'spec_helper'
2
+ require 'ostruct'
3
+
4
+ describe SeatGeek::Connection do
5
+ let(:klass) { SeatGeek::Connection }
6
+ let(:instance) { klass.new }
7
+
8
+ describe ".adapter" do
9
+ subject { klass.adapter }
10
+ let(:default) { :net_http }
11
+
12
+ it { should == default }
13
+ it "should be writable" do
14
+ klass.adapter = :typhoeus
15
+ klass.adapter.should == :typhoeus
16
+ end
17
+
18
+ after { klass.adapter = default }
19
+ end
20
+
21
+ describe ".events" do
22
+ it "proxies to #events" do
23
+ klass.any_instance.should_receive(:events).and_return(nil)
24
+ klass.events
25
+ end
26
+
27
+ it "passes any attributes to #events" do
28
+ klass.any_instance.should_receive(:events).with(1, 2).and_return(nil)
29
+ klass.events(1, 2)
30
+ end
31
+ end
32
+
33
+ describe ".logger" do
34
+ subject { klass.logger }
35
+ let(:default) { nil }
36
+ let(:logger) { Logger.new(STDOUT) }
37
+
38
+ it { should == default }
39
+ it "should be writable" do
40
+ klass.logger = logger
41
+ klass.logger.should == logger
42
+ end
43
+
44
+ after { klass.logger = default }
45
+ end
46
+
47
+ describe ".options" do
48
+ it "should return a hash of all of the class level settings" do
49
+ klass.options.should == {
50
+ :adapter => :net_http,
51
+ :logger => nil,
52
+ :protocol => :http,
53
+ :response_format => :ruby,
54
+ :url => "api.seatgeek.com",
55
+ :version => 2
56
+ }
57
+ end
58
+ end
59
+
60
+ describe ".performers" do
61
+ it "proxies to #performers" do
62
+ klass.any_instance.should_receive(:performers).and_return(nil)
63
+ klass.performers
64
+ end
65
+
66
+ it "passes any attributes to #performers" do
67
+ klass.any_instance.should_receive(:performers).with(1, 2).and_return(nil)
68
+ klass.performers(1, 2)
69
+ end
70
+ end
71
+
72
+ describe ".protocol" do
73
+ subject { klass.protocol }
74
+ let(:default) { :http }
75
+
76
+ it { should == default }
77
+ it "should be writable" do
78
+ klass.protocol = :https
79
+ klass.protocol.should == :https
80
+ end
81
+
82
+ after { klass.protocol = default }
83
+ end
84
+
85
+ describe ".response_format" do
86
+ subject { klass.response_format }
87
+ let(:default) { :ruby }
88
+
89
+ it { should == default }
90
+ it "should be writable" do
91
+ klass.response_format = :jsonp
92
+ klass.response_format.should == :jsonp
93
+ end
94
+
95
+ after { klass.response_format = default }
96
+ end
97
+
98
+ describe ".taxonomies" do
99
+ it "proxies to #taxonomies" do
100
+ klass.any_instance.should_receive(:taxonomies).and_return(nil)
101
+ klass.taxonomies
102
+ end
103
+
104
+ it "passes any attributes to #taxonomies" do
105
+ klass.any_instance.should_receive(:taxonomies).with(1, 2).and_return(nil)
106
+ klass.taxonomies(1, 2)
107
+ end
108
+ end
109
+
110
+ describe ".url" do
111
+ subject { klass.url }
112
+ let(:default) { "api.seatgeek.com" }
113
+
114
+ it { should == default }
115
+ it "should be writable" do
116
+ klass.url = "ticketevolution.com"
117
+ klass.url.should == "ticketevolution.com"
118
+ end
119
+
120
+ after { klass.url = default }
121
+ end
122
+
123
+ describe ".venues" do
124
+ it "proxies to #venues" do
125
+ klass.any_instance.should_receive(:venues).and_return(nil)
126
+ klass.venues
127
+ end
128
+
129
+ it "passes any attributes to #venues" do
130
+ klass.any_instance.should_receive(:venues).with(1, 2).and_return(nil)
131
+ klass.venues(1, 2)
132
+ end
133
+ end
134
+
135
+ describe ".version" do
136
+ subject { klass.version }
137
+ let(:default) { 2 }
138
+
139
+ it { should == 2 }
140
+ it "should be writable" do
141
+ klass.version = 1
142
+ klass.version.should == 1
143
+ end
144
+
145
+ after { klass.version = default }
146
+ end
147
+
148
+ describe "#initialize" do
149
+ let(:expected) { klass.options.merge(options) }
150
+ let(:options) { { :testing => 123, :clone => :hello } }
151
+ let(:str_options) { {}.tap{|o| options.each{|k, v| o[k.to_s] = v}} }
152
+ let(:instance) { klass.new(options) }
153
+
154
+ it "should take options passed and store them on top of the class options hash" do
155
+ instance.instance_eval('@options').should == expected
156
+ end
157
+
158
+ it "should convert the keys passed to symbols" do
159
+ klass.new(str_options).instance_eval('@options').should == expected
160
+ end
161
+
162
+ it "should serve options up via read accessor methods unless the methods already exist" do
163
+ instance.testing.should == options[:testing]
164
+ instance.clone.should_not == options[:clone]
165
+ end
166
+ end
167
+
168
+ describe "#events" do
169
+ let(:url) { '/events'}
170
+ let(:params) { {:test => 123} }
171
+
172
+ it "should call #request with the correct url segment and the params passed" do
173
+ instance.should_receive(:request).with(url, params)
174
+ instance.events(params)
175
+ end
176
+ end
177
+
178
+ describe "#handle_response" do
179
+ let(:response) { double(Faraday::Response, :status => status, :body => body)}
180
+
181
+ context "when response_format is set to ruby" do
182
+ context "and the request was successful" do
183
+ let(:status) { 200 }
184
+ let(:body) { "{\"meta\":{\"per_page\":1,\"total\":63188,\"page\":1,\"took\":4,\"geolocation\":null},\"events\":[{\"stats\":{\"listing_count\":0,\"average_price\":0,\"lowest_price\":null,\"highest_price\":null},\"relative_url\":\"/palm-beach-cardinals-at-jupiter-hammerheads-tickets/minor-league-baseball/2012-05-14/798459/\",\"title\":\"Palm Beach Cardinals at Jupiter Hammerheads\",\"url\":\"http://seatgeek.com/palm-beach-cardinals-at-jupiter-hammerheads-tickets/minor-league-baseball/2012-05-14/798459/\",\"datetime_local\":\"2012-05-14T10:35:00\",\"performers\":[{\"away_team\":true,\"name\":\"Palm Beach Cardinals\",\"url\":\"http://seatgeek.com/palm-beach-cardinals-tickets/\",\"image\":null,\"short_name\":\"Palm Beach Cardinals\",\"slug\":\"palm-beach-cardinals\",\"score\":0,\"images\":[],\"type\":\"minor_league_baseball\",\"id\":9420},{\"home_team\":true,\"name\":\"Jupiter Hammerheads\",\"url\":\"http://seatgeek.com/jupiter-hammerheads-tickets/\",\"image\":null,\"short_name\":\"Jupiter Hammerheads\",\"primary\":true,\"slug\":\"jupiter-hammerheads\",\"score\":0,\"images\":[],\"type\":\"minor_league_baseball\",\"id\":9421}],\"venue\":{\"city\":\"Jupiter\",\"name\":\"Roger Dean Stadium\",\"url\":\"http://seatgeek.com/roger-dean-stadium-tickets/\",\"country\":\"US\",\"state\":\"FL\",\"score\":16592,\"postal_code\":\"33468\",\"location\":{\"lat\":26.8936,\"lon\":-80.1156},\"extended_address\":null,\"address\":\"4751 Main St\",\"id\":3927},\"short_title\":\"Palm Beach Cardinals at Jupiter Hammerheads\",\"datetime_utc\":\"2012-05-14T14:35:00\",\"score\":0,\"taxonomies\":[{\"parent_id\":null,\"id\":1000000,\"name\":\"sports\"},{\"parent_id\":1000000,\"id\":1010000,\"name\":\"baseball\"},{\"parent_id\":1010000,\"id\":1010300,\"name\":\"minor_league_baseball\"}],\"type\":\"minor_league_baseball\",\"id\":798459}]}" }
185
+
186
+ it "should parse the json returned and respond with a ruby object" do
187
+ instance.handle_response(response).should == MultiJson.decode(body)
188
+ end
189
+ end
190
+
191
+ context "and the request was not successful" do
192
+ let(:status) { 500 }
193
+ let(:body) { "Internal Server Error" }
194
+
195
+ it "should return the status code and exact result body" do
196
+ instance.handle_response(response).should == {:status => status, :body => body}
197
+ end
198
+ end
199
+ end
200
+
201
+ context "when response format is not set to ruby" do
202
+ let(:status) { 200 }
203
+ let(:body) { "{\"meta\":{\"per_page\":1,\"total\":63188,\"page\":1,\"took\":4,\"geolocation\":null},\"events\":[{\"stats\":{\"listing_count\":0,\"average_price\":0,\"lowest_price\":null,\"highest_price\":null},\"relative_url\":\"/palm-beach-cardinals-at-jupiter-hammerheads-tickets/minor-league-baseball/2012-05-14/798459/\",\"title\":\"Palm Beach Cardinals at Jupiter Hammerheads\",\"url\":\"http://seatgeek.com/palm-beach-cardinals-at-jupiter-hammerheads-tickets/minor-league-baseball/2012-05-14/798459/\",\"datetime_local\":\"2012-05-14T10:35:00\",\"performers\":[{\"away_team\":true,\"name\":\"Palm Beach Cardinals\",\"url\":\"http://seatgeek.com/palm-beach-cardinals-tickets/\",\"image\":null,\"short_name\":\"Palm Beach Cardinals\",\"slug\":\"palm-beach-cardinals\",\"score\":0,\"images\":[],\"type\":\"minor_league_baseball\",\"id\":9420},{\"home_team\":true,\"name\":\"Jupiter Hammerheads\",\"url\":\"http://seatgeek.com/jupiter-hammerheads-tickets/\",\"image\":null,\"short_name\":\"Jupiter Hammerheads\",\"primary\":true,\"slug\":\"jupiter-hammerheads\",\"score\":0,\"images\":[],\"type\":\"minor_league_baseball\",\"id\":9421}],\"venue\":{\"city\":\"Jupiter\",\"name\":\"Roger Dean Stadium\",\"url\":\"http://seatgeek.com/roger-dean-stadium-tickets/\",\"country\":\"US\",\"state\":\"FL\",\"score\":16592,\"postal_code\":\"33468\",\"location\":{\"lat\":26.8936,\"lon\":-80.1156},\"extended_address\":null,\"address\":\"4751 Main St\",\"id\":3927},\"short_title\":\"Palm Beach Cardinals at Jupiter Hammerheads\",\"datetime_utc\":\"2012-05-14T14:35:00\",\"score\":0,\"taxonomies\":[{\"parent_id\":null,\"id\":1000000,\"name\":\"sports\"},{\"parent_id\":1000000,\"id\":1010000,\"name\":\"baseball\"},{\"parent_id\":1010000,\"id\":1010300,\"name\":\"minor_league_baseball\"}],\"type\":\"minor_league_baseball\",\"id\":798459}]}" }
204
+
205
+ it "should return the status code and exact result body" do
206
+ klass.new(:response_format => :json).\
207
+ handle_response(response).should == {:status => status, :body => body}
208
+ end
209
+ end
210
+ end
211
+
212
+ describe "#performers" do
213
+ let(:url) { '/performers'}
214
+ let(:params) { {:test => 123} }
215
+
216
+ it "should call #request with the correct url segment and the params passed" do
217
+ instance.should_receive(:request).with(url, params)
218
+ instance.performers(params)
219
+ end
220
+ end
221
+
222
+ describe "#request" do
223
+ let(:url) { 'http://api.seatgeek.com/2/events' }
224
+ let(:params) { {} }
225
+ let(:faraday) { mock(:faraday, :get => OpenStruct.new({:status => 200, :body => "[]"})) }
226
+
227
+ context "when .response_format is jsonp" do
228
+ let(:instance) { klass.new({:response_format => :jsonp}) }
229
+ let(:expected_params) { {:params => params.merge({:format => :jsonp})} }
230
+
231
+ it "should set the format param to jsonp" do
232
+ Faraday.should_receive(:new).with(url, expected_params).and_return(faraday)
233
+ instance.request(url, params)
234
+ end
235
+ end
236
+
237
+ context "when .response_format is xml" do
238
+ let(:instance) { klass.new({:response_format => :xml}) }
239
+ let(:expected_params) { {:params => params.merge({:format => :xml})} }
240
+
241
+ it "should set the format param to xml" do
242
+ Faraday.should_receive(:new).with(url, expected_params).and_return(faraday)
243
+ instance.request(url, params)
244
+ end
245
+ end
246
+
247
+ context "when additional parameters were passed to #initialize" do
248
+ let(:instance) { klass.new({:response_format => :jsonp, :testing => 123}) }
249
+ let(:expected_params) { {:params => params.merge({:format => :jsonp, :testing => 123})} }
250
+
251
+ it "should add those parameters to the request params" do
252
+ Faraday.should_receive(:new).with(url, expected_params).and_return(faraday)
253
+ instance.request(url, params)
254
+ end
255
+ end
256
+ end
257
+
258
+ describe "#taxonomies" do
259
+ let(:url) { '/taxonomies'}
260
+ let(:params) { {:test => 123} }
261
+
262
+ it "should call #request with the correct url segment and the params passed" do
263
+ instance.should_receive(:request).with(url, params)
264
+ instance.taxonomies(params)
265
+ end
266
+ end
267
+
268
+ describe "#uri" do
269
+ it "should take in a path and combine it with protocol, url and version" do
270
+ instance.uri('/events').should == "http://api.seatgeek.com/2/events"
271
+ end
272
+ end
273
+
274
+ describe "#venues" do
275
+ let(:url) { '/venues'}
276
+ let(:params) { {:test => 123} }
277
+
278
+ it "should call #request with the correct url segment and the params passed" do
279
+ instance.should_receive(:request).with(url, params)
280
+ instance.venues(params)
281
+ end
282
+ end
283
+ end
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ describe SeatGeek::VERSION do
4
+ it "should match a three segment version number format" do
5
+ subject.should =~ /^\d+\.\d+\.\d+(rc\d+)?$/
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ require 'seatgeek'
2
+
3
+ RSpec.configure do |config|
4
+ config.treat_symbols_as_metadata_keys_with_true_values = true
5
+ config.run_all_when_everything_filtered = true
6
+ config.filter_run :focus
7
+ end
metadata ADDED
@@ -0,0 +1,127 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: seatgeek
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Dan Matthews
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-05-15 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: faraday
16
+ requirement: &70300193146140 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70300193146140
25
+ - !ruby/object:Gem::Dependency
26
+ name: multi_json
27
+ requirement: &70300193145080 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70300193145080
36
+ - !ruby/object:Gem::Dependency
37
+ name: rake
38
+ requirement: &70300193143640 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :runtime
45
+ prerelease: false
46
+ version_requirements: *70300193143640
47
+ - !ruby/object:Gem::Dependency
48
+ name: yajl-ruby
49
+ requirement: &70300193142460 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :runtime
56
+ prerelease: false
57
+ version_requirements: *70300193142460
58
+ - !ruby/object:Gem::Dependency
59
+ name: rspec
60
+ requirement: &70300193141520 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *70300193141520
69
+ description: This gem provides Ruby functionality around the SeatGeek Platform API
70
+ (http://platform.seatgeek.com). It is designed to be framework agnostic and was
71
+ originally developed for use in my day job at Ticket Evolution.
72
+ email:
73
+ - dan@bluefoc.us
74
+ executables: []
75
+ extensions: []
76
+ extra_rdoc_files: []
77
+ files:
78
+ - .gitignore
79
+ - .rdebugrc
80
+ - .rspec
81
+ - .travis.yml
82
+ - Gemfile
83
+ - Gemfile.lock
84
+ - README.markdown
85
+ - Rakefile
86
+ - lib/faraday/response/verbose_logger.rb
87
+ - lib/seat_geek/connection.rb
88
+ - lib/seat_geek/version.rb
89
+ - lib/seatgeek.rb
90
+ - seatgeek.gemspec
91
+ - spec/lib/seat_geek/connection_spec.rb
92
+ - spec/lib/seat_geek/version_spec.rb
93
+ - spec/spec_helper.rb
94
+ homepage: http://platform.seatgeek.com
95
+ licenses: []
96
+ post_install_message:
97
+ rdoc_options: []
98
+ require_paths:
99
+ - lib
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ none: false
102
+ requirements:
103
+ - - ! '>='
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ segments:
107
+ - 0
108
+ hash: -569337518630215415
109
+ required_rubygems_version: !ruby/object:Gem::Requirement
110
+ none: false
111
+ requirements:
112
+ - - ! '>='
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ segments:
116
+ - 0
117
+ hash: -569337518630215415
118
+ requirements: []
119
+ rubyforge_project: seatgeek
120
+ rubygems_version: 1.8.6
121
+ signing_key:
122
+ specification_version: 3
123
+ summary: A Ruby wrapper for the SeatGeek Platform API.
124
+ test_files:
125
+ - spec/lib/seat_geek/connection_spec.rb
126
+ - spec/lib/seat_geek/version_spec.rb
127
+ - spec/spec_helper.rb