sendgrid4r 1.12.0 → 1.13.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -1
- data/README.md +2 -1
- data/lib/sendgrid4r/cli/alert.rb +51 -0
- data/lib/sendgrid4r/cli/campaign/campaign.rb +2 -2
- data/lib/sendgrid4r/cli/campaign/contact/custom_field.rb +1 -1
- data/lib/sendgrid4r/cli/campaign/contact/list.rb +1 -1
- data/lib/sendgrid4r/cli/campaign/contact/recipient.rb +2 -2
- data/lib/sendgrid4r/cli/campaign/contact/segment.rb +12 -3
- data/lib/sendgrid4r/cli/ipam/whitelist.rb +1 -1
- data/lib/sendgrid4r/cli/settings/enforced_tls.rb +2 -2
- data/lib/sendgrid4r/cli/settings/mail.rb +33 -9
- data/lib/sendgrid4r/cli/settings/partner.rb +4 -1
- data/lib/sendgrid4r/cli/settings/tracking.rb +13 -4
- data/lib/sendgrid4r/cli/sg.rb +16 -10
- data/lib/sendgrid4r/cli/sg_thor.rb +27 -11
- data/lib/sendgrid4r/cli/stats/advanced.rb +22 -20
- data/lib/sendgrid4r/cli/stats/category.rb +8 -8
- data/lib/sendgrid4r/cli/stats/global.rb +3 -3
- data/lib/sendgrid4r/cli/stats/parse.rb +3 -3
- data/lib/sendgrid4r/cli/stats/subuser.rb +10 -10
- data/lib/sendgrid4r/cli/suppressions/block.rb +2 -2
- data/lib/sendgrid4r/cli/suppressions/bounce.rb +2 -2
- data/lib/sendgrid4r/cli/suppressions/global_unsubscribe.rb +2 -2
- data/lib/sendgrid4r/cli/suppressions/group.rb +6 -1
- data/lib/sendgrid4r/cli/suppressions/group_unsubscribe.rb +9 -0
- data/lib/sendgrid4r/cli/suppressions/invalid_email.rb +2 -2
- data/lib/sendgrid4r/cli/suppressions/spam_report.rb +2 -2
- data/lib/sendgrid4r/cli/templates/version.rb +2 -2
- data/lib/sendgrid4r/cli/user.rb +5 -5
- data/lib/sendgrid4r/cli/webhooks/parse.rb +42 -2
- data/lib/sendgrid4r/cli/whitelabel/domain.rb +3 -3
- data/lib/sendgrid4r/cli/whitelabel/link.rb +2 -2
- data/lib/sendgrid4r/rest/alerts.rb +81 -0
- data/lib/sendgrid4r/rest/api.rb +1 -0
- data/lib/sendgrid4r/rest/blocks.rb +2 -4
- data/lib/sendgrid4r/rest/bounces.rb +2 -4
- data/lib/sendgrid4r/rest/invalid_emails.rb +2 -4
- data/lib/sendgrid4r/rest/request.rb +10 -6
- data/lib/sendgrid4r/rest/sm/groups.rb +3 -2
- data/lib/sendgrid4r/rest/sm/suppressions.rb +61 -14
- data/lib/sendgrid4r/rest/spam_reports.rb +2 -4
- data/lib/sendgrid4r/rest/webhooks/parse.rb +47 -6
- data/lib/sendgrid4r/version.rb +1 -1
- data/lib/sendgrid4r.rb +3 -0
- data/spec/cli/alert_spec.rb +71 -0
- data/spec/cli/sg_spec.rb +5 -0
- data/spec/cli/suppressions/group_spec.rb +11 -2
- data/spec/cli/suppressions/group_unsubscribe_spec.rb +12 -2
- data/spec/cli/webhooks/parse_spec.rb +53 -1
- data/spec/client_spec.rb +17 -1
- data/spec/rest/alerts_spec.rb +188 -0
- data/spec/rest/mail/mail_spec.rb +10 -10
- data/spec/rest/request_spec.rb +41 -0
- data/spec/rest/sm/groups_spec.rb +9 -0
- data/spec/rest/sm/suppressions_spec.rb +122 -35
- data/spec/rest/webhooks/parse_spec.rb +94 -7
- metadata +10 -2
@@ -5,8 +5,8 @@ module SendGrid4r::CLI
|
|
5
5
|
#
|
6
6
|
class Block < SgThor
|
7
7
|
desc 'list', 'List blocks'
|
8
|
-
option :start_time, type: :numeric
|
9
|
-
option :end_time, type: :numeric
|
8
|
+
option :start_time, banner: SgThor::UTS, type: :numeric
|
9
|
+
option :end_time, banner: SgThor::UTS, type: :numeric
|
10
10
|
option :limit, type: :numeric
|
11
11
|
option :offset, type: :numeric
|
12
12
|
def list
|
@@ -5,8 +5,8 @@ module SendGrid4r::CLI
|
|
5
5
|
#
|
6
6
|
class Bounce < SgThor
|
7
7
|
desc 'list', 'List bounces'
|
8
|
-
option :start_time, type: :numeric
|
9
|
-
option :end_time, type: :numeric
|
8
|
+
option :start_time, banner: SgThor::UTS, type: :numeric
|
9
|
+
option :end_time, banner: SgThor::UTS, type: :numeric
|
10
10
|
def list
|
11
11
|
puts @client.get_bounces(parameterise(options))
|
12
12
|
rescue RestClient::ExceptionWithResponse => e
|
@@ -5,8 +5,8 @@ module SendGrid4r::CLI
|
|
5
5
|
#
|
6
6
|
class GlobalUnsubscribe < SgThor
|
7
7
|
desc 'list', 'List global unsubscribes'
|
8
|
-
option :start_time, type: :numeric
|
9
|
-
option :end_time, type: :numeric
|
8
|
+
option :start_time, banner: SgThor::UTS, type: :numeric
|
9
|
+
option :end_time, banner: SgThor::UTS, type: :numeric
|
10
10
|
option :limit, type: :numeric
|
11
11
|
option :offset, type: :numeric
|
12
12
|
def list
|
@@ -15,8 +15,13 @@ module SendGrid4r::CLI
|
|
15
15
|
end
|
16
16
|
|
17
17
|
desc 'list', 'List supression groups'
|
18
|
+
option :email_address
|
18
19
|
def list
|
19
|
-
|
20
|
+
if options[:email_address].nil?
|
21
|
+
puts @client.get_groups
|
22
|
+
else
|
23
|
+
puts @client.get_groups_by_email(parameterise(options))
|
24
|
+
end
|
20
25
|
rescue RestClient::ExceptionWithResponse => e
|
21
26
|
puts e.inspect
|
22
27
|
end
|
@@ -21,6 +21,15 @@ module SendGrid4r::CLI
|
|
21
21
|
puts e.inspect
|
22
22
|
end
|
23
23
|
|
24
|
+
desc 'search', 'Search suppressed addresses for a given group'
|
25
|
+
option :group_id, require: true
|
26
|
+
option :recipient_emails, type: :array, require: true
|
27
|
+
def search
|
28
|
+
puts @client.search_suppressed_emails(parameterise(options))
|
29
|
+
rescue RestClient::ExceptionWithResponse => e
|
30
|
+
puts e.inspect
|
31
|
+
end
|
32
|
+
|
24
33
|
desc 'remove', 'Remove an email address from the given group'
|
25
34
|
option :group_id, require: true
|
26
35
|
option :email_address, require: true
|
@@ -5,8 +5,8 @@ module SendGrid4r::CLI
|
|
5
5
|
#
|
6
6
|
class InvalidEmail < SgThor
|
7
7
|
desc 'list', 'List blocks'
|
8
|
-
option :start_time, type: :numeric
|
9
|
-
option :end_time, type: :numeric
|
8
|
+
option :start_time, banner: SgThor::UTS, type: :numeric
|
9
|
+
option :end_time, banner: SgThor::UTS, type: :numeric
|
10
10
|
option :limit, type: :numeric
|
11
11
|
option :offset, type: :numeric
|
12
12
|
def list
|
@@ -5,8 +5,8 @@ module SendGrid4r::CLI
|
|
5
5
|
#
|
6
6
|
class SpamReport < SgThor
|
7
7
|
desc 'list', 'List spam reports'
|
8
|
-
option :start_time, type: :numeric
|
9
|
-
option :end_time, type: :numeric
|
8
|
+
option :start_time, banner: SgThor::UTS, type: :numeric
|
9
|
+
option :end_time, banner: SgThor::UTS, type: :numeric
|
10
10
|
option :limit, type: :numeric
|
11
11
|
option :offset, type: :numeric
|
12
12
|
def list
|
@@ -10,7 +10,7 @@ module SendGrid4r::CLI
|
|
10
10
|
option :subject, require: true
|
11
11
|
option :html_content, require: true
|
12
12
|
option :plain_content, require: true
|
13
|
-
option :active, type: :numeric
|
13
|
+
option :active, type: :numeric, banner: '[0|1]'
|
14
14
|
def create
|
15
15
|
factory = SendGrid4r::Factory::VersionFactory.new
|
16
16
|
params = parameterise(options)
|
@@ -49,7 +49,7 @@ module SendGrid4r::CLI
|
|
49
49
|
option :subject
|
50
50
|
option :html_content
|
51
51
|
option :plain_content
|
52
|
-
option :active
|
52
|
+
option :active, type: :numeric, banner: '[0|1]'
|
53
53
|
def update
|
54
54
|
factory = SendGrid4r::Factory::VersionFactory.new
|
55
55
|
params = parameterise(options)
|
data/lib/sendgrid4r/cli/user.rb
CHANGED
@@ -3,7 +3,7 @@ module SendGrid4r::CLI
|
|
3
3
|
# SendGrid Web API v3 User
|
4
4
|
#
|
5
5
|
class User < SgThor
|
6
|
-
desc 'profile', 'Get or Update user Profile'
|
6
|
+
desc 'profile [get|update]', 'Get or Update user Profile'
|
7
7
|
option :address
|
8
8
|
option :city
|
9
9
|
option :company
|
@@ -27,7 +27,7 @@ module SendGrid4r::CLI
|
|
27
27
|
puts e.inspect
|
28
28
|
end
|
29
29
|
|
30
|
-
desc 'account', 'Get user account'
|
30
|
+
desc 'account [get]', 'Get user account'
|
31
31
|
def account(action)
|
32
32
|
case action
|
33
33
|
when 'get'
|
@@ -39,7 +39,7 @@ module SendGrid4r::CLI
|
|
39
39
|
puts e.inspect
|
40
40
|
end
|
41
41
|
|
42
|
-
desc 'email', 'Get or update user email'
|
42
|
+
desc 'email [get|update]', 'Get or update user email'
|
43
43
|
option :email
|
44
44
|
def email(action)
|
45
45
|
case action
|
@@ -54,7 +54,7 @@ module SendGrid4r::CLI
|
|
54
54
|
puts e.inspect
|
55
55
|
end
|
56
56
|
|
57
|
-
desc 'username', 'Get or update username'
|
57
|
+
desc 'username [get|update]', 'Get or update username'
|
58
58
|
option :username
|
59
59
|
def username(action)
|
60
60
|
case action
|
@@ -69,7 +69,7 @@ module SendGrid4r::CLI
|
|
69
69
|
puts e.inspect
|
70
70
|
end
|
71
71
|
|
72
|
-
desc('password', 'Update password')
|
72
|
+
desc('password [update]', 'Update password')
|
73
73
|
option :new_password, require: true
|
74
74
|
option :old_password, require: true
|
75
75
|
def password(action)
|
@@ -4,9 +4,49 @@ module SendGrid4r::CLI
|
|
4
4
|
# SendGrid Web API v3 Webhook Parse
|
5
5
|
#
|
6
6
|
class Parse < SgThor
|
7
|
-
desc '
|
7
|
+
desc 'list', 'List parse webhook settings'
|
8
|
+
option :limit, type: :numeric
|
9
|
+
option :offset, type: :numeric
|
10
|
+
def list
|
11
|
+
puts @client.get_parse_settings(parameterise(options))
|
12
|
+
rescue RestClient::ExceptionWithResponse => e
|
13
|
+
puts e.inspect
|
14
|
+
end
|
15
|
+
|
16
|
+
desc 'create', 'Create a parse webhook setting'
|
17
|
+
option :hostname, require: true
|
18
|
+
option :url, require: true
|
19
|
+
option :spam_check, type: :boolean, require: true
|
20
|
+
option :send_raw, type: :boolean, require: true
|
21
|
+
def create
|
22
|
+
puts @client.post_parse_setting(parameterise(options))
|
23
|
+
rescue RestClient::ExceptionWithResponse => e
|
24
|
+
puts e.inspect
|
25
|
+
end
|
26
|
+
|
27
|
+
desc 'get', 'Get a parse webhook setting'
|
28
|
+
option :hostname
|
8
29
|
def get
|
9
|
-
puts @client.
|
30
|
+
puts @client.get_parse_setting(parameterise(options))
|
31
|
+
rescue RestClient::ExceptionWithResponse => e
|
32
|
+
puts e.inspect
|
33
|
+
end
|
34
|
+
|
35
|
+
desc 'update', 'Update a parse webhook setting'
|
36
|
+
option :hostname, require: true
|
37
|
+
option :url
|
38
|
+
option :spam_check, type: :boolean
|
39
|
+
option :send_raw, type: :boolean
|
40
|
+
def update
|
41
|
+
puts @client.patch_parse_setting(parameterise(options))
|
42
|
+
rescue RestClient::ExceptionWithResponse => e
|
43
|
+
puts e.inspect
|
44
|
+
end
|
45
|
+
|
46
|
+
desc 'delete', 'Delete a parse webhook setting'
|
47
|
+
option :hostname, require: true
|
48
|
+
def delete
|
49
|
+
puts @client.delete_parse_setting(parameterise(options))
|
10
50
|
rescue RestClient::ExceptionWithResponse => e
|
11
51
|
puts e.inspect
|
12
52
|
end
|
@@ -5,9 +5,9 @@ module SendGrid4r::CLI
|
|
5
5
|
#
|
6
6
|
class Domain < SgThor
|
7
7
|
desc 'list', 'List all Domain whitelabels'
|
8
|
-
option :limit
|
9
|
-
option :offset
|
10
|
-
option :exclude_subusers
|
8
|
+
option :limit, type: :numeric
|
9
|
+
option :offset, type: :numeric
|
10
|
+
option :exclude_subusers, type: :boolean
|
11
11
|
option :username
|
12
12
|
option :domain
|
13
13
|
def list
|
@@ -0,0 +1,81 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
module SendGrid4r::REST
|
4
|
+
#
|
5
|
+
# SendGrid Web API v3 Alerts
|
6
|
+
#
|
7
|
+
module Alerts
|
8
|
+
include Request
|
9
|
+
|
10
|
+
Alert = Struct.new(
|
11
|
+
:created_at,
|
12
|
+
:email_to,
|
13
|
+
:frequency,
|
14
|
+
:id,
|
15
|
+
:percentage,
|
16
|
+
:type,
|
17
|
+
:updated_at
|
18
|
+
)
|
19
|
+
|
20
|
+
def self.url(alert_id = nil)
|
21
|
+
url = "#{BASE_URL}/alerts"
|
22
|
+
url = "#{url}/#{alert_id}" unless alert_id.nil?
|
23
|
+
url
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.create_alerts(resp)
|
27
|
+
return resp if resp.nil?
|
28
|
+
resp.map { |alert| Alerts.create_alert(alert) }
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.create_alert(resp)
|
32
|
+
return resp if resp.nil?
|
33
|
+
created_at = Time.at(resp['created_at'])
|
34
|
+
updated_at = Time.at(resp['updated_at'])
|
35
|
+
Alert.new(
|
36
|
+
created_at,
|
37
|
+
resp['email_to'],
|
38
|
+
resp['frequency'],
|
39
|
+
resp['id'],
|
40
|
+
resp['percentage'],
|
41
|
+
resp['type'],
|
42
|
+
updated_at
|
43
|
+
)
|
44
|
+
end
|
45
|
+
|
46
|
+
def get_alerts(&block)
|
47
|
+
resp = get(@auth, Alerts.url, &block)
|
48
|
+
finish(resp, @raw_resp) { |r| Alerts.create_alerts(r) }
|
49
|
+
end
|
50
|
+
|
51
|
+
def post_alert(type:, email_to:, percentage: nil, frequency: nil, &block)
|
52
|
+
params = { type: type, email_to: email_to }
|
53
|
+
params[:percentage] = percentage unless percentage.nil?
|
54
|
+
params[:frequency] = frequency unless frequency.nil?
|
55
|
+
resp = post(@auth, Alerts.url, params, &block)
|
56
|
+
finish(resp, @raw_resp) { |r| Alerts.create_alert(r) }
|
57
|
+
end
|
58
|
+
|
59
|
+
def get_alert(alert_id:, &block)
|
60
|
+
endpoint = Alerts.url(alert_id)
|
61
|
+
resp = get(@auth, endpoint, &block)
|
62
|
+
finish(resp, @raw_resp) { |r| Alerts.create_alert(r) }
|
63
|
+
end
|
64
|
+
|
65
|
+
def delete_alert(alert_id:, &block)
|
66
|
+
delete(@auth, Alerts.url(alert_id), &block)
|
67
|
+
end
|
68
|
+
|
69
|
+
def patch_alert(
|
70
|
+
alert_id:, email_to: nil, frequency: nil, percentage: nil, &block
|
71
|
+
)
|
72
|
+
params = {}
|
73
|
+
params[:email_to] = email_to unless email_to.nil?
|
74
|
+
params[:frequency] = frequency unless frequency.nil?
|
75
|
+
params[:percentage] = percentage unless percentage.nil?
|
76
|
+
endpoint = Alerts.url(alert_id)
|
77
|
+
resp = patch(@auth, endpoint, params, &block)
|
78
|
+
finish(resp, @raw_resp) { |r| Alerts.create_alert(r) }
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
data/lib/sendgrid4r/rest/api.rb
CHANGED
@@ -19,6 +19,7 @@ module SendGrid4r::REST
|
|
19
19
|
include SendGrid4r::REST::Ips::Addresses
|
20
20
|
include SendGrid4r::REST::Ips::Warmup
|
21
21
|
include SendGrid4r::REST::Ips::Pools
|
22
|
+
include SendGrid4r::REST::Alerts
|
22
23
|
include SendGrid4r::REST::Categories
|
23
24
|
include SendGrid4r::REST::Stats::Global
|
24
25
|
include SendGrid4r::REST::Stats::Category
|
@@ -48,14 +48,12 @@ module SendGrid4r::REST
|
|
48
48
|
end
|
49
49
|
|
50
50
|
def get_block(email:, &block)
|
51
|
-
|
52
|
-
resp = get(@auth, Blocks.url(email), params, &block)
|
51
|
+
resp = get(@auth, Blocks.url(email), &block)
|
53
52
|
finish(resp, @raw_resp) { |r| Blocks.create_blocks(r) }
|
54
53
|
end
|
55
54
|
|
56
55
|
def delete_block(email:, &block)
|
57
|
-
|
58
|
-
delete(@auth, Blocks.url(email), params, &block)
|
56
|
+
delete(@auth, Blocks.url(email), &block)
|
59
57
|
end
|
60
58
|
end
|
61
59
|
end
|
@@ -44,14 +44,12 @@ module SendGrid4r::REST
|
|
44
44
|
end
|
45
45
|
|
46
46
|
def get_bounce(email:, &block)
|
47
|
-
|
48
|
-
resp = get(@auth, Bounces.url(email), params, &block)
|
47
|
+
resp = get(@auth, Bounces.url(email), &block)
|
49
48
|
finish(resp, @raw_resp) { |r| Bounces.create_bounces(r) }
|
50
49
|
end
|
51
50
|
|
52
51
|
def delete_bounce(email:, &block)
|
53
|
-
|
54
|
-
delete(@auth, Bounces.url(email), params, &block)
|
52
|
+
delete(@auth, Bounces.url(email), &block)
|
55
53
|
end
|
56
54
|
end
|
57
55
|
end
|
@@ -50,14 +50,12 @@ module SendGrid4r::REST
|
|
50
50
|
end
|
51
51
|
|
52
52
|
def get_invalid_email(email:, &block)
|
53
|
-
|
54
|
-
resp = get(@auth, InvalidEmails.url(email), params, &block)
|
53
|
+
resp = get(@auth, InvalidEmails.url(email), &block)
|
55
54
|
finish(resp, @raw_resp) { |r| InvalidEmails.create_invalid_emails(r) }
|
56
55
|
end
|
57
56
|
|
58
57
|
def delete_invalid_email(email:, &block)
|
59
|
-
|
60
|
-
delete(@auth, InvalidEmails.url(email), params, &block)
|
58
|
+
delete(@auth, InvalidEmails.url(email), &block)
|
61
59
|
end
|
62
60
|
end
|
63
61
|
end
|
@@ -61,14 +61,18 @@ module SendGrid4r::REST
|
|
61
61
|
end
|
62
62
|
|
63
63
|
def process_url_params(endpoint, params)
|
64
|
-
if params.nil? || params.empty?
|
65
|
-
|
66
|
-
|
67
|
-
|
64
|
+
return endpoint if params.nil? || params.empty?
|
65
|
+
if params.is_a?(Array)
|
66
|
+
ary_params = params
|
67
|
+
elsif params.is_a?(Hash)
|
68
|
+
ary_params = [params]
|
69
|
+
end
|
70
|
+
query_string = ary_params.collect do |hash|
|
71
|
+
hash.collect do |k, v|
|
68
72
|
"#{k}=#{CGI.escape(process_array_params(v))}"
|
69
73
|
end.join('&')
|
70
|
-
|
71
|
-
|
74
|
+
end.join('&')
|
75
|
+
"#{endpoint}?#{query_string}"
|
72
76
|
end
|
73
77
|
|
74
78
|
def process_array_params(v)
|
@@ -43,8 +43,9 @@ module SendGrid4r::REST
|
|
43
43
|
finish(resp, @raw_resp) { |r| Sm::Groups.create_group(r) }
|
44
44
|
end
|
45
45
|
|
46
|
-
def get_groups(&block)
|
47
|
-
|
46
|
+
def get_groups(ids: nil, &block)
|
47
|
+
i = ids.map { |id| { id: id } } unless ids.nil?
|
48
|
+
resp = get(@auth, Sm::Groups.url, i, &block)
|
48
49
|
finish(resp, @raw_resp) { |r| Sm::Groups.create_groups(r) }
|
49
50
|
end
|
50
51
|
|
@@ -8,8 +8,10 @@ module SendGrid4r::REST
|
|
8
8
|
module Suppressions
|
9
9
|
include Request
|
10
10
|
|
11
|
-
|
12
|
-
|
11
|
+
Group = Struct.new(
|
12
|
+
:id, :name, :description, :suppressed, :is_default
|
13
|
+
)
|
14
|
+
Groups = Struct.new(:suppressions)
|
13
15
|
|
14
16
|
def self.url(group_id, email_address = nil)
|
15
17
|
url = "#{BASE_URL}/asm/groups/#{group_id}/suppressions"
|
@@ -17,21 +19,64 @@ module SendGrid4r::REST
|
|
17
19
|
url
|
18
20
|
end
|
19
21
|
|
20
|
-
def self.
|
22
|
+
def self.create_groups(resp)
|
21
23
|
return resp if resp.nil?
|
22
24
|
suppressions = resp['suppressions'].map do |suppression|
|
23
|
-
Sm::Suppressions.
|
25
|
+
Sm::Suppressions.create_group(suppression)
|
24
26
|
end
|
25
|
-
|
27
|
+
Groups.new(suppressions)
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.create_group(resp)
|
31
|
+
return resp if resp.nil?
|
32
|
+
Group.new(
|
33
|
+
resp['id'],
|
34
|
+
resp['name'],
|
35
|
+
resp['description'],
|
36
|
+
resp['suppressed'],
|
37
|
+
resp['is_default']
|
38
|
+
)
|
39
|
+
end
|
40
|
+
|
41
|
+
Suppression = Struct.new(
|
42
|
+
:email, :group_id, :group_name, :created_at
|
43
|
+
)
|
44
|
+
|
45
|
+
def self.suppressions_url(email = nil)
|
46
|
+
url = "#{BASE_URL}/asm/suppressions"
|
47
|
+
url = "#{url}/#{email}" unless email.nil?
|
48
|
+
url
|
26
49
|
end
|
27
50
|
|
28
51
|
def self.create_suppression(resp)
|
29
52
|
return resp if resp.nil?
|
53
|
+
created_at = Time.at(resp['created_at'])
|
30
54
|
Suppression.new(
|
31
|
-
resp['
|
55
|
+
resp['email'],
|
56
|
+
resp['group_id'],
|
57
|
+
resp['group_name'],
|
58
|
+
created_at
|
32
59
|
)
|
33
60
|
end
|
34
61
|
|
62
|
+
def get_suppressions(&block)
|
63
|
+
endpoint = Sm::Suppressions.suppressions_url
|
64
|
+
resp = get(@auth, endpoint, &block)
|
65
|
+
finish(resp, @raw_resp) do |r|
|
66
|
+
r.map do |suppression|
|
67
|
+
Sm::Suppressions.create_suppression(suppression)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def get_groups_by_email(email_address:, &block)
|
73
|
+
endpoint = Sm::Suppressions.suppressions_url(email_address)
|
74
|
+
resp = get(@auth, endpoint, &block)
|
75
|
+
finish(resp, @raw_resp) do |r|
|
76
|
+
Sm::Suppressions.create_groups(r)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
35
80
|
def post_suppressed_emails(group_id:, recipient_emails:, &block)
|
36
81
|
resp = post(
|
37
82
|
@auth,
|
@@ -48,14 +93,6 @@ module SendGrid4r::REST
|
|
48
93
|
finish(resp, @raw_resp) { |r| r }
|
49
94
|
end
|
50
95
|
|
51
|
-
def get_suppressions(email_address:, &block)
|
52
|
-
endpoint = "#{BASE_URL}/asm/suppressions/#{email_address}"
|
53
|
-
resp = get(@auth, endpoint, &block)
|
54
|
-
finish(resp, @raw_resp) do |r|
|
55
|
-
Sm::Suppressions.create_suppressions(r)
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
96
|
def delete_suppressed_email(group_id:, email_address:, &block)
|
60
97
|
delete(
|
61
98
|
@auth,
|
@@ -63,6 +100,16 @@ module SendGrid4r::REST
|
|
63
100
|
&block
|
64
101
|
)
|
65
102
|
end
|
103
|
+
|
104
|
+
def search_suppressed_emails(group_id:, recipient_emails:, &block)
|
105
|
+
resp = post(
|
106
|
+
@auth,
|
107
|
+
Sm::Suppressions.url(group_id, :search),
|
108
|
+
recipient_emails: recipient_emails,
|
109
|
+
&block
|
110
|
+
)
|
111
|
+
finish(resp, @raw_resp) { |r| r }
|
112
|
+
end
|
66
113
|
end
|
67
114
|
end
|
68
115
|
end
|
@@ -48,14 +48,12 @@ module SendGrid4r::REST
|
|
48
48
|
end
|
49
49
|
|
50
50
|
def get_spam_report(email:, &block)
|
51
|
-
|
52
|
-
resp = get(@auth, SpamReports.url(email), params, &block)
|
51
|
+
resp = get(@auth, SpamReports.url(email), &block)
|
53
52
|
finish(resp, @raw_resp) { |r| SpamReports.create_spam_reports(r) }
|
54
53
|
end
|
55
54
|
|
56
55
|
def delete_spam_report(email:, &block)
|
57
|
-
|
58
|
-
delete(@auth, SpamReports.url(email), params, &block)
|
56
|
+
delete(@auth, SpamReports.url(email), &block)
|
59
57
|
end
|
60
58
|
end
|
61
59
|
end
|
@@ -12,10 +12,12 @@ module SendGrid4r::REST
|
|
12
12
|
include Request
|
13
13
|
|
14
14
|
ParseSettings = Struct.new(:result)
|
15
|
-
ParseSetting = Struct.new(:url, :hostname, :
|
15
|
+
ParseSetting = Struct.new(:url, :hostname, :spam_check, :send_raw)
|
16
16
|
|
17
|
-
def self.url
|
18
|
-
"#{BASE_URL}/user/webhooks/parse/settings"
|
17
|
+
def self.url(hostname = nil)
|
18
|
+
url = "#{BASE_URL}/user/webhooks/parse/settings"
|
19
|
+
url = "#{url}/#{hostname}" unless hostname.nil?
|
20
|
+
url
|
19
21
|
end
|
20
22
|
|
21
23
|
def self.create_parse_settings(resp)
|
@@ -29,14 +31,53 @@ module SendGrid4r::REST
|
|
29
31
|
def self.create_parse_setting(resp)
|
30
32
|
return resp if resp.nil?
|
31
33
|
ParseSetting.new(
|
32
|
-
resp['url'],
|
34
|
+
resp['url'],
|
35
|
+
resp['hostname'],
|
36
|
+
resp['spam_check'],
|
37
|
+
resp['send_raw']
|
33
38
|
)
|
34
39
|
end
|
35
40
|
|
36
|
-
def get_parse_settings(&block)
|
37
|
-
|
41
|
+
def get_parse_settings(limit: nil, offset: nil, &block)
|
42
|
+
params = {}
|
43
|
+
params[:limit] = limit unless limit.nil?
|
44
|
+
params[:offset] = offset unless offset.nil?
|
45
|
+
resp = get(@auth, Parse.url, params, &block)
|
38
46
|
finish(resp, @raw_resp) { |r| Parse.create_parse_settings(r) }
|
39
47
|
end
|
48
|
+
|
49
|
+
def post_parse_setting(
|
50
|
+
hostname:, url:, spam_check:, send_raw:, &block
|
51
|
+
)
|
52
|
+
params = {
|
53
|
+
hostname: hostname,
|
54
|
+
url: url,
|
55
|
+
spam_check: spam_check,
|
56
|
+
send_raw: send_raw
|
57
|
+
}
|
58
|
+
resp = post(@auth, Parse.url, params, &block)
|
59
|
+
finish(resp, @raw_resp) { |r| Parse.create_parse_setting(r) }
|
60
|
+
end
|
61
|
+
|
62
|
+
def get_parse_setting(hostname:, &block)
|
63
|
+
resp = get(@auth, Parse.url(hostname), &block)
|
64
|
+
finish(resp, @raw_resp) { |r| Parse.create_parse_setting(r) }
|
65
|
+
end
|
66
|
+
|
67
|
+
def patch_parse_setting(
|
68
|
+
hostname:, url: nil, spam_check: nil, send_raw: nil, &block
|
69
|
+
)
|
70
|
+
params = {}
|
71
|
+
params[:url] = url unless url.nil?
|
72
|
+
params[:spam_check] = spam_check unless spam_check.nil?
|
73
|
+
params[:send_raw] = send_raw unless send_raw.nil?
|
74
|
+
resp = patch(@auth, Parse.url(hostname), params, &block)
|
75
|
+
finish(resp, @raw_resp) { |r| Parse.create_parse_setting(r) }
|
76
|
+
end
|
77
|
+
|
78
|
+
def delete_parse_setting(hostname:, &block)
|
79
|
+
delete(@auth, Parse.url(hostname), &block)
|
80
|
+
end
|
40
81
|
end
|
41
82
|
end
|
42
83
|
end
|
data/lib/sendgrid4r/version.rb
CHANGED
data/lib/sendgrid4r.rb
CHANGED
@@ -32,6 +32,8 @@ require 'sendgrid4r/rest/marketing_campaigns/contacts/recipients'
|
|
32
32
|
require 'sendgrid4r/rest/marketing_campaigns/contacts/reserved_fields'
|
33
33
|
require 'sendgrid4r/rest/marketing_campaigns/contacts/segments'
|
34
34
|
|
35
|
+
require 'sendgrid4r/rest/alerts'
|
36
|
+
|
35
37
|
require 'sendgrid4r/rest/categories'
|
36
38
|
|
37
39
|
require 'sendgrid4r/rest/email_activity'
|
@@ -126,6 +128,7 @@ require 'sendgrid4r/cli/whitelabel/ip'
|
|
126
128
|
require 'sendgrid4r/cli/whitelabel/link'
|
127
129
|
require 'sendgrid4r/cli/whitelabel/whitelabel'
|
128
130
|
require 'sendgrid4r/cli/category'
|
131
|
+
require 'sendgrid4r/cli/alert'
|
129
132
|
require 'sendgrid4r/cli/user'
|
130
133
|
require 'sendgrid4r/cli/campaign/contact/custom_field'
|
131
134
|
require 'sendgrid4r/cli/campaign/contact/list'
|