Class: Readiness::Zendesk::OAuthTokens
- Inherits:
-
Client
- Object
- Client
- Readiness::Zendesk::OAuthTokens
show all
- Defined in:
- lib/support_readiness/zendesk/oauth_tokens.rb
Overview
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Client
auth_error, bad_request_error, convert_actions, convert_conditions, convert_standard_names_to_ids, convert_ticket_form_agent_conditions, convert_ticket_form_brands, convert_ticket_form_end_user_conditions, convert_ticket_form_names_to_ids, convert_view_names_to_ids, convert_view_restrictions, covert_ticket_form_field_ids, create_package!, erb_renderer, handle_request_error, not_found_error, not_processible_error, put_into_archive, recursively_deflate_directory, timestamp_filename, to_clean_json, to_clean_json_with_key, to_hash, to_nearly_clean_json, to_nearly_clean_json_with_key, to_param_string, write_entries
Constructor Details
#initialize(object = {}) ⇒ OAuthTokens
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/support_readiness/zendesk/oauth_tokens.rb', line 24
def initialize(object = {})
@client_id = object['client_id']
@created_at = object['created_at']
@expires_at = object['expires_at']
@full_token = object['full_token']
@id = object['id']
@refresh_token = object['refresh_token']
@refresh_token_expires_at = object['refresh_token_expires_at']
@scopes = object['scopes']
@token = object['token']
@used_at = object['used_at']
@user_id = object['user_id']
end
|
Instance Attribute Details
#client_id ⇒ Object
13
14
15
|
# File 'lib/support_readiness/zendesk/oauth_tokens.rb', line 13
def client_id
@client_id
end
|
#created_at ⇒ Object
13
14
15
|
# File 'lib/support_readiness/zendesk/oauth_tokens.rb', line 13
def created_at
@created_at
end
|
#expires_at ⇒ Object
13
14
15
|
# File 'lib/support_readiness/zendesk/oauth_tokens.rb', line 13
def expires_at
@expires_at
end
|
#full_token ⇒ Object
13
14
15
|
# File 'lib/support_readiness/zendesk/oauth_tokens.rb', line 13
def full_token
@full_token
end
|
#id ⇒ Object
13
14
15
|
# File 'lib/support_readiness/zendesk/oauth_tokens.rb', line 13
def id
@id
end
|
#refresh_token ⇒ Object
13
14
15
|
# File 'lib/support_readiness/zendesk/oauth_tokens.rb', line 13
def refresh_token
@refresh_token
end
|
#refresh_token_expires_at ⇒ Object
13
14
15
|
# File 'lib/support_readiness/zendesk/oauth_tokens.rb', line 13
def refresh_token_expires_at
@refresh_token_expires_at
end
|
#scopes ⇒ Object
13
14
15
|
# File 'lib/support_readiness/zendesk/oauth_tokens.rb', line 13
def scopes
@scopes
end
|
#token ⇒ Object
13
14
15
|
# File 'lib/support_readiness/zendesk/oauth_tokens.rb', line 13
def token
@token
end
|
#used_at ⇒ Object
13
14
15
|
# File 'lib/support_readiness/zendesk/oauth_tokens.rb', line 13
def used_at
@used_at
end
|
#user_id ⇒ Object
13
14
15
|
# File 'lib/support_readiness/zendesk/oauth_tokens.rb', line 13
def user_id
@user_id
end
|
Class Method Details
.create!(client, token) ⇒ Object
Creates an Oauth token. Will exit if unsuccessful.
148
149
150
151
152
153
|
# File 'lib/support_readiness/zendesk/oauth_tokens.rb', line 148
def self.create!(client, token)
pp to_clean_json_with_key(token, 'token')
response = client.connection.post 'oauth/tokens', to_clean_json_with_key(token, 'token')
handle_request_error(1, 'Zendesk', response.status, { action: 'Create Oauth token', message: Oj.load(response.body)}) unless response.status == 201
OAuthTokens.new(Oj.load(response.body)['token'])
end
|
.find(client, tid) ⇒ Object
Locates an OAuth token within Zendesk. This will not exit on error (except Authentication errors)
90
91
92
93
94
95
96
|
# File 'lib/support_readiness/zendesk/oauth_tokens.rb', line 90
def self.find(client, tid)
response = client.connection.get("oauth/tokens/#{tid}")
handle_request_error(0, 'Zendesk', response.status, { action: 'get', id: cid }) unless response.status == 200
return OAuthTokens.new(Oj.load(response.body)['token']) if response.status == 200
Oj.load(response.body)
end
|
.find!(client, tid) ⇒ Object
Locates an OAuth token within Zendesk. This will exit on error
117
118
119
120
121
|
# File 'lib/support_readiness/zendesk/oauth_tokens.rb', line 117
def self.find!(client, tid)
response = client.connection.get("oauth/tokens/#{tid}")
handle_request_error(1, 'Zendesk', response.status, { action: 'Find OAuth token', id: tid }) unless response.status == 200
OAuthTokens.new(Oj.load(response.body)['token'])
end
|
.list(client) ⇒ Array
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
# File 'lib/support_readiness/zendesk/oauth_tokens.rb', line 56
def self.list(client)
array = []
opts = 'page[size]=100'
loop do
response = client.connection.get("oauth/tokens?#{opts}")
handle_request_error(0, 'Zendesk', response.status) unless response.status == 200
body = Oj.load(response.body)
array += body['tokens'].map { |t| OAuthTokens.new(t) }
break unless body['meta']['has_more']
opts = body['links']['next'].split('?').last
end
array
end
|
.revoke!(client, token) ⇒ Boolean
Revkokes an OAuth token. Will exit if unsuccessful
175
176
177
178
179
|
# File 'lib/support_readiness/zendesk/oauth_tokens.rb', line 175
def self.revoke!(client, token)
response = client.connection.delete "oauth/tokens/#{token.id}"
handle_request_error(1, 'Zendesk', response.status, { action: 'Revoke a token', id: token.id, message: Oj.load(response.body)}) unless response.status == 204
true
end
|