viagogo-client 0.0.1.pre
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.
- checksums.yaml +7 -0
- data/.gitignore +18 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/lib/viagogo-client.rb +1 -0
- data/lib/viagogo.rb +3 -0
- data/lib/viagogo/category.rb +21 -0
- data/lib/viagogo/client.rb +105 -0
- data/lib/viagogo/connection.rb +43 -0
- data/lib/viagogo/country.rb +16 -0
- data/lib/viagogo/error.rb +25 -0
- data/lib/viagogo/event.rb +31 -0
- data/lib/viagogo/geography.rb +16 -0
- data/lib/viagogo/link.rb +16 -0
- data/lib/viagogo/listing.rb +28 -0
- data/lib/viagogo/metro_area.rb +17 -0
- data/lib/viagogo/page.rb +74 -0
- data/lib/viagogo/public/api/categories.rb +45 -0
- data/lib/viagogo/public/api/countries.rb +29 -0
- data/lib/viagogo/public/api/events.rb +61 -0
- data/lib/viagogo/public/api/geographies.rb +29 -0
- data/lib/viagogo/public/api/listings.rb +29 -0
- data/lib/viagogo/public/api/metro_areas.rb +29 -0
- data/lib/viagogo/public/api/venues.rb +29 -0
- data/lib/viagogo/public/client.rb +27 -0
- data/lib/viagogo/public/oauth.rb +25 -0
- data/lib/viagogo/resource.rb +14 -0
- data/lib/viagogo/response/follow_redirects.rb +17 -0
- data/lib/viagogo/response/raise_error.rb +36 -0
- data/lib/viagogo/site_url.rb +15 -0
- data/lib/viagogo/token.rb +17 -0
- data/lib/viagogo/utils.rb +12 -0
- data/lib/viagogo/venue.rb +24 -0
- data/lib/viagogo/version.rb +3 -0
- data/spec/spec_helper.rb +42 -0
- data/spec/viagogo/client_spec.rb +224 -0
- data/spec/viagogo/public/api/categories_spec.rb +96 -0
- data/spec/viagogo/public/api/countries_spec.rb +54 -0
- data/spec/viagogo/public/api/events_spec.rb +138 -0
- data/spec/viagogo/public/api/geographies_spec.rb +54 -0
- data/spec/viagogo/public/api/listings_spec.rb +54 -0
- data/spec/viagogo/public/api/metro_areas_spec.rb +54 -0
- data/spec/viagogo/public/api/venues_spec.rb +54 -0
- data/spec/viagogo/public/client_spec.rb +5 -0
- data/spec/viagogo/public/oauth_spec.rb +83 -0
- data/spec/viagogo/response/follow_redirects_spec.rb +30 -0
- data/spec/viagogo/response/raise_error_spec.rb +79 -0
- data/spec/viagogo/version_spec.rb +10 -0
- data/viagogo.gemspec +32 -0
- metadata +248 -0
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'viagogo'
|
2
|
+
require 'webmock/rspec'
|
3
|
+
|
4
|
+
def a_delete(path)
|
5
|
+
a_request(:delete, Viagogo::Client::API_ENDPOINT + path)
|
6
|
+
end
|
7
|
+
|
8
|
+
def a_get(path)
|
9
|
+
a_request(:get, Viagogo::Client::API_ENDPOINT + path)
|
10
|
+
end
|
11
|
+
|
12
|
+
def a_head(path)
|
13
|
+
a_request(:head, Viagogo::Client::API_ENDPOINT + path)
|
14
|
+
end
|
15
|
+
|
16
|
+
def a_post(path)
|
17
|
+
a_request(:post, Viagogo::Client::API_ENDPOINT + path)
|
18
|
+
end
|
19
|
+
|
20
|
+
def a_put(path)
|
21
|
+
a_request(:put, Viagogo::Client::API_ENDPOINT + path)
|
22
|
+
end
|
23
|
+
|
24
|
+
def stub_delete(path)
|
25
|
+
stub_request(:delete, Viagogo::Client::API_ENDPOINT + path)
|
26
|
+
end
|
27
|
+
|
28
|
+
def stub_get(path)
|
29
|
+
stub_request(:get, Viagogo::Client::API_ENDPOINT + path)
|
30
|
+
end
|
31
|
+
|
32
|
+
def stub_head(path)
|
33
|
+
stub_request(:head, Viagogo::Client::API_ENDPOINT + path)
|
34
|
+
end
|
35
|
+
|
36
|
+
def stub_post(path)
|
37
|
+
stub_request(:post, Viagogo::Client::API_ENDPOINT + path)
|
38
|
+
end
|
39
|
+
|
40
|
+
def stub_put(path)
|
41
|
+
stub_request(:put, Viagogo::Client::API_ENDPOINT + path)
|
42
|
+
end
|
@@ -0,0 +1,224 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
shared_examples_for "a Client" do
|
4
|
+
let(:client) { described_class.new(:consumer_key => 'CK',
|
5
|
+
:consumer_secret => 'CS',
|
6
|
+
:access_token => 'AT',
|
7
|
+
:access_token_secret => 'AS') }
|
8
|
+
|
9
|
+
describe "#new" do
|
10
|
+
context "when options are given" do
|
11
|
+
it "sets consumer_key to given value" do
|
12
|
+
expected_consumer_key = "my key"
|
13
|
+
client = described_class.new(:consumer_key => expected_consumer_key)
|
14
|
+
expect(client.consumer_key).to eq(expected_consumer_key)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "sets consumer_secret to given value" do
|
18
|
+
expected_consumer_secret = "my secret"
|
19
|
+
client = described_class.new(:consumer_secret => expected_consumer_secret)
|
20
|
+
expect(client.consumer_secret).to eq(expected_consumer_secret)
|
21
|
+
end
|
22
|
+
|
23
|
+
it "sets access_token to given value" do
|
24
|
+
expected_access_token = "my access token"
|
25
|
+
client = described_class.new(:access_token => expected_access_token)
|
26
|
+
expect(client.access_token).to eq(expected_access_token)
|
27
|
+
end
|
28
|
+
|
29
|
+
it "sets access_token_secret to given value" do
|
30
|
+
expected_access_token_secret = "my access token secret"
|
31
|
+
client = described_class.new(:access_token_secret => expected_access_token_secret)
|
32
|
+
expect(client.access_token_secret).to eq(expected_access_token_secret)
|
33
|
+
end
|
34
|
+
|
35
|
+
it "raises Viagogo::Error::ConfigurationError when :consumer_key is invalid" do
|
36
|
+
expect { described_class.new(:consumer_key => [50, 1]) }.to raise_error Viagogo::ConfigurationError
|
37
|
+
end
|
38
|
+
|
39
|
+
it "raises Viagogo::Error::ConfigurationError when :consumer_secret is invalid" do
|
40
|
+
expect { described_class.new(:consumer_secret => [3, 'A']) }.to raise_error Viagogo::ConfigurationError
|
41
|
+
end
|
42
|
+
|
43
|
+
it "raises Viagogo::Error::ConfigurationError when :access_token is invalid" do
|
44
|
+
expect { described_class.new(:access_token => [3, 'A']) }.to raise_error Viagogo::ConfigurationError
|
45
|
+
end
|
46
|
+
|
47
|
+
it "raises Viagogo::Error::ConfigurationError when :access_token_secret is invalid" do
|
48
|
+
expect { described_class.new(:access_token_secret => [3, 'A']) }.to raise_error Viagogo::ConfigurationError
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
context "when block is given" do
|
53
|
+
it "passes the current instance to be configured in the block" do
|
54
|
+
actual_client = nil
|
55
|
+
expected_client = described_class.new do |config|
|
56
|
+
config.consumer_key = "CK"
|
57
|
+
config.consumer_secret = "CS"
|
58
|
+
actual_client = config
|
59
|
+
end
|
60
|
+
|
61
|
+
expect(actual_client.object_id).to equal(expected_client.object_id)
|
62
|
+
end
|
63
|
+
|
64
|
+
it "raises Viagogo::Error::ConfigurationError when :consumer_key is invalid" do
|
65
|
+
expect { described_class.new do |config|
|
66
|
+
config.consumer_key = 50
|
67
|
+
end }.to raise_error Viagogo::ConfigurationError
|
68
|
+
end
|
69
|
+
|
70
|
+
it "raises Viagogo::Error::ConfigurationError when :consumer_secret is invalid" do
|
71
|
+
expect { described_class.new do |config|
|
72
|
+
config.consumer_secret = 6
|
73
|
+
end }.to raise_error Viagogo::ConfigurationError
|
74
|
+
end
|
75
|
+
|
76
|
+
it "raises Viagogo::Error::ConfigurationError when :access_token is invalid" do
|
77
|
+
expect { described_class.new do |config|
|
78
|
+
config.access_token = 50
|
79
|
+
end }.to raise_error Viagogo::ConfigurationError
|
80
|
+
end
|
81
|
+
|
82
|
+
it "raises Viagogo::Error::ConfigurationError when :access_token_secret is invalid" do
|
83
|
+
expect { described_class.new do |config|
|
84
|
+
config.access_token_secret = 50
|
85
|
+
end }.to raise_error Viagogo::ConfigurationError
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
describe "#user_agent" do
|
91
|
+
it "returns the gem name and version" do
|
92
|
+
version = Viagogo::VERSION
|
93
|
+
expected_user_agent = "viagogo Ruby Gem #{version}"
|
94
|
+
expect(client.user_agent).to eq(expected_user_agent)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
describe "#credentials?" do
|
99
|
+
it "returns false if :consumer_key is not supplied" do
|
100
|
+
client = described_class.new(:consumer_secret => "CS",
|
101
|
+
:access_token => "AT",
|
102
|
+
:access_token_secret => "AS")
|
103
|
+
expect(client.credentials?).to be_false
|
104
|
+
end
|
105
|
+
|
106
|
+
it "returns false if :consumer_secret is not supplied" do
|
107
|
+
client = described_class.new(:consumer_key => "CK",
|
108
|
+
:access_token => "AT",
|
109
|
+
:access_token_secret => "AS")
|
110
|
+
expect(client.credentials?).to be_false
|
111
|
+
end
|
112
|
+
|
113
|
+
it "returns false if :access_token is not supplied" do
|
114
|
+
client = described_class.new(:consumer_key => "CK",
|
115
|
+
:consumer_secret => "CS",
|
116
|
+
:access_token_secret => "AS")
|
117
|
+
expect(client.credentials?).to be_false
|
118
|
+
end
|
119
|
+
|
120
|
+
it "returns false if :access_token_secret is not supplied" do
|
121
|
+
client = described_class.new(:consumer_key => "CK",
|
122
|
+
:consumer_secret => "CS",
|
123
|
+
:access_token => "AT")
|
124
|
+
expect(client.credentials?).to be_false
|
125
|
+
end
|
126
|
+
|
127
|
+
it "returns true if all credentials are supplied" do
|
128
|
+
client = described_class.new(:consumer_key => "CK",
|
129
|
+
:consumer_secret => "CS",
|
130
|
+
:access_token => "AT",
|
131
|
+
:access_token_secret => "AS")
|
132
|
+
expect(client.credentials?).to be_true
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
describe "#request" do
|
137
|
+
[:get, :post, :head, :put, :delete, :patch].each do |method|
|
138
|
+
context "when HTTP method is #{method}" do
|
139
|
+
it "makes an HTTP request with the parameters given" do
|
140
|
+
expected_path = "/some/path"
|
141
|
+
stub_request(:any, Viagogo::Client::API_ENDPOINT + expected_path)
|
142
|
+
client.send(:request, method, expected_path)
|
143
|
+
expect(a_request(method, Viagogo::Client::API_ENDPOINT + expected_path)).to have_been_made
|
144
|
+
end
|
145
|
+
|
146
|
+
it "makes an HTTP request with JSON Content-Type" do
|
147
|
+
expected_content_type = "application/json"
|
148
|
+
stub_request(:any, /.*/).with(:headers => { "Content-Type" => expected_content_type })
|
149
|
+
client.send(:request, method, "/")
|
150
|
+
expect(a_request(:any, /.*/).with(:headers => { "Content-Type" => expected_content_type })).to have_been_made
|
151
|
+
end
|
152
|
+
|
153
|
+
it "makes an HTTP request with user-agent set to the return value of #user_agent" do
|
154
|
+
expected_user_agent = "some user agent"
|
155
|
+
allow(client).to receive(:user_agent).and_return(expected_user_agent)
|
156
|
+
stub_request(:any, /.*/).with(:headers => { "User-Agent" => expected_user_agent })
|
157
|
+
client.send(:request, method, "/")
|
158
|
+
expect(a_request(:any, /.*/).with(:headers => { "User-Agent" => expected_user_agent })).to have_been_made
|
159
|
+
end
|
160
|
+
|
161
|
+
it "returns the response env Hash" do
|
162
|
+
expected_response_hash = {:body => "abc"}
|
163
|
+
stub_request(:any, Viagogo::Client::API_ENDPOINT + "/foo").to_return(expected_response_hash)
|
164
|
+
actual_response_hash = client.send(:request, method, "/foo", :is_token_request => true)
|
165
|
+
expect(actual_response_hash[:body]).to eq(expected_response_hash[:body])
|
166
|
+
end
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
describe "#get" do
|
172
|
+
it "performs an get request" do
|
173
|
+
expected_path = "/custom/path"
|
174
|
+
expected_params = {:foo => "foo", :bar => "bar"}
|
175
|
+
stub_get(expected_path).with(:query => expected_params)
|
176
|
+
client.get(expected_path, expected_params)
|
177
|
+
expect(a_get(expected_path).with(:query => expected_params)).to have_been_made
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
describe "#head" do
|
182
|
+
it "performs an head request" do
|
183
|
+
expected_path = "/custom/path"
|
184
|
+
expected_params = {:foo => "foo", :bar => "bar"}
|
185
|
+
stub_head(expected_path).with(:query => expected_params)
|
186
|
+
client.head(expected_path, expected_params)
|
187
|
+
expect(a_head(expected_path).with(:query => expected_params)).to have_been_made
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
describe "#delete" do
|
192
|
+
it "performs an delete request" do
|
193
|
+
expected_path = "/custom/path"
|
194
|
+
expected_params = {:foo => "foo", :bar => "bar"}
|
195
|
+
stub_delete(expected_path).with(:query => expected_params)
|
196
|
+
client.delete(expected_path, expected_params)
|
197
|
+
expect(a_delete(expected_path).with(:query => expected_params)).to have_been_made
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
201
|
+
describe "#post" do
|
202
|
+
it "performs an post request" do
|
203
|
+
expected_path = "/custom/path"
|
204
|
+
expected_body = {:foo => "foo", :bar => "bar"}
|
205
|
+
stub_post(expected_path).with(:body => expected_body)
|
206
|
+
client.post(expected_path, expected_body)
|
207
|
+
expect(a_post(expected_path).with(:body => expected_body)).to have_been_made
|
208
|
+
end
|
209
|
+
end
|
210
|
+
|
211
|
+
describe "#put" do
|
212
|
+
it "performs an put request" do
|
213
|
+
expected_path = "/custom/path"
|
214
|
+
expected_body = {:foo => "foo", :bar => "bar"}
|
215
|
+
stub_put(expected_path).with(:body => expected_body)
|
216
|
+
client.put(expected_path, expected_body)
|
217
|
+
expect(a_put(expected_path).with(:body => expected_body)).to have_been_made
|
218
|
+
end
|
219
|
+
end
|
220
|
+
end
|
221
|
+
|
222
|
+
describe Viagogo::Client do
|
223
|
+
it_behaves_like "a Client"
|
224
|
+
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Viagogo::Public::API::Categories do
|
4
|
+
before do
|
5
|
+
@client = Viagogo::Public::Client.new(:consumer_key => 'CK',
|
6
|
+
:consumer_secret => 'CS',
|
7
|
+
:access_token => 'AT',
|
8
|
+
:access_token_secret => 'AS')
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "#category" do
|
12
|
+
it "makes HTTP get request" do
|
13
|
+
stub_request(:any, /.*/).to_return(:body => "{}")
|
14
|
+
@client.category 1
|
15
|
+
expect(a_request(:get, /.*/)).to have_been_made
|
16
|
+
end
|
17
|
+
|
18
|
+
it "makes request for the correct resource" do
|
19
|
+
expected_resource = 50
|
20
|
+
expected_params = {:foo => "foo", :bar => "bar"}
|
21
|
+
stub_get("/Public/Category/#{expected_resource}").
|
22
|
+
with(:query => expected_params).
|
23
|
+
to_return(:body => "{}")
|
24
|
+
@client.category expected_resource, expected_params
|
25
|
+
expect(a_get("/Public/Category/#{expected_resource}").with(:query => expected_params)).to have_been_made
|
26
|
+
end
|
27
|
+
|
28
|
+
it "returns Viagogo::Category created from the response" do
|
29
|
+
stub_get("/Public/Category/1").to_return({:body => "{\"Id\": 5, \"Parents\": []}"})
|
30
|
+
expect(@client.category 1).to be_an_instance_of(Viagogo::Category)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "#categories_top" do
|
35
|
+
it "makes HTTP get request" do
|
36
|
+
stub_request(:any, /.*/).to_return(:body => "{}")
|
37
|
+
@client.categories_top "US"
|
38
|
+
expect(a_request(:get, /.*/)).to have_been_made
|
39
|
+
end
|
40
|
+
|
41
|
+
it "makes request for the correct resource" do
|
42
|
+
expected_resource = "/Public/Category/AD/Top"
|
43
|
+
expected_params = {:foo => "foo", :bar => "bar"}
|
44
|
+
stub_get(expected_resource).with(:query => expected_params).to_return(:body => "{}")
|
45
|
+
@client.categories_top "AD", expected_params
|
46
|
+
expect(a_get(expected_resource).with(:query => expected_params)).to have_been_made
|
47
|
+
end
|
48
|
+
|
49
|
+
it "returns Viagogo::Page created from the response" do
|
50
|
+
stub_request(:any, /.*/).to_return(:body => "{}")
|
51
|
+
expect(@client.categories_top "GB").to be_an_instance_of(Viagogo::Page)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
describe "#categories_parents" do
|
56
|
+
it "makes HTTP get request" do
|
57
|
+
stub_request(:any, /.*/).to_return(:body => "{}")
|
58
|
+
@client.categories_parents "US", 501
|
59
|
+
expect(a_request(:get, /.*/)).to have_been_made
|
60
|
+
end
|
61
|
+
|
62
|
+
it "makes request for the correct resource" do
|
63
|
+
expected_resource = "/Public/Category/GB/Parents/21"
|
64
|
+
expected_params = {:foo => "foo", :bar => "bar"}
|
65
|
+
stub_get(expected_resource).with(:query => expected_params).to_return(:body => "{}")
|
66
|
+
@client.categories_parents "GB", 21, expected_params
|
67
|
+
expect(a_get(expected_resource).with(:query => expected_params)).to have_been_made
|
68
|
+
end
|
69
|
+
|
70
|
+
it "returns Viagogo::Page created from the response" do
|
71
|
+
stub_request(:any, /.*/).to_return(:body => "{}")
|
72
|
+
expect(@client.categories_parents "GB", 0).to be_an_instance_of(Viagogo::Page)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
describe "#categories_children" do
|
77
|
+
it "makes HTTP get request" do
|
78
|
+
stub_request(:any, /.*/).to_return(:body => "{}")
|
79
|
+
@client.categories_children "US", 501
|
80
|
+
expect(a_request(:get, /.*/)).to have_been_made
|
81
|
+
end
|
82
|
+
|
83
|
+
it "makes request for the correct resource" do
|
84
|
+
expected_resource = "/Public/Category/GB/Children/21"
|
85
|
+
expected_params = {:foo => "foo", :bar => "bar"}
|
86
|
+
stub_get(expected_resource).with(:query => expected_params).to_return(:body => "{}")
|
87
|
+
@client.categories_children "GB", 21, expected_params
|
88
|
+
expect(a_get(expected_resource).with(:query => expected_params)).to have_been_made
|
89
|
+
end
|
90
|
+
|
91
|
+
it "returns Viagogo::Page created from the response" do
|
92
|
+
stub_request(:any, /.*/).to_return(:body => "{}")
|
93
|
+
expect(@client.categories_children "GB", 0).to be_an_instance_of(Viagogo::Page)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Viagogo::Public::API::Countries do
|
4
|
+
before do
|
5
|
+
@client = Viagogo::Public::Client.new(:consumer_key => 'CK',
|
6
|
+
:consumer_secret => 'CS',
|
7
|
+
:access_token => 'AT',
|
8
|
+
:access_token_secret => 'AS')
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "#country" do
|
12
|
+
it "makes HTTP get request" do
|
13
|
+
stub_request(:any, /.*/).to_return(:body => "{}")
|
14
|
+
@client.country "BB"
|
15
|
+
expect(a_request(:get, /.*/)).to have_been_made
|
16
|
+
end
|
17
|
+
|
18
|
+
it "makes request for the correct resource" do
|
19
|
+
expected_resource = "US"
|
20
|
+
expected_params = {:foo => "foo", :bar => "bar"}
|
21
|
+
stub_get("/Public/Country/#{expected_resource}").
|
22
|
+
with(:query => expected_params).
|
23
|
+
to_return(:body => "{}")
|
24
|
+
@client.country expected_resource, expected_params
|
25
|
+
expect(a_get("/Public/Country/#{expected_resource}").with(:query => expected_params)).to have_been_made
|
26
|
+
end
|
27
|
+
|
28
|
+
it "returns Viagogo::Country created from the response" do
|
29
|
+
stub_get("/Public/Country/GB").to_return({:body => "{\"name\":\"GB\"}"})
|
30
|
+
expect(@client.country "GB").to be_an_instance_of(Viagogo::Country)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "#countries" do
|
35
|
+
it "makes HTTP get request" do
|
36
|
+
stub_request(:any, /.*/).to_return(:body => "{}")
|
37
|
+
@client.countries
|
38
|
+
expect(a_request(:get, /.*/)).to have_been_made
|
39
|
+
end
|
40
|
+
|
41
|
+
it "makes request for the correct resource" do
|
42
|
+
expected_resource = "/Public/Country/All"
|
43
|
+
expected_params = {:foo => "foo", :bar => "bar"}
|
44
|
+
stub_get(expected_resource).with(:query => expected_params).to_return(:body => "{}")
|
45
|
+
@client.countries expected_params
|
46
|
+
expect(a_get(expected_resource).with(:query => expected_params)).to have_been_made
|
47
|
+
end
|
48
|
+
|
49
|
+
it "returns Viagogo::Page created from the response" do
|
50
|
+
stub_get("/Public/Country/All").to_return({:body => "{}"})
|
51
|
+
expect(@client.countries).to be_an_instance_of(Viagogo::Page)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,138 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Viagogo::Public::API::Events do
|
4
|
+
before do
|
5
|
+
@client = Viagogo::Public::Client.new(:consumer_key => 'CK',
|
6
|
+
:consumer_secret => 'CS',
|
7
|
+
:access_token => 'AT',
|
8
|
+
:access_token_secret => 'AS')
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "#event" do
|
12
|
+
it "makes HTTP get request" do
|
13
|
+
stub_request(:any, /.*/).to_return(:body => "{}")
|
14
|
+
@client.event 1
|
15
|
+
expect(a_request(:get, /.*/)).to have_been_made
|
16
|
+
end
|
17
|
+
|
18
|
+
it "makes request for the correct resource" do
|
19
|
+
expected_resource = 50
|
20
|
+
expected_params = {:foo => "foo", :bar => "bar"}
|
21
|
+
stub_get("/Public/Event/#{expected_resource}").
|
22
|
+
with(:query => expected_params).
|
23
|
+
to_return(:body => "{}")
|
24
|
+
@client.event expected_resource, expected_params
|
25
|
+
expect(a_get("/Public/Event/#{expected_resource}").with(:query => expected_params)).to have_been_made
|
26
|
+
end
|
27
|
+
|
28
|
+
it "returns Viagogo::Event created from the response" do
|
29
|
+
stub_get("/Public/Event/1").to_return({:body => "{\"Id\": 5}"})
|
30
|
+
expect(@client.event 1).to be_an_instance_of(Viagogo::Event)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "#events_by_category" do
|
35
|
+
it "makes HTTP get request" do
|
36
|
+
stub_request(:any, /.*/).to_return(:body => "{}")
|
37
|
+
@client.events_by_category 2
|
38
|
+
expect(a_request(:get, /.*/)).to have_been_made
|
39
|
+
end
|
40
|
+
|
41
|
+
it "makes request for the correct resource" do
|
42
|
+
expected_resource = "/Public/Event/ByCategory/50"
|
43
|
+
expected_params = {:foo => "foo", :bar => "bar"}
|
44
|
+
stub_get(expected_resource).with(:query => expected_params).to_return(:body => "{}")
|
45
|
+
@client.events_by_category 50, expected_params
|
46
|
+
expect(a_get(expected_resource).with(:query => expected_params)).to have_been_made
|
47
|
+
end
|
48
|
+
|
49
|
+
it "returns Viagogo::Page created from the response" do
|
50
|
+
stub_request(:any, /.*/).to_return(:body => "{}")
|
51
|
+
expect(@client.events_by_category 20).to be_an_instance_of(Viagogo::Page)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
describe "#events_by_metro_area" do
|
56
|
+
it "makes HTTP get request" do
|
57
|
+
stub_request(:any, /.*/).to_return(:body => "{}")
|
58
|
+
@client.events_by_metro_area 2
|
59
|
+
expect(a_request(:get, /.*/)).to have_been_made
|
60
|
+
end
|
61
|
+
|
62
|
+
it "makes request for the correct resource" do
|
63
|
+
expected_resource = "/Public/Event/ByMetroArea/50"
|
64
|
+
expected_params = {:foo => "foo", :bar => "bar"}
|
65
|
+
stub_get(expected_resource).with(:query => expected_params).to_return(:body => "{}")
|
66
|
+
@client.events_by_metro_area 50, expected_params
|
67
|
+
expect(a_get(expected_resource).with(:query => expected_params)).to have_been_made
|
68
|
+
end
|
69
|
+
|
70
|
+
it "returns Viagogo::Page created from the response" do
|
71
|
+
stub_request(:any, /.*/).to_return(:body => "{}")
|
72
|
+
expect(@client.events_by_metro_area 20).to be_an_instance_of(Viagogo::Page)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
describe "#events_by_venue" do
|
77
|
+
it "makes HTTP get request" do
|
78
|
+
stub_request(:any, /.*/).to_return(:body => "{}")
|
79
|
+
@client.events_by_venue 2
|
80
|
+
expect(a_request(:get, /.*/)).to have_been_made
|
81
|
+
end
|
82
|
+
|
83
|
+
it "makes request for the correct resource" do
|
84
|
+
expected_resource = "/Public/Event/ByVenue/50"
|
85
|
+
expected_params = {:foo => "foo", :bar => "bar"}
|
86
|
+
stub_get(expected_resource).with(:query => expected_params).to_return(:body => "{}")
|
87
|
+
@client.events_by_venue 50, expected_params
|
88
|
+
expect(a_get(expected_resource).with(:query => expected_params)).to have_been_made
|
89
|
+
end
|
90
|
+
|
91
|
+
it "returns Viagogo::Page created from the response" do
|
92
|
+
stub_request(:any, /.*/).to_return(:body => "{}")
|
93
|
+
expect(@client.events_by_venue 20).to be_an_instance_of(Viagogo::Page)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
describe "#events_by_utc_start_date" do
|
98
|
+
it "makes HTTP get request" do
|
99
|
+
stub_request(:any, /.*/).to_return(:body => "{}")
|
100
|
+
@client.events_by_utc_start_date 2000, 1, 1
|
101
|
+
expect(a_request(:get, /.*/)).to have_been_made
|
102
|
+
end
|
103
|
+
|
104
|
+
it "makes request for the correct resource" do
|
105
|
+
expected_resource = "/Public/Event/ByUtcStartDate/2003/3/15"
|
106
|
+
expected_params = {:foo => "foo", :bar => "bar"}
|
107
|
+
stub_get(expected_resource).with(:query => expected_params).to_return(:body => "{}")
|
108
|
+
@client.events_by_utc_start_date 2003, 3, 15, expected_params
|
109
|
+
expect(a_get(expected_resource).with(:query => expected_params)).to have_been_made
|
110
|
+
end
|
111
|
+
|
112
|
+
it "returns Viagogo::Page created from the response" do
|
113
|
+
stub_request(:any, /.*/).to_return(:body => "{}")
|
114
|
+
expect(@client.events_by_utc_start_date 2011, 11, 11).to be_an_instance_of(Viagogo::Page)
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
describe "#events_search" do
|
119
|
+
it "makes HTTP get request" do
|
120
|
+
stub_request(:any, /.*/).to_return(:body => "{}")
|
121
|
+
@client.events_search "foo"
|
122
|
+
expect(a_request(:get, /.*/)).to have_been_made
|
123
|
+
end
|
124
|
+
|
125
|
+
it "makes request for the correct resource" do
|
126
|
+
expected_resource = "/Public/Event/Search"
|
127
|
+
expected_params = {:searchText => "some query", :foo => "foo", :bar => "bar"}
|
128
|
+
stub_get(expected_resource).with(:query => expected_params).to_return(:body => "{}")
|
129
|
+
@client.events_search expected_params[:searchText], expected_params
|
130
|
+
expect(a_get(expected_resource).with(:query => expected_params)).to have_been_made
|
131
|
+
end
|
132
|
+
|
133
|
+
it "returns Viagogo::Page created from the response" do
|
134
|
+
stub_request(:any, /.*/).to_return(:body => "{}")
|
135
|
+
expect(@client.events_search "foo").to be_an_instance_of(Viagogo::Page)
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|