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.
Files changed (52) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +18 -0
  3. data/Gemfile +4 -0
  4. data/LICENSE.txt +22 -0
  5. data/README.md +29 -0
  6. data/Rakefile +1 -0
  7. data/lib/viagogo-client.rb +1 -0
  8. data/lib/viagogo.rb +3 -0
  9. data/lib/viagogo/category.rb +21 -0
  10. data/lib/viagogo/client.rb +105 -0
  11. data/lib/viagogo/connection.rb +43 -0
  12. data/lib/viagogo/country.rb +16 -0
  13. data/lib/viagogo/error.rb +25 -0
  14. data/lib/viagogo/event.rb +31 -0
  15. data/lib/viagogo/geography.rb +16 -0
  16. data/lib/viagogo/link.rb +16 -0
  17. data/lib/viagogo/listing.rb +28 -0
  18. data/lib/viagogo/metro_area.rb +17 -0
  19. data/lib/viagogo/page.rb +74 -0
  20. data/lib/viagogo/public/api/categories.rb +45 -0
  21. data/lib/viagogo/public/api/countries.rb +29 -0
  22. data/lib/viagogo/public/api/events.rb +61 -0
  23. data/lib/viagogo/public/api/geographies.rb +29 -0
  24. data/lib/viagogo/public/api/listings.rb +29 -0
  25. data/lib/viagogo/public/api/metro_areas.rb +29 -0
  26. data/lib/viagogo/public/api/venues.rb +29 -0
  27. data/lib/viagogo/public/client.rb +27 -0
  28. data/lib/viagogo/public/oauth.rb +25 -0
  29. data/lib/viagogo/resource.rb +14 -0
  30. data/lib/viagogo/response/follow_redirects.rb +17 -0
  31. data/lib/viagogo/response/raise_error.rb +36 -0
  32. data/lib/viagogo/site_url.rb +15 -0
  33. data/lib/viagogo/token.rb +17 -0
  34. data/lib/viagogo/utils.rb +12 -0
  35. data/lib/viagogo/venue.rb +24 -0
  36. data/lib/viagogo/version.rb +3 -0
  37. data/spec/spec_helper.rb +42 -0
  38. data/spec/viagogo/client_spec.rb +224 -0
  39. data/spec/viagogo/public/api/categories_spec.rb +96 -0
  40. data/spec/viagogo/public/api/countries_spec.rb +54 -0
  41. data/spec/viagogo/public/api/events_spec.rb +138 -0
  42. data/spec/viagogo/public/api/geographies_spec.rb +54 -0
  43. data/spec/viagogo/public/api/listings_spec.rb +54 -0
  44. data/spec/viagogo/public/api/metro_areas_spec.rb +54 -0
  45. data/spec/viagogo/public/api/venues_spec.rb +54 -0
  46. data/spec/viagogo/public/client_spec.rb +5 -0
  47. data/spec/viagogo/public/oauth_spec.rb +83 -0
  48. data/spec/viagogo/response/follow_redirects_spec.rb +30 -0
  49. data/spec/viagogo/response/raise_error_spec.rb +79 -0
  50. data/spec/viagogo/version_spec.rb +10 -0
  51. data/viagogo.gemspec +32 -0
  52. metadata +248 -0
@@ -0,0 +1,54 @@
1
+ require 'spec_helper'
2
+
3
+ describe Viagogo::Public::API::Geographies 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 "#geography" do
12
+ it "makes HTTP get request" do
13
+ stub_request(:any, /.*/).to_return(:body => "{}")
14
+ @client.geography 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/Geography/#{expected_resource}").
22
+ with(:query => expected_params).
23
+ to_return(:body => "{}")
24
+ @client.geography expected_resource, expected_params
25
+ expect(a_get("/Public/Geography/#{expected_resource}").with(:query => expected_params)).to have_been_made
26
+ end
27
+
28
+ it "returns Viagogo::Geography created from the response" do
29
+ stub_get("/Public/Geography/1").to_return({:body => "{\"Id\": 5}"})
30
+ expect(@client.geography 1).to be_an_instance_of(Viagogo::Geography)
31
+ end
32
+ end
33
+
34
+ describe "#geographies" do
35
+ it "makes HTTP get request" do
36
+ stub_request(:any, /.*/).to_return(:body => "{}")
37
+ @client.geographies
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/Geography/All"
43
+ expected_params = {:foo => "foo", :bar => "bar"}
44
+ stub_get(expected_resource).with(:query => expected_params).to_return(:body => "{}")
45
+ @client.geographies 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/Geography/All").to_return({:body => "{}"})
51
+ expect(@client.geographies).to be_an_instance_of(Viagogo::Page)
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,54 @@
1
+ require 'spec_helper'
2
+
3
+ describe Viagogo::Public::API::Listings 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 "#listing" do
12
+ it "makes HTTP get request" do
13
+ stub_request(:any, /.*/).to_return(:body => "{}")
14
+ @client.listing 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/Listing/#{expected_resource}").
22
+ with(:query => expected_params).
23
+ to_return(:body => "{}")
24
+ @client.listing expected_resource, expected_params
25
+ expect(a_get("/Public/Listing/#{expected_resource}").with(:query => expected_params)).to have_been_made
26
+ end
27
+
28
+ it "returns Viagogo::Listing created from the response" do
29
+ stub_get("/Public/Listing/1").to_return({:body => "{\"Id\": 5}"})
30
+ expect(@client.listing 1).to be_an_instance_of(Viagogo::Listing)
31
+ end
32
+ end
33
+
34
+ describe "#listings_by_event" do
35
+ it "makes HTTP get request" do
36
+ stub_request(:any, /.*/).to_return(:body => "{}")
37
+ @client.listings_by_event 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/Listing/ByEvent/50"
43
+ expected_params = {:foo => "foo", :bar => "bar"}
44
+ stub_get(expected_resource).with(:query => expected_params).to_return(:body => "{}")
45
+ @client.listings_by_event 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.listings_by_event 20).to be_an_instance_of(Viagogo::Page)
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,54 @@
1
+ require 'spec_helper'
2
+
3
+ describe Viagogo::Public::API::MetroAreas 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 "#metro_area" do
12
+ it "makes HTTP get request" do
13
+ stub_request(:any, /.*/).to_return(:body => "{}")
14
+ @client.metro_area 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/MetroArea/#{expected_resource}").
22
+ with(:query => expected_params).
23
+ to_return(:body => "{}")
24
+ @client.metro_area expected_resource, expected_params
25
+ expect(a_get("/Public/MetroArea/#{expected_resource}").with(:query => expected_params)).to have_been_made
26
+ end
27
+
28
+ it "returns Viagogo::MetroArea created from the response" do
29
+ stub_get("/Public/MetroArea/1").to_return({:body => "{\"Id\": 5}"})
30
+ expect(@client.metro_area 1).to be_an_instance_of(Viagogo::MetroArea)
31
+ end
32
+ end
33
+
34
+ describe "#metro_areas" do
35
+ it "makes HTTP get request" do
36
+ stub_request(:any, /.*/).to_return(:body => "{}")
37
+ @client.metro_areas
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/MetroArea/All"
43
+ expected_params = {:foo => "foo", :bar => "bar"}
44
+ stub_get(expected_resource).with(:query => expected_params).to_return(:body => "{}")
45
+ @client.metro_areas 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/MetroArea/All").to_return({:body => "{}"})
51
+ expect(@client.metro_areas).to be_an_instance_of(Viagogo::Page)
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,54 @@
1
+ require 'spec_helper'
2
+
3
+ describe Viagogo::Public::API::Venues 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 "#venue" do
12
+ it "makes HTTP get request" do
13
+ stub_request(:any, /.*/).to_return(:body => "{}")
14
+ @client.venue 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/Venue/#{expected_resource}").
22
+ with(:query => expected_params).
23
+ to_return(:body => "{}")
24
+ @client.venue expected_resource, expected_params
25
+ expect(a_get("/Public/Venue/#{expected_resource}").with(:query => expected_params)).to have_been_made
26
+ end
27
+
28
+ it "returns Viagogo::Venue created from the response" do
29
+ stub_get("/Public/Venue/1").to_return({:body => "{\"Id\": 5}"})
30
+ expect(@client.venue 1).to be_an_instance_of(Viagogo::Venue)
31
+ end
32
+ end
33
+
34
+ describe "#venues_by_metro_area" do
35
+ it "makes HTTP get request" do
36
+ stub_request(:any, /.*/).to_return(:body => "{}")
37
+ @client.venues_by_metro_area 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/Venue/ByMetroArea/50"
43
+ expected_params = {:foo => "foo", :bar => "bar"}
44
+ stub_get(expected_resource).with(:query => expected_params).to_return(:body => "{}")
45
+ @client.venues_by_metro_area 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.venues_by_metro_area 20).to be_an_instance_of(Viagogo::Page)
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,5 @@
1
+ require 'spec_helper'
2
+
3
+ describe Viagogo::Public::Client do
4
+
5
+ end
@@ -0,0 +1,83 @@
1
+ require 'spec_helper'
2
+ require 'timecop'
3
+
4
+ describe Viagogo::Public::OAuth do
5
+ before do
6
+ @client = Viagogo::Public::Client.new(:consumer_key => 'CK', :consumer_secret => 'CS')
7
+ end
8
+
9
+ describe "#get_access_token" do
10
+ it "makes a request to the public authentication url" do
11
+ expected_path = "/Public/SimpleOAuthAccessRequest"
12
+ stub_get(expected_path).with(:query => hash_including())
13
+ @client.get_access_token
14
+ expect(a_get(expected_path).with(:query => hash_including())).to have_been_made
15
+ end
16
+
17
+ context "when :scope is supplied" do
18
+ it "passes the :scope as a query parameter" do
19
+ expected_scope = "my scope"
20
+ stub_request(:any, /.*/).with(:query => {"scope" => expected_scope})
21
+ @client.get_access_token(expected_scope)
22
+ expect(a_request(:any, /.*/).with(:query => {"scope" => expected_scope})).to have_been_made
23
+ end
24
+ end
25
+
26
+ context "when :scope is not supplied" do
27
+ it "passes the API.Public as a query parameter" do
28
+ expected_scope = "API.Public"
29
+ stub_request(:any, /.*/).with(:query => {"scope" => expected_scope})
30
+ @client.get_access_token
31
+ expect(a_request(:any, /.*/).with(:query => {"scope" => expected_scope})).to have_been_made
32
+ end
33
+ end
34
+
35
+ it "returns a Viagogo::Token" do
36
+ stub_request(:any, /.*/)
37
+ access_token = @client.get_access_token
38
+ expect(access_token).to be_an_instance_of(Viagogo::Token)
39
+ end
40
+
41
+ it "returns Viagogo::Token with given scope" do
42
+ expected_scope = "my scope"
43
+ stub_request(:any, /.*/)
44
+ access_token = @client.get_access_token(expected_scope)
45
+ expect(access_token.scope).to eq(expected_scope)
46
+ end
47
+
48
+ it "returns Viagogo::Token of access token type" do
49
+ stub_request(:any, /.*/)
50
+ access_token = @client.get_access_token
51
+ expect(access_token.type).to eq("access token")
52
+ end
53
+
54
+ it "returns Viagogo::Token with :issue_timestamp set to now" do
55
+ expected_issue_timestamp = Timecop.freeze(Time.new(2014, 1, 22, 14, 5, 30, '+00:00'))
56
+ stub_request(:any, /.*/)
57
+ access_token = @client.get_access_token
58
+ Timecop.return
59
+ expect(access_token.issue_timestamp).to eq(expected_issue_timestamp)
60
+ end
61
+
62
+ it "returns Viagogo::Token with :expiry_timestamp set 24 hours from now" do
63
+ expected_expiry_timestamp = Time.new(2014, 1, 22, 14, 5, 0, '+00:00')
64
+ Timecop.freeze(expected_expiry_timestamp - (24 * 60 * 60))
65
+ stub_request(:any, /.*/)
66
+ access_token = @client.get_access_token
67
+ Timecop.return
68
+ expect(access_token.expiry_timestamp).to eq(expected_expiry_timestamp)
69
+ end
70
+
71
+ it "returns Viagogo::Token of with :oauth_token from response" do
72
+ stub_request(:any, /.*/).to_return(:body => "oauth_token=encoded%2Btoken%3D&oauth_token_secret=secret")
73
+ access_token = @client.get_access_token
74
+ expect(access_token.oauth_token).to eq("encoded+token=")
75
+ end
76
+
77
+ it "returns Viagogo::Token of with :oauth_token_secret from response" do
78
+ stub_request(:any, /.*/).to_return(:body => "oauth_token=encoded%2Btoken%3D&oauth_token_secret=encoded%2Btoken%2Fsecret%3D")
79
+ access_token = @client.get_access_token
80
+ expect(access_token.oauth_token_secret).to eq("encoded+token/secret=")
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,30 @@
1
+ require 'spec_helper'
2
+
3
+ describe Viagogo::Response::FollowRedirects do
4
+ def connection
5
+ Faraday.new do |c|
6
+ c.use described_class, {}
7
+
8
+ c.adapter :test do |stub|
9
+ yield(stub) if block_given?
10
+ end
11
+ end
12
+ end
13
+
14
+ describe "#call" do
15
+ it "redirects without original authorization headers" do
16
+ conn = connection do |stub|
17
+ stub.get('/redirect') {[301, {'Location' => '/found'}, '']}
18
+ stub.get('/found') { |env|
19
+ [200, {'Content-Type' => 'text/plain'}, env[:request_headers]['Authorization']]
20
+ }
21
+ end
22
+
23
+ response = conn.get('/redirect') { |req|
24
+ req.headers['Authorization'] = 'failed'
25
+ }
26
+
27
+ expect(response.body).to be_nil
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,79 @@
1
+ require 'spec_helper'
2
+
3
+ describe Viagogo::Response::RaiseError do
4
+ def connection
5
+ Faraday.new do |c|
6
+ c.use described_class, {}
7
+
8
+ c.adapter :test do |stub|
9
+ yield(stub) if block_given?
10
+ end
11
+ end
12
+ end
13
+
14
+ [200, 204, 301, 302, 303, 307].each do |status|
15
+ context "for an HTTP #{status} response" do
16
+ it "should not raise an error" do
17
+ expect { connection do |stub|
18
+ stub.get('/') {[status, {}, '']}
19
+ end.get('/')
20
+ }.not_to raise_error
21
+ end
22
+ end
23
+ end
24
+
25
+ context "for an HTTP 400 response" do
26
+ it "should raise a Viagogo::BadRequestError" do
27
+ expect { connection do |stub|
28
+ stub.get('/') {[400, {}, '']}
29
+ end.get('/')
30
+ }.to raise_error Viagogo::BadRequestError
31
+ end
32
+ end
33
+
34
+ context "for an HTTP 404 response" do
35
+ it "should raise a Viagogo::NotFoundError" do
36
+ expect { connection do |stub|
37
+ stub.get('/') {[404, {}, '']}
38
+ end.get('/')
39
+ }.to raise_error Viagogo::NotFoundError
40
+ end
41
+ end
42
+
43
+ context "for an HTTP 405 response" do
44
+ it "should raise a Viagogo::MethodNotAllowedError" do
45
+ expect { connection do |stub|
46
+ stub.get('/') {[405, {}, '']}
47
+ end.get('/')
48
+ }.to raise_error Viagogo::MethodNotAllowedError
49
+ end
50
+ end
51
+
52
+ context "for an HTTP 500 response" do
53
+ it "should raise a Viagogo::InternalServerError" do
54
+ expect { connection do |stub|
55
+ stub.get('/') {[500, {}, '']}
56
+ end.get('/')
57
+ }.to raise_error Viagogo::InternalServerError
58
+ end
59
+ end
60
+
61
+ context "for an HTTP 403 response" do
62
+ it "should raise a Viagogo::ForbiddenError" do
63
+ expect { connection do |stub|
64
+ stub.get('/') {[403, {}, '']}
65
+ end.get('/')
66
+ }.to raise_error Viagogo::ForbiddenError
67
+ end
68
+ end
69
+
70
+ context "for an HTTP 401 response" do
71
+ it "should raise a Viagogo::UnauthorizedError" do
72
+ expect { connection do |stub|
73
+ stub.get('/') {[401, {}, '']}
74
+ end.get('/')
75
+ }.to raise_error Viagogo::UnauthorizedError
76
+ end
77
+ end
78
+
79
+ end
@@ -0,0 +1,10 @@
1
+ require 'spec_helper'
2
+
3
+ describe Viagogo do
4
+
5
+ describe "::VERSION" do
6
+ it "should have a value" do
7
+ expect(Viagogo::VERSION).not_to be_nil
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,32 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'viagogo/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "viagogo-client"
8
+ spec.version = Viagogo::VERSION
9
+ spec.authors = ["Akil Burgess"]
10
+ spec.email = ["akilburgess@gmail.com"]
11
+ spec.summary = %q{Ruby toolkit for working with the viagogo API}
12
+ spec.description = spec.summary
13
+ spec.homepage = "https://github.com/akilb/viagogo.rb"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "faraday", "~> 0.8.9"
22
+ spec.add_dependency "faraday_middleware", "~> 0.9.0"
23
+ spec.add_dependency "simple_oauth", "~> 0.2.0"
24
+ spec.add_dependency "json", "~> 1.8.1"
25
+ spec.add_dependency "representable", "~> 1.7.5"
26
+
27
+ spec.add_development_dependency "bundler", "~> 1.5"
28
+ spec.add_development_dependency "rake"
29
+ spec.add_development_dependency "rspec"
30
+ spec.add_development_dependency "webmock"
31
+ spec.add_development_dependency "timecop"
32
+ end