gogokit 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +15 -0
  2. data/LICENSE.txt +19 -0
  3. data/README.md +18 -0
  4. data/Rakefile +12 -0
  5. data/gogokit.gemspec +27 -0
  6. data/lib/gogokit.rb +6 -0
  7. data/lib/gogokit/client.rb +171 -0
  8. data/lib/gogokit/client/category.rb +39 -0
  9. data/lib/gogokit/client/country.rb +38 -0
  10. data/lib/gogokit/client/currency.rb +38 -0
  11. data/lib/gogokit/client/event.rb +41 -0
  12. data/lib/gogokit/client/language.rb +38 -0
  13. data/lib/gogokit/client/listing.rb +41 -0
  14. data/lib/gogokit/client/metro_area.rb +39 -0
  15. data/lib/gogokit/client/oauth.rb +55 -0
  16. data/lib/gogokit/client/root.rb +24 -0
  17. data/lib/gogokit/client/search.rb +27 -0
  18. data/lib/gogokit/client/venue.rb +39 -0
  19. data/lib/gogokit/configuration.rb +40 -0
  20. data/lib/gogokit/connection.rb +34 -0
  21. data/lib/gogokit/default.rb +10 -0
  22. data/lib/gogokit/error.rb +12 -0
  23. data/lib/gogokit/middleware/raise_error.rb +27 -0
  24. data/lib/gogokit/money.rb +19 -0
  25. data/lib/gogokit/oauth_token.rb +21 -0
  26. data/lib/gogokit/paged_resource.rb +23 -0
  27. data/lib/gogokit/resource.rb +18 -0
  28. data/lib/gogokit/resource/category.rb +43 -0
  29. data/lib/gogokit/resource/country.rb +27 -0
  30. data/lib/gogokit/resource/currency.rb +27 -0
  31. data/lib/gogokit/resource/event.rb +54 -0
  32. data/lib/gogokit/resource/language.rb +27 -0
  33. data/lib/gogokit/resource/listing.rb +89 -0
  34. data/lib/gogokit/resource/listing_note.rb +17 -0
  35. data/lib/gogokit/resource/metro_area.rb +29 -0
  36. data/lib/gogokit/resource/root.rb +15 -0
  37. data/lib/gogokit/resource/search_result.rb +52 -0
  38. data/lib/gogokit/resource/ticket_type.rb +17 -0
  39. data/lib/gogokit/resource/venue.rb +49 -0
  40. data/lib/gogokit/seating.rb +19 -0
  41. data/lib/gogokit/utils.rb +18 -0
  42. data/lib/gogokit/version.rb +17 -0
  43. metadata +155 -0
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ ZDY1MDA2YjY5NTUyNmFjNzIzNjljNjNkNzUwYzM1MDU1YjlkNWY5Nw==
5
+ data.tar.gz: !binary |-
6
+ ODUxMjIyZGY2MDk3ODA0ZTM3NTFiYmRlNmQxYThkNjc4YjU4NjYxNg==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ MTRhYjI4YTk2YTMzNTE3MTRkY2YwMjNmZjRiMjQ3MmY3ZDVkODhlNjlhMjQ1
10
+ NDU2MGVmNDU1ZGViYTM3ZWNiMDkxYTg3YTg0NDY0OTc5MjJhY2E3NTJiMTc3
11
+ NDUzYTFhMzJjYjc3ZTgwOWM3Yzk5ZWIzMTQ1ZGJjYjJhM2NlN2M=
12
+ data.tar.gz: !binary |-
13
+ NmU2ZmY4NDc2NTcyZTc5NzY3ZDNlYzYxZTVhZTcxNjlkNzViOGMxMmJjNDcx
14
+ YTg2NDEyOWZiMjJhOWZhZTQ3ZmRhMzViZGQ0OGVhYjViMDFhN2IxNjIxYTg4
15
+ OTdhMmU4MmFmNTUzMjJkOGUyMTA0Y2NiYWIyYTYyMGY5ZmI3NWI=
data/LICENSE.txt ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2015 viagogo
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,18 @@
1
+ # The GogoKit Ruby Gem
2
+
3
+ [![Build Status](https://travis-ci.org/viagogo/gogokit.rb.svg?branch=master)][travis]
4
+ [![Dependency Status](https://gemnasium.com/viagogo/gogokit.rb.svg)][gemnasium]
5
+ [![Code Climate](https://codeclimate.com/github/viagogo/gogokit.rb/badges/gpa.svg)][codeclimate]
6
+ [![Coverage Status](https://coveralls.io/repos/viagogo/gogokit.rb/badge.svg)][coverage]
7
+
8
+ [travis]: https://travis-ci.org/viagogo/gogokit.rb
9
+ [gemnasium]: https://gemnasium.com/viagogo/gogokit.rb
10
+ [codeclimate]: https://codeclimate.com/github/viagogo/gogokit.rb
11
+ [coverage]: https://coveralls.io/r/viagogo/gogokit.rb
12
+
13
+
14
+ Ruby toolkit for working with the viagogo API
15
+
16
+ ## Troubleshooting on Windows
17
+
18
+ GogoKit uses SSL for all HTTP requests. On Windows you will need to configure where your certificates live since OpenSSL cannot find one to validate the authenticity. [This post](https://github.com/jnunemaker/httparty/wiki/Troubleshooting-on-Windows) describes how you can get this working on windows.
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ require 'rspec/core/rake_task'
5
+ RSpec::Core::RakeTask.new(:spec)
6
+
7
+ task test: :spec
8
+
9
+ require 'rubocop/rake_task'
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: [:spec, :rubocop]
data/gogokit.gemspec ADDED
@@ -0,0 +1,27 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'gogokit/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'gogokit'
7
+ spec.version = GogoKit::VERSION
8
+ spec.authors = ['viagogo']
9
+ spec.email = ['api@viagogo.com']
10
+ spec.description = 'Ruby toolkit for working with the viagogo API'
11
+ spec.summary = 'viagogo API library'
12
+ spec.homepage = 'https://github.com/viagogo/gogokit.rb'
13
+ spec.licenses = 'MIT'
14
+
15
+ spec.files = %w(LICENSE.txt README.md Rakefile gogokit.gemspec)
16
+ spec.files = spec.files + Dir.glob('lib/**/*.rb')
17
+ spec.require_paths = ['lib']
18
+ spec.required_ruby_version = '>= 1.9.3'
19
+ spec.required_rubygems_version = '>= 1.3.5'
20
+
21
+ spec.add_dependency 'faraday', '~> 0.9.1'
22
+ spec.add_dependency 'addressable', '~> 2.3'
23
+ spec.add_dependency 'roar', '~> 1.0'
24
+ spec.add_dependency 'virtus', '~> 1.0'
25
+
26
+ spec.add_development_dependency 'bundler', '~> 1.5'
27
+ end
data/lib/gogokit.rb ADDED
@@ -0,0 +1,6 @@
1
+ require 'gogokit/client'
2
+ require 'gogokit/version'
3
+
4
+ # Ruby toolkit for the viagogo API
5
+ module GogoKit
6
+ end
@@ -0,0 +1,171 @@
1
+ require 'addressable/uri'
2
+ require 'addressable/template'
3
+ require 'gogokit/configuration'
4
+ require 'gogokit/connection'
5
+ require 'gogokit/error'
6
+ require 'gogokit/client/category'
7
+ require 'gogokit/client/country'
8
+ require 'gogokit/client/currency'
9
+ require 'gogokit/client/event'
10
+ require 'gogokit/client/language'
11
+ require 'gogokit/client/listing'
12
+ require 'gogokit/client/metro_area'
13
+ require 'gogokit/client/oauth'
14
+ require 'gogokit/client/root'
15
+ require 'gogokit/client/search'
16
+ require 'gogokit/client/venue'
17
+ require 'gogokit/version'
18
+
19
+ module GogoKit
20
+ # Client for the viagogo API
21
+ #
22
+ # @see http://developer.viagogo.net
23
+ class Client
24
+ include GogoKit::Configuration
25
+ include GogoKit::Connection
26
+ include GogoKit::Client::Category
27
+ include GogoKit::Client::Country
28
+ include GogoKit::Client::Currency
29
+ include GogoKit::Client::Event
30
+ include GogoKit::Client::Language
31
+ include GogoKit::Client::Listing
32
+ include GogoKit::Client::MetroArea
33
+ include GogoKit::Client::OAuth
34
+ include GogoKit::Client::Root
35
+ include GogoKit::Client::Search
36
+ include GogoKit::Client::Venue
37
+
38
+ attr_accessor :client_id,
39
+ :client_secret,
40
+ :access_token
41
+
42
+ # Initializes a new {GogoKit::Client}
43
+ #
44
+ # @param options [Hash]
45
+ # @option options [String] :client_id Client Id of your application
46
+ # @option options [String] :client_secret Client Secret of your application
47
+ # @option options [String] :oauth_token_endpoint Endpoint for obtaining
48
+ # OAuth access tokens
49
+ # @raise [GogoKit::Error::ConfigurationError] Error is raised when supplied
50
+ # client credentials are not a String or Symbol.
51
+ # @return [GogoKit::Client]
52
+ def initialize(options = {})
53
+ options.each do |key, value|
54
+ send(:"#{key}=", value)
55
+ end
56
+ yield self if block_given?
57
+
58
+ validate_credential_type!
59
+ validate_configuration!
60
+ end
61
+
62
+ # The User-Agent header used when making HTTP requests
63
+ #
64
+ # @return [String]
65
+ def user_agent
66
+ @user_agent ||= "GogoKit Ruby Gem #{GogoKit::VERSION}"
67
+ end
68
+
69
+ # Perform an HTTP DELETE request
70
+ #
71
+ # @return [Hash] object containing response information
72
+ def delete(url, options = {})
73
+ request(:delete, url, options)
74
+ end
75
+
76
+ # Perform an HTTP GET request
77
+ #
78
+ # @return [Hash] object containing response information
79
+ def get(url, options = {})
80
+ request(:get, url, options)
81
+ end
82
+
83
+ # Perform an HTTP HEAD request
84
+ #
85
+ # @return [Hash] object containing response information
86
+ def head(url, options = {})
87
+ request(:head, url, options)
88
+ end
89
+
90
+ # Perform an HTTP PATCH request
91
+ #
92
+ # @return [Hash] object containing response information
93
+ def patch(url, options = {})
94
+ request(:patch, url, options)
95
+ end
96
+
97
+ # Perform an HTTP POST request
98
+ #
99
+ # @return [Hash] object containing response information
100
+ def post(url, options = {})
101
+ request(:post, url, options)
102
+ end
103
+
104
+ # Perform an HTTP PUT request
105
+ #
106
+ # @return [Hash] object containing response information
107
+ def put(url, options = {})
108
+ request(:put, url, options)
109
+ end
110
+
111
+ private
112
+
113
+ # Perform an HTTP request
114
+ #
115
+ # @return [Hash] object containing response information
116
+ def request(method, url, options = {})
117
+ options ||= {}
118
+ url = expand_url(url, options[:params])
119
+ try_add_authorization_header(options)
120
+
121
+ connection.send(method.to_sym, url, options[:body], options[:headers]).env
122
+ end
123
+
124
+ # Expands a URI template with the given parameters
125
+ def expand_url(url, params)
126
+ params ||= {}
127
+ template = url.respond_to?(:expand) ? url : Addressable::Template.new(url)
128
+ if template.variables.empty? && !params.empty?
129
+ # the URI isn't templated so just append the query parameters
130
+ non_templated_url = Addressable::URI.parse(url)
131
+ existing_query_values = non_templated_url.query_values(Hash) || {}
132
+ non_templated_url.query_values = existing_query_values.merge(params)
133
+ return non_templated_url.to_s
134
+ end
135
+
136
+ template.expand(params || {}).to_s
137
+ end
138
+
139
+ def try_add_authorization_header(options)
140
+ options[:headers] ||= {}
141
+ return unless options[:headers]['Authorization'].nil? &&
142
+ options[:headers][:authorization].nil?
143
+
144
+ # Add an Authorization header since we don't have one yet
145
+ options[:headers]['Authorization'] = "Bearer #{access_token}"
146
+ end
147
+
148
+ # @return [Hash]
149
+ def credentials
150
+ {
151
+ client_id: client_id,
152
+ client_secret: client_secret,
153
+ access_token: access_token
154
+ }
155
+ end
156
+
157
+ # Ensures that all credentials set during configuration are of a valid type.
158
+ # Valid types are String and Symbol.
159
+ #
160
+ # @raise [GogoKit::Error::ConfigurationError] Error is raised when supplied
161
+ # credentials are not a String or Symbol.
162
+ def validate_credential_type!
163
+ credentials.each do |credential, value|
164
+ next if value.nil? || value.is_a?(String) || value.is_a?(Symbol)
165
+ fail(ConfigurationError,
166
+ "Invalid #{credential} specified: #{value.inspect} must be a" \
167
+ ' string or symbol.')
168
+ end
169
+ end
170
+ end
171
+ end
@@ -0,0 +1,39 @@
1
+ require 'gogokit/utils'
2
+ require 'gogokit/resource/category'
3
+
4
+ module GogoKit
5
+ class Client
6
+ # {GogoKit::Client} methods for getting categories
7
+ module Category
8
+ include GogoKit::Utils
9
+
10
+ # Retrieves a category by ID
11
+ #
12
+ # @param [Integer] category_id The ID of the category to be retrieved
13
+ # @param [Hash] options Optional options
14
+ # @return [GogoKit::Category] The requested category
15
+ def get_category(category_id, options = {})
16
+ root = get_root
17
+ object_from_response(GogoKit::Category,
18
+ GogoKit::CategoryRepresenter,
19
+ :get,
20
+ "#{root.links['self'].href}/categories/" \
21
+ "#{category_id}",
22
+ options)
23
+ end
24
+
25
+ # Retrieves the genre categories (e.g. Sports, Concerts, Theatre)
26
+ #
27
+ # @see http://viagogo.github.io/developer.viagogo.net/#viagogogenres
28
+ # @param [Hash] options Optional options
29
+ # @return [GogoKit::PagedResource] The genre categories
30
+ def get_genres(options = {})
31
+ object_from_response(GogoKit::PagedResource,
32
+ GogoKit::CategoriesRepresenter,
33
+ :get,
34
+ get_root.links['viagogo:genres'].href,
35
+ options)
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,38 @@
1
+ require 'gogokit/utils'
2
+ require 'gogokit/resource/country'
3
+
4
+ module GogoKit
5
+ class Client
6
+ # {GogoKit::Client} methods for getting countries
7
+ module Country
8
+ include GogoKit::Utils
9
+
10
+ # Retrieves a country by country code
11
+ #
12
+ # @param [String] code The country code of the country to be retrieved
13
+ # @param [Hash] options Optional options
14
+ # @return [GogoKit::Country] The requested country
15
+ def get_country(code, options = {})
16
+ root = get_root
17
+ object_from_response(GogoKit::Country,
18
+ GogoKit::CountryRepresenter,
19
+ :get,
20
+ "#{root.links['self'].href}/countries/#{code}",
21
+ options)
22
+ end
23
+
24
+ # Retrieves all countries
25
+ #
26
+ # @see http://viagogo.github.io/developer.viagogo.net/#viagogocountries
27
+ # @param [Hash] options Optional options
28
+ # @return [GogoKit::PagedResource] All countries
29
+ def get_countries(options = {})
30
+ object_from_response(GogoKit::PagedResource,
31
+ GogoKit::CountriesRepresenter,
32
+ :get,
33
+ get_root.links['viagogo:countries'].href,
34
+ options)
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,38 @@
1
+ require 'gogokit/utils'
2
+ require 'gogokit/resource/currency'
3
+
4
+ module GogoKit
5
+ class Client
6
+ # {GogoKit::Client} methods for getting currencies
7
+ module Currency
8
+ include GogoKit::Utils
9
+
10
+ # Retrieves a currency by currency code
11
+ #
12
+ # @param [String] code The currency code of the currency to be retrieved
13
+ # @param [Hash] options Optional options
14
+ # @return [GogoKit::Country] The requested currency
15
+ def get_currency(code, options = {})
16
+ root = get_root
17
+ object_from_response(GogoKit::Currency,
18
+ GogoKit::CurrencyRepresenter,
19
+ :get,
20
+ "#{root.links['self'].href}/currencies/#{code}",
21
+ options)
22
+ end
23
+
24
+ # Retrieves all currencies supported by viagogo
25
+ #
26
+ # @see http://viagogo.github.io/developer.viagogo.net/#viagogocurrencies
27
+ # @param [Hash] options Optional options
28
+ # @return [GogoKit::PagedResource] All currencies
29
+ def get_currencies(options = {})
30
+ object_from_response(GogoKit::PagedResource,
31
+ GogoKit::CurrenciesRepresenter,
32
+ :get,
33
+ get_root.links['viagogo:currencies'].href,
34
+ options)
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,41 @@
1
+ require 'gogokit/utils'
2
+ require 'gogokit/resource/event'
3
+
4
+ module GogoKit
5
+ class Client
6
+ # {GogoKit::Client} methods for getting events
7
+ module Event
8
+ include GogoKit::Utils
9
+
10
+ # Retrieves a event by ID
11
+ #
12
+ # @param [Integer] event_id The ID of the event to be retrieved
13
+ # @param [Hash] options Optional options
14
+ # @return [GogoKit::Event] The requested event
15
+ def get_event(event_id, options = {})
16
+ root = get_root
17
+ object_from_response(GogoKit::Event,
18
+ GogoKit::EventRepresenter,
19
+ :get,
20
+ "#{root.links['self'].href}/events/" \
21
+ "#{event_id}",
22
+ options)
23
+ end
24
+
25
+ # Retrieves all events in a particular category
26
+ #
27
+ # @see http://viagogo.github.io/developer.viagogo.net/#categoryevents
28
+ # @param [Hash] options Optional options
29
+ # @return [GogoKit::PagedResource] All events in the specified category
30
+ def get_events_by_category(category_id, options = {})
31
+ root = get_root
32
+ object_from_response(GogoKit::PagedResource,
33
+ GogoKit::EventsRepresenter,
34
+ :get,
35
+ "#{root.links['self'].href}/categories/" \
36
+ "#{category_id}/events",
37
+ options)
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,38 @@
1
+ require 'gogokit/utils'
2
+ require 'gogokit/resource/language'
3
+
4
+ module GogoKit
5
+ class Client
6
+ # {GogoKit::Client} methods for getting languages
7
+ module Language
8
+ include GogoKit::Utils
9
+
10
+ # Retrieves a language by language code
11
+ #
12
+ # @param [String] code The language code of the language to be retrieved
13
+ # @param [Hash] options Optional options
14
+ # @return [GogoKit::Country] The requested language
15
+ def get_language(code, options = {})
16
+ root = get_root
17
+ object_from_response(GogoKit::Language,
18
+ GogoKit::LanguageRepresenter,
19
+ :get,
20
+ "#{root.links['self'].href}/languages/#{code}",
21
+ options)
22
+ end
23
+
24
+ # Retrieves all languages supported by viagogo
25
+ #
26
+ # @see http://viagogo.github.io/developer.viagogo.net/#viagogolanguages
27
+ # @param [Hash] options Optional options
28
+ # @return [GogoKit::PagedResource] All languages
29
+ def get_languages(options = {})
30
+ object_from_response(GogoKit::PagedResource,
31
+ GogoKit::LanguagesRepresenter,
32
+ :get,
33
+ get_root.links['viagogo:languages'].href,
34
+ options)
35
+ end
36
+ end
37
+ end
38
+ end