sendgrid4r 1.8.1 → 1.10.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 +6 -2
- data/README.md +1 -0
- data/lib/sendgrid4r/factory/campaign_factory.rb +18 -5
- data/lib/sendgrid4r/factory/condition_factory.rb +1 -1
- data/lib/sendgrid4r/factory/mail_factory.rb +57 -0
- data/lib/sendgrid4r/factory/segment_factory.rb +2 -5
- data/lib/sendgrid4r/factory/version_factory.rb +1 -1
- data/lib/sendgrid4r/rest/api.rb +48 -49
- data/lib/sendgrid4r/rest/api_keys_management/api_keys.rb +75 -0
- data/lib/sendgrid4r/rest/api_keys_management/permissions.rb +31 -0
- data/lib/sendgrid4r/rest/blocks.rb +49 -68
- data/lib/sendgrid4r/rest/bounces.rb +45 -64
- data/lib/sendgrid4r/rest/cancel_scheduled_sends.rb +53 -72
- data/lib/sendgrid4r/rest/categories.rb +31 -0
- data/lib/sendgrid4r/rest/email_activity.rb +72 -0
- data/lib/sendgrid4r/rest/invalid_emails.rb +50 -68
- data/lib/sendgrid4r/rest/ip_access_management.rb +86 -111
- data/lib/sendgrid4r/rest/ips/addresses.rb +50 -59
- data/lib/sendgrid4r/rest/ips/pools.rb +42 -53
- data/lib/sendgrid4r/rest/ips/warmup.rb +46 -55
- data/lib/sendgrid4r/rest/mail/address.rb +14 -0
- data/lib/sendgrid4r/rest/mail/attachment.rb +22 -0
- data/lib/sendgrid4r/rest/mail/content.rb +10 -0
- data/lib/sendgrid4r/rest/mail/mail.rb +28 -0
- data/lib/sendgrid4r/rest/mail/mail_settings.rb +62 -0
- data/lib/sendgrid4r/rest/mail/params.rb +64 -0
- data/lib/sendgrid4r/rest/mail/personalization.rb +33 -0
- data/lib/sendgrid4r/rest/mail/tracking_settings.rb +74 -0
- data/lib/sendgrid4r/rest/{contacts → marketing_campaigns/contacts}/custom_fields.rb +12 -27
- data/lib/sendgrid4r/rest/{contacts → marketing_campaigns/contacts}/lists.rb +20 -34
- data/lib/sendgrid4r/rest/marketing_campaigns/contacts/recipients.rb +134 -0
- data/lib/sendgrid4r/rest/{contacts → marketing_campaigns/contacts}/reserved_fields.rb +6 -9
- data/lib/sendgrid4r/rest/marketing_campaigns/contacts/segments.rb +86 -0
- data/lib/sendgrid4r/rest/marketing_campaigns/marketing_campaigns.rb +119 -0
- data/lib/sendgrid4r/rest/marketing_campaigns/senders.rb +101 -0
- data/lib/sendgrid4r/rest/request.rb +61 -63
- data/lib/sendgrid4r/rest/settings/enforced_tls.rb +23 -26
- data/lib/sendgrid4r/rest/settings/mail.rb +167 -183
- data/lib/sendgrid4r/rest/settings/partner.rb +33 -36
- data/lib/sendgrid4r/rest/settings/settings.rb +17 -22
- data/lib/sendgrid4r/rest/settings/tracking.rb +97 -107
- data/lib/sendgrid4r/rest/sm/global_unsubscribes.rb +52 -60
- data/lib/sendgrid4r/rest/sm/groups.rb +52 -58
- data/lib/sendgrid4r/rest/sm/sm.rb +15 -17
- data/lib/sendgrid4r/rest/sm/suppressions.rb +50 -67
- data/lib/sendgrid4r/rest/spam_reports.rb +49 -69
- data/lib/sendgrid4r/rest/stats/advanced.rb +100 -102
- data/lib/sendgrid4r/rest/stats/category.rb +31 -33
- data/lib/sendgrid4r/rest/stats/global.rb +17 -19
- data/lib/sendgrid4r/rest/stats/parse.rb +18 -20
- data/lib/sendgrid4r/rest/stats/stats.rb +59 -69
- data/lib/sendgrid4r/rest/stats/subuser.rb +70 -32
- data/lib/sendgrid4r/rest/subusers.rb +106 -134
- data/lib/sendgrid4r/rest/transactional_templates/templates.rb +63 -0
- data/lib/sendgrid4r/rest/transactional_templates/versions.rb +90 -0
- data/lib/sendgrid4r/rest/users.rb +125 -57
- data/lib/sendgrid4r/rest/webhooks/event.rb +36 -42
- data/lib/sendgrid4r/rest/webhooks/parse.rb +28 -37
- data/lib/sendgrid4r/rest/whitelabel/domains.rb +176 -222
- data/lib/sendgrid4r/rest/whitelabel/ips.rb +107 -128
- data/lib/sendgrid4r/rest/whitelabel/links.rb +131 -167
- data/lib/sendgrid4r/version.rb +1 -1
- data/lib/sendgrid4r.rb +23 -13
- data/sendgrid4r.gemspec +1 -1
- data/spec/client_spec.rb +12 -1
- data/spec/factory/campaign_factory_spec.rb +75 -35
- data/spec/factory/condition_factory_spec.rb +19 -18
- data/spec/factory/segment_factory_spec.rb +28 -21
- data/spec/factory/version_factory_spec.rb +28 -27
- data/spec/photo.jpg +0 -0
- data/spec/rest/api_keys_management/api_keys_spec.rb +174 -0
- data/spec/rest/api_keys_management/permissions_spec.rb +54 -0
- data/spec/rest/blocks_spec.rb +78 -106
- data/spec/rest/bounces_spec.rb +91 -118
- data/spec/rest/cancel_scheduled_sends_spec.rb +94 -149
- data/spec/rest/categories_spec.rb +77 -0
- data/spec/rest/email_activity_spec.rb +151 -0
- data/spec/rest/invalid_emails_spec.rb +85 -119
- data/spec/rest/ip_access_management_spec.rb +157 -195
- data/spec/rest/ips/addresses_spec.rb +94 -122
- data/spec/rest/ips/pools_spec.rb +84 -112
- data/spec/rest/ips/warmup_spec.rb +63 -71
- data/spec/rest/mail/address_spec.rb +28 -0
- data/spec/rest/mail/attachment_spec.rb +48 -0
- data/spec/rest/mail/content_spec.rb +32 -0
- data/spec/rest/mail/mail_settings_spec.rb +51 -0
- data/spec/rest/mail/mail_spec.rb +136 -0
- data/spec/rest/mail/params_spec.rb +152 -0
- data/spec/rest/mail/personalization_spec.rb +66 -0
- data/spec/rest/mail/tracking_settings_spec.rb +63 -0
- data/spec/rest/marketing_campaigns/contacts/custom_fields_spec.rb +146 -0
- data/spec/rest/marketing_campaigns/contacts/lists_spec.rb +307 -0
- data/spec/rest/marketing_campaigns/contacts/recipients_spec.rb +331 -0
- data/spec/rest/marketing_campaigns/contacts/reserved_fields_spec.rb +119 -0
- data/spec/rest/marketing_campaigns/contacts/segments_spec.rb +268 -0
- data/spec/rest/marketing_campaigns/marketing_campaigns_spec.rb +427 -0
- data/spec/rest/marketing_campaigns/senders_spec.rb +230 -0
- data/spec/rest/settings/enforced_tls_spec.rb +38 -54
- data/spec/rest/settings/mail_spec.rb +227 -330
- data/spec/rest/settings/partner_spec.rb +40 -59
- data/spec/rest/settings/settings_spec.rb +44 -42
- data/spec/rest/settings/tracking_spec.rb +130 -189
- data/spec/rest/sm/global_unsubscribes_spec.rb +47 -72
- data/spec/rest/sm/groups_spec.rb +88 -123
- data/spec/rest/sm/sm_spec.rb +32 -30
- data/spec/rest/sm/suppressions_spec.rb +105 -140
- data/spec/rest/spam_reports_spec.rb +81 -109
- data/spec/rest/stats/advanced_spec.rb +67 -125
- data/spec/rest/stats/category_spec.rb +27 -45
- data/spec/rest/stats/global_spec.rb +34 -42
- data/spec/rest/stats/parse_spec.rb +32 -30
- data/spec/rest/stats/stats_spec.rb +174 -172
- data/spec/rest/stats/subuser_spec.rb +97 -57
- data/spec/rest/subusers_spec.rb +156 -209
- data/spec/rest/transactional_templates/templates_spec.rb +199 -0
- data/spec/rest/transactional_templates/versions_spec.rb +228 -0
- data/spec/rest/users_spec.rb +176 -91
- data/spec/rest/webhooks/event_spec.rb +59 -85
- data/spec/rest/webhooks/parse_spec.rb +51 -71
- data/spec/rest/whitelabel/domains_spec.rb +333 -513
- data/spec/rest/whitelabel/ips_spec.rb +109 -147
- data/spec/rest/whitelabel/links_spec.rb +181 -265
- metadata +70 -40
- data/lib/sendgrid4r/rest/api_keys/api_keys.rb +0 -80
- data/lib/sendgrid4r/rest/api_keys/permissions.rb +0 -33
- data/lib/sendgrid4r/rest/campaigns/campaigns.rb +0 -126
- data/lib/sendgrid4r/rest/categories/categories.rb +0 -43
- data/lib/sendgrid4r/rest/contacts/recipients.rb +0 -150
- data/lib/sendgrid4r/rest/contacts/segments.rb +0 -97
- data/lib/sendgrid4r/rest/email_activity/email_activity.rb +0 -81
- data/lib/sendgrid4r/rest/templates/templates.rb +0 -69
- data/lib/sendgrid4r/rest/templates/versions.rb +0 -95
- data/spec/rest/api_keys/api_keys_spec.rb +0 -210
- data/spec/rest/api_keys/permissions_spec.rb +0 -65
- data/spec/rest/campaigns/campaigns_spec.rb +0 -492
- data/spec/rest/categories/categories_spec.rb +0 -96
- data/spec/rest/contacts/custom_fields_spec.rb +0 -174
- data/spec/rest/contacts/lists_spec.rb +0 -372
- data/spec/rest/contacts/recipients_spec.rb +0 -343
- data/spec/rest/contacts/reserved_fields_spec.rb +0 -146
- data/spec/rest/contacts/segments_spec.rb +0 -307
- data/spec/rest/email_activity/email_activity_spec.rb +0 -179
- data/spec/rest/templates/templates_spec.rb +0 -222
- data/spec/rest/templates/versions_spec.rb +0 -252
@@ -1,13 +1,13 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
|
3
|
-
module SendGrid4r
|
4
|
-
module
|
3
|
+
module SendGrid4r::REST
|
4
|
+
module MarketingCampaigns
|
5
5
|
module Contacts
|
6
6
|
#
|
7
7
|
# SendGrid Web API v3 Contacts - Custom Fields
|
8
8
|
#
|
9
9
|
module CustomFields
|
10
|
-
include
|
10
|
+
include Request
|
11
11
|
|
12
12
|
Field = Struct.new(:id, :name, :type, :value) do
|
13
13
|
def eql?(other)
|
@@ -34,11 +34,8 @@ module SendGrid4r
|
|
34
34
|
|
35
35
|
def self.create_fields(resp)
|
36
36
|
return resp if resp.nil?
|
37
|
-
custom_fields = []
|
38
|
-
|
39
|
-
custom_fields.push(
|
40
|
-
SendGrid4r::REST::Contacts::CustomFields.create_field(field)
|
41
|
-
)
|
37
|
+
custom_fields = resp['custom_fields'].map do |field|
|
38
|
+
Contacts::CustomFields.create_field(field)
|
42
39
|
end
|
43
40
|
Fields.new(custom_fields)
|
44
41
|
end
|
@@ -47,34 +44,22 @@ module SendGrid4r
|
|
47
44
|
params = {}
|
48
45
|
params['name'] = name
|
49
46
|
params['type'] = type
|
50
|
-
resp = post(
|
51
|
-
|
52
|
-
)
|
53
|
-
SendGrid4r::REST::Contacts::CustomFields.create_field(resp)
|
47
|
+
resp = post(@auth, Contacts::CustomFields.url, params, &block)
|
48
|
+
Contacts::CustomFields.create_field(resp)
|
54
49
|
end
|
55
50
|
|
56
51
|
def get_custom_fields(&block)
|
57
|
-
resp = get(
|
58
|
-
|
59
|
-
)
|
60
|
-
SendGrid4r::REST::Contacts::CustomFields.create_fields(resp)
|
52
|
+
resp = get(@auth, Contacts::CustomFields.url, &block)
|
53
|
+
Contacts::CustomFields.create_fields(resp)
|
61
54
|
end
|
62
55
|
|
63
56
|
def get_custom_field(custom_field_id:, &block)
|
64
|
-
resp = get(
|
65
|
-
|
66
|
-
SendGrid4r::REST::Contacts::CustomFields.url(custom_field_id),
|
67
|
-
&block
|
68
|
-
)
|
69
|
-
SendGrid4r::REST::Contacts::CustomFields.create_field(resp)
|
57
|
+
resp = get(@auth, Contacts::CustomFields.url(custom_field_id), &block)
|
58
|
+
Contacts::CustomFields.create_field(resp)
|
70
59
|
end
|
71
60
|
|
72
61
|
def delete_custom_field(custom_field_id:, &block)
|
73
|
-
delete(
|
74
|
-
@auth,
|
75
|
-
SendGrid4r::REST::Contacts::CustomFields.url(custom_field_id),
|
76
|
-
&block
|
77
|
-
)
|
62
|
+
delete(@auth, Contacts::CustomFields.url(custom_field_id), &block)
|
78
63
|
end
|
79
64
|
end
|
80
65
|
end
|
@@ -1,13 +1,13 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
|
3
|
-
module SendGrid4r
|
4
|
-
module
|
3
|
+
module SendGrid4r::REST
|
4
|
+
module MarketingCampaigns
|
5
5
|
module Contacts
|
6
6
|
#
|
7
7
|
# SendGrid Web API v3 Contacts - Lists
|
8
8
|
#
|
9
9
|
module Lists
|
10
|
-
include
|
10
|
+
include Request
|
11
11
|
|
12
12
|
List = Struct.new(:id, :name, :recipient_count)
|
13
13
|
Lists = Struct.new(:lists)
|
@@ -19,7 +19,7 @@ module SendGrid4r
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def self.recipients_url(list_id, recipient_id = nil)
|
22
|
-
url = "#{
|
22
|
+
url = "#{Contacts::Lists.url(list_id)}/recipients"
|
23
23
|
url = "#{url}/#{recipient_id}" unless recipient_id.nil?
|
24
24
|
url
|
25
25
|
end
|
@@ -31,50 +31,41 @@ module SendGrid4r
|
|
31
31
|
|
32
32
|
def self.create_lists(resp)
|
33
33
|
return resp if resp.nil?
|
34
|
-
lists = []
|
35
|
-
resp['lists'].each do |list|
|
36
|
-
lists.push(SendGrid4r::REST::Contacts::Lists.create_list(list))
|
37
|
-
end
|
34
|
+
lists = resp['lists'].map { |list| Contacts::Lists.create_list(list) }
|
38
35
|
Lists.new(lists)
|
39
36
|
end
|
40
37
|
|
41
38
|
def post_list(name:, &block)
|
42
39
|
params = {}
|
43
40
|
params['name'] = name
|
44
|
-
resp = post(
|
45
|
-
|
46
|
-
)
|
47
|
-
SendGrid4r::REST::Contacts::Lists.create_list(resp)
|
41
|
+
resp = post(@auth, Contacts::Lists.url, params, &block)
|
42
|
+
Contacts::Lists.create_list(resp)
|
48
43
|
end
|
49
44
|
|
50
45
|
def get_lists(&block)
|
51
|
-
resp = get(@auth,
|
52
|
-
|
46
|
+
resp = get(@auth, Contacts::Lists.url, &block)
|
47
|
+
Contacts::Lists.create_lists(resp)
|
53
48
|
end
|
54
49
|
|
55
50
|
def get_list(list_id:, &block)
|
56
|
-
resp = get(
|
57
|
-
|
58
|
-
)
|
59
|
-
SendGrid4r::REST::Contacts::Lists.create_list(resp)
|
51
|
+
resp = get(@auth, Contacts::Lists.url(list_id), &block)
|
52
|
+
Contacts::Lists.create_list(resp)
|
60
53
|
end
|
61
54
|
|
62
55
|
def patch_list(list_id:, name:, &block)
|
63
56
|
params = {}
|
64
57
|
params['name'] = name
|
65
|
-
|
66
|
-
resp
|
67
|
-
SendGrid4r::REST::Contacts::Lists.create_list(resp)
|
58
|
+
resp = patch(@auth, Contacts::Lists.url(list_id), params, &block)
|
59
|
+
Contacts::Lists.create_list(resp)
|
68
60
|
end
|
69
61
|
|
70
62
|
def delete_list(list_id:, &block)
|
71
|
-
delete(@auth,
|
63
|
+
delete(@auth, Contacts::Lists.url(list_id), &block)
|
72
64
|
end
|
73
65
|
|
74
66
|
# no bodies returned
|
75
67
|
def post_recipients_to_list(list_id:, recipients:, &block)
|
76
|
-
|
77
|
-
endpoint = "#{url}/recipients"
|
68
|
+
endpoint = "#{Contacts::Lists.url(list_id)}/recipients"
|
78
69
|
post(@auth, endpoint, recipients, &block)
|
79
70
|
end
|
80
71
|
|
@@ -84,28 +75,23 @@ module SendGrid4r
|
|
84
75
|
params = {}
|
85
76
|
params['page'] = page unless page.nil?
|
86
77
|
params['page_size'] = page_size unless page_size.nil?
|
87
|
-
endpoint =
|
78
|
+
endpoint = Contacts::Lists.recipients_url(list_id)
|
88
79
|
resp = get(@auth, endpoint, params, &block)
|
89
|
-
|
80
|
+
Contacts::Recipients.create_recipients(resp)
|
90
81
|
end
|
91
82
|
|
92
83
|
def post_recipient_to_list(list_id:, recipient_id:, &block)
|
93
|
-
endpoint =
|
94
|
-
list_id, recipient_id
|
95
|
-
)
|
84
|
+
endpoint = Contacts::Lists.recipients_url(list_id, recipient_id)
|
96
85
|
post(@auth, endpoint, &block)
|
97
86
|
end
|
98
87
|
|
99
88
|
def delete_recipient_from_list(list_id:, recipient_id:, &block)
|
100
|
-
endpoint =
|
101
|
-
list_id, recipient_id
|
102
|
-
)
|
89
|
+
endpoint = Contacts::Lists.recipients_url(list_id, recipient_id)
|
103
90
|
delete(@auth, endpoint, &block)
|
104
91
|
end
|
105
92
|
|
106
93
|
def delete_lists(list_ids:, &block)
|
107
|
-
|
108
|
-
delete(@auth, endpoint, nil, list_ids, &block)
|
94
|
+
delete(@auth, "#{BASE_URL}/contactdb/lists", nil, list_ids, &block)
|
109
95
|
end
|
110
96
|
end
|
111
97
|
end
|
@@ -0,0 +1,134 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
module SendGrid4r::REST
|
4
|
+
module MarketingCampaigns
|
5
|
+
module Contacts
|
6
|
+
#
|
7
|
+
# SendGrid Web API v3 Contacts - Recipients
|
8
|
+
#
|
9
|
+
module Recipients
|
10
|
+
include Request
|
11
|
+
|
12
|
+
Recipient = Struct.new(
|
13
|
+
:created_at,
|
14
|
+
:custom_fields,
|
15
|
+
:email,
|
16
|
+
:first_name,
|
17
|
+
:id,
|
18
|
+
:last_clicked,
|
19
|
+
:last_emailed,
|
20
|
+
:last_name,
|
21
|
+
:last_opened,
|
22
|
+
:updated_at
|
23
|
+
)
|
24
|
+
|
25
|
+
Recipients = Struct.new(:recipients)
|
26
|
+
|
27
|
+
def self.create_recipient(resp)
|
28
|
+
return resp if resp.nil?
|
29
|
+
custom_fields = []
|
30
|
+
custom_fields = resp['custom_fields'].map do |field|
|
31
|
+
Contacts::CustomFields.create_field(field)
|
32
|
+
end unless resp['custom_fields'].nil?
|
33
|
+
Recipient.new(
|
34
|
+
Time.at(resp['created_at']), custom_fields,
|
35
|
+
resp['email'], resp['first_name'], resp['id'],
|
36
|
+
resp['last_clicked'], resp['last_emailed'],
|
37
|
+
resp['last_name'], resp['last_opened'],
|
38
|
+
Time.at(resp['updated_at'])
|
39
|
+
)
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.create_recipients(resp)
|
43
|
+
return resp if resp.nil?
|
44
|
+
recipients = resp['recipients'].map do |recipient|
|
45
|
+
Contacts::Recipients.create_recipient(recipient)
|
46
|
+
end
|
47
|
+
Recipients.new(recipients)
|
48
|
+
end
|
49
|
+
|
50
|
+
def self.url(recipient_id = nil)
|
51
|
+
url = "#{BASE_URL}/contactdb/recipients"
|
52
|
+
url = "#{url}/#{recipient_id}" unless recipient_id.nil?
|
53
|
+
url
|
54
|
+
end
|
55
|
+
|
56
|
+
def post_recipients(params:, &block)
|
57
|
+
resp = post(@auth, Contacts::Recipients.url, params, &block)
|
58
|
+
Contacts::Recipients.create_result(resp)
|
59
|
+
end
|
60
|
+
|
61
|
+
def patch_recipients(params:, &block)
|
62
|
+
resp = patch(@auth, Contacts::Recipients.url, params, &block)
|
63
|
+
Contacts::Recipients.create_result(resp)
|
64
|
+
end
|
65
|
+
|
66
|
+
def delete_recipients(recipient_ids:, &block)
|
67
|
+
delete(@auth, Contacts::Recipients.url, nil, recipient_ids, &block)
|
68
|
+
end
|
69
|
+
|
70
|
+
def get_recipients(page: nil, page_size: nil, &block)
|
71
|
+
params = {}
|
72
|
+
params['page_size'] = page_size unless page_size.nil?
|
73
|
+
params['page'] = page unless page.nil?
|
74
|
+
resp = get(@auth, Contacts::Recipients.url, params, &block)
|
75
|
+
Contacts::Recipients.create_recipients(resp)
|
76
|
+
end
|
77
|
+
|
78
|
+
def get_recipient(recipient_id:, &block)
|
79
|
+
resp = get(@auth, Contacts::Recipients.url(recipient_id), &block)
|
80
|
+
Contacts::Recipients.create_recipient(resp)
|
81
|
+
end
|
82
|
+
|
83
|
+
def delete_recipient(recipient_id:, &block)
|
84
|
+
delete(@auth, Contacts::Recipients.url(recipient_id), &block)
|
85
|
+
end
|
86
|
+
|
87
|
+
def get_lists_recipient_belong(recipient_id:, &block)
|
88
|
+
resp = get(
|
89
|
+
@auth, "#{Contacts::Recipients.url(recipient_id)}/lists", &block
|
90
|
+
)
|
91
|
+
Contacts::Lists.create_lists(resp)
|
92
|
+
end
|
93
|
+
|
94
|
+
def get_recipients_count(&block)
|
95
|
+
resp = get(@auth, "#{Contacts::Recipients.url}/count", &block)
|
96
|
+
resp['recipient_count'] unless resp.nil?
|
97
|
+
end
|
98
|
+
|
99
|
+
def search_recipients(params:, &block)
|
100
|
+
endpoint = "#{Contacts::Recipients.url}/search"
|
101
|
+
resp = get(@auth, endpoint, params, &block)
|
102
|
+
Contacts::Recipients.create_recipients(resp)
|
103
|
+
end
|
104
|
+
|
105
|
+
Result = Struct.new(
|
106
|
+
:error_count,
|
107
|
+
:error_indices,
|
108
|
+
:new_count,
|
109
|
+
:persisted_recipients,
|
110
|
+
:updated_count,
|
111
|
+
:errors
|
112
|
+
)
|
113
|
+
|
114
|
+
def self.create_result(resp)
|
115
|
+
return resp if resp.nil?
|
116
|
+
errors = resp['errors'].map do |error|
|
117
|
+
Contacts::Recipients.create_error(error)
|
118
|
+
end unless resp['errors'].nil?
|
119
|
+
Result.new(
|
120
|
+
resp['error_count'], resp['error_indices'], resp['new_count'],
|
121
|
+
resp['persisted_recipients'], resp['updated_count'], errors
|
122
|
+
)
|
123
|
+
end
|
124
|
+
|
125
|
+
Error = Struct.new(:error_indices, :message)
|
126
|
+
|
127
|
+
def self.create_error(resp)
|
128
|
+
return resp if resp.nil?
|
129
|
+
Error.new(resp['error_indices'], resp['message'])
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
@@ -1,13 +1,13 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
|
3
|
-
module SendGrid4r
|
4
|
-
module
|
3
|
+
module SendGrid4r::REST
|
4
|
+
module MarketingCampaigns
|
5
5
|
module Contacts
|
6
6
|
#
|
7
7
|
# SendGrid Web API v3 Contacts - Reserved Fields
|
8
8
|
#
|
9
9
|
module ReservedFields
|
10
|
-
include
|
10
|
+
include Request
|
11
11
|
|
12
12
|
Field = Struct.new(:name, :type) do
|
13
13
|
def eql?(other)
|
@@ -23,11 +23,8 @@ module SendGrid4r
|
|
23
23
|
|
24
24
|
def self.create_fields(resp)
|
25
25
|
return resp if resp.nil?
|
26
|
-
reserved_fields = []
|
27
|
-
|
28
|
-
reserved_fields.push(
|
29
|
-
SendGrid4r::REST::Contacts::ReservedFields.create_field(field)
|
30
|
-
)
|
26
|
+
reserved_fields = resp['reserved_fields'].map do |field|
|
27
|
+
Contacts::ReservedFields.create_field(field)
|
31
28
|
end
|
32
29
|
Fields.new(reserved_fields)
|
33
30
|
end
|
@@ -39,7 +36,7 @@ module SendGrid4r
|
|
39
36
|
|
40
37
|
def get_reserved_fields(&block)
|
41
38
|
resp = get(@auth, "#{BASE_URL}/contactdb/reserved_fields", &block)
|
42
|
-
|
39
|
+
Contacts::ReservedFields.create_fields(resp)
|
43
40
|
end
|
44
41
|
end
|
45
42
|
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
module SendGrid4r::REST
|
4
|
+
module MarketingCampaigns
|
5
|
+
module Contacts
|
6
|
+
#
|
7
|
+
# SendGrid Web API v3 Contacts - Segments
|
8
|
+
#
|
9
|
+
module Segments
|
10
|
+
include Request
|
11
|
+
|
12
|
+
Condition = Struct.new(:field, :value, :operator, :and_or)
|
13
|
+
Segment = Struct.new(
|
14
|
+
:id, :name, :list_id, :conditions, :recipient_count
|
15
|
+
)
|
16
|
+
Segments = Struct.new(:segments)
|
17
|
+
|
18
|
+
def self.url(segment_id = nil)
|
19
|
+
url = "#{BASE_URL}/contactdb/segments"
|
20
|
+
url = "#{url}/#{segment_id}" unless segment_id.nil?
|
21
|
+
url
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.create_condition(resp)
|
25
|
+
return resp if resp.nil?
|
26
|
+
Condition.new(
|
27
|
+
resp['field'], resp['value'], resp['operator'], resp['and_or']
|
28
|
+
)
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.create_segment(resp)
|
32
|
+
return resp if resp.nil?
|
33
|
+
conditions = resp['conditions'].map do |condition|
|
34
|
+
Contacts::Segments.create_condition(condition)
|
35
|
+
end
|
36
|
+
Segment.new(
|
37
|
+
resp['id'],
|
38
|
+
resp['name'],
|
39
|
+
resp['list_id'],
|
40
|
+
conditions,
|
41
|
+
resp['recipient_count']
|
42
|
+
)
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.create_segments(resp)
|
46
|
+
return resp if resp.nil?
|
47
|
+
segments = resp['segments'].map do |segment|
|
48
|
+
Contacts::Segments.create_segment(segment)
|
49
|
+
end
|
50
|
+
Segments.new(segments)
|
51
|
+
end
|
52
|
+
|
53
|
+
def post_segment(params:, &block)
|
54
|
+
resp = post(@auth, Contacts::Segments.url, params.to_h, &block)
|
55
|
+
Contacts::Segments.create_segment(resp)
|
56
|
+
end
|
57
|
+
|
58
|
+
def get_segments(&block)
|
59
|
+
resp = get(@auth, Contacts::Segments.url, &block)
|
60
|
+
Contacts::Segments.create_segments(resp)
|
61
|
+
end
|
62
|
+
|
63
|
+
def get_segment(segment_id:, &block)
|
64
|
+
resp = get(@auth, Contacts::Segments.url(segment_id), &block)
|
65
|
+
Contacts::Segments.create_segment(resp)
|
66
|
+
end
|
67
|
+
|
68
|
+
def patch_segment(segment_id:, params:, &block)
|
69
|
+
endpoint = Contacts::Segments.url(segment_id)
|
70
|
+
resp = patch(@auth, endpoint, params, &block)
|
71
|
+
Contacts::Segments.create_segment(resp)
|
72
|
+
end
|
73
|
+
|
74
|
+
def delete_segment(segment_id:, &block)
|
75
|
+
delete(@auth, Contacts::Segments.url(segment_id), &block)
|
76
|
+
end
|
77
|
+
|
78
|
+
def get_recipients_on_segment(segment_id:, &block)
|
79
|
+
endpoint = "#{Contacts::Segments.url(segment_id)}/recipients"
|
80
|
+
resp = get(@auth, endpoint, nil, &block)
|
81
|
+
Contacts::Recipients.create_recipients(resp)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
@@ -0,0 +1,119 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
module SendGrid4r::REST
|
4
|
+
#
|
5
|
+
# SendGrid Web API v3 MarketingCampaigns
|
6
|
+
#
|
7
|
+
module MarketingCampaigns
|
8
|
+
include Request
|
9
|
+
|
10
|
+
Campaign = Struct.new(
|
11
|
+
:id, :title, :subject, :sender_id, :list_ids, :segment_ids,
|
12
|
+
:categories, :suppression_group_id, :custom_unsubscribe_url,
|
13
|
+
:ip_pool, :html_content, :plain_content, :send_at, :status
|
14
|
+
)
|
15
|
+
|
16
|
+
Campaigns = Struct.new(:result)
|
17
|
+
|
18
|
+
def self.create_campaign(resp)
|
19
|
+
return resp if resp.nil?
|
20
|
+
send_at = Time.at(resp['send_at']) unless resp['send_at'].nil?
|
21
|
+
Campaign.new(
|
22
|
+
resp['id'], resp['title'], resp['subject'], resp['sender_id'],
|
23
|
+
resp['list_ids'], resp['segment_ids'], resp['categories'],
|
24
|
+
resp['suppression_group_id'], resp['custom_unsubscribe_url'],
|
25
|
+
resp['ip_pool'], resp['html_content'], resp['plain_content'],
|
26
|
+
send_at, resp['status']
|
27
|
+
)
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.create_campaigns(resp)
|
31
|
+
return resp if resp.nil?
|
32
|
+
result = resp['result'].map do |campaign|
|
33
|
+
MarketingCampaigns.create_campaign(campaign)
|
34
|
+
end
|
35
|
+
Campaigns.new(result)
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.url(campaign_id = nil)
|
39
|
+
url = "#{BASE_URL}/campaigns"
|
40
|
+
url = "#{url}/#{campaign_id}" unless campaign_id.nil?
|
41
|
+
url
|
42
|
+
end
|
43
|
+
|
44
|
+
def post_campaign(params:, &block)
|
45
|
+
endpoint = MarketingCampaigns.url
|
46
|
+
resp = post(@auth, endpoint, params, &block)
|
47
|
+
MarketingCampaigns.create_campaign(resp)
|
48
|
+
end
|
49
|
+
|
50
|
+
def get_campaigns(&block)
|
51
|
+
endpoint = MarketingCampaigns.url
|
52
|
+
resp = get(@auth, endpoint, &block)
|
53
|
+
MarketingCampaigns.create_campaigns(resp)
|
54
|
+
end
|
55
|
+
|
56
|
+
def get_campaign(campaign_id:, &block)
|
57
|
+
endpoint = MarketingCampaigns.url(campaign_id)
|
58
|
+
resp = get(@auth, endpoint, &block)
|
59
|
+
MarketingCampaigns.create_campaign(resp)
|
60
|
+
end
|
61
|
+
|
62
|
+
def delete_campaign(campaign_id:, &block)
|
63
|
+
endpoint = MarketingCampaigns.url(campaign_id)
|
64
|
+
delete(@auth, endpoint, &block)
|
65
|
+
end
|
66
|
+
|
67
|
+
def patch_campaign(campaign_id:, params:, &block)
|
68
|
+
endpoint = MarketingCampaigns.url(campaign_id)
|
69
|
+
resp = patch(@auth, endpoint, params.to_h, &block)
|
70
|
+
MarketingCampaigns.create_campaign(resp)
|
71
|
+
end
|
72
|
+
|
73
|
+
def send_campaign(campaign_id:, &block)
|
74
|
+
endpoint = MarketingCampaigns.url(campaign_id)
|
75
|
+
endpoint = "#{endpoint}/schedules/now"
|
76
|
+
resp = post(@auth, endpoint, nil, &block)
|
77
|
+
MarketingCampaigns.create_campaign(resp)
|
78
|
+
end
|
79
|
+
|
80
|
+
def schedule_campaign(campaign_id:, send_at:, &block)
|
81
|
+
endpoint = MarketingCampaigns.url(campaign_id)
|
82
|
+
endpoint = "#{endpoint}/schedules"
|
83
|
+
payload = {}
|
84
|
+
payload['send_at'] = send_at.to_i
|
85
|
+
resp = post(@auth, endpoint, payload, &block)
|
86
|
+
MarketingCampaigns.create_campaign(resp)
|
87
|
+
end
|
88
|
+
|
89
|
+
def reschedule_campaign(campaign_id:, send_at:, &block)
|
90
|
+
endpoint = MarketingCampaigns.url(campaign_id)
|
91
|
+
endpoint = "#{endpoint}/schedules"
|
92
|
+
payload = {}
|
93
|
+
payload['send_at'] = send_at.to_i
|
94
|
+
resp = patch(@auth, endpoint, payload, &block)
|
95
|
+
MarketingCampaigns.create_campaign(resp)
|
96
|
+
end
|
97
|
+
|
98
|
+
def get_schedule_time_campaign(campaign_id:, &block)
|
99
|
+
endpoint = MarketingCampaigns.url(campaign_id)
|
100
|
+
endpoint = "#{endpoint}/schedules"
|
101
|
+
resp = get(@auth, endpoint, &block)
|
102
|
+
MarketingCampaigns.create_campaign(resp)
|
103
|
+
end
|
104
|
+
|
105
|
+
def unschedule_campaign(campaign_id:, &block)
|
106
|
+
endpoint = MarketingCampaigns.url(campaign_id)
|
107
|
+
endpoint = "#{endpoint}/schedules"
|
108
|
+
delete(@auth, endpoint, &block)
|
109
|
+
end
|
110
|
+
|
111
|
+
def test_campaign(campaign_id:, to:, &block)
|
112
|
+
endpoint = MarketingCampaigns.url(campaign_id)
|
113
|
+
endpoint = "#{endpoint}/schedules/test"
|
114
|
+
payload = {}
|
115
|
+
payload['to'] = to
|
116
|
+
post(@auth, endpoint, payload, &block)
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
@@ -0,0 +1,101 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
module SendGrid4r::REST
|
4
|
+
#
|
5
|
+
# SendGrid Web API v3 MarketingCampaigns
|
6
|
+
#
|
7
|
+
module MarketingCampaigns
|
8
|
+
include Request
|
9
|
+
|
10
|
+
Sender = Struct.new(
|
11
|
+
:id, :nickname, :from, :reply_to, :address, :address_2, :city, :state,
|
12
|
+
:zip, :country, :verified, :updated_at, :created_at, :locked
|
13
|
+
) do
|
14
|
+
def from=(from)
|
15
|
+
tap { |s| s[:from] = from.to_h }
|
16
|
+
end
|
17
|
+
|
18
|
+
def reply_to=(reply_to)
|
19
|
+
tap { |s| s[:reply_to] = reply_to.to_h }
|
20
|
+
end
|
21
|
+
|
22
|
+
def to_h
|
23
|
+
super.reject { |_key, value| value.nil? }
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
Address = Struct.new(:email, :name)
|
28
|
+
|
29
|
+
Verified = Struct.new(:status, :reason)
|
30
|
+
|
31
|
+
def self.create_sender(resp)
|
32
|
+
return resp if resp.nil?
|
33
|
+
from = MarketingCampaigns.create_address(resp['from'])
|
34
|
+
reply_to = MarketingCampaigns.create_address(resp['reply_to'])
|
35
|
+
verified = MarketingCampaigns.create_verified(resp['verified'])
|
36
|
+
Sender.new(
|
37
|
+
resp['id'], resp['nickname'], from, reply_to, resp['address'],
|
38
|
+
resp['address_2'], resp['city'], resp['state'], resp['zip'],
|
39
|
+
resp['country'], verified, Time.at(resp['updated_at']),
|
40
|
+
Time.at(resp['created_at']), resp['locked']
|
41
|
+
)
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.create_senders(resp)
|
45
|
+
return resp if resp.nil?
|
46
|
+
resp.map do |sender|
|
47
|
+
MarketingCampaigns.create_sender(sender)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.create_address(resp)
|
52
|
+
return resp if resp.nil?
|
53
|
+
Address.new(resp['email'], resp['name'])
|
54
|
+
end
|
55
|
+
|
56
|
+
def self.create_verified(resp)
|
57
|
+
return resp if resp.nil?
|
58
|
+
Verified.new(resp['status'], resp['reason'])
|
59
|
+
end
|
60
|
+
|
61
|
+
def self.url_sender(sender_id = nil)
|
62
|
+
url = "#{BASE_URL}/senders"
|
63
|
+
url = "#{url}/#{sender_id}" unless sender_id.nil?
|
64
|
+
url
|
65
|
+
end
|
66
|
+
|
67
|
+
def post_sender(params:, &block)
|
68
|
+
endpoint = MarketingCampaigns.url_sender
|
69
|
+
resp = post(@auth, endpoint, params.to_h, &block)
|
70
|
+
MarketingCampaigns.create_sender(resp)
|
71
|
+
end
|
72
|
+
|
73
|
+
def get_senders(&block)
|
74
|
+
endpoint = MarketingCampaigns.url_sender
|
75
|
+
resp = get(@auth, endpoint, &block)
|
76
|
+
MarketingCampaigns.create_senders(resp)
|
77
|
+
end
|
78
|
+
|
79
|
+
def patch_sender(sender_id:, params:, &block)
|
80
|
+
endpoint = MarketingCampaigns.url_sender(sender_id)
|
81
|
+
resp = patch(@auth, endpoint, params.to_h, &block)
|
82
|
+
MarketingCampaigns.create_sender(resp)
|
83
|
+
end
|
84
|
+
|
85
|
+
def delete_sender(sender_id:, &block)
|
86
|
+
endpoint = MarketingCampaigns.url_sender(sender_id)
|
87
|
+
delete(@auth, endpoint, &block)
|
88
|
+
end
|
89
|
+
|
90
|
+
def resend_sender_verification(sender_id:, &block)
|
91
|
+
endpoint = MarketingCampaigns.url_sender(sender_id)
|
92
|
+
post(@auth, "#{endpoint}/resend_verification", nil, &block)
|
93
|
+
end
|
94
|
+
|
95
|
+
def get_sender(sender_id:, &block)
|
96
|
+
endpoint = MarketingCampaigns.url_sender(sender_id)
|
97
|
+
resp = get(@auth, endpoint, &block)
|
98
|
+
MarketingCampaigns.create_sender(resp)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|