seatgeek 0.1.3 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +31 -3
- data/.travis.yml +1 -2
- data/Gemfile +7 -7
- data/Gemfile.lock +38 -20
- data/README.md +5 -2
- data/lib/seat_geek/connection.rb +83 -34
- data/lib/seat_geek/version.rb +3 -1
- data/spec/fixtures/handle_response.json +1 -0
- data/spec/lib/seat_geek/connection_spec.rb +175 -117
- data/spec/lib/seat_geek/version_spec.rb +2 -2
- data/spec/lib/sg_spec.rb +1 -1
- data/spec/spec_helper.rb +0 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4fff0f590450a4239ba544957b7015ef1e7a5a5e
|
4
|
+
data.tar.gz: dd74c176439117ac90b7e54d71eff24ff3df1b3c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ee80b3beca64bd2804568275f0664083157429923832700b0328682ac0473f864e3da469fe1f521591162c9fb69ab18172500c4f9c0a35951f4a899dd5b8a751
|
7
|
+
data.tar.gz: 4314cf7470e706942425395ab5996269555a248f27e08860fcec58db6c306a383afe952fd0d4b4b8980ec205f1e42eabf20921c63de674f7fa230054ec3c4eb3
|
data/.gitignore
CHANGED
@@ -1,5 +1,33 @@
|
|
1
1
|
.DS_Store
|
2
|
-
|
3
|
-
*.
|
4
|
-
|
2
|
+
|
3
|
+
*.gem
|
4
|
+
*.rbc
|
5
|
+
/.config
|
6
|
+
/coverage/
|
7
|
+
/InstalledFiles
|
8
|
+
/pkg/
|
9
|
+
/spec/reports/
|
10
|
+
/spec/examples.txt
|
11
|
+
/test/tmp/
|
12
|
+
/test/version_tmp/
|
13
|
+
/tmp/
|
14
|
+
|
15
|
+
## Documentation cache and generated files:
|
16
|
+
/.yardoc/
|
17
|
+
/_yardoc/
|
18
|
+
/doc/
|
19
|
+
/rdoc/
|
20
|
+
|
21
|
+
## Environment normalization:
|
22
|
+
/.bundle/
|
23
|
+
/vendor/bundle
|
24
|
+
/lib/bundler/man/
|
25
|
+
|
26
|
+
# for a library or gem, you might want to ignore these files since the code is
|
27
|
+
# intended to run in multiple environments; otherwise, check them in:
|
28
|
+
# Gemfile.lock
|
29
|
+
# .ruby-version
|
30
|
+
# .ruby-gemset
|
31
|
+
|
32
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
5
33
|
.rvmrc
|
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
source 'https://rubygems.org'
|
2
2
|
|
3
|
-
gem 'faraday'
|
4
|
-
gem 'multi_json'
|
5
|
-
gem 'rake'
|
6
|
-
gem 'yajl-ruby'
|
3
|
+
gem 'faraday', '~> 0.8.11'
|
4
|
+
gem 'multi_json', '~> 1.3.5'
|
5
|
+
gem 'rake', '~> 0.9.2'
|
6
|
+
gem 'yajl-ruby', '~> 1.1.0'
|
7
7
|
|
8
8
|
group :test do
|
9
|
-
gem 'rspec'
|
9
|
+
gem 'rspec', '~> 3.4.0'
|
10
10
|
end
|
11
11
|
|
12
12
|
group :no_travis do
|
13
|
-
gem 'awesome_print'
|
14
|
-
|
13
|
+
gem 'awesome_print', '~> 1.6.1'
|
14
|
+
gem 'debugger', '~> 1.6.8'
|
15
15
|
end
|
16
16
|
|
17
17
|
gemspec
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
seatgeek (0.1.
|
4
|
+
seatgeek (0.1.3)
|
5
5
|
faraday
|
6
6
|
multi_json
|
7
7
|
rake
|
@@ -10,29 +10,47 @@ PATH
|
|
10
10
|
GEM
|
11
11
|
remote: https://rubygems.org/
|
12
12
|
specs:
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
13
|
+
awesome_print (1.6.1)
|
14
|
+
columnize (0.9.0)
|
15
|
+
debugger (1.6.8)
|
16
|
+
columnize (>= 0.3.1)
|
17
|
+
debugger-linecache (~> 1.2.0)
|
18
|
+
debugger-ruby_core_source (~> 1.3.5)
|
19
|
+
debugger-linecache (1.2.0)
|
20
|
+
debugger-ruby_core_source (1.3.8)
|
21
|
+
diff-lcs (1.2.5)
|
22
|
+
faraday (0.8.11)
|
23
|
+
multipart-post (~> 1.2.0)
|
24
|
+
multi_json (1.3.7)
|
25
|
+
multipart-post (1.2.0)
|
26
|
+
rake (0.9.6)
|
27
|
+
rspec (3.4.0)
|
28
|
+
rspec-core (~> 3.4.0)
|
29
|
+
rspec-expectations (~> 3.4.0)
|
30
|
+
rspec-mocks (~> 3.4.0)
|
31
|
+
rspec-core (3.4.4)
|
32
|
+
rspec-support (~> 3.4.0)
|
33
|
+
rspec-expectations (3.4.0)
|
34
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
35
|
+
rspec-support (~> 3.4.0)
|
36
|
+
rspec-mocks (3.4.1)
|
37
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
38
|
+
rspec-support (~> 3.4.0)
|
39
|
+
rspec-support (3.4.1)
|
27
40
|
yajl-ruby (1.1.0)
|
28
41
|
|
29
42
|
PLATFORMS
|
30
43
|
ruby
|
31
44
|
|
32
45
|
DEPENDENCIES
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
46
|
+
awesome_print (~> 1.6.1)
|
47
|
+
debugger (~> 1.6.8)
|
48
|
+
faraday (~> 0.8.11)
|
49
|
+
multi_json (~> 1.3.5)
|
50
|
+
rake (~> 0.9.2)
|
51
|
+
rspec (~> 3.4.0)
|
37
52
|
seatgeek!
|
38
|
-
yajl-ruby
|
53
|
+
yajl-ruby (~> 1.1.0)
|
54
|
+
|
55
|
+
BUNDLED WITH
|
56
|
+
1.11.2
|
data/README.md
CHANGED
@@ -9,8 +9,7 @@ For more information, including a detailed description of the functionality avai
|
|
9
9
|
**Rubies supported**
|
10
10
|
|
11
11
|
- 1.9.2
|
12
|
-
- 1.
|
13
|
-
- ree
|
12
|
+
- 2.1.0
|
14
13
|
|
15
14
|
Installation
|
16
15
|
------------
|
@@ -32,6 +31,10 @@ NOTE: Unless it is already defined in your application, SG will be defined as a
|
|
32
31
|
|
33
32
|
SeatGeek::Connection is where all the meat is.
|
34
33
|
|
34
|
+
You will first need to provide the `client_id` for your application. For assistance registering and locating your `client_id`, please see [the platform documentation](http://platform.seatgeek.com/#authentication).
|
35
|
+
|
36
|
+
SeatGeek::Connection.client_id = 'some_client_id'
|
37
|
+
|
35
38
|
Each of the four endpoints can be accessed with a class method reflecting the endpoint's name.
|
36
39
|
|
37
40
|
SeatGeek::Connection.events
|
data/lib/seat_geek/connection.rb
CHANGED
@@ -1,44 +1,95 @@
|
|
1
1
|
require 'faraday'
|
2
2
|
|
3
|
+
##
|
4
|
+
# Module: SeatGeek
|
3
5
|
module SeatGeek
|
6
|
+
##
|
7
|
+
# Class: Connection
|
4
8
|
class Connection
|
5
9
|
class << self; self; end.class_eval do
|
6
|
-
def adapter
|
7
|
-
|
10
|
+
def adapter
|
11
|
+
@@adapter ||= :net_http
|
12
|
+
end
|
13
|
+
|
14
|
+
def adapter=(input)
|
15
|
+
@@adapter = input
|
16
|
+
end
|
17
|
+
|
18
|
+
def events(*args)
|
19
|
+
new.events(*args)
|
20
|
+
end
|
8
21
|
|
9
|
-
def
|
22
|
+
def logger
|
23
|
+
@@logger ||= nil
|
24
|
+
end
|
10
25
|
|
11
|
-
def logger
|
12
|
-
|
26
|
+
def logger=(input)
|
27
|
+
@@logger = input
|
28
|
+
end
|
13
29
|
|
14
30
|
def options
|
15
31
|
{
|
16
|
-
:
|
17
|
-
:
|
18
|
-
:
|
19
|
-
:
|
20
|
-
:
|
21
|
-
:
|
32
|
+
adapter: adapter,
|
33
|
+
logger: logger,
|
34
|
+
protocol: protocol,
|
35
|
+
response_format: response_format,
|
36
|
+
url: url,
|
37
|
+
version: version,
|
38
|
+
client_id: client_id
|
22
39
|
}
|
23
40
|
end
|
24
41
|
|
25
|
-
def performers(*args)
|
42
|
+
def performers(*args)
|
43
|
+
new.performers(*args)
|
44
|
+
end
|
45
|
+
|
46
|
+
def protocol
|
47
|
+
@@protocol ||= :https
|
48
|
+
end
|
26
49
|
|
27
|
-
def protocol
|
28
|
-
|
50
|
+
def protocol=(input)
|
51
|
+
@@protocol = input
|
52
|
+
end
|
29
53
|
|
30
|
-
def response_format
|
31
|
-
|
54
|
+
def response_format
|
55
|
+
@@response_format ||= :ruby
|
56
|
+
end
|
32
57
|
|
33
|
-
def
|
58
|
+
def response_format=(input)
|
59
|
+
@@response_format = input
|
60
|
+
end
|
34
61
|
|
35
|
-
def
|
36
|
-
|
62
|
+
def taxonomies(*args)
|
63
|
+
new.taxonomies(*args)
|
64
|
+
end
|
37
65
|
|
38
|
-
def
|
66
|
+
def url
|
67
|
+
@@url ||= 'api.seatgeek.com'
|
68
|
+
end
|
39
69
|
|
40
|
-
def
|
41
|
-
|
70
|
+
def url=(input)
|
71
|
+
@@url = input
|
72
|
+
end
|
73
|
+
|
74
|
+
def venues(*args)
|
75
|
+
new.venues(*args)
|
76
|
+
end
|
77
|
+
|
78
|
+
def version
|
79
|
+
@@version ||= 2
|
80
|
+
end
|
81
|
+
|
82
|
+
def version=(input)
|
83
|
+
@@version = input
|
84
|
+
end
|
85
|
+
|
86
|
+
def client_id
|
87
|
+
@@client_id ||= nil
|
88
|
+
end
|
89
|
+
|
90
|
+
def client_id=(input)
|
91
|
+
@@client_id = input
|
92
|
+
end
|
42
93
|
end
|
43
94
|
|
44
95
|
def initialize(options = {})
|
@@ -54,26 +105,25 @@ module SeatGeek
|
|
54
105
|
end
|
55
106
|
|
56
107
|
def handle_response(response)
|
57
|
-
if response_format == :ruby
|
108
|
+
if response_format == :ruby && response.status == 200
|
58
109
|
MultiJson.decode(response.body)
|
59
110
|
else
|
60
|
-
{:
|
111
|
+
{ status: response.status, body: response.body }
|
61
112
|
end
|
62
113
|
end
|
63
114
|
|
64
|
-
# Ruby 1.8.7 / ree compatibility
|
65
|
-
def id
|
66
|
-
@options[:id]
|
67
|
-
end
|
68
|
-
|
69
115
|
def performers(params = {})
|
70
116
|
request('/performers', params)
|
71
117
|
end
|
72
118
|
|
73
119
|
def request(url, params)
|
120
|
+
raise 'You must provide a `client_id` for SeatGeek' unless client_id || params[:client_id]
|
74
121
|
handle_response(Faraday.new(*builder(url, params.clone)) do |build|
|
75
|
-
|
122
|
+
if client_id
|
123
|
+
build.use Faraday::Request::BasicAuthentication, client_id, nil
|
124
|
+
end
|
76
125
|
build.use Faraday::Response::VerboseLogger, logger unless logger.nil?
|
126
|
+
build.adapter adapter
|
77
127
|
end.get)
|
78
128
|
end
|
79
129
|
|
@@ -100,15 +150,14 @@ module SeatGeek
|
|
100
150
|
end
|
101
151
|
|
102
152
|
def builder(uri_segment, params)
|
103
|
-
|
153
|
+
[
|
104
154
|
uri([].tap do |part|
|
105
155
|
part << uri_segment
|
106
156
|
part << "/#{params.delete(:id)}" unless params[:id].nil?
|
107
157
|
end.join),
|
108
158
|
{
|
109
|
-
:
|
110
|
-
[:jsonp, :xml].include?(response_format) ?
|
111
|
-
params.merge(:format => response_format) : params))
|
159
|
+
params: custom_options.merge((
|
160
|
+
[:jsonp, :xml].include?(response_format) ? params.merge(format: response_format) : params))
|
112
161
|
}
|
113
162
|
]
|
114
163
|
end
|
data/lib/seat_geek/version.rb
CHANGED
@@ -0,0 +1 @@
|
|
1
|
+
{"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":"https://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":"https://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":"https://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":"https://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}]}
|
@@ -3,281 +3,339 @@ require 'ostruct'
|
|
3
3
|
|
4
4
|
describe SeatGeek::Connection do
|
5
5
|
let(:klass) { SeatGeek::Connection }
|
6
|
-
let(:instance) { klass.new }
|
6
|
+
let(:instance) { klass.new(client_id: 'foobar') }
|
7
7
|
|
8
|
-
describe
|
8
|
+
describe '.adapter' do
|
9
9
|
subject { klass.adapter }
|
10
10
|
let(:default) { :net_http }
|
11
11
|
|
12
12
|
it { should == default }
|
13
|
-
it
|
13
|
+
it 'should be writable' do
|
14
14
|
klass.adapter = :typhoeus
|
15
|
-
klass.adapter.
|
15
|
+
expect(klass.adapter).to eq(:typhoeus)
|
16
16
|
end
|
17
17
|
|
18
18
|
after { klass.adapter = default }
|
19
19
|
end
|
20
20
|
|
21
|
-
describe
|
22
|
-
it
|
23
|
-
klass.
|
21
|
+
describe '.events' do
|
22
|
+
it 'proxies to #events' do
|
23
|
+
expect_any_instance_of(klass).to receive(:events).and_return(nil)
|
24
24
|
klass.events
|
25
25
|
end
|
26
26
|
|
27
|
-
it
|
28
|
-
klass.
|
27
|
+
it 'passes any attributes to #events' do
|
28
|
+
expect_any_instance_of(klass).to receive(:events).with(1, 2)
|
29
|
+
.and_return(nil)
|
29
30
|
klass.events(1, 2)
|
30
31
|
end
|
31
32
|
end
|
32
33
|
|
33
|
-
describe
|
34
|
+
describe '.logger' do
|
34
35
|
subject { klass.logger }
|
35
36
|
let(:default) { nil }
|
36
37
|
let(:logger) { Logger.new(STDOUT) }
|
37
38
|
|
38
39
|
it { should == default }
|
39
|
-
it
|
40
|
+
it 'should be writable' do
|
40
41
|
klass.logger = logger
|
41
|
-
klass.logger.
|
42
|
+
expect(klass.logger).to eq(logger)
|
42
43
|
end
|
43
44
|
|
44
45
|
after { klass.logger = default }
|
45
46
|
end
|
46
47
|
|
47
|
-
describe
|
48
|
-
it
|
49
|
-
klass.options.
|
50
|
-
:
|
51
|
-
:
|
52
|
-
:
|
53
|
-
:
|
54
|
-
:
|
55
|
-
:
|
56
|
-
|
48
|
+
describe '.options' do
|
49
|
+
it 'should return a hash of all of the class level settings' do
|
50
|
+
expect(klass.options).to eq(
|
51
|
+
adapter: :net_http,
|
52
|
+
logger: nil,
|
53
|
+
protocol: :https,
|
54
|
+
response_format: :ruby,
|
55
|
+
url: 'api.seatgeek.com',
|
56
|
+
version: 2,
|
57
|
+
client_id: nil
|
58
|
+
)
|
57
59
|
end
|
58
60
|
end
|
59
61
|
|
60
|
-
describe
|
61
|
-
it
|
62
|
-
klass.
|
62
|
+
describe '.performers' do
|
63
|
+
it 'proxies to #performers' do
|
64
|
+
expect_any_instance_of(klass).to receive(:performers).and_return(nil)
|
63
65
|
klass.performers
|
64
66
|
end
|
65
67
|
|
66
|
-
it
|
67
|
-
klass.
|
68
|
+
it 'passes any attributes to #performers' do
|
69
|
+
expect_any_instance_of(klass).to receive(:performers).with(1, 2)
|
70
|
+
.and_return(nil)
|
68
71
|
klass.performers(1, 2)
|
69
72
|
end
|
70
73
|
end
|
71
74
|
|
72
|
-
describe
|
75
|
+
describe '.protocol' do
|
73
76
|
subject { klass.protocol }
|
74
77
|
let(:default) { :https }
|
75
78
|
|
76
79
|
it { should == default }
|
77
|
-
it
|
80
|
+
it 'should be writable' do
|
78
81
|
klass.protocol = :https
|
79
|
-
klass.protocol.
|
82
|
+
expect(klass.protocol).to eq(:https)
|
80
83
|
end
|
81
84
|
|
82
85
|
after { klass.protocol = default }
|
83
86
|
end
|
84
87
|
|
85
|
-
describe
|
88
|
+
describe '.client_id' do
|
89
|
+
subject { klass.client_id }
|
90
|
+
let(:default) { nil }
|
91
|
+
|
92
|
+
it { should == default }
|
93
|
+
it 'should be writable' do
|
94
|
+
klass.client_id = 'some_client_id'
|
95
|
+
expect(klass.client_id).to eq('some_client_id')
|
96
|
+
end
|
97
|
+
|
98
|
+
after { klass.client_id = default }
|
99
|
+
end
|
100
|
+
|
101
|
+
describe '.response_format' do
|
86
102
|
subject { klass.response_format }
|
87
103
|
let(:default) { :ruby }
|
88
104
|
|
89
105
|
it { should == default }
|
90
|
-
it
|
106
|
+
it 'should be writable' do
|
91
107
|
klass.response_format = :jsonp
|
92
|
-
klass.response_format.
|
108
|
+
expect(klass.response_format).to eq(:jsonp)
|
93
109
|
end
|
94
110
|
|
95
111
|
after { klass.response_format = default }
|
96
112
|
end
|
97
113
|
|
98
|
-
describe
|
99
|
-
it
|
100
|
-
klass.
|
114
|
+
describe '.taxonomies' do
|
115
|
+
it 'proxies to #taxonomies' do
|
116
|
+
expect_any_instance_of(klass).to receive(:taxonomies).and_return(nil)
|
101
117
|
klass.taxonomies
|
102
118
|
end
|
103
119
|
|
104
|
-
it
|
105
|
-
klass.
|
120
|
+
it 'passes any attributes to #taxonomies' do
|
121
|
+
expect_any_instance_of(klass).to receive(:taxonomies).with(1, 2)
|
122
|
+
.and_return(nil)
|
106
123
|
klass.taxonomies(1, 2)
|
107
124
|
end
|
108
125
|
end
|
109
126
|
|
110
|
-
describe
|
127
|
+
describe '.url' do
|
111
128
|
subject { klass.url }
|
112
|
-
let(:default) {
|
129
|
+
let(:default) { 'api.seatgeek.com' }
|
113
130
|
|
114
131
|
it { should == default }
|
115
|
-
it
|
116
|
-
klass.url =
|
117
|
-
klass.url.
|
132
|
+
it 'should be writable' do
|
133
|
+
klass.url = 'ticketevolution.com'
|
134
|
+
expect(klass.url).to eq('ticketevolution.com')
|
118
135
|
end
|
119
136
|
|
120
137
|
after { klass.url = default }
|
121
138
|
end
|
122
139
|
|
123
|
-
describe
|
124
|
-
it
|
125
|
-
klass.
|
140
|
+
describe '.venues' do
|
141
|
+
it 'proxies to #venues' do
|
142
|
+
expect_any_instance_of(klass).to receive(:venues).and_return(nil)
|
126
143
|
klass.venues
|
127
144
|
end
|
128
145
|
|
129
|
-
it
|
130
|
-
klass.
|
146
|
+
it 'passes any attributes to #venues' do
|
147
|
+
expect_any_instance_of(klass).to receive(:venues).with(1, 2)
|
148
|
+
.and_return(nil)
|
131
149
|
klass.venues(1, 2)
|
132
150
|
end
|
133
151
|
end
|
134
152
|
|
135
|
-
describe
|
153
|
+
describe '.version' do
|
136
154
|
subject { klass.version }
|
137
155
|
let(:default) { 2 }
|
138
156
|
|
139
157
|
it { should == 2 }
|
140
|
-
it
|
158
|
+
it 'should be writable' do
|
141
159
|
klass.version = 1
|
142
|
-
klass.version.
|
160
|
+
expect(klass.version).to eq(1)
|
143
161
|
end
|
144
162
|
|
145
163
|
after { klass.version = default }
|
146
164
|
end
|
147
165
|
|
148
|
-
describe
|
166
|
+
describe '#initialize' do
|
149
167
|
let(:expected) { klass.options.merge(options) }
|
150
|
-
let(:options) { { :
|
151
|
-
let(:str_options) { {}.tap{|o| options.each{|k, v| o[k.to_s] = v}} }
|
168
|
+
let(:options) { { testing: 123, clone: 'hello', client_id: 'some_data' } }
|
169
|
+
let(:str_options) { {}.tap { |o| options.each { |k, v| o[k.to_s] = v } } }
|
152
170
|
let(:instance) { klass.new(options) }
|
153
171
|
|
154
|
-
it
|
155
|
-
|
172
|
+
it 'should take options passed and store '\
|
173
|
+
'them on top of the class options hash' do
|
174
|
+
expect(instance.instance_eval('@options')).to eq(expected)
|
156
175
|
end
|
157
176
|
|
158
|
-
it
|
159
|
-
klass.new(str_options).instance_eval('@options').
|
177
|
+
it 'should convert the keys passed to symbols' do
|
178
|
+
expect(klass.new(str_options).instance_eval('@options')).to eq(expected)
|
160
179
|
end
|
161
180
|
|
162
|
-
it
|
163
|
-
|
164
|
-
instance.
|
181
|
+
it 'should serve options up via read accessor '\
|
182
|
+
'methods unless the methods already exist' do
|
183
|
+
expect(instance.testing).to eq(options[:testing])
|
184
|
+
expect(instance.clone).not_to eq(options[:clone])
|
165
185
|
end
|
166
186
|
end
|
167
187
|
|
168
|
-
describe
|
169
|
-
let(:url) { '/events'}
|
170
|
-
let(:params) { {:
|
188
|
+
describe '#events' do
|
189
|
+
let(:url) { '/events' }
|
190
|
+
let(:params) { { test: 123 } }
|
171
191
|
|
172
|
-
it
|
173
|
-
|
192
|
+
it 'should call #request with the correct'\
|
193
|
+
'url segment and the params passed' do
|
194
|
+
expect(instance).to receive(:request).with(url, params)
|
174
195
|
instance.events(params)
|
175
196
|
end
|
176
197
|
end
|
177
198
|
|
178
|
-
describe
|
179
|
-
let(:response) { double(Faraday::Response, :
|
199
|
+
describe '#handle_response' do
|
200
|
+
let(:response) { double(Faraday::Response, status: status, body: body) }
|
180
201
|
|
181
|
-
context
|
182
|
-
context
|
202
|
+
context 'when response_format is set to ruby' do
|
203
|
+
context 'and the request was successful' do
|
183
204
|
let(:status) { 200 }
|
184
|
-
let(:body) {
|
205
|
+
let(:body) { File.read('spec/fixtures/handle_response.json') }
|
185
206
|
|
186
|
-
it
|
187
|
-
instance.handle_response(response)
|
207
|
+
it 'should parse the json returned and respond with a ruby object' do
|
208
|
+
expect(instance.handle_response(response))
|
209
|
+
.to eq(MultiJson.decode(body))
|
188
210
|
end
|
189
211
|
end
|
190
212
|
|
191
|
-
context
|
213
|
+
context 'and the request was not successful' do
|
192
214
|
let(:status) { 500 }
|
193
|
-
let(:body) {
|
215
|
+
let(:body) { 'Internal Server Error' }
|
194
216
|
|
195
|
-
it
|
196
|
-
instance.handle_response(response)
|
217
|
+
it 'should return the status code and exact result body' do
|
218
|
+
expect(instance.handle_response(response))
|
219
|
+
.to eq(status: status, body: body)
|
197
220
|
end
|
198
221
|
end
|
199
222
|
end
|
200
223
|
|
201
|
-
context
|
224
|
+
context 'when response format is not set to ruby' do
|
202
225
|
let(:status) { 200 }
|
203
|
-
let(:body) {
|
226
|
+
let(:body) { File.read('spec/fixtures/handle_response.json') }
|
204
227
|
|
205
|
-
it
|
206
|
-
klass.new(:
|
207
|
-
|
228
|
+
it 'should return the status code and exact result body' do
|
229
|
+
expect(klass.new(response_format: :json).handle_response(response))
|
230
|
+
.to eq(status: status, body: body)
|
208
231
|
end
|
209
232
|
end
|
210
233
|
end
|
211
234
|
|
212
|
-
describe
|
213
|
-
let(:url) { '/performers'}
|
214
|
-
let(:params) { {:
|
235
|
+
describe '#performers' do
|
236
|
+
let(:url) { '/performers' }
|
237
|
+
let(:params) { { test: 123 } }
|
215
238
|
|
216
|
-
it
|
217
|
-
|
239
|
+
it 'should call #request with the correct '\
|
240
|
+
'url segment and the params passed' do
|
241
|
+
expect(instance).to receive(:request).with(url, params)
|
218
242
|
instance.performers(params)
|
219
243
|
end
|
220
244
|
end
|
221
245
|
|
222
|
-
describe
|
246
|
+
describe '#request' do
|
223
247
|
let(:uri_segment) { '/venues' }
|
224
248
|
let(:url) { "https://api.seatgeek.com/2#{uri_segment}" }
|
225
249
|
let(:params) { {} }
|
226
|
-
let(:faraday) {
|
250
|
+
let(:faraday) { double(:faraday, get: OpenStruct.new(status: 200, body: '[]')) }
|
251
|
+
|
252
|
+
context 'when .client_id is not set as class property' do
|
253
|
+
let(:instance) { klass.new }
|
254
|
+
let(:expected_params) { { params: params.merge(format: :jsonp) } }
|
255
|
+
|
256
|
+
it 'should throw an exception' do
|
257
|
+
expect { instance.request(uri_segment, params) }
|
258
|
+
.to raise_error('You must provide a `client_id` for SeatGeek')
|
259
|
+
end
|
260
|
+
|
261
|
+
it 'should not throw an exception if provided in paramters' do
|
262
|
+
expect {
|
263
|
+
params[:client_id] = 'foobar'
|
264
|
+
instance.request(uri_segment, params)
|
265
|
+
}.to_not raise_error
|
266
|
+
end
|
267
|
+
end
|
268
|
+
|
269
|
+
context 'when .response_format is jsonp' do
|
270
|
+
let(:instance) { klass.new(response_format: :jsonp, client_id: 'foobar') }
|
271
|
+
let(:expected_params) { { params: params.merge(format: :jsonp) } }
|
272
|
+
|
273
|
+
it 'should set the format param to jsonp' do
|
274
|
+
expect(Faraday).to receive(:new).with(url, expected_params)
|
275
|
+
.and_return(faraday)
|
276
|
+
instance.request(uri_segment, params)
|
277
|
+
end
|
278
|
+
end
|
227
279
|
|
228
|
-
context
|
229
|
-
let(:instance) { klass.new(
|
230
|
-
let(:expected_params) { {:
|
280
|
+
context 'when .response_format is xml' do
|
281
|
+
let(:instance) { klass.new(response_format: :xml, client_id: 'foobar') }
|
282
|
+
let(:expected_params) { { params: params.merge(format: :xml) } }
|
231
283
|
|
232
|
-
it
|
233
|
-
Faraday.
|
284
|
+
it 'should set the format param to xml' do
|
285
|
+
expect(Faraday).to receive(:new).with(url, expected_params)
|
286
|
+
.and_return(faraday)
|
234
287
|
instance.request(uri_segment, params)
|
235
288
|
end
|
236
289
|
end
|
237
290
|
|
238
|
-
context
|
239
|
-
let(:instance) { klass.new(
|
240
|
-
let(:expected_params) { {:
|
291
|
+
context 'when additional parameters were passed to #initialize' do
|
292
|
+
let(:instance) { klass.new(response_format: :jsonp, testing: 123, client_id: 'foobar') }
|
293
|
+
let(:expected_params) { { params: params.merge(format: :jsonp, testing: 123)} }
|
241
294
|
|
242
|
-
it
|
243
|
-
Faraday.
|
295
|
+
it 'should add those parameters to the request params' do
|
296
|
+
expect(Faraday).to receive(:new).with(url, expected_params)
|
297
|
+
.and_return(faraday)
|
244
298
|
instance.request(uri_segment, params)
|
245
299
|
end
|
246
300
|
end
|
247
301
|
|
248
|
-
context
|
249
|
-
let(:instance) { klass.new
|
250
|
-
let(:
|
302
|
+
context 'when client_id was passed as a parameter' do
|
303
|
+
let(:instance) { klass.new }
|
304
|
+
let(:params) { { client_id: 'foobar' } }
|
305
|
+
let(:expected_params) { { params: params.merge(client_id: 'foobar') } }
|
251
306
|
|
252
|
-
it
|
253
|
-
Faraday.
|
307
|
+
it 'should make the request with the client_id parameter set' do
|
308
|
+
expect(Faraday).to receive(:new).with(url, expected_params)
|
309
|
+
.and_return(faraday)
|
254
310
|
instance.request(uri_segment, params)
|
255
311
|
end
|
256
312
|
end
|
257
313
|
end
|
258
314
|
|
259
|
-
describe
|
260
|
-
let(:url) { '/taxonomies'}
|
261
|
-
let(:params) { {:
|
315
|
+
describe '#taxonomies' do
|
316
|
+
let(:url) { '/taxonomies' }
|
317
|
+
let(:params) { { test: 123 } }
|
262
318
|
|
263
|
-
it
|
264
|
-
|
319
|
+
it 'should call #request with the correct '\
|
320
|
+
'url segment and the params passed' do
|
321
|
+
expect(instance).to receive(:request).with(url, params)
|
265
322
|
instance.taxonomies(params)
|
266
323
|
end
|
267
324
|
end
|
268
325
|
|
269
|
-
describe
|
270
|
-
it
|
271
|
-
instance.uri('/events').
|
326
|
+
describe '#uri' do
|
327
|
+
it 'should take in a path and combine it with protocol, url and version' do
|
328
|
+
expect(instance.uri('/events')).to eq('https://api.seatgeek.com/2/events')
|
272
329
|
end
|
273
330
|
end
|
274
331
|
|
275
|
-
describe
|
276
|
-
let(:url) { '/venues'}
|
277
|
-
let(:params) { {:
|
332
|
+
describe '#venues' do
|
333
|
+
let(:url) { '/venues' }
|
334
|
+
let(:params) { { test: 123 } }
|
278
335
|
|
279
|
-
it
|
280
|
-
|
336
|
+
it 'should call #request with the correct '\
|
337
|
+
'url segment and the params passed' do
|
338
|
+
expect(instance).to receive(:request).with(url, params)
|
281
339
|
instance.venues(params)
|
282
340
|
end
|
283
341
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe SeatGeek::VERSION do
|
4
|
-
it
|
5
|
-
subject.
|
4
|
+
it 'should match a three segment version number format' do
|
5
|
+
expect(subject).to match(/^\d+\.\d+\.\d+(rc\d+)?$/)
|
6
6
|
end
|
7
7
|
end
|
data/spec/lib/sg_spec.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: seatgeek
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dan Matthews
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-03-
|
11
|
+
date: 2016-03-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -103,6 +103,7 @@ files:
|
|
103
103
|
- lib/seat_geek/version.rb
|
104
104
|
- lib/seatgeek.rb
|
105
105
|
- seatgeek.gemspec
|
106
|
+
- spec/fixtures/handle_response.json
|
106
107
|
- spec/lib/seat_geek/connection_spec.rb
|
107
108
|
- spec/lib/seat_geek/version_spec.rb
|
108
109
|
- spec/lib/sg_spec.rb
|
@@ -131,6 +132,7 @@ signing_key:
|
|
131
132
|
specification_version: 4
|
132
133
|
summary: A Ruby wrapper for the SeatGeek Platform API.
|
133
134
|
test_files:
|
135
|
+
- spec/fixtures/handle_response.json
|
134
136
|
- spec/lib/seat_geek/connection_spec.rb
|
135
137
|
- spec/lib/seat_geek/version_spec.rb
|
136
138
|
- spec/lib/sg_spec.rb
|