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,29 +1,24 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
 
3
- module SendGrid4r
4
- module REST
5
- #
6
- # SendGrid Web API v3 Settings
7
- #
8
- module Settings
9
- Results = Struct.new(:result)
10
- Result = Struct.new(:name, :title, :description, :enabled)
3
+ module SendGrid4r::REST
4
+ #
5
+ # SendGrid Web API v3 Settings
6
+ #
7
+ module Settings
8
+ Results = Struct.new(:result)
9
+ Result = Struct.new(:name, :title, :description, :enabled)
11
10
 
12
- def self.create_results(resp)
13
- return resp if resp.nil?
14
- results = []
15
- resp['result'].each do |result|
16
- results.push(SendGrid4r::REST::Settings.create_result(result))
17
- end
18
- Results.new(results)
19
- end
11
+ def self.create_results(resp)
12
+ return resp if resp.nil?
13
+ results = resp['result'].map { |result| Settings.create_result(result) }
14
+ Results.new(results)
15
+ end
20
16
 
21
- def self.create_result(resp)
22
- return resp if resp.nil?
23
- Result.new(
24
- resp['name'], resp['title'], resp['description'], resp['enabled']
25
- )
26
- end
17
+ def self.create_result(resp)
18
+ return resp if resp.nil?
19
+ Result.new(
20
+ resp['name'], resp['title'], resp['description'], resp['enabled']
21
+ )
27
22
  end
28
23
  end
29
24
  end
@@ -1,119 +1,109 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
 
3
- module SendGrid4r
4
- module REST
5
- module Settings
6
- #
7
- # SendGrid Web API v3 Settings - Tracking
8
- #
9
- module Tracking
10
- include SendGrid4r::REST::Request
11
-
12
- Click = Struct.new(:enabled)
13
-
14
- def self.create_click(resp)
15
- return resp if resp.nil?
16
- Click.new(resp['enabled'])
17
- end
18
-
19
- GoogleAnalytics = Struct.new(
20
- :enabled, :utm_source, :utm_medium, :utm_term, :utm_content,
21
- :utm_campaign
3
+ module SendGrid4r::REST
4
+ module Settings
5
+ #
6
+ # SendGrid Web API v3 Settings - Tracking
7
+ #
8
+ module Tracking
9
+ include Request
10
+
11
+ Click = Struct.new(:enabled)
12
+
13
+ def self.create_click(resp)
14
+ return resp if resp.nil?
15
+ Click.new(resp['enabled'])
16
+ end
17
+
18
+ GoogleAnalytics = Struct.new(
19
+ :enabled, :utm_source, :utm_medium, :utm_term, :utm_content,
20
+ :utm_campaign
21
+ )
22
+
23
+ def self.create_google_analytics(resp)
24
+ return resp if resp.nil?
25
+ GoogleAnalytics.new(
26
+ resp['enabled'], resp['utm_source'], resp['utm_medium'],
27
+ resp['utm_term'], resp['utm_content'], resp['utm_campaign']
22
28
  )
29
+ end
23
30
 
24
- def self.create_google_analytics(resp)
25
- return resp if resp.nil?
26
- GoogleAnalytics.new(
27
- resp['enabled'], resp['utm_source'], resp['utm_medium'],
28
- resp['utm_term'], resp['utm_content'], resp['utm_campaign']
29
- )
30
- end
31
+ Open = Struct.new(:enabled)
31
32
 
32
- Open = Struct.new(:enabled)
33
+ def self.create_open(resp)
34
+ return resp if resp.nil?
35
+ Open.new(resp['enabled'])
36
+ end
33
37
 
34
- def self.create_open(resp)
35
- return resp if resp.nil?
36
- Open.new(resp['enabled'])
37
- end
38
+ Subscription = Struct.new(
39
+ :enabled, :landing, :url, :replace, :html_content, :plain_content
40
+ )
38
41
 
39
- Subscription = Struct.new(
40
- :enabled, :landing, :url, :replace, :html_content, :plain_content
42
+ def self.create_subscription(resp)
43
+ return resp if resp.nil?
44
+ Subscription.new(
45
+ resp['enabled'], resp['landing'], resp['url'], resp['replace'],
46
+ resp['html_content'], resp['plain_content']
41
47
  )
48
+ end
49
+
50
+ def self.url(name = nil)
51
+ url = "#{BASE_URL}/tracking_settings"
52
+ url = "#{url}/#{name}" unless name.nil?
53
+ url
54
+ end
55
+
56
+ def get_tracking_settings(limit: nil, offset: nil, &block)
57
+ params = {}
58
+ params[:limit] = limit unless limit.nil?
59
+ params[:offset] = offset unless offset.nil?
60
+ resp = get(@auth, Settings::Tracking.url, params, &block)
61
+ Settings.create_results(resp)
62
+ end
63
+
64
+ def get_settings_click(&block)
65
+ resp = get(@auth, Settings::Tracking.url(:click), &block)
66
+ Settings::Tracking.create_click(resp)
67
+ end
68
+
69
+ def patch_settings_click(params:, &block)
70
+ endpoint = Settings::Tracking.url(:click)
71
+ resp = patch(@auth, endpoint, params.to_h, &block)
72
+ Settings::Tracking.create_click(resp)
73
+ end
74
+
75
+ def get_settings_google_analytics(&block)
76
+ endpoint = Settings::Tracking.url(:google_analytics)
77
+ resp = get(@auth, endpoint, &block)
78
+ Settings::Tracking.create_google_analytics(resp)
79
+ end
80
+
81
+ def patch_settings_google_analytics(params:, &block)
82
+ endpoint = Settings::Tracking.url(:google_analytics)
83
+ resp = patch(@auth, endpoint, params.to_h, &block)
84
+ Settings::Tracking.create_google_analytics(resp)
85
+ end
86
+
87
+ def get_settings_open(&block)
88
+ resp = get(@auth, Settings::Tracking.url(:open), &block)
89
+ Settings::Tracking.create_open(resp)
90
+ end
91
+
92
+ def patch_settings_open(params:, &block)
93
+ resp = patch(@auth, Settings::Tracking.url(:open), params.to_h, &block)
94
+ Settings::Tracking.create_open(resp)
95
+ end
96
+
97
+ def get_settings_subscription(&block)
98
+ endpoint = Settings::Tracking.url(:subscription)
99
+ resp = get(@auth, endpoint, &block)
100
+ Settings::Tracking.create_subscription(resp)
101
+ end
42
102
 
43
- def self.create_subscription(resp)
44
- return resp if resp.nil?
45
- Subscription.new(
46
- resp['enabled'], resp['landing'], resp['url'], resp['replace'],
47
- resp['html_content'], resp['plain_content']
48
- )
49
- end
50
-
51
- def self.url(name = nil)
52
- url = "#{BASE_URL}/tracking_settings"
53
- url = "#{url}/#{name}" unless name.nil?
54
- url
55
- end
56
-
57
- def get_tracking_settings(limit: nil, offset: nil, &block)
58
- params = {}
59
- params['limit'] = limit unless limit.nil?
60
- params['offset'] = offset unless offset.nil?
61
- endpoint = SendGrid4r::REST::Settings::Tracking.url
62
- resp = get(@auth, endpoint, params, &block)
63
- SendGrid4r::REST::Settings.create_results(resp)
64
- end
65
-
66
- def get_settings_click(&block)
67
- endpoint = SendGrid4r::REST::Settings::Tracking.url('click')
68
- resp = get(@auth, endpoint, &block)
69
- SendGrid4r::REST::Settings::Tracking.create_click(resp)
70
- end
71
-
72
- def patch_settings_click(params:, &block)
73
- endpoint = SendGrid4r::REST::Settings::Tracking.url('click')
74
- resp = patch(@auth, endpoint, params.to_h, &block)
75
- SendGrid4r::REST::Settings::Tracking.create_click(resp)
76
- end
77
-
78
- def get_settings_google_analytics(&block)
79
- endpoint = SendGrid4r::REST::Settings::Tracking.url(
80
- 'google_analytics'
81
- )
82
- resp = get(@auth, endpoint, &block)
83
- SendGrid4r::REST::Settings::Tracking.create_google_analytics(resp)
84
- end
85
-
86
- def patch_settings_google_analytics(params:, &block)
87
- endpoint = SendGrid4r::REST::Settings::Tracking.url(
88
- 'google_analytics'
89
- )
90
- resp = patch(@auth, endpoint, params.to_h, &block)
91
- SendGrid4r::REST::Settings::Tracking.create_google_analytics(resp)
92
- end
93
-
94
- def get_settings_open(&block)
95
- endpoint = SendGrid4r::REST::Settings::Tracking.url('open')
96
- resp = get(@auth, endpoint, &block)
97
- SendGrid4r::REST::Settings::Tracking.create_open(resp)
98
- end
99
-
100
- def patch_settings_open(params:, &block)
101
- endpoint = SendGrid4r::REST::Settings::Tracking.url('open')
102
- resp = patch(@auth, endpoint, params.to_h, &block)
103
- SendGrid4r::REST::Settings::Tracking.create_open(resp)
104
- end
105
-
106
- def get_settings_subscription(&block)
107
- endpoint = SendGrid4r::REST::Settings::Tracking.url('subscription')
108
- resp = get(@auth, endpoint, &block)
109
- SendGrid4r::REST::Settings::Tracking.create_subscription(resp)
110
- end
111
-
112
- def patch_settings_subscription(params:, &block)
113
- endpoint = SendGrid4r::REST::Settings::Tracking.url('subscription')
114
- resp = patch(@auth, endpoint, params.to_h, &block)
115
- SendGrid4r::REST::Settings::Tracking.create_subscription(resp)
116
- end
103
+ def patch_settings_subscription(params:, &block)
104
+ endpoint = Settings::Tracking.url(:subscription)
105
+ resp = patch(@auth, endpoint, params.to_h, &block)
106
+ Settings::Tracking.create_subscription(resp)
117
107
  end
118
108
  end
119
109
  end
@@ -1,75 +1,67 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
 
3
- module SendGrid4r
4
- module REST
5
- module Sm
6
- #
7
- # SendGrid Web API v3 Suppression Management - Global Unsubscribes
8
- #
9
- module GlobalUnsubscribes
10
- include SendGrid4r::REST::Request
3
+ module SendGrid4r::REST
4
+ module Sm
5
+ #
6
+ # SendGrid Web API v3 Suppression Management - Global Unsubscribes
7
+ #
8
+ module GlobalUnsubscribes
9
+ include Request
11
10
 
12
- Unsubscribe = Struct.new(:created, :email)
11
+ Unsubscribe = Struct.new(:created, :email)
13
12
 
14
- def self.url(email_address = nil)
15
- url = "#{BASE_URL}/asm/suppressions/global"
16
- url = "#{url}/#{email_address}" unless email_address.nil?
17
- url
18
- end
19
-
20
- def self.url_unsubscribes
21
- "#{BASE_URL}/suppression/unsubscribes"
22
- end
13
+ def self.url(email_address = nil)
14
+ url = "#{BASE_URL}/asm/suppressions/global"
15
+ url = "#{url}/#{email_address}" unless email_address.nil?
16
+ url
17
+ end
23
18
 
24
- def self.create_supressions(resp)
25
- return resp if resp.nil?
26
- suppressions = []
27
- resp.each do |suppression|
28
- created = Time.at(suppression['created'])
29
- suppressions.push(Unsubscribe.new(created, suppression['email']))
30
- end
31
- suppressions
32
- end
19
+ def self.url_unsubscribes
20
+ "#{BASE_URL}/suppression/unsubscribes"
21
+ end
33
22
 
34
- def get_global_unsubscribes(
35
- start_time: nil, end_time: nil, limit: nil, offset: nil, &block
36
- )
37
- params = {}
38
- params['start_time'] = start_time.to_i unless start_time.nil?
39
- params['end_time'] = end_time.to_i unless end_time.nil?
40
- params['limit'] = limit.to_i unless limit.nil?
41
- params['offset'] = offset.to_i unless offset.nil?
42
- endpoint = SendGrid4r::REST::Sm::GlobalUnsubscribes.url_unsubscribes
43
- resp = get(@auth, endpoint, params, &block)
44
- SendGrid4r::REST::Sm::GlobalUnsubscribes.create_supressions(resp)
23
+ def self.create_supressions(resp)
24
+ return resp if resp.nil?
25
+ resp.map do |suppression|
26
+ created = Time.at(suppression['created'])
27
+ Unsubscribe.new(created, suppression['email'])
45
28
  end
29
+ end
46
30
 
47
- def post_global_suppressed_emails(recipient_emails:, &block)
48
- params = { recipient_emails: recipient_emails }
49
- endpoint = SendGrid4r::REST::Sm::GlobalUnsubscribes.url
50
- resp = post(@auth, endpoint, params, &block)
51
- SendGrid4r::REST::Sm.create_recipient_emails(resp)
52
- end
31
+ def get_global_unsubscribes(
32
+ start_time: nil, end_time: nil, limit: nil, offset: nil, &block
33
+ )
34
+ params = {}
35
+ params[:start_time] = start_time.to_i unless start_time.nil?
36
+ params[:end_time] = end_time.to_i unless end_time.nil?
37
+ params[:limit] = limit.to_i unless limit.nil?
38
+ params[:offset] = offset.to_i unless offset.nil?
39
+ endpoint = Sm::GlobalUnsubscribes.url_unsubscribes
40
+ resp = get(@auth, endpoint, params, &block)
41
+ Sm::GlobalUnsubscribes.create_supressions(resp)
42
+ end
53
43
 
54
- def get_global_suppressed_email(email_address:, &block)
55
- endpoint =
56
- SendGrid4r::REST::Sm::GlobalUnsubscribes.url(email_address)
57
- resp = get(@auth, endpoint, &block)
58
- SendGrid4r::REST::Sm.create_recipient_email(resp)
59
- end
44
+ def post_global_suppressed_emails(recipient_emails:, &block)
45
+ params = { recipient_emails: recipient_emails }
46
+ endpoint = Sm::GlobalUnsubscribes.url
47
+ resp = post(@auth, endpoint, params, &block)
48
+ Sm.create_recipient_emails(resp)
49
+ end
60
50
 
61
- def delete_global_suppressed_email(email_address:, &block)
62
- endpoint =
63
- SendGrid4r::REST::Sm::GlobalUnsubscribes.url(email_address)
64
- delete(@auth, endpoint, &block)
65
- end
51
+ def get_global_suppressed_email(email_address:, &block)
52
+ resp = get(@auth, Sm::GlobalUnsubscribes.url(email_address), &block)
53
+ Sm.create_recipient_email(resp)
54
+ end
66
55
 
67
- alias_method(:post_global_unsubscribes, :post_global_suppressed_emails)
68
- alias_method(:get_global_unsubscribe, :get_global_suppressed_email)
69
- alias_method(
70
- :delete_global_unsubscribe, :delete_global_suppressed_email
71
- )
56
+ def delete_global_suppressed_email(email_address:, &block)
57
+ delete(@auth, Sm::GlobalUnsubscribes.url(email_address), &block)
72
58
  end
59
+
60
+ alias_method(:post_global_unsubscribes, :post_global_suppressed_emails)
61
+ alias_method(:get_global_unsubscribe, :get_global_suppressed_email)
62
+ alias_method(
63
+ :delete_global_unsubscribe, :delete_global_suppressed_email
64
+ )
73
65
  end
74
66
  end
75
67
  end
@@ -1,72 +1,66 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
 
3
- module SendGrid4r
4
- module REST
5
- module Sm
6
- #
7
- # SendGrid Web API v3 Suppression Management - Groups
8
- #
9
- module Groups
10
- include SendGrid4r::REST::Request
3
+ module SendGrid4r::REST
4
+ module Sm
5
+ #
6
+ # SendGrid Web API v3 Suppression Management - Groups
7
+ #
8
+ module Groups
9
+ include Request
11
10
 
12
- Group = Struct.new(
13
- :id, :name, :description, :last_email_sent_at, :is_default,
14
- :unsubscribes
15
- )
11
+ Group = Struct.new(
12
+ :id, :name, :description, :last_email_sent_at, :is_default,
13
+ :unsubscribes
14
+ )
16
15
 
17
- def self.url(group_id = nil)
18
- url = "#{BASE_URL}/asm/groups"
19
- url = "#{url}/#{group_id}" unless group_id.nil?
20
- url
21
- end
16
+ def self.url(group_id = nil)
17
+ url = "#{BASE_URL}/asm/groups"
18
+ url = "#{url}/#{group_id}" unless group_id.nil?
19
+ url
20
+ end
22
21
 
23
- def self.create_groups(resp)
24
- return resp if resp.nil?
25
- groups = []
26
- resp.each do |group|
27
- groups.push(SendGrid4r::REST::Sm::Groups.create_group(group))
28
- end
29
- groups
30
- end
22
+ def self.create_groups(resp)
23
+ return resp if resp.nil?
24
+ resp.map { |group| Sm::Groups.create_group(group) }
25
+ end
31
26
 
32
- def self.create_group(resp)
33
- return resp if resp.nil?
34
- Group.new(
35
- resp['id'],
36
- resp['name'],
37
- resp['description'],
38
- resp['last_email_sent_at'],
39
- resp['is_default'],
40
- resp['unsubscribes']
41
- )
42
- end
27
+ def self.create_group(resp)
28
+ return resp if resp.nil?
29
+ Group.new(
30
+ resp['id'],
31
+ resp['name'],
32
+ resp['description'],
33
+ resp['last_email_sent_at'],
34
+ resp['is_default'],
35
+ resp['unsubscribes']
36
+ )
37
+ end
43
38
 
44
- def post_group(name:, description:, is_default: nil, &block)
45
- params = { name: name, description: description }
46
- params['is_default'] = is_default unless is_default.nil?
47
- resp = post(@auth, SendGrid4r::REST::Sm::Groups.url, params, &block)
48
- SendGrid4r::REST::Sm::Groups.create_group(resp)
49
- end
39
+ def post_group(name:, description:, is_default: nil, &block)
40
+ params = { name: name, description: description }
41
+ params[:is_default] = is_default unless is_default.nil?
42
+ resp = post(@auth, Sm::Groups.url, params, &block)
43
+ Sm::Groups.create_group(resp)
44
+ end
50
45
 
51
- def get_groups(&block)
52
- resp = get(@auth, SendGrid4r::REST::Sm::Groups.url, &block)
53
- SendGrid4r::REST::Sm::Groups.create_groups(resp)
54
- end
46
+ def get_groups(&block)
47
+ resp = get(@auth, Sm::Groups.url, &block)
48
+ Sm::Groups.create_groups(resp)
49
+ end
55
50
 
56
- def get_group(group_id:, &block)
57
- resp = get(@auth, SendGrid4r::REST::Sm::Groups.url(group_id), &block)
58
- SendGrid4r::REST::Sm::Groups.create_group(resp)
59
- end
51
+ def get_group(group_id:, &block)
52
+ resp = get(@auth, Sm::Groups.url(group_id), &block)
53
+ Sm::Groups.create_group(resp)
54
+ end
60
55
 
61
- def patch_group(group_id:, group:, &block)
62
- endpoint = SendGrid4r::REST::Sm::Groups.url(group_id)
63
- resp = patch(@auth, endpoint, group.to_h, &block)
64
- SendGrid4r::REST::Sm::Groups.create_group(resp)
65
- end
56
+ def patch_group(group_id:, group:, &block)
57
+ endpoint = Sm::Groups.url(group_id)
58
+ resp = patch(@auth, endpoint, group.to_h, &block)
59
+ Sm::Groups.create_group(resp)
60
+ end
66
61
 
67
- def delete_group(group_id:, &block)
68
- delete(@auth, SendGrid4r::REST::Sm::Groups.url(group_id), &block)
69
- end
62
+ def delete_group(group_id:, &block)
63
+ delete(@auth, Sm::Groups.url(group_id), &block)
70
64
  end
71
65
  end
72
66
  end
@@ -1,25 +1,23 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
 
3
- module SendGrid4r
4
- module REST
5
- #
6
- # SendGrid Web API v3 Suppression Management
7
- #
8
- module Sm
9
- include SendGrid4r::REST::Request
3
+ module SendGrid4r::REST
4
+ #
5
+ # SendGrid Web API v3 Suppression Management
6
+ #
7
+ module Sm
8
+ include Request
10
9
 
11
- RecipientEmails = Struct.new(:recipient_emails)
12
- RecipientEmail = Struct.new(:recipient_email)
10
+ RecipientEmails = Struct.new(:recipient_emails)
11
+ RecipientEmail = Struct.new(:recipient_email)
13
12
 
14
- def self.create_recipient_emails(resp)
15
- return resp if resp.nil?
16
- RecipientEmails.new(resp['recipient_emails'])
17
- end
13
+ def self.create_recipient_emails(resp)
14
+ return resp if resp.nil?
15
+ RecipientEmails.new(resp['recipient_emails'])
16
+ end
18
17
 
19
- def self.create_recipient_email(resp)
20
- return resp if resp.nil?
21
- RecipientEmail.new(resp['recipient_email'])
22
- end
18
+ def self.create_recipient_email(resp)
19
+ return resp if resp.nil?
20
+ RecipientEmail.new(resp['recipient_email'])
23
21
  end
24
22
  end
25
23
  end