gogokit 0.4.1 → 0.5.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 +8 -8
- data/README.md +12 -1
- data/lib/gogokit/client.rb +1 -0
- data/lib/gogokit/client/oauth.rb +56 -11
- data/lib/gogokit/configuration.rb +49 -9
- data/lib/gogokit/connection.rb +1 -1
- data/lib/gogokit/default.rb +29 -6
- data/lib/gogokit/middleware/raise_error.rb +1 -1
- data/lib/gogokit/version.rb +3 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
OTEzMTlkMzNlMjczMTQ3OTgxYmVlNmUzODA1YTkzODEyYTk2MTdhZg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
YTE1ZWRjOTViOTk5MDkyY2Q5YzAzN2JiNzk1ZTNmNWRlN2RkMjA1OQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MzM2ZGVkYzA0ZDRhNTNjYmM5ZjNhM2NiMjY2OGRlOTNlN2ZlZmY2MWMyMTI2
|
10
|
+
MzM2ZTQwODE0NTZhOTJiOTJjOTI0ZmM2N2VlMmJlYzg1MDIzM2M5OGQ2ZmJj
|
11
|
+
NDIxMDQ5ZjA5ODZmNzA0ZmU4NTFjOTY0YWFlMTllMjI4YmUzOGM=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ODJhY2NhMDU3MzNjNjVjMDY2ZjkyZWIxOTg4YmE1YmVhNzcyYzIxYjA1ODdl
|
14
|
+
OWRiZjAyYjBlNDZjZTMzY2YxZTY0ZmY0NzJkYWZmOTZkY2NiODdhMDc5YjYy
|
15
|
+
MDQ2MjM2OTNmZWU2NTliYjAzOTcyMDgzYzgwYzdkZGNmNDI5NWI=
|
data/README.md
CHANGED
@@ -18,6 +18,7 @@
|
|
18
18
|
[troubleshootwindows]: https://github.com/jnunemaker/httparty/wiki/Troubleshooting-on-Windows
|
19
19
|
[submitanissue]: https://github.com/viagogo/gogokit.rb/issues
|
20
20
|
[apidocsgettingstarted]: http://developer.viagogo.net/#getting-started
|
21
|
+
[rubysamples]: https://github.com/viagogo/gogokit.rb/tree/master/samples
|
21
22
|
|
22
23
|
|
23
24
|
Ruby toolkit for working with the viagogo API. Our [developer site][apidocs]
|
@@ -37,7 +38,8 @@ Install via Ruby gems
|
|
37
38
|
|
38
39
|
## Usage
|
39
40
|
|
40
|
-
See our [developer site][apidocsgettingstarted]
|
41
|
+
See our [developer site][apidocsgettingstarted] and
|
42
|
+
[samples][rubysamples] for more examples.
|
41
43
|
|
42
44
|
```ruby
|
43
45
|
require 'gogokit'
|
@@ -113,6 +115,15 @@ client.api_root_endpoint
|
|
113
115
|
# => "http://sandbox.api.viagogo.net"
|
114
116
|
```
|
115
117
|
|
118
|
+
#### Sandbox Environment
|
119
|
+
|
120
|
+
```ruby
|
121
|
+
# You can use the GogoKitConfiguration to switch between the sandbox and
|
122
|
+
# production environments. See http://developer.viagogo.net/#sandbox-environment
|
123
|
+
client = GogoKit::Client.new
|
124
|
+
client.api_environment = :sandbox
|
125
|
+
```
|
126
|
+
|
116
127
|
## How to contribute
|
117
128
|
|
118
129
|
All submissions are welcome. Fork the repository, read the rest of this README
|
data/lib/gogokit/client.rb
CHANGED
data/lib/gogokit/client/oauth.rb
CHANGED
@@ -8,6 +8,61 @@ module GogoKit
|
|
8
8
|
module OAuth
|
9
9
|
include GogoKit::Utils
|
10
10
|
|
11
|
+
# Gets the URL where applications can obtain a users consent to make API
|
12
|
+
# calls on their behalf.
|
13
|
+
# @see http://developer.viagogo.net/#user-login-authentication-flow
|
14
|
+
# @param [String] redirect_uri Application redirect URL where the
|
15
|
+
# authorization code is sent. This must match the URL registered for your
|
16
|
+
# application.
|
17
|
+
# @param [Array] scopes The scopes that specify the type of access that is
|
18
|
+
# needed.
|
19
|
+
# @param [String] state An opaque value used to maintain state between the
|
20
|
+
# authorize request and the callback.
|
21
|
+
def get_authorization_url(redirect_uri, scopes, state = nil)
|
22
|
+
scope_value = scopes.nil? ? '' : scopes.join('%20')
|
23
|
+
"#{authorization_endpoint}?client_id=#{client_id}&response_type=code&" \
|
24
|
+
"redirect_uri=#{redirect_uri}&scope=#{scope_value}&state=#{state}"
|
25
|
+
end
|
26
|
+
|
27
|
+
# Requests an access token that will provide access to user-specific data
|
28
|
+
# (sales, sellerlistings, webhooks, purchases, etc)
|
29
|
+
# @see http://developer.viagogo.net/#user-login-authentication-flow
|
30
|
+
# @param [String] code The authorization code that was sent to your
|
31
|
+
# applications return URL.
|
32
|
+
# @param [String] redirect_uri Application redirect URL where the
|
33
|
+
# authorization code is sent. This must match the URL registered for your
|
34
|
+
# application.
|
35
|
+
# @param [Array] scopes The scopes that specify the type of access that is
|
36
|
+
# needed.
|
37
|
+
def get_authorization_code_access_token(code,
|
38
|
+
redirect_uri,
|
39
|
+
scopes,
|
40
|
+
options = {})
|
41
|
+
scope_value = scopes.nil? ? '' : scopes.join(' ')
|
42
|
+
merged_options = options.merge(code: code,
|
43
|
+
redirect_uri: redirect_uri,
|
44
|
+
scope: scope_value)
|
45
|
+
get_access_token('authorization_code', merged_options)
|
46
|
+
end
|
47
|
+
|
48
|
+
# Get an OAuth access token for an application.
|
49
|
+
#
|
50
|
+
# @see http://developer.viagogo.net/#application-only-authentication-flow
|
51
|
+
# @param [Hash] options Token request information
|
52
|
+
# @return [GogoKit::OAuthToken] The OAuth token
|
53
|
+
def get_client_access_token(options = {})
|
54
|
+
get_access_token('client_credentials', options)
|
55
|
+
end
|
56
|
+
|
57
|
+
# Obtain additional access tokens in order to prolong access to a users
|
58
|
+
# data
|
59
|
+
# @param [GogoKit::OAuthToken] token The token to be refreshed.
|
60
|
+
def get_refresh_token(token, options = {})
|
61
|
+
merged_options = options.merge(refresh_token: token.refresh_token,
|
62
|
+
scope: token.scope)
|
63
|
+
get_access_token('refresh_token', merged_options)
|
64
|
+
end
|
65
|
+
|
11
66
|
# Get an OAuth access token
|
12
67
|
#
|
13
68
|
# @see http://viagogo.github.io/developer.viagogo.net/#authentication
|
@@ -23,16 +78,6 @@ module GogoKit
|
|
23
78
|
headers: token_request_headers)
|
24
79
|
end
|
25
80
|
|
26
|
-
# Get an OAuth access token for an application.
|
27
|
-
#
|
28
|
-
# @see
|
29
|
-
# http://viagogo.github.io/developer.viagogo.net/#client-credentials-grant
|
30
|
-
# @param [Hash] options Token request information
|
31
|
-
# @return [GogoKit::OAuthToken] The OAuth token
|
32
|
-
def get_client_access_token(options = {})
|
33
|
-
get_access_token('client_credentials', options)
|
34
|
-
end
|
35
|
-
|
36
81
|
private
|
37
82
|
|
38
83
|
def token_request_body(grant_type, options)
|
@@ -43,7 +88,7 @@ module GogoKit
|
|
43
88
|
|
44
89
|
def token_request_headers
|
45
90
|
credentials = "#{client_id}:#{client_secret}"
|
46
|
-
basic_header_value = Base64.encode64(credentials).
|
91
|
+
basic_header_value = Base64.encode64(credentials).delete("\n")
|
47
92
|
{
|
48
93
|
content_type: 'application/x-www-form-urlencoded',
|
49
94
|
accept: 'application/json',
|
@@ -9,7 +9,8 @@ module GogoKit
|
|
9
9
|
:client_secret,
|
10
10
|
:access_token,
|
11
11
|
:api_root_endpoint,
|
12
|
-
:oauth_token_endpoint
|
12
|
+
:oauth_token_endpoint,
|
13
|
+
:authorization_endpoint
|
13
14
|
|
14
15
|
# Reset configuration options to default values
|
15
16
|
def reset!
|
@@ -19,6 +20,32 @@ module GogoKit
|
|
19
20
|
self
|
20
21
|
end
|
21
22
|
|
23
|
+
# Gets the current API environment in use
|
24
|
+
#
|
25
|
+
# @return [Symbol]
|
26
|
+
# @raise [GogoKit::Error::ConfigurationError] Error is raised when supplied
|
27
|
+
# environment is not :production or :sandbox.
|
28
|
+
def api_environment
|
29
|
+
@api_environment
|
30
|
+
end
|
31
|
+
|
32
|
+
# Sets the API environment to be used. Setting this value will configure the
|
33
|
+
# values for {GogoKit::Configuration#api_root_endpoint},
|
34
|
+
# {GogoKit::Configuration#oauth_token_endpoint} and
|
35
|
+
# {GogoKit::Configuration#authorization_endpoint}.
|
36
|
+
# See http://developer.viagogo.net/#sandbox-environment
|
37
|
+
def api_environment=(api_environment)
|
38
|
+
@api_environment = api_environment.to_sym
|
39
|
+
validate_configuration_api_environment!
|
40
|
+
|
41
|
+
self.api_root_endpoint =
|
42
|
+
GogoKit::Default::API_ROOT_ENDPOINTS[@api_environment]
|
43
|
+
self.oauth_token_endpoint =
|
44
|
+
GogoKit::Default::OAUTH_TOKEN_ENDPOINTS[@api_environment]
|
45
|
+
self.authorization_endpoint =
|
46
|
+
GogoKit::Default::AUTHORIZATION_ENDPOINTS[@api_environment]
|
47
|
+
end
|
48
|
+
|
22
49
|
private
|
23
50
|
|
24
51
|
def keys
|
@@ -26,8 +53,10 @@ module GogoKit
|
|
26
53
|
:client_id,
|
27
54
|
:client_secret,
|
28
55
|
:access_token,
|
56
|
+
:api_environment,
|
29
57
|
:api_root_endpoint,
|
30
|
-
:oauth_token_endpoint
|
58
|
+
:oauth_token_endpoint,
|
59
|
+
:authorization_endpoint
|
31
60
|
]
|
32
61
|
end
|
33
62
|
|
@@ -43,7 +72,8 @@ module GogoKit
|
|
43
72
|
def endpoints
|
44
73
|
{
|
45
74
|
api_root_endpoint: api_root_endpoint,
|
46
|
-
oauth_token_endpoint: oauth_token_endpoint
|
75
|
+
oauth_token_endpoint: oauth_token_endpoint,
|
76
|
+
authorization_endpoint: authorization_endpoint
|
47
77
|
}
|
48
78
|
end
|
49
79
|
|
@@ -55,9 +85,9 @@ module GogoKit
|
|
55
85
|
def validate_configuration_credentials!
|
56
86
|
credentials.each do |credential, value|
|
57
87
|
next if value.nil? || value.is_a?(String) || value.is_a?(Symbol)
|
58
|
-
|
59
|
-
|
60
|
-
|
88
|
+
raise(ConfigurationError,
|
89
|
+
"Invalid #{credential} specified: #{value.inspect} must be a" \
|
90
|
+
' string or symbol.')
|
61
91
|
end
|
62
92
|
end
|
63
93
|
|
@@ -65,10 +95,20 @@ module GogoKit
|
|
65
95
|
endpoints.each do |endpoint, value|
|
66
96
|
next if !value.nil? && value =~ /\A#{URI.regexp}\z/
|
67
97
|
|
68
|
-
|
69
|
-
|
70
|
-
|
98
|
+
raise(ConfigurationError,
|
99
|
+
"Invalid #{endpoint} specified: " \
|
100
|
+
"#{value.inspect} must be a valid URL")
|
71
101
|
end
|
72
102
|
end
|
103
|
+
|
104
|
+
def validate_configuration_api_environment!
|
105
|
+
return if api_environment.nil? ||
|
106
|
+
api_environment == :production ||
|
107
|
+
api_environment == :sandbox
|
108
|
+
|
109
|
+
raise(ConfigurationError,
|
110
|
+
'Invalid api_environment specified: ' \
|
111
|
+
"#{api_environment.inspect} must be :production or :sandbox")
|
112
|
+
end
|
73
113
|
end
|
74
114
|
end
|
data/lib/gogokit/connection.rb
CHANGED
data/lib/gogokit/default.rb
CHANGED
@@ -1,11 +1,23 @@
|
|
1
1
|
module GogoKit
|
2
2
|
# Default configuration options for {GogoKit::Client}
|
3
3
|
module Default
|
4
|
-
# Default API root
|
5
|
-
|
4
|
+
# Default API root endpoints
|
5
|
+
API_ROOT_ENDPOINTS = {
|
6
|
+
production: 'https://api.viagogo.net/v2'.freeze,
|
7
|
+
sandbox: 'https://sandbox.api.viagogo.net/v2'.freeze
|
8
|
+
}.freeze
|
6
9
|
|
7
|
-
# Default OAuth token
|
8
|
-
|
10
|
+
# Default OAuth token endpoints
|
11
|
+
OAUTH_TOKEN_ENDPOINTS = {
|
12
|
+
production: 'https://account.viagogo.com/oauth2/token'.freeze,
|
13
|
+
sandbox: 'https://sandbox.account.viagogo.com/oauth2/token'.freeze
|
14
|
+
}.freeze
|
15
|
+
|
16
|
+
# Default Authorize endpoints
|
17
|
+
AUTHORIZATION_ENDPOINTS = {
|
18
|
+
production: 'https://account.viagogo.com/authorize'.freeze,
|
19
|
+
sandbox: 'https://sandbox.account.viagogo.com/authorize'.freeze
|
20
|
+
}.freeze
|
9
21
|
|
10
22
|
class << self
|
11
23
|
def client_id
|
@@ -20,13 +32,24 @@ module GogoKit
|
|
20
32
|
ENV['GOGOKIT_ACCESS_TOKEN']
|
21
33
|
end
|
22
34
|
|
35
|
+
def api_environment
|
36
|
+
env_api_environment = ENV['GOGOKIT_API_ENVIRONMENT']
|
37
|
+
env_api_environment.nil? ? :production : env_api_environment.to_sym
|
38
|
+
end
|
39
|
+
|
23
40
|
def api_root_endpoint
|
24
|
-
ENV['GOGOKIT_API_ROOT_ENDPOINT'] ||
|
41
|
+
ENV['GOGOKIT_API_ROOT_ENDPOINT'] ||
|
42
|
+
GogoKit::Default::API_ROOT_ENDPOINTS[api_environment]
|
25
43
|
end
|
26
44
|
|
27
45
|
def oauth_token_endpoint
|
28
46
|
ENV['GOGOKIT_OAUTH_TOKEN_ENDPOINT'] ||
|
29
|
-
GogoKit::Default::
|
47
|
+
GogoKit::Default::OAUTH_TOKEN_ENDPOINTS[api_environment]
|
48
|
+
end
|
49
|
+
|
50
|
+
def authorization_endpoint
|
51
|
+
ENV['GOGOKIT_AUTHORIZATION_ENDPOINT'] ||
|
52
|
+
GogoKit::Default::AUTHORIZATION_ENDPOINTS[api_environment]
|
30
53
|
end
|
31
54
|
end
|
32
55
|
end
|
data/lib/gogokit/version.rb
CHANGED
@@ -5,13 +5,13 @@ module GogoKit
|
|
5
5
|
|
6
6
|
# Current minor release.
|
7
7
|
# @return [Integer]
|
8
|
-
MINOR =
|
8
|
+
MINOR = 5
|
9
9
|
|
10
10
|
# Current patch level.
|
11
11
|
# @return [Integer]
|
12
|
-
PATCH =
|
12
|
+
PATCH = 0
|
13
13
|
|
14
14
|
# Full release version.
|
15
15
|
# @return [String]
|
16
|
-
VERSION = [MAJOR, MINOR, PATCH].join('.')
|
16
|
+
VERSION = [MAJOR, MINOR, PATCH].join('.')
|
17
17
|
end
|
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.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- viagogo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-06-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|