Module: SendGrid4r::REST::Subusers
- Includes:
- Request
- Included in:
- API
- Defined in:
- lib/sendgrid4r/rest/subusers.rb
Overview
SendGrid Web API v3 Subusers
Defined Under Namespace
Classes: Ips, Monitor, Subuser
Constant Summary
Constants included
from Request
Request::BASE_URL
Class Method Summary
collapse
Instance Method Summary
collapse
-
#delete_subuser(username:, &block) ⇒ Object
-
#delete_subuser_monitor(username:, &block) ⇒ Object
-
#get_subuser_monitor(username:, &block) ⇒ Object
-
#get_subuser_reputation(usernames:, &block) ⇒ Object
-
#get_subusers(limit: nil, offset: nil, username: nil, &block) ⇒ Object
-
#patch_subuser(username:, disabled:, &block) ⇒ Object
-
#post_subuser(username:, email:, password:, ips:, &block) ⇒ Object
-
#post_subuser_monitor(username:, email:, frequency:, &block) ⇒ Object
-
#put_subuser_assigned_ips(username:, ips:, &block) ⇒ Object
-
#put_subuser_monitor(username:, email:, frequency:, &block) ⇒ Object
Methods included from Request
#create_args, #delete, #execute, #finish, #get, #patch, #post, #process_array_params, #process_url_params, #put
Class Method Details
.create_monitor(resp) ⇒ Object
45
46
47
48
|
# File 'lib/sendgrid4r/rest/subusers.rb', line 45
def self.create_monitor(resp)
return resp if resp.nil?
Monitor.new(resp['email'], resp['frequency'])
end
|
.create_subuser(resp) ⇒ Object
30
31
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/sendgrid4r/rest/subusers.rb', line 30
def self.create_subuser(resp)
return resp if resp.nil?
Subuser.new(
resp['id'],
resp['username'],
resp['email'],
resp['password'],
resp['ips'],
resp['reputation'],
resp['disabled']
)
end
|
.create_subusers(resp) ⇒ Object
25
26
27
28
|
# File 'lib/sendgrid4r/rest/subusers.rb', line 25
def self.create_subusers(resp)
return resp if resp.nil?
resp.map { |subuser| Subusers.create_subuser(subuser) }
end
|
.url(subuser_name = nil) ⇒ Object
15
16
17
18
19
|
# File 'lib/sendgrid4r/rest/subusers.rb', line 15
def self.url(subuser_name = nil)
url = "#{BASE_URL}/subusers"
url = "#{url}/#{subuser_name}" unless subuser_name.nil?
url
end
|
.url_monitor(username) ⇒ Object
21
22
23
|
# File 'lib/sendgrid4r/rest/subusers.rb', line 21
def self.url_monitor(username)
"#{Subusers.url(username)}/monitor"
end
|
Instance Method Details
#delete_subuser(username:, &block) ⇒ Object
76
77
78
|
# File 'lib/sendgrid4r/rest/subusers.rb', line 76
def delete_subuser(username:, &block)
delete(@auth, Subusers.url(username), &block)
end
|
#delete_subuser_monitor(username:, &block) ⇒ Object
100
101
102
|
# File 'lib/sendgrid4r/rest/subusers.rb', line 100
def delete_subuser_monitor(username:, &block)
delete(@auth, Subusers.url_monitor(username), &block)
end
|
#get_subuser_monitor(username:, &block) ⇒ Object
80
81
82
83
84
|
# File 'lib/sendgrid4r/rest/subusers.rb', line 80
def get_subuser_monitor(username:, &block)
endpoint = Subusers.url_monitor(username)
resp = get(@auth, endpoint, nil, &block)
finish(resp, @raw_resp) { |r| Subusers.create_monitor(r) }
end
|
#get_subuser_reputation(usernames:, &block) ⇒ Object
104
105
106
107
108
109
110
|
# File 'lib/sendgrid4r/rest/subusers.rb', line 104
def get_subuser_reputation(usernames:, &block)
params = ''
usernames.each { |username| params += "usernames=#{username}&" }
endpoint = "#{Subusers.url}/reputations?#{params}"
resp = get(@auth, endpoint, usernames, &block)
finish(resp, @raw_resp) { |r| Subusers.create_subusers(r) }
end
|
#get_subusers(limit: nil, offset: nil, username: nil, &block) ⇒ Object
50
51
52
53
54
55
56
57
|
# File 'lib/sendgrid4r/rest/subusers.rb', line 50
def get_subusers(limit: nil, offset: nil, username: nil, &block)
params = {}
params[:limit] = limit unless limit.nil?
params[:offset] = offset unless offset.nil?
params[:username] = username unless username.nil?
resp = get(@auth, Subusers.url, params, &block)
finish(resp, @raw_resp) { |r| Subusers.create_subusers(r) }
end
|
#patch_subuser(username:, disabled:, &block) ⇒ Object
70
71
72
73
74
|
# File 'lib/sendgrid4r/rest/subusers.rb', line 70
def patch_subuser(username:, disabled:, &block)
payload = { disabled: disabled }
resp = patch(@auth, Subusers.url(username), payload, &block)
finish(resp, @raw_resp) { |r| Subusers.create_subuser(r) }
end
|
#post_subuser(username:, email:, password:, ips:, &block) ⇒ Object
59
60
61
62
63
64
65
66
67
68
|
# File 'lib/sendgrid4r/rest/subusers.rb', line 59
def post_subuser(username:, email:, password:, ips:, &block)
params = {
username: username,
email: email,
password: password,
ips: ips
}
resp = post(@auth, Subusers.url, params, &block)
finish(resp, @raw_resp) { |r| Subusers.create_subuser(r) }
end
|
#post_subuser_monitor(username:, email:, frequency:, &block) ⇒ Object
86
87
88
89
90
91
|
# File 'lib/sendgrid4r/rest/subusers.rb', line 86
def post_subuser_monitor(username:, email:, frequency:, &block)
endpoint = Subusers.url_monitor(username)
payload = { email: email, frequency: frequency }
resp = post(@auth, endpoint, payload, &block)
finish(resp, @raw_resp) { |r| Subusers.create_monitor(r) }
end
|
#put_subuser_assigned_ips(username:, ips:, &block) ⇒ Object
112
113
114
115
|
# File 'lib/sendgrid4r/rest/subusers.rb', line 112
def put_subuser_assigned_ips(username:, ips:, &block)
resp = put(@auth, "#{Subusers.url(username)}/ips", ips, &block)
finish(resp, @raw_resp) { |r| Subusers.create_subuser(r) }
end
|
#put_subuser_monitor(username:, email:, frequency:, &block) ⇒ Object
93
94
95
96
97
98
|
# File 'lib/sendgrid4r/rest/subusers.rb', line 93
def put_subuser_monitor(username:, email:, frequency:, &block)
endpoint = Subusers.url_monitor(username)
payload = { email: email, frequency: frequency }
resp = put(@auth, endpoint, payload, &block)
finish(resp, @raw_resp) { |r| Subusers.create_monitor(r) }
end
|