sendgrid4r 1.8.1 → 1.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (145) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +6 -2
  3. data/README.md +1 -0
  4. data/lib/sendgrid4r/factory/campaign_factory.rb +18 -5
  5. data/lib/sendgrid4r/factory/condition_factory.rb +1 -1
  6. data/lib/sendgrid4r/factory/mail_factory.rb +57 -0
  7. data/lib/sendgrid4r/factory/segment_factory.rb +2 -5
  8. data/lib/sendgrid4r/factory/version_factory.rb +1 -1
  9. data/lib/sendgrid4r/rest/api.rb +48 -49
  10. data/lib/sendgrid4r/rest/api_keys_management/api_keys.rb +75 -0
  11. data/lib/sendgrid4r/rest/api_keys_management/permissions.rb +31 -0
  12. data/lib/sendgrid4r/rest/blocks.rb +49 -68
  13. data/lib/sendgrid4r/rest/bounces.rb +45 -64
  14. data/lib/sendgrid4r/rest/cancel_scheduled_sends.rb +53 -72
  15. data/lib/sendgrid4r/rest/categories.rb +31 -0
  16. data/lib/sendgrid4r/rest/email_activity.rb +72 -0
  17. data/lib/sendgrid4r/rest/invalid_emails.rb +50 -68
  18. data/lib/sendgrid4r/rest/ip_access_management.rb +86 -111
  19. data/lib/sendgrid4r/rest/ips/addresses.rb +50 -59
  20. data/lib/sendgrid4r/rest/ips/pools.rb +42 -53
  21. data/lib/sendgrid4r/rest/ips/warmup.rb +46 -55
  22. data/lib/sendgrid4r/rest/mail/address.rb +14 -0
  23. data/lib/sendgrid4r/rest/mail/attachment.rb +22 -0
  24. data/lib/sendgrid4r/rest/mail/content.rb +10 -0
  25. data/lib/sendgrid4r/rest/mail/mail.rb +28 -0
  26. data/lib/sendgrid4r/rest/mail/mail_settings.rb +62 -0
  27. data/lib/sendgrid4r/rest/mail/params.rb +64 -0
  28. data/lib/sendgrid4r/rest/mail/personalization.rb +33 -0
  29. data/lib/sendgrid4r/rest/mail/tracking_settings.rb +74 -0
  30. data/lib/sendgrid4r/rest/{contacts → marketing_campaigns/contacts}/custom_fields.rb +12 -27
  31. data/lib/sendgrid4r/rest/{contacts → marketing_campaigns/contacts}/lists.rb +20 -34
  32. data/lib/sendgrid4r/rest/marketing_campaigns/contacts/recipients.rb +134 -0
  33. data/lib/sendgrid4r/rest/{contacts → marketing_campaigns/contacts}/reserved_fields.rb +6 -9
  34. data/lib/sendgrid4r/rest/marketing_campaigns/contacts/segments.rb +86 -0
  35. data/lib/sendgrid4r/rest/marketing_campaigns/marketing_campaigns.rb +119 -0
  36. data/lib/sendgrid4r/rest/marketing_campaigns/senders.rb +101 -0
  37. data/lib/sendgrid4r/rest/request.rb +61 -63
  38. data/lib/sendgrid4r/rest/settings/enforced_tls.rb +23 -26
  39. data/lib/sendgrid4r/rest/settings/mail.rb +167 -183
  40. data/lib/sendgrid4r/rest/settings/partner.rb +33 -36
  41. data/lib/sendgrid4r/rest/settings/settings.rb +17 -22
  42. data/lib/sendgrid4r/rest/settings/tracking.rb +97 -107
  43. data/lib/sendgrid4r/rest/sm/global_unsubscribes.rb +52 -60
  44. data/lib/sendgrid4r/rest/sm/groups.rb +52 -58
  45. data/lib/sendgrid4r/rest/sm/sm.rb +15 -17
  46. data/lib/sendgrid4r/rest/sm/suppressions.rb +50 -67
  47. data/lib/sendgrid4r/rest/spam_reports.rb +49 -69
  48. data/lib/sendgrid4r/rest/stats/advanced.rb +100 -102
  49. data/lib/sendgrid4r/rest/stats/category.rb +31 -33
  50. data/lib/sendgrid4r/rest/stats/global.rb +17 -19
  51. data/lib/sendgrid4r/rest/stats/parse.rb +18 -20
  52. data/lib/sendgrid4r/rest/stats/stats.rb +59 -69
  53. data/lib/sendgrid4r/rest/stats/subuser.rb +70 -32
  54. data/lib/sendgrid4r/rest/subusers.rb +106 -134
  55. data/lib/sendgrid4r/rest/transactional_templates/templates.rb +63 -0
  56. data/lib/sendgrid4r/rest/transactional_templates/versions.rb +90 -0
  57. data/lib/sendgrid4r/rest/users.rb +125 -57
  58. data/lib/sendgrid4r/rest/webhooks/event.rb +36 -42
  59. data/lib/sendgrid4r/rest/webhooks/parse.rb +28 -37
  60. data/lib/sendgrid4r/rest/whitelabel/domains.rb +176 -222
  61. data/lib/sendgrid4r/rest/whitelabel/ips.rb +107 -128
  62. data/lib/sendgrid4r/rest/whitelabel/links.rb +131 -167
  63. data/lib/sendgrid4r/version.rb +1 -1
  64. data/lib/sendgrid4r.rb +23 -13
  65. data/sendgrid4r.gemspec +1 -1
  66. data/spec/client_spec.rb +12 -1
  67. data/spec/factory/campaign_factory_spec.rb +75 -35
  68. data/spec/factory/condition_factory_spec.rb +19 -18
  69. data/spec/factory/segment_factory_spec.rb +28 -21
  70. data/spec/factory/version_factory_spec.rb +28 -27
  71. data/spec/photo.jpg +0 -0
  72. data/spec/rest/api_keys_management/api_keys_spec.rb +174 -0
  73. data/spec/rest/api_keys_management/permissions_spec.rb +54 -0
  74. data/spec/rest/blocks_spec.rb +78 -106
  75. data/spec/rest/bounces_spec.rb +91 -118
  76. data/spec/rest/cancel_scheduled_sends_spec.rb +94 -149
  77. data/spec/rest/categories_spec.rb +77 -0
  78. data/spec/rest/email_activity_spec.rb +151 -0
  79. data/spec/rest/invalid_emails_spec.rb +85 -119
  80. data/spec/rest/ip_access_management_spec.rb +157 -195
  81. data/spec/rest/ips/addresses_spec.rb +94 -122
  82. data/spec/rest/ips/pools_spec.rb +84 -112
  83. data/spec/rest/ips/warmup_spec.rb +63 -71
  84. data/spec/rest/mail/address_spec.rb +28 -0
  85. data/spec/rest/mail/attachment_spec.rb +48 -0
  86. data/spec/rest/mail/content_spec.rb +32 -0
  87. data/spec/rest/mail/mail_settings_spec.rb +51 -0
  88. data/spec/rest/mail/mail_spec.rb +136 -0
  89. data/spec/rest/mail/params_spec.rb +152 -0
  90. data/spec/rest/mail/personalization_spec.rb +66 -0
  91. data/spec/rest/mail/tracking_settings_spec.rb +63 -0
  92. data/spec/rest/marketing_campaigns/contacts/custom_fields_spec.rb +146 -0
  93. data/spec/rest/marketing_campaigns/contacts/lists_spec.rb +307 -0
  94. data/spec/rest/marketing_campaigns/contacts/recipients_spec.rb +331 -0
  95. data/spec/rest/marketing_campaigns/contacts/reserved_fields_spec.rb +119 -0
  96. data/spec/rest/marketing_campaigns/contacts/segments_spec.rb +268 -0
  97. data/spec/rest/marketing_campaigns/marketing_campaigns_spec.rb +427 -0
  98. data/spec/rest/marketing_campaigns/senders_spec.rb +230 -0
  99. data/spec/rest/settings/enforced_tls_spec.rb +38 -54
  100. data/spec/rest/settings/mail_spec.rb +227 -330
  101. data/spec/rest/settings/partner_spec.rb +40 -59
  102. data/spec/rest/settings/settings_spec.rb +44 -42
  103. data/spec/rest/settings/tracking_spec.rb +130 -189
  104. data/spec/rest/sm/global_unsubscribes_spec.rb +47 -72
  105. data/spec/rest/sm/groups_spec.rb +88 -123
  106. data/spec/rest/sm/sm_spec.rb +32 -30
  107. data/spec/rest/sm/suppressions_spec.rb +105 -140
  108. data/spec/rest/spam_reports_spec.rb +81 -109
  109. data/spec/rest/stats/advanced_spec.rb +67 -125
  110. data/spec/rest/stats/category_spec.rb +27 -45
  111. data/spec/rest/stats/global_spec.rb +34 -42
  112. data/spec/rest/stats/parse_spec.rb +32 -30
  113. data/spec/rest/stats/stats_spec.rb +174 -172
  114. data/spec/rest/stats/subuser_spec.rb +97 -57
  115. data/spec/rest/subusers_spec.rb +156 -209
  116. data/spec/rest/transactional_templates/templates_spec.rb +199 -0
  117. data/spec/rest/transactional_templates/versions_spec.rb +228 -0
  118. data/spec/rest/users_spec.rb +176 -91
  119. data/spec/rest/webhooks/event_spec.rb +59 -85
  120. data/spec/rest/webhooks/parse_spec.rb +51 -71
  121. data/spec/rest/whitelabel/domains_spec.rb +333 -513
  122. data/spec/rest/whitelabel/ips_spec.rb +109 -147
  123. data/spec/rest/whitelabel/links_spec.rb +181 -265
  124. metadata +70 -40
  125. data/lib/sendgrid4r/rest/api_keys/api_keys.rb +0 -80
  126. data/lib/sendgrid4r/rest/api_keys/permissions.rb +0 -33
  127. data/lib/sendgrid4r/rest/campaigns/campaigns.rb +0 -126
  128. data/lib/sendgrid4r/rest/categories/categories.rb +0 -43
  129. data/lib/sendgrid4r/rest/contacts/recipients.rb +0 -150
  130. data/lib/sendgrid4r/rest/contacts/segments.rb +0 -97
  131. data/lib/sendgrid4r/rest/email_activity/email_activity.rb +0 -81
  132. data/lib/sendgrid4r/rest/templates/templates.rb +0 -69
  133. data/lib/sendgrid4r/rest/templates/versions.rb +0 -95
  134. data/spec/rest/api_keys/api_keys_spec.rb +0 -210
  135. data/spec/rest/api_keys/permissions_spec.rb +0 -65
  136. data/spec/rest/campaigns/campaigns_spec.rb +0 -492
  137. data/spec/rest/categories/categories_spec.rb +0 -96
  138. data/spec/rest/contacts/custom_fields_spec.rb +0 -174
  139. data/spec/rest/contacts/lists_spec.rb +0 -372
  140. data/spec/rest/contacts/recipients_spec.rb +0 -343
  141. data/spec/rest/contacts/reserved_fields_spec.rb +0 -146
  142. data/spec/rest/contacts/segments_spec.rb +0 -307
  143. data/spec/rest/email_activity/email_activity_spec.rb +0 -179
  144. data/spec/rest/templates/templates_spec.rb +0 -222
  145. data/spec/rest/templates/versions_spec.rb +0 -252
@@ -1,75 +1,66 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
 
3
- module SendGrid4r
4
- module REST
3
+ module SendGrid4r::REST
4
+ #
5
+ # SendGrid Web API v3 Ip Management
6
+ #
7
+ module Ips
5
8
  #
6
- # SendGrid Web API v3 Ip Management
9
+ # SendGrid Web API v3 Ip Management - Pools
7
10
  #
8
- module Ips
9
- #
10
- # SendGrid Web API v3 Ip Management - Pools
11
- #
12
- module Addresses
13
- include SendGrid4r::REST::Request
11
+ module Addresses
12
+ include Request
14
13
 
15
- Address = Struct.new(
16
- :ip, :pools, :warmup, :start_date, :subusers, :rdns, :pool_name)
14
+ Address = Struct.new(
15
+ :ip, :pools, :warmup, :start_date, :subusers, :rdns, :pool_name
16
+ )
17
17
 
18
- def self.create_addresses(resp)
19
- return resp if resp.nil?
20
- ips = []
21
- resp.each do |address|
22
- ips.push(SendGrid4r::REST::Ips::Addresses.create_address(address))
23
- end
24
- ips
25
- end
18
+ def self.create_addresses(resp)
19
+ return resp if resp.nil?
20
+ resp.map { |address| Ips::Addresses.create_address(address) }
21
+ end
26
22
 
27
- def self.create_address(resp)
28
- return resp if resp.nil?
29
- Address.new(
30
- resp['ip'],
31
- resp['pools'],
32
- resp['warmup'],
33
- resp['start_date'].nil? ? nil : Time.at(resp['start_date']),
34
- resp['subusers'],
35
- resp['rdns'],
36
- resp['pool_name']
37
- )
38
- end
23
+ def self.create_address(resp)
24
+ return resp if resp.nil?
25
+ Address.new(
26
+ resp['ip'],
27
+ resp['pools'],
28
+ resp['warmup'],
29
+ resp['start_date'].nil? ? nil : Time.at(resp['start_date']),
30
+ resp['subusers'],
31
+ resp['rdns'],
32
+ resp['pool_name']
33
+ )
34
+ end
39
35
 
40
- def self.url(ip = nil)
41
- url = "#{BASE_URL}/ips"
42
- url = "#{url}/#{ip}" unless ip.nil?
43
- url
44
- end
36
+ def self.url(ip = nil)
37
+ url = "#{BASE_URL}/ips"
38
+ url = "#{url}/#{ip}" unless ip.nil?
39
+ url
40
+ end
45
41
 
46
- def post_ip_to_pool(pool_name:, ip:, &block)
47
- endpoint = SendGrid4r::REST::Ips::Pools.url(pool_name, 'ips')
48
- resp = post(@auth, endpoint, ip: ip, &block)
49
- SendGrid4r::REST::Ips::Addresses.create_address(resp)
50
- end
42
+ def post_ip_to_pool(pool_name:, ip:, &block)
43
+ resp = post(@auth, Ips::Pools.url(pool_name, :ips), ip: ip, &block)
44
+ Ips::Addresses.create_address(resp)
45
+ end
51
46
 
52
- def get_ips(&block)
53
- resp = get(@auth, SendGrid4r::REST::Ips::Addresses.url, &block)
54
- SendGrid4r::REST::Ips::Addresses.create_addresses(resp)
55
- end
47
+ def get_ips(&block)
48
+ resp = get(@auth, Ips::Addresses.url, &block)
49
+ Ips::Addresses.create_addresses(resp)
50
+ end
56
51
 
57
- def get_ips_assigned(&block)
58
- endpoint = SendGrid4r::REST::Ips::Addresses.url('assigned')
59
- resp = get(@auth, endpoint, &block)
60
- SendGrid4r::REST::Ips::Addresses.create_addresses(resp)
61
- end
52
+ def get_ips_assigned(&block)
53
+ resp = get(@auth, Ips::Addresses.url(:assigned), &block)
54
+ Ips::Addresses.create_addresses(resp)
55
+ end
62
56
 
63
- def get_ip(ip:, &block)
64
- endpoint = SendGrid4r::REST::Ips::Addresses.url(ip)
65
- resp = get(@auth, endpoint, &block)
66
- SendGrid4r::REST::Ips::Addresses.create_address(resp)
67
- end
57
+ def get_ip(ip:, &block)
58
+ resp = get(@auth, Ips::Addresses.url(ip), &block)
59
+ Ips::Addresses.create_address(resp)
60
+ end
68
61
 
69
- def delete_ip_from_pool(pool_name:, ip:, &block)
70
- endpoint = SendGrid4r::REST::Ips::Pools.url(pool_name, 'ips', ip)
71
- delete(@auth, endpoint, &block)
72
- end
62
+ def delete_ip_from_pool(pool_name:, ip:, &block)
63
+ delete(@auth, Ips::Pools.url(pool_name, :ips, ip), &block)
73
64
  end
74
65
  end
75
66
  end
@@ -1,69 +1,58 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
 
3
- module SendGrid4r
4
- module REST
3
+ module SendGrid4r::REST
4
+ #
5
+ # SendGrid Web API v3 Ip Management
6
+ #
7
+ module Ips
5
8
  #
6
- # SendGrid Web API v3 Ip Management
9
+ # SendGrid Web API v3 Ip Management - Pools
7
10
  #
8
- module Ips
9
- #
10
- # SendGrid Web API v3 Ip Management - Pools
11
- #
12
- module Pools
13
- include SendGrid4r::REST::Request
11
+ module Pools
12
+ include Request
14
13
 
15
- Pool = Struct.new(:pool_name, :name, :ips)
14
+ Pool = Struct.new(:pool_name, :name, :ips)
16
15
 
17
- def self.create_pools(resp)
18
- return resp if resp.nil?
19
- pools = []
20
- resp.each do |pool|
21
- pools.push(SendGrid4r::REST::Ips::Pools.create_pool(pool))
22
- end
23
- pools
24
- end
16
+ def self.create_pools(resp)
17
+ return resp if resp.nil?
18
+ resp.map { |pool| Ips::Pools.create_pool(pool) }
19
+ end
25
20
 
26
- def self.create_pool(resp)
27
- return resp if resp.nil?
28
- ips = []
29
- Array(resp['ips']).each { |ip| ips.push(ip) }
30
- Pool.new(resp['pool_name'], resp['name'], ips)
31
- end
21
+ def self.create_pool(resp)
22
+ return resp if resp.nil?
23
+ Pool.new(resp['pool_name'], resp['name'], resp['ips'])
24
+ end
32
25
 
33
- def self.url(name = nil, ips = nil, ip = nil)
34
- url = "#{BASE_URL}/ips/pools"
35
- url = "#{url}/#{name}" unless name.nil?
36
- url = "#{url}/#{ips}" unless ips.nil?
37
- url = "#{url}/#{ip}" unless ip.nil?
38
- url
39
- end
26
+ def self.url(name = nil, ips = nil, ip = nil)
27
+ url = "#{BASE_URL}/ips/pools"
28
+ url = "#{url}/#{name}" unless name.nil?
29
+ url = "#{url}/#{ips}" unless ips.nil?
30
+ url = "#{url}/#{ip}" unless ip.nil?
31
+ url
32
+ end
40
33
 
41
- def post_pool(name:, &block)
42
- endpoint = SendGrid4r::REST::Ips::Pools.url
43
- resp = post(@auth, endpoint, name: name, &block)
44
- SendGrid4r::REST::Ips::Pools.create_pool(resp)
45
- end
34
+ def post_pool(name:, &block)
35
+ resp = post(@auth, Ips::Pools.url, name: name, &block)
36
+ Ips::Pools.create_pool(resp)
37
+ end
46
38
 
47
- def get_pools(&block)
48
- resp = get(@auth, SendGrid4r::REST::Ips::Pools.url, &block)
49
- SendGrid4r::REST::Ips::Pools.create_pools(resp)
50
- end
39
+ def get_pools(&block)
40
+ resp = get(@auth, Ips::Pools.url, &block)
41
+ Ips::Pools.create_pools(resp)
42
+ end
51
43
 
52
- def get_pool(name:, &block)
53
- endpoint = SendGrid4r::REST::Ips::Pools.url(name)
54
- resp = get(@auth, endpoint, &block)
55
- SendGrid4r::REST::Ips::Pools.create_pool(resp)
56
- end
44
+ def get_pool(name:, &block)
45
+ resp = get(@auth, Ips::Pools.url(name), &block)
46
+ Ips::Pools.create_pool(resp)
47
+ end
57
48
 
58
- def put_pool(name:, new_name:, &block)
59
- endpoint = SendGrid4r::REST::Ips::Pools.url(name)
60
- resp = put(@auth, endpoint, name: new_name, &block)
61
- SendGrid4r::REST::Ips::Pools.create_pool(resp)
62
- end
49
+ def put_pool(name:, new_name:, &block)
50
+ resp = put(@auth, Ips::Pools.url(name), name: new_name, &block)
51
+ Ips::Pools.create_pool(resp)
52
+ end
63
53
 
64
- def delete_pool(name:, &block)
65
- delete(@auth, SendGrid4r::REST::Ips::Pools.url(name), &block)
66
- end
54
+ def delete_pool(name:, &block)
55
+ delete(@auth, Ips::Pools.url(name), &block)
67
56
  end
68
57
  end
69
58
  end
@@ -1,60 +1,51 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
 
3
- module SendGrid4r
4
- module REST
5
- module Ips
6
- #
7
- # SendGrid Web API v3 Ip Management - Warmup
8
- #
9
- module Warmup
10
- include SendGrid4r::REST::Request
11
-
12
- WarmupIp = Struct.new(:ip, :start_date)
13
-
14
- def self.create_warmup_ips(resp)
15
- return resp if resp.nil?
16
- ips = []
17
- resp.each do |warmup_ip|
18
- ips.push(SendGrid4r::REST::Ips::Warmup.create_warmup_ip(warmup_ip))
19
- end
20
- ips
21
- end
22
-
23
- def self.create_warmup_ip(resp)
24
- return resp if resp.nil?
25
- WarmupIp.new(
26
- resp['ip'],
27
- resp['start_date'].nil? ? nil : Time.at(resp['start_date'])
28
- )
29
- end
30
-
31
- def self.url(ip_address = nil)
32
- url = "#{BASE_URL}/ips/warmup"
33
- url = "#{url}/#{ip_address}" unless ip_address.nil?
34
- url
35
- end
36
-
37
- def get_warmup_ips(&block)
38
- resp = get(@auth, SendGrid4r::REST::Ips::Warmup.url, &block)
39
- SendGrid4r::REST::Ips::Warmup.create_warmup_ips(resp)
40
- end
41
-
42
- def get_warmup_ip(ip:, &block)
43
- endpoint = SendGrid4r::REST::Ips::Warmup.url(ip)
44
- resp = get(@auth, endpoint, &block)
45
- SendGrid4r::REST::Ips::Warmup.create_warmup_ip(resp)
46
- end
47
-
48
- def post_warmup_ip(ip:, &block)
49
- endpoint = SendGrid4r::REST::Ips::Warmup.url
50
- resp = post(@auth, endpoint, ip: ip, &block)
51
- SendGrid4r::REST::Ips::Warmup.create_warmup_ip(resp)
52
- end
53
-
54
- def delete_warmup_ip(ip:, &block)
55
- endpoint = SendGrid4r::REST::Ips::Warmup.url(ip)
56
- delete(@auth, endpoint, &block)
57
- end
3
+ module SendGrid4r::REST
4
+ module Ips
5
+ #
6
+ # SendGrid Web API v3 Ip Management - Warmup
7
+ #
8
+ module Warmup
9
+ include Request
10
+
11
+ WarmupIp = Struct.new(:ip, :start_date)
12
+
13
+ def self.create_warmup_ips(resp)
14
+ return resp if resp.nil?
15
+ resp.map { |warmup_ip| Ips::Warmup.create_warmup_ip(warmup_ip) }
16
+ end
17
+
18
+ def self.create_warmup_ip(resp)
19
+ return resp if resp.nil?
20
+ WarmupIp.new(
21
+ resp['ip'],
22
+ resp['start_date'].nil? ? nil : Time.at(resp['start_date'])
23
+ )
24
+ end
25
+
26
+ def self.url(ip_address = nil)
27
+ url = "#{BASE_URL}/ips/warmup"
28
+ url = "#{url}/#{ip_address}" unless ip_address.nil?
29
+ url
30
+ end
31
+
32
+ def get_warmup_ips(&block)
33
+ resp = get(@auth, Ips::Warmup.url, &block)
34
+ Ips::Warmup.create_warmup_ips(resp)
35
+ end
36
+
37
+ def get_warmup_ip(ip:, &block)
38
+ resp = get(@auth, Ips::Warmup.url(ip), &block)
39
+ Ips::Warmup.create_warmup_ip(resp)
40
+ end
41
+
42
+ def post_warmup_ip(ip:, &block)
43
+ resp = post(@auth, Ips::Warmup.url, ip: ip, &block)
44
+ Ips::Warmup.create_warmup_ip(resp)
45
+ end
46
+
47
+ def delete_warmup_ip(ip:, &block)
48
+ delete(@auth, Ips::Warmup.url(ip), &block)
58
49
  end
59
50
  end
60
51
  end
@@ -0,0 +1,14 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ module SendGrid4r::REST
4
+ #
5
+ # SendGrid Web API v3 Mail
6
+ #
7
+ module Mail
8
+ Address = Struct.new(:email, :name) do
9
+ def to_h
10
+ super.reject { |_key, value| value.nil? }
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require 'base64'
4
+
5
+ module SendGrid4r::REST
6
+ #
7
+ # SendGrid Web API v3 Mail
8
+ #
9
+ module Mail
10
+ Attachment = Struct.new(
11
+ :content, :filename, :type, :disposition, :content_id
12
+ ) do
13
+ def content=(content)
14
+ tap { |s| s[:content] = Base64.strict_encode64(content) }
15
+ end
16
+
17
+ def to_h
18
+ super.reject { |_key, value| value.nil? }
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,10 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ module SendGrid4r::REST
4
+ #
5
+ # SendGrid Web API v3 Mail
6
+ #
7
+ module Mail
8
+ Content = Struct.new(:type, :value)
9
+ end
10
+ end
@@ -0,0 +1,28 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ module SendGrid4r::REST
4
+ #
5
+ # SendGrid Web API v3 Mail
6
+ #
7
+ module Mail
8
+ include Request
9
+
10
+ def self.url
11
+ "#{BASE_URL}/mail/send/beta"
12
+ end
13
+
14
+ def self.warn_beta
15
+ warn(
16
+ '[WARN] Mail endpoint is currently in beta! Do not use '\
17
+ 'this method in production. When this endpoint is ready for '\
18
+ 'general release, your code might require an update in order to '\
19
+ 'use the official one.'
20
+ )
21
+ end
22
+
23
+ def send(params:, &block)
24
+ Mail.warn_beta
25
+ post(@auth, Mail.url, params.to_h, &block)
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,62 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ module SendGrid4r::REST
4
+ #
5
+ # SendGrid Web API v3 Mail
6
+ #
7
+ module Mail
8
+ MailSettings = Struct.new(
9
+ :bcc, :bypass_list_management, :footer, :sandbox_mode, :spam_check
10
+ ) do
11
+ def enable_bcc(email)
12
+ tap { |s| s[:bcc] = { enable: true, email: email } }
13
+ end
14
+
15
+ def disable_bcc
16
+ tap { |s| s[:bcc] = { enable: false } }
17
+ end
18
+
19
+ def enable_bypass_list_management
20
+ tap { |s| s[:bypass_list_management] = { enable: true } }
21
+ end
22
+
23
+ def disable_bypass_list_management
24
+ tap { |s| s[:bypass_list_management] = { enable: false } }
25
+ end
26
+
27
+ def enable_footer(text, html)
28
+ tap { |s| s[:footer] = { enable: true, text: text, html: html } }
29
+ end
30
+
31
+ def disable_footer
32
+ tap { |s| s[:footer] = { enable: false } }
33
+ end
34
+
35
+ def enable_sandbox_mode
36
+ tap { |s| s[:sandbox_mode] = { enable: true } }
37
+ end
38
+
39
+ def disable_sandbox_mode
40
+ tap { |s| s[:sandbox_mode] = { enable: false } }
41
+ end
42
+
43
+ def enable_spam_check(threshold, post_to_url)
44
+ tap do |s|
45
+ s[:spam_check] = {
46
+ enable: true,
47
+ threshold: threshold,
48
+ post_to_url: post_to_url
49
+ }
50
+ end
51
+ end
52
+
53
+ def disable_spam_check
54
+ tap { |s| s[:spam_check] = { enable: false } }
55
+ end
56
+
57
+ def to_h
58
+ super.reject { |_key, value| value.nil? }
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,64 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ module SendGrid4r::REST
4
+ #
5
+ # SendGrid Web API v3 Mail
6
+ #
7
+ module Mail
8
+ Params = Struct.new(
9
+ :personalizations, :from, :content, :reply_to, :attachments,
10
+ :template_id, :sections, :headers, :categories, :custom_args,
11
+ :send_at, :batch_id, :asm, :ip_pool_name, :mail_settings,
12
+ :tracking_settings, :subject
13
+ ) do
14
+ def personalizations=(personalizations)
15
+ tap do |s|
16
+ s[:personalizations] = personalizations.map(&:to_h)
17
+ end
18
+ end
19
+
20
+ def from=(from)
21
+ tap { |s| s[:from] = from.to_h }
22
+ end
23
+
24
+ def content=(content)
25
+ tap { |s| s[:content] = content.map(&:to_h) }
26
+ end
27
+
28
+ def reply_to=(reply_to)
29
+ tap { |s| s[:reply_to] = reply_to.to_h }
30
+ end
31
+
32
+ def attachments=(attachments)
33
+ tap { |s| s[:attachments] = attachments.map(&:to_h) }
34
+ end
35
+
36
+ def send_at=(send_at)
37
+ tap { |s| s[:send_at] = send_at.to_i }
38
+ end
39
+
40
+ def asm=(asm)
41
+ if asm.is_a?(Fixnum)
42
+ tap { |s| s[:asm] = { group_id: asm } }
43
+ elsif asm.is_a?(Array)
44
+ tap do |s|
45
+ s[:asm] = { group_id: asm[0] }
46
+ s[:asm][:groups_to_display] = asm[1]
47
+ end
48
+ end
49
+ end
50
+
51
+ def mail_settings=(mail_settings)
52
+ tap { |s| s[:mail_settings] = mail_settings.to_h }
53
+ end
54
+
55
+ def tracking_settings=(tracking_settings)
56
+ tap { |s| s[:tracking_settings] = tracking_settings.to_h }
57
+ end
58
+
59
+ def to_h
60
+ super.reject { |_key, value| value.nil? }
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,33 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ module SendGrid4r::REST
4
+ #
5
+ # SendGrid Web API v3 Mail
6
+ #
7
+ module Mail
8
+ Personalization = Struct.new(
9
+ :to, :subject, :cc, :bcc, :headers, :substitutions, :custom_args,
10
+ :send_at
11
+ ) do
12
+ def to=(to)
13
+ tap { |s| s[:to] = to.map(&:to_h) }
14
+ end
15
+
16
+ def cc=(cc)
17
+ tap { |s| s[:cc] = cc.map(&:to_h) }
18
+ end
19
+
20
+ def bcc=(bcc)
21
+ tap { |s| s[:bcc] = bcc.map(&:to_h) }
22
+ end
23
+
24
+ def send_at=(send_at)
25
+ tap { |s| s[:send_at] = send_at.to_i }
26
+ end
27
+
28
+ def to_h
29
+ super.reject { |_key, value| value.nil? }
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,74 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ module SendGrid4r::REST
4
+ #
5
+ # SendGrid Web API v3 Mail
6
+ #
7
+ module Mail
8
+ TrackingSettings = Struct.new(
9
+ :click_tracking, :open_tracking, :subscription_tracking,
10
+ :ganalytics
11
+ ) do
12
+ def enable_click_tracking(enable_text)
13
+ tap do |s|
14
+ s[:click_tracking] = { enable: true, enable_text: enable_text }
15
+ end
16
+ end
17
+
18
+ def disable_click_tracking
19
+ tap { |s| s[:click_tracking] = { enable: false } }
20
+ end
21
+
22
+ def enable_open_tracking(substitution_tag)
23
+ tap do |s|
24
+ s[:open_tracking] = {
25
+ enable: true,
26
+ substitution_tag: substitution_tag
27
+ }
28
+ end
29
+ end
30
+
31
+ def disable_open_tracking
32
+ tap { |s| s[:open_tracking] = { enable: false } }
33
+ end
34
+
35
+ def enable_subscription_tracking(text, html, substitution_tag)
36
+ tap do |s|
37
+ s[:subscription_tracking] = {
38
+ enable: true,
39
+ text: text,
40
+ html: html,
41
+ substitution_tag: substitution_tag
42
+ }
43
+ end
44
+ end
45
+
46
+ def disable_subscription_tracking
47
+ tap { |s| s[:subscription_tracking] = { enable: false } }
48
+ end
49
+
50
+ def enable_ganalytics(
51
+ utm_source, utm_medium, utm_term, utm_content, utm_campaign
52
+ )
53
+ tap do |s|
54
+ s[:ganalytics] = {
55
+ enable: true,
56
+ utm_source: utm_source,
57
+ utm_medium: utm_medium,
58
+ utm_term: utm_term,
59
+ utm_content: utm_content,
60
+ utm_campaign: utm_campaign
61
+ }
62
+ end
63
+ end
64
+
65
+ def disable_ganalytics
66
+ tap { |s| s[:ganalytics] = { enable: false } }
67
+ end
68
+
69
+ def to_h
70
+ super.reject { |_key, value| value.nil? }
71
+ end
72
+ end
73
+ end
74
+ end