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,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ed92f607696324531344d5e3857043930e1704e7
4
+ data.tar.gz: 80f90573bdb4a563f3414c5b7a3336abfb91b9e5
5
+ SHA512:
6
+ metadata.gz: eecc02b778d2a878c7b62f0c0bac583be5be8a9485167269aab156f69956288d30ad615c30383720022e4b827c74e08005342c3720cff019b973b1b723e6e1b1
7
+ data.tar.gz: 1a8b0989dc73bc0eda514808e0c3aa9eb0317ccb873b12dbfb95a9eaf587fc28a63878c27e010fb3159904b9d22250a12ea6e4343a90dd5a58853b5ca231856b
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ .idea/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in viagogo.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Akil Burgess
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,29 @@
1
+ # Viagogo
2
+
3
+ Ruby toolkit for working with the viagogo API
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'viagogo-client'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install viagogo-client
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it ( http://github.com/akilb/viagogo.rb/fork )
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1 @@
1
+ require 'viagogo'
@@ -0,0 +1,3 @@
1
+ require 'viagogo/client'
2
+ require 'viagogo/public/client'
3
+ require 'viagogo/version'
@@ -0,0 +1,21 @@
1
+ require 'ostruct'
2
+ require 'representable/json'
3
+ require 'viagogo/resource'
4
+ require 'viagogo/site_url'
5
+
6
+ module Viagogo
7
+ class Category < OpenStruct
8
+ end
9
+
10
+ module CategoryRepresenter
11
+ include Representable::JSON
12
+
13
+ property :id, as: :Id
14
+ property :name, as: :Name
15
+ property :image_url, as: :ImageUrl
16
+ property :events, as: :Events, extend: Viagogo::ResourceRepresenter, class: Viagogo::Resource
17
+ collection :child_categories, as: :ChildCategories, extend: Viagogo::ResourceRepresenter, class: Viagogo::Resource
18
+ collection :parent_categories, as: :ParentCategories, extend: Viagogo::ResourceRepresenter, class: Viagogo::Resource
19
+ collection :site_urls, as: :SiteUrls, extend: Viagogo::SiteUrlRepresenter, class: Viagogo::SiteUrl
20
+ end
21
+ end
@@ -0,0 +1,105 @@
1
+ require 'faraday'
2
+ require 'viagogo/connection'
3
+ require 'viagogo/error'
4
+ require 'viagogo/version'
5
+
6
+ module Viagogo
7
+
8
+ # Client for the viagogo API
9
+ #
10
+ # @see http://developer.viagogo.net
11
+ class Client
12
+ attr_accessor :access_token,
13
+ :access_token_secret,
14
+ :consumer_key,
15
+ :consumer_secret
16
+ include Viagogo::Connection
17
+
18
+ # TODO: Use SSL
19
+ API_ENDPOINT = "http://api.viagogo.net".freeze
20
+
21
+ # Initializes a new Client
22
+ #
23
+ # @param options [Hash]
24
+ # @raise [Viagogo::Error::ConfigurationError] Error is raised when supplied
25
+ # viagogo credentials are not a String or Symbol.
26
+ # @return [Viagogo::Client]
27
+ def initialize(options={})
28
+ options.each do |key, value|
29
+ send(:"#{key}=", value)
30
+ end
31
+ yield self if block_given?
32
+
33
+ validate_credential_type!
34
+ end
35
+
36
+ # @return [Hash]
37
+ def credentials
38
+ {
39
+ :consumer_key => consumer_key,
40
+ :consumer_secret => consumer_secret,
41
+ :token => access_token,
42
+ :token_secret => access_token_secret,
43
+ }
44
+ end
45
+
46
+ # @return [Boolean]
47
+ def credentials?
48
+ credentials.values.all?
49
+ end
50
+
51
+ # @return [String]
52
+ def user_agent
53
+ @user_agent ||= "viagogo Ruby Gem #{Viagogo::VERSION}"
54
+ end
55
+
56
+ # Perform an HTTP HEAD request
57
+ def delete(path, params = {})
58
+ request(:delete, path, params)
59
+ end
60
+
61
+ # Perform an HTTP GET request
62
+ def get(path, params = {})
63
+ request(:get, path, params)
64
+ end
65
+
66
+ # Perform an HTTP HEAD request
67
+ def head(path, params = {})
68
+ request(:head, path, params)
69
+ end
70
+
71
+ # Perform an HTTP POST request
72
+ def post(path, params = {})
73
+ request(:post, path, params)
74
+ end
75
+
76
+ # Perform an HTTP PUT request
77
+ def put(path, params = {})
78
+ request(:put, path, params)
79
+ end
80
+
81
+ private
82
+
83
+ # Perform an HTTP request
84
+ #
85
+ # @return [Hash] object containing response information
86
+ def request(method, path, params = {})
87
+ is_token_request = params.delete(:is_token_request)
88
+
89
+ connection(API_ENDPOINT, is_token_request || false).send(method.to_sym, path, params).env
90
+ end
91
+
92
+ # Ensures that all credentials set during configuration are of a
93
+ # valid type. Valid types are String and Symbol.
94
+ #
95
+ # @raise [Viagogo::Error::ConfigurationError] Error is raised when
96
+ # supplied viagogo credentials are not a String or Symbol.
97
+ def validate_credential_type!
98
+ credentials.each do |credential, value|
99
+ next if value.nil? || value.is_a?(String) || value.is_a?(Symbol)
100
+ fail(ConfigurationError,
101
+ "Invalid #{credential} specified: #{value.inspect} must be a string or symbol.")
102
+ end
103
+ end
104
+ end
105
+ end
@@ -0,0 +1,43 @@
1
+ require 'faraday'
2
+ require 'faraday_middleware'
3
+ require 'viagogo/response/follow_redirects'
4
+ require 'viagogo/response/raise_error'
5
+
6
+ module Viagogo
7
+ module Connection
8
+ private
9
+
10
+ def connection_options
11
+ @connection_options ||= {
12
+ :headers => {
13
+ :accept => 'application/json',
14
+ :content_type => 'application/json',
15
+ :user_agent => user_agent,
16
+ },
17
+ :request => {
18
+ :open_timeout => 5,
19
+ :timeout => 10
20
+ },
21
+ }
22
+ end
23
+
24
+ def connection(endpoint, is_token_request=false)
25
+ Faraday::Connection.new(endpoint, connection_options) do |builder|
26
+ request_credentials = credentials.clone.delete_if do |k,v|
27
+ k == :token || k == :token_secret if is_token_request
28
+ end
29
+ # Signs requests according to the OAuth protocol
30
+ builder.use FaradayMiddleware::OAuth, request_credentials
31
+ # Encodes request the body as JSON
32
+ builder.use FaradayMiddleware::EncodeJson
33
+ # Automatically follow 301, 302 and 307 redirects
34
+ builder.use Viagogo::Response::FollowRedirects
35
+ # Handle error responses
36
+ builder.use Viagogo::Response::RaiseError
37
+
38
+ # Set Faraday's HTTP adapter
39
+ builder.adapter Faraday.default_adapter
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,16 @@
1
+ require 'ostruct'
2
+ require 'representable/json'
3
+ require 'viagogo/resource'
4
+
5
+ module Viagogo
6
+ class Country < OpenStruct
7
+ end
8
+
9
+ module CountryRepresenter
10
+ include Representable::JSON
11
+
12
+ property :code, as: :Code
13
+ property :name, as: :Name
14
+ property :geography, as: :Geography, extend: Viagogo::ResourceRepresenter, class: Viagogo::Resource
15
+ end
16
+ end
@@ -0,0 +1,25 @@
1
+ module Viagogo
2
+ # Custom error class for rescuing from all viagogo errors
3
+ class Error < StandardError; end
4
+
5
+ class ConfigurationError < Error; end
6
+
7
+ # Raised when viagogo returns the HTTP status code 400
8
+ class BadRequestError < Error; end
9
+
10
+ # Raised when viagogo returns the HTTP status code 401
11
+ class UnauthorizedError < Error; end
12
+
13
+ # Raised when viagogo returns the HTTP status code 403
14
+ class ForbiddenError < Error; end
15
+
16
+ # Raised when viagogo returns the HTTP status code 404
17
+ class NotFoundError < Error; end
18
+
19
+ # Raised when viagogo returns the HTTP status code 405
20
+ class MethodNotAllowedError < Error; end
21
+
22
+ # Raised when viagogo returns the HTTP status code 500
23
+ class InternalServerError < Error; end
24
+
25
+ end
@@ -0,0 +1,31 @@
1
+ require 'ostruct'
2
+ require 'representable/json'
3
+ require 'viagogo/site_url'
4
+ require 'viagogo/resource'
5
+
6
+ module Viagogo
7
+ class Event < OpenStruct
8
+ end
9
+
10
+ module EventRepresenter
11
+ include Representable::JSON
12
+
13
+ property :id, as: :Id
14
+ property :name, as: :Name
15
+ property :start_datetime_utc, as: :StartDateTimeUtc #TODO Convert to DateTime
16
+ property :end_datetime_utc, as: :EndDateTimeUtc #TODO Convert to DateTime
17
+ property :start_datetime_local, as: :StartDateTimeLocal #TODO Convert to DateTime
18
+ property :end_datetime_local, as: :EndDateTimeUtc #TODO Convert to DateTime
19
+ property :total_listings, as: :TotalListings
20
+ property :total_available_tickets, as: :TotalAvailableTickets
21
+ property :minimum_price, as: :MinimumPrice
22
+ property :maximum_price, as: :MaximumPrice
23
+ property :default_currency_code, as: :DefaultCurrencyCode
24
+ property :is_available_for_public_listing, as: :IsAvailableForPublicListing
25
+ property :is_available_for_public_purchase, as: :IsAvailableForPublicPurchase
26
+ property :has_premium_listings, as: :HasPremiumListings
27
+ property :venue, as: :Venue, extend: Viagogo::ResourceRepresenter, class: Viagogo::Resource
28
+ property :listings, as: :Listings, extend: Viagogo::ResourceRepresenter, class: Viagogo::Resource
29
+ collection :site_urls, as: :SiteUrls, extend: Viagogo::SiteUrlRepresenter, class: Viagogo::SiteUrl
30
+ end
31
+ end
@@ -0,0 +1,16 @@
1
+ require 'ostruct'
2
+ require 'representable/json'
3
+ require 'viagogo/resource'
4
+
5
+ module Viagogo
6
+ class Geography < OpenStruct
7
+ end
8
+
9
+ module GeographyRepresenter
10
+ include Representable::JSON
11
+
12
+ property :id, as: :Id
13
+ property :name, as: :Name
14
+ property :country, as: :Country, extend: Viagogo::ResourceRepresenter, class: Viagogo::Resource
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ require 'ostruct'
2
+ require 'representable/json'
3
+
4
+ module Viagogo
5
+ class Link < OpenStruct
6
+ end
7
+
8
+ module LinkRepresenter
9
+ include Representable::JSON
10
+
11
+ property :href, as: :HRef
12
+ property :type, as: :Type
13
+ property :rel, as: :Rel
14
+ property :target, as: :Target
15
+ end
16
+ end
@@ -0,0 +1,28 @@
1
+ require 'ostruct'
2
+ require 'representable/json'
3
+ require 'viagogo/resource'
4
+
5
+ module Viagogo
6
+ class Listing < OpenStruct
7
+ end
8
+
9
+ module ListingRepresenter
10
+ include Representable::JSON
11
+
12
+ property :id, as: :Id
13
+ property :event_id, as: :EventId
14
+ property :event_name, as: :EventName
15
+ property :event, as: :Event, extend: Viagogo::ResourceRepresenter, class: Viagogo::Resource
16
+ property :section, as: :Section
17
+ property :row, as: :Row
18
+ property :seat_from, as: :SeatFrom
19
+ property :seat_to, as: :SeatTo
20
+ property :available_tickets, as: :AvailableTickets
21
+ property :default_current_price, as: :DefaultCurrentPrice
22
+ property :currency_code, as: :CurrencyCode
23
+ property :is_active, as: :IsActive
24
+ property :ticket_class_description, as: :TicketClassDescription
25
+ property :ticket_type, as: :TicketType
26
+ property :splitting, as: :Splitting
27
+ end
28
+ end
@@ -0,0 +1,17 @@
1
+ require 'ostruct'
2
+ require 'representable/json'
3
+ require 'viagogo/resource'
4
+
5
+ module Viagogo
6
+ class MetroArea < OpenStruct
7
+ end
8
+
9
+ module MetroAreaRepresenter
10
+ include Representable::JSON
11
+
12
+ property :id, as: :Id
13
+ property :name, as: :Name
14
+ property :geography, as: :Geography, extend: Viagogo::ResourceRepresenter, class: Viagogo::Resource
15
+ property :venues, as: :Venues, extend: Viagogo::ResourceRepresenter, class: Viagogo::Resource
16
+ end
17
+ end
@@ -0,0 +1,74 @@
1
+ require 'ostruct'
2
+ require 'representable/json'
3
+ require 'viagogo/category'
4
+ require 'viagogo/country'
5
+ require 'viagogo/event'
6
+ require 'viagogo/geography'
7
+ require 'viagogo/listing'
8
+ require 'viagogo/metro_area'
9
+ require 'viagogo/venue'
10
+
11
+ module Viagogo
12
+ class Page < OpenStruct
13
+ end
14
+
15
+ module PageRepresenter
16
+ include Representable::JSON
17
+
18
+ property :maximum_timestamp, as: :MaximumTimeStamp
19
+ property :total_result_count, as: :TotalResultCount
20
+ property :total_number_of_page, as: :TotalNumberOfPages
21
+ property :current_page, as: :Currentpage
22
+ property :page_size, as: :PageSize
23
+ #TODO DeletedItems
24
+ end
25
+
26
+ module CategoryPageRepresenter
27
+ include Representable::JSON
28
+ include Viagogo::PageRepresenter
29
+
30
+ collection :results, as: :Results, extend: Viagogo::CategoryRepresenter, class: Viagogo::Category
31
+ end
32
+
33
+ module CountryPageRepresenter
34
+ include Representable::JSON
35
+ include Viagogo::PageRepresenter
36
+
37
+ collection :results, as: :Results, extend: Viagogo::CountryRepresenter, class: Viagogo::Country
38
+ end
39
+
40
+ module EventPageRepresenter
41
+ include Representable::JSON
42
+ include Viagogo::PageRepresenter
43
+
44
+ collection :results, as: :Results, extend: Viagogo::EventRepresenter, class: Viagogo::Event
45
+ end
46
+
47
+ module GeographyPageRepresenter
48
+ include Representable::JSON
49
+ include Viagogo::PageRepresenter
50
+
51
+ collection :results, as: :Results, extend: Viagogo::GeographyRepresenter, class: Viagogo::Geography
52
+ end
53
+
54
+ module ListingPageRepresenter
55
+ include Representable::JSON
56
+ include Viagogo::PageRepresenter
57
+
58
+ collection :results, as: :Results, extend: Viagogo::ListingRepresenter, class: Viagogo::Listing
59
+ end
60
+
61
+ module MetroAreaPageRepresenter
62
+ include Representable::JSON
63
+ include Viagogo::PageRepresenter
64
+
65
+ collection :results, as: :Results, extend: Viagogo::MetroAreaRepresenter, class: Viagogo::MetroArea
66
+ end
67
+
68
+ module VenuePageRepresenter
69
+ include Representable::JSON
70
+ include Viagogo::PageRepresenter
71
+
72
+ collection :results, as: :Results, extend: Viagogo::VenueRepresenter, class: Viagogo::Venue
73
+ end
74
+ end