gogokit 0.2.0 → 0.3.0

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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MWVkMTVkMmRmMzc0ZTYzNTVjYTg2ZDVhZWNlYzMzMjVkZjk2MDZmMw==
4
+ OWQzMmUzYzU1MDVmZGUxY2M4ZjI1Njk4MDE2MWM5MzIwZDYyZGM2NA==
5
5
  data.tar.gz: !binary |-
6
- ZTQyNjU2M2Q5NzJhOGUyYjAyZTdjNWM2NjY1MzgzYTQ1YWUzYWM3Nw==
6
+ MDMxOTMzZWFhYTcwMmViYmIxZTNmMTQ0MGY0MWU0MTFkMWQ5ZWRlYw==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MjgxZGFjZjhiMGQ4OTFiMThlYWUyNTM0N2JjNDkyZDhhYjkxZWUyYzIwM2U3
10
- NmI3Y2Q3NDFhOGQwNzE4ZTJiMWRmNGI4MDg2NDM2NzZjYzdmMTQ3ZTcxMmM0
11
- M2ExNmVkMDlhNTQxZGEyNjg4ZTZkMWQ5ZDA5Y2NkOTczZWIzYzA=
9
+ M2RlN2YzMDk2NzdmNDdlMzczYzJlMzkzYzI3MDA2NTliMzQ2YjJmNDMxMTlm
10
+ OGVhMTJjNGMyNWVlOGUwZDRlYTUzZjVhMzA0MjJhMWJjNDBiNDkyNGI3ZDZm
11
+ ODRlMGU5ZmFjMjU1NTcwM2I2MWExODc1Yzk5ZDA3OTBiNDM5YmQ=
12
12
  data.tar.gz: !binary |-
13
- NzZmZGUyYjY0YjAwMTQ3NmU0MzMyMzliNTU4YTBhOTAyZGU4MmI3MTE0NGIw
14
- OTljMjk3MzkzZjkxYzUyZDM4NGE1ODhhMDkzNTA3YmRjNGE5ZmU1Y2FiYmFl
15
- ODQ1Yzc0M2IwNGQ0ODcyN2YyYWY5YTNkNTVhMDQ1OTY2ZGIyZDk=
13
+ YzVjM2UzNWM4MWRmNWIyOGVlZGQ5YTZmYzFmYjcyNTAzMWY1YjExNzZlYjhm
14
+ ZmMxNjVhOTcyYzdkNzFiMjhhOTU0MTNiOWFlY2U4MjNlNGEwMjk5YmNlMTJh
15
+ NmE4NzMzOTJmMjlkMzE1N2M5Y2YyNzYxNTIxNjQ4MTJmZDcxMzk=
data/README.md CHANGED
@@ -32,7 +32,7 @@ Install via Ruby gems
32
32
 
33
33
  ... or add to your Gemfile
34
34
 
35
- gem 'gogokit', '~> 0.2'
35
+ gem 'gogokit', '~> 0.3'
36
36
 
37
37
 
38
38
  ## Usage
@@ -62,6 +62,46 @@ genres = client.get_genres
62
62
  ```
63
63
 
64
64
 
65
+ ## Configuration and defaults
66
+
67
+ GogoKit::Client accepts a range of options when creating a new client instance.
68
+
69
+ ### Configuring client instances
70
+
71
+ Every writeable attribute in {GogoKit::Configuration} can be set one at a time
72
+
73
+ ```ruby
74
+ client = GogoKit::Client.new
75
+ client.client_id = YOUR_CLIENT_ID
76
+ client.api_root_endpoint = 'https://sandbox.api.viagogo.net'
77
+ ```
78
+
79
+ or in a block:
80
+
81
+ ```ruby
82
+ client = GogoKit::Client.new do |config|
83
+ config.client_id = YOUR_CLIENT_ID
84
+ config.api_root_endpoint = 'https://sandbox.api.viagogo.net'
85
+ end
86
+ ```
87
+
88
+ ### Using ENV variables
89
+
90
+ Default configuration values are specified in {GogoKit::Default}. Many
91
+ attributes will look for a default value from the ENV before returning GogoKit's
92
+ default.
93
+
94
+ ```ruby
95
+ # Given $GOGOKIT_CLIENT_ID is "abcd1234" and $GOGOKIT_API_ROOT_ENDPOINT is
96
+ # "http://sandbox.api.viagogo.net"
97
+ client = GogoKit::Client.new
98
+ client.client_id
99
+ client.api_root_endpoint
100
+
101
+ # => "abcd1234"
102
+ # => "http://sandbox.api.viagogo.net"
103
+ ```
104
+
65
105
  ## How to contribute
66
106
 
67
107
  All submissions are welcome. Fork the repository, read the rest of this README
@@ -118,4 +158,4 @@ introduced with new major versions. As a result of this policy, you can (and
118
158
  should) specify a dependency on this gem using the [Pessimistic Version
119
159
  Constraint][pvc] with two digits of precision. For example:
120
160
 
121
- spec.add_dependency 'gogokit', '~> 0.1'
161
+ spec.add_dependency 'gogokit', '~> 0.3'
@@ -43,28 +43,28 @@ module GogoKit
43
43
  include GogoKit::Client::User
44
44
  include GogoKit::Client::Venue
45
45
 
46
- attr_accessor :client_id,
47
- :client_secret,
48
- :access_token
49
-
50
46
  # Initializes a new {GogoKit::Client}
51
47
  #
52
48
  # @param options [Hash]
53
49
  # @option options [String] :client_id Client Id of your application
54
50
  # @option options [String] :client_secret Client Secret of your application
51
+ # @option options [String] :api_root_endpoint Endpoint where the API root
52
+ # is located
55
53
  # @option options [String] :oauth_token_endpoint Endpoint for obtaining
56
54
  # OAuth access tokens
57
55
  # @raise [GogoKit::Error::ConfigurationError] Error is raised when supplied
58
56
  # client credentials are not a String or Symbol.
59
57
  # @return [GogoKit::Client]
60
58
  def initialize(options = {})
59
+ reset!
60
+
61
61
  options.each do |key, value|
62
62
  send(:"#{key}=", value)
63
63
  end
64
64
  yield self if block_given?
65
65
 
66
- validate_credential_type!
67
- validate_configuration!
66
+ validate_configuration_credentials!
67
+ validate_configuration_endpoints!
68
68
  end
69
69
 
70
70
  # The User-Agent header used when making HTTP requests
@@ -152,28 +152,5 @@ module GogoKit
152
152
  # Add an Authorization header since we don't have one yet
153
153
  options[:headers]['Authorization'] = "Bearer #{access_token}"
154
154
  end
155
-
156
- # @return [Hash]
157
- def credentials
158
- {
159
- client_id: client_id,
160
- client_secret: client_secret,
161
- access_token: access_token
162
- }
163
- end
164
-
165
- # Ensures that all credentials set during configuration are of a valid type.
166
- # Valid types are String and Symbol.
167
- #
168
- # @raise [GogoKit::Error::ConfigurationError] Error is raised when supplied
169
- # credentials are not a String or Symbol.
170
- def validate_credential_type!
171
- credentials.each do |credential, value|
172
- next if value.nil? || value.is_a?(String) || value.is_a?(Symbol)
173
- fail(ConfigurationError,
174
- "Invalid #{credential} specified: #{value.inspect} must be a" \
175
- ' string or symbol.')
176
- end
177
- end
178
155
  end
179
156
  end
@@ -5,20 +5,40 @@ module GogoKit
5
5
  # Configuration options for {GogoKit::Client} or falls back to
6
6
  # {GogoKit::Default}
7
7
  module Configuration
8
- attr_writer :api_root_endpoint,
9
- :oauth_token_endpoint
8
+ attr_accessor :client_id,
9
+ :client_secret,
10
+ :access_token,
11
+ :api_root_endpoint,
12
+ :oauth_token_endpoint
10
13
 
11
- # The endpoint for the API root resource
12
- def api_root_endpoint
13
- @api_root_endpoint || GogoKit::Default::API_ROOT_ENDPOINT
14
+ # Reset configuration options to default values
15
+ def reset!
16
+ keys.each do |key|
17
+ instance_variable_set(:"@#{key}", GogoKit::Default.send(key))
18
+ end
19
+ self
14
20
  end
15
21
 
16
- # The endpoint for obtaining OAuth access tokens
17
- def oauth_token_endpoint
18
- @oauth_token_endpoint || GogoKit::Default::OAUTH_TOKEN_ENDPOINT
22
+ private
23
+
24
+ def keys
25
+ @keys ||= [
26
+ :client_id,
27
+ :client_secret,
28
+ :access_token,
29
+ :api_root_endpoint,
30
+ :oauth_token_endpoint
31
+ ]
19
32
  end
20
33
 
21
- private
34
+ # @return [Hash]
35
+ def credentials
36
+ {
37
+ client_id: client_id,
38
+ client_secret: client_secret,
39
+ access_token: access_token
40
+ }
41
+ end
22
42
 
23
43
  def endpoints
24
44
  {
@@ -27,7 +47,21 @@ module GogoKit
27
47
  }
28
48
  end
29
49
 
30
- def validate_configuration!
50
+ # Ensures that all credentials set during configuration are of a valid type.
51
+ # Valid types are String and Symbol.
52
+ #
53
+ # @raise [GogoKit::Error::ConfigurationError] Error is raised when supplied
54
+ # credentials are not a String or Symbol.
55
+ def validate_configuration_credentials!
56
+ credentials.each do |credential, value|
57
+ next if value.nil? || value.is_a?(String) || value.is_a?(Symbol)
58
+ fail(ConfigurationError,
59
+ "Invalid #{credential} specified: #{value.inspect} must be a" \
60
+ ' string or symbol.')
61
+ end
62
+ end
63
+
64
+ def validate_configuration_endpoints!
31
65
  endpoints.each do |endpoint, value|
32
66
  next if !value.nil? && value =~ /\A#{URI.regexp}\z/
33
67
 
@@ -6,5 +6,28 @@ module GogoKit
6
6
 
7
7
  # Default OAuth token endpoint
8
8
  OAUTH_TOKEN_ENDPOINT = 'https://www.viagogo.com/secure/oauth2/token'.freeze
9
+
10
+ class << self
11
+ def client_id
12
+ ENV['GOGOKIT_CLIENT_ID']
13
+ end
14
+
15
+ def client_secret
16
+ ENV['GOGOKIT_CLIENT_SECRET']
17
+ end
18
+
19
+ def access_token
20
+ ENV['GOGOKIT_ACCESS_TOKEN']
21
+ end
22
+
23
+ def api_root_endpoint
24
+ ENV['GOGOKIT_API_ROOT_ENDPOINT'] || GogoKit::Default::API_ROOT_ENDPOINT
25
+ end
26
+
27
+ def oauth_token_endpoint
28
+ ENV['GOGOKIT_OAUTH_TOKEN_ENDPOINT'] ||
29
+ GogoKit::Default::OAUTH_TOKEN_ENDPOINT
30
+ end
31
+ end
9
32
  end
10
33
  end
@@ -5,7 +5,7 @@ module GogoKit
5
5
 
6
6
  # Current minor release.
7
7
  # @return [Integer]
8
- MINOR = 2
8
+ MINOR = 3
9
9
 
10
10
  # Current patch level.
11
11
  # @return [Integer]
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gogokit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - viagogo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-03 00:00:00.000000000 Z
11
+ date: 2015-07-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday