gitlab_support_readiness 1.0.131 → 1.0.132
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 +4 -4
- data/lib/support_readiness/zendesk/oauth_tokens.rb +115 -7
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7aefa86729b110948e278e94a4d413fe3ba5bda9093acc857c113fe2bd8aa793
|
4
|
+
data.tar.gz: 72651512ad7e1774e9545480b1643750d205662decda5cadb6269868647974ad
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fa3c300cf2f5e6118bf9cd18e8d3c3c8017e699da2d3a01767616280a89fa9e2e04aceaa273620f9a993565d6c64bf1fc949223ed7133bb1e8976aa17ba79774
|
7
|
+
data.tar.gz: 0b701da3bf48d539258245893fc4fa6e11eae69cbd8f4337644019fb18037601de6b778b0cde4ac950e21870527f3c0b20fb5ef7f1f0067d5538037f197f7df5
|
@@ -9,9 +9,6 @@ module Readiness
|
|
9
9
|
#
|
10
10
|
# @author Jason Colyer
|
11
11
|
# @since 1.0.125
|
12
|
-
# @todo list - https://developer.zendesk.com/api-reference/ticketing/oauth/oauth_tokens/#list-tokens
|
13
|
-
# @todo show - https://developer.zendesk.com/api-reference/ticketing/oauth/oauth_tokens/#show-token
|
14
|
-
# @todo revoke - https://developer.zendesk.com/api-reference/ticketing/oauth/oauth_tokens/#revoke-token
|
15
12
|
class OAuthTokens < Readiness::Client
|
16
13
|
attr_accessor :client_id, :created_at, :expires_at, :full_token, :id, :refresh_token, :refresh_token_expires_at, :scopes, :token, :used_at, :user_id
|
17
14
|
|
@@ -37,7 +34,92 @@ module Readiness
|
|
37
34
|
@used_at = object['used_at']
|
38
35
|
@user_id = object['user_id']
|
39
36
|
end
|
40
|
-
|
37
|
+
|
38
|
+
##
|
39
|
+
# Lists all OAuth tokens.
|
40
|
+
#
|
41
|
+
# @author Jason Colyer
|
42
|
+
# @since 1.0.132
|
43
|
+
# @param client [Object] An instance of {Readiness::Zendesk::Client}
|
44
|
+
# @return [Array]
|
45
|
+
# @see https://developer.zendesk.com/api-reference/ticketing/oauth/oauth_tokens/#list-tokens Zendesk API > OAuth Tokens > List Tokens
|
46
|
+
# @example
|
47
|
+
# require 'support_readiness'
|
48
|
+
# config = Readiness::Zendesk::Configuration.new
|
49
|
+
# config.username = 'alice@example.com'
|
50
|
+
# config.token = 'test123abc'
|
51
|
+
# config.url = 'https://example.zendesk.com/api/v2'
|
52
|
+
# client = Readiness::Zendesk::Client.new(config)
|
53
|
+
# oauth_tokens = Readiness::Zendesk::OAuthTokens.list(client)
|
54
|
+
# pp oauth_tokens.count
|
55
|
+
# # => 24
|
56
|
+
def self.list(client)
|
57
|
+
array = []
|
58
|
+
opts = 'page[size]=100'
|
59
|
+
loop do
|
60
|
+
response = client.connection.get("oauth/tokens?#{opts}")
|
61
|
+
handle_request_error(0, 'Zendesk', response.status) unless response.status == 200
|
62
|
+
body = Oj.load(response.body)
|
63
|
+
array += body['tokens'].map { |t| OAuthTokens.new(t) }
|
64
|
+
break unless body['meta']['has_more']
|
65
|
+
|
66
|
+
opts = body['links']['next'].split('?').last
|
67
|
+
end
|
68
|
+
array
|
69
|
+
end
|
70
|
+
|
71
|
+
##
|
72
|
+
# Locates an OAuth token within Zendesk. This will not exit on error (except Authentication errors)
|
73
|
+
#
|
74
|
+
# @author Jason Colyer
|
75
|
+
# @since 1.0.132
|
76
|
+
# @param client [Object] An instance of {Readiness::Zendesk::Client}
|
77
|
+
# @param tid [Integer[ The OAuth token ID to find
|
78
|
+
# @param return [Hash]
|
79
|
+
# @see https://developer.zendesk.com/api-reference/ticketing/oauth/oauth_tokens/#show-token Zendesk API > OAuth Tokens > Show Token
|
80
|
+
# @example
|
81
|
+
# require 'support_readiness'
|
82
|
+
# config = Readiness::Zendesk::Configuration.new
|
83
|
+
# config.username = 'alice@example.com'
|
84
|
+
# config.token = 'test123abc'
|
85
|
+
# config.url = 'https://example.zendesk.com/api/v2'
|
86
|
+
# client = Readiness::Zendesk::Client.new(config)
|
87
|
+
# oauth_token = Readiness::Zendesk::OAuthTokens.find(client, 223443)
|
88
|
+
# pp oauth_token.client_id
|
89
|
+
# # => 1234
|
90
|
+
def self.find(client, tid)
|
91
|
+
response = client.connection.get("oauth/tokens/#{tid}")
|
92
|
+
handle_request_error(0, 'Zendesk', response.status, { action: 'get', id: cid }) unless response.status == 200
|
93
|
+
return OAuthTokens.new(Oj.load(response.body)['token']) if response.status == 200
|
94
|
+
|
95
|
+
Oj.load(response.body)
|
96
|
+
end
|
97
|
+
|
98
|
+
##
|
99
|
+
# Locates an OAuth token within Zendesk. This will exit on error
|
100
|
+
#
|
101
|
+
# @author Jason Colyer
|
102
|
+
# @since 1.0.132
|
103
|
+
# @param client [Object] An instance of {Readiness::Zendesk::Client}
|
104
|
+
# @param tid [Integer[ The OAuth token ID to find
|
105
|
+
# @param return [Hash]
|
106
|
+
# @see https://developer.zendesk.com/api-reference/ticketing/oauth/oauth_tokens/#show-token Zendesk API > OAuth Tokens > Show Token
|
107
|
+
# @example
|
108
|
+
# require 'support_readiness'
|
109
|
+
# config = Readiness::Zendesk::Configuration.new
|
110
|
+
# config.username = 'alice@example.com'
|
111
|
+
# config.token = 'test123abc'
|
112
|
+
# config.url = 'https://example.zendesk.com/api/v2'
|
113
|
+
# client = Readiness::Zendesk::Client.new(config)
|
114
|
+
# oauth_token = Readiness::Zendesk::OAuthTokens.find!(client, 223443)
|
115
|
+
# pp oauth_token.client_id
|
116
|
+
# # => 1234
|
117
|
+
def self.find!(client, tid)
|
118
|
+
response = client.connection.get("oauth/tokens/#{tid}")
|
119
|
+
handle_request_error(1, 'Zendesk', response.status, { action: 'Find OAuth token', id: tid }) unless response.status == 200
|
120
|
+
OAuthTokens.new(Oj.load(response.body)['token'])
|
121
|
+
end
|
122
|
+
|
41
123
|
##
|
42
124
|
# Creates an Oauth token. Will exit if unsuccessful.
|
43
125
|
#
|
@@ -65,9 +147,35 @@ module Readiness
|
|
65
147
|
# # => "4v8AR9vXCM7dV4murXlIaBAAzDrAw9lIbaHF7X9VbVPtOABAyy3dnTtHE3A6AdNC"
|
66
148
|
def self.create!(client, token)
|
67
149
|
pp to_clean_json_with_key(token, 'token')
|
68
|
-
|
69
|
-
|
70
|
-
|
150
|
+
response = client.connection.post 'oauth/tokens', to_clean_json_with_key(token, 'token')
|
151
|
+
handle_request_error(1, 'Zendesk', response.status, { action: 'Create Oauth token', message: Oj.load(response.body)}) unless response.status == 201
|
152
|
+
OAuthTokens.new(Oj.load(response.body)['token'])
|
153
|
+
end
|
154
|
+
|
155
|
+
##
|
156
|
+
# Revkokes an OAuth token. Will exit if unsuccessful
|
157
|
+
#
|
158
|
+
# @author Jason Colyer
|
159
|
+
# @since 1.0.132
|
160
|
+
# @param client [Object] An instance of {Readiness::Zendesk::Client}
|
161
|
+
# @param token [Object] An instance of {Readiness::Zendesk::OAuthTokens}
|
162
|
+
# @return [Boolean]
|
163
|
+
# @see https://developer.zendesk.com/api-reference/ticketing/oauth/oauth_tokens/#revoke-token Zendesk API > OAuth Tokens > Revoke Token
|
164
|
+
# @example
|
165
|
+
# require 'support_readiness'
|
166
|
+
# config = Readiness::Zendesk::Configuration.new
|
167
|
+
# config.username = 'alice@example.com'
|
168
|
+
# config.token = 'test123abc'
|
169
|
+
# config.url = 'https://example.zendesk.com/api/v2'
|
170
|
+
# client = Readiness::Zendesk::Client.new(config)
|
171
|
+
# oauth_token = Readiness::Zendesk::OAuthTokens.find!(client, 223443)
|
172
|
+
# revoke = Readiness::Zendesk::OAuthTokens.revoke!(client, oauth_token)
|
173
|
+
# pp revoke
|
174
|
+
# # => true
|
175
|
+
def self.revoke!(client, token)
|
176
|
+
response = client.connection.delete "oauth/tokens/#{token.id}"
|
177
|
+
handle_request_error(1, 'Zendesk', response.status, { action: 'Revoke a token', id: token.id, message: Oj.load(response.body)}) unless response.status == 204
|
178
|
+
true
|
71
179
|
end
|
72
180
|
end
|
73
181
|
end
|