Module: SendGrid4r::REST::ApiKeysManagement
- Includes:
- Request
- Included in:
- API
- Defined in:
- lib/sendgrid4r/rest/api_keys_management/api_keys.rb,
lib/sendgrid4r/rest/api_keys_management/permissions.rb
Overview
SendGrid Web API v3 ApiKeysManagement
Defined Under Namespace
Modules: Permissions
Classes: ApiKey, ApiKeys
Constant Summary
Constants included
from Request
Request::BASE_URL
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Request
#create_args, #delete, #execute, #finish, #get, #patch, #post, #process_array_params, #process_url_params, #put
Class Method Details
.create_api_key(resp) ⇒ Object
27
28
29
30
31
32
33
34
35
|
# File 'lib/sendgrid4r/rest/api_keys_management/api_keys.rb', line 27
def self.create_api_key(resp)
return resp if resp.nil?
ApiKey.new(
resp['name'],
resp['api_key_id'],
resp['api_key'],
resp['scopes']
)
end
|
.create_api_keys(resp) ⇒ Object
19
20
21
22
23
24
25
|
# File 'lib/sendgrid4r/rest/api_keys_management/api_keys.rb', line 19
def self.create_api_keys(resp)
return resp if resp.nil?
api_keys = resp['result'].map do |api_key|
ApiKeysManagement.create_api_key(api_key)
end
ApiKeys.new(api_keys)
end
|
.url(api_key_id = nil) ⇒ Object
13
14
15
16
17
|
# File 'lib/sendgrid4r/rest/api_keys_management/api_keys.rb', line 13
def self.url(api_key_id = nil)
url = "#{BASE_URL}/api_keys"
url = "#{url}/#{api_key_id}" unless api_key_id.nil?
url
end
|
Instance Method Details
#delete_api_key(api_key_id:, &block) ⇒ Object
55
56
57
|
# File 'lib/sendgrid4r/rest/api_keys_management/api_keys.rb', line 55
def delete_api_key(api_key_id:, &block)
delete(@auth, ApiKeysManagement.url(api_key_id), &block)
end
|
#get_api_key(api_key_id:, &block) ⇒ Object
49
50
51
52
53
|
# File 'lib/sendgrid4r/rest/api_keys_management/api_keys.rb', line 49
def get_api_key(api_key_id:, &block)
endpoint = ApiKeysManagement.url(api_key_id)
resp = get(@auth, endpoint, &block)
finish(resp, @raw_resp) { |r| ApiKeysManagement.create_api_key(r) }
end
|
#get_api_keys(&block) ⇒ Object
#patch_api_key(api_key_id:, name:, &block) ⇒ Object
59
60
61
62
63
64
|
# File 'lib/sendgrid4r/rest/api_keys_management/api_keys.rb', line 59
def patch_api_key(api_key_id:, name:, &block)
params = { name: name }
endpoint = ApiKeysManagement.url(api_key_id)
resp = patch(@auth, endpoint, params, &block)
finish(resp, @raw_resp) { |r| ApiKeysManagement.create_api_key(r) }
end
|
#post_api_key(name:, scopes: nil, &block) ⇒ Object
42
43
44
45
46
47
|
# File 'lib/sendgrid4r/rest/api_keys_management/api_keys.rb', line 42
def post_api_key(name:, scopes: nil, &block)
params = { name: name }
params[:scopes] = scopes unless scopes.nil?
resp = post(@auth, ApiKeysManagement.url, params, &block)
finish(resp, @raw_resp) { |r| ApiKeysManagement.create_api_key(r) }
end
|
#put_api_key(api_key_id:, name:, scopes:, &block) ⇒ Object
66
67
68
69
70
71
72
73
|
# File 'lib/sendgrid4r/rest/api_keys_management/api_keys.rb', line 66
def put_api_key(api_key_id:, name:, scopes:, &block)
params = {}
params[:name] = name unless name.nil?
params[:scopes] = scopes unless scopes.nil?
endpoint = ApiKeysManagement.url(api_key_id)
resp = put(@auth, endpoint, params, &block)
finish(resp, @raw_resp) { |r| ApiKeysManagement.create_api_key(r) }
end
|