sendgrid4r 1.8.1 → 1.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5a3b5f08893c6357875c03762c4a6a674f812cf1
4
- data.tar.gz: 4b6f9b1a2661a880d52625c6286b30829c6dff63
3
+ metadata.gz: e26da8c2d562f33c4745134539a4cd52eab206a7
4
+ data.tar.gz: 5625dabfb3c35a7caa4cd56245c2cca645498633
5
5
  SHA512:
6
- metadata.gz: 586c11ea85418575c8e5a3421cacbe5f85f1f7d9521040006f38e8549e1c3b5fee1f014d032491877b8261b696c3ad1b71015bf353afd7ea348d2284a92028b9
7
- data.tar.gz: 89c62cbb80bf983d366e737c75bacdf42ff4b837a395fcb89717097d67811f282aef6ebb3e5196336ddf63702920ae7bf93fed698bd61c60f3c422411439aa63
6
+ metadata.gz: 9590d767b8b961ddb477e403426fd552191f801c4ffbefb92854c245469f10c3a328ae9a580575b5b44b439e894cb18afdd44b649ed40c8fd5f83eecee6fb9b4
7
+ data.tar.gz: b51a20b262ca15afd06406514ef0d7355a8c19c41e007a8a1e55eee2ed5e441e6bd0b5f1ba13753182533d963a642903aebaab0dfc983f6b76e8463fe250cffe
data/.rubocop.yml CHANGED
@@ -9,7 +9,7 @@ MethodLength:
9
9
 
10
10
  # Change limitation of module length
11
11
  ModuleLength:
12
- Max: 300
12
+ Max: 600
13
13
 
14
14
  # Change limitation of the number of params
15
15
  ParameterLists:
@@ -18,8 +18,12 @@ ParameterLists:
18
18
 
19
19
  # Change limitation of AbcSize
20
20
  AbcSize:
21
- Max: 21
21
+ Max: 22
22
22
 
23
23
  # Change numeric literals
24
24
  NumericLiterals:
25
25
  MinDigits: 20
26
+
27
+ # Disable force module and class style
28
+ ClassAndModuleChildren:
29
+ Enabled: false
data/README.md CHANGED
@@ -4,6 +4,7 @@ This gem allows you to quickly and easily access to SendGrid Web API v3 for Ruby
4
4
  See [api reference](https://sendgrid.com/docs/API_Reference/Web_API_v3/index.html) for more detail
5
5
 
6
6
  [![Build Status](https://travis-ci.org/awwa/sendgrid4r.svg?branch=master)](https://travis-ci.org/awwa/sendgrid4r)
7
+ [![Gem Version](https://badge.fury.io/rb/sendgrid4r.svg)](https://badge.fury.io/rb/sendgrid4r)
7
8
 
8
9
  # [Documentation](https://github.com/awwa/sendgrid4r/wiki)
9
10
 
@@ -10,16 +10,29 @@ module SendGrid4r
10
10
  segment_ids: nil, categories: nil, suppression_group_id: nil,
11
11
  custom_unsubscribe_url: nil, ip_pool: nil, html_content: nil,
12
12
  plain_content: nil)
13
- segment = SendGrid4r::REST::Campaigns::Campaigns::Campaign.new(
13
+ campaign = REST::MarketingCampaigns::Campaign.new(
14
14
  nil, title, subject, sender_id, list_ids, segment_ids, categories,
15
15
  suppression_group_id, custom_unsubscribe_url, ip_pool, html_content,
16
16
  plain_content, nil, nil
17
17
  )
18
- hash = segment.to_h
19
- segment.to_h.each do |key, value|
20
- hash.delete(key) if value.nil?
18
+ campaign.to_h.reject { |_key, value| value.nil? }
19
+ end
20
+
21
+ def create_sender(
22
+ nickname:, from:, reply_to:, address:, address_2:, city:, state:,
23
+ zip:, country:
24
+ )
25
+ REST::MarketingCampaigns::Sender.new(
26
+ nil, nickname, nil, nil, address, address_2,
27
+ city, state, zip, country, nil, nil, nil, nil
28
+ ).tap do |sender|
29
+ sender.from = from
30
+ sender.reply_to = reply_to
21
31
  end
22
- hash
32
+ end
33
+
34
+ def create_address(email:, name:)
35
+ REST::MarketingCampaigns::Address.new(email, name)
23
36
  end
24
37
  end
25
38
  end
@@ -7,7 +7,7 @@ module SendGrid4r
7
7
  #
8
8
  class ConditionFactory
9
9
  def create(field:, value:, operator:, and_or:)
10
- SendGrid4r::REST::Contacts::Segments::Condition.new(
10
+ REST::MarketingCampaigns::Contacts::Segments::Condition.new(
11
11
  field,
12
12
  value,
13
13
  operator,
@@ -0,0 +1,57 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ module SendGrid4r
4
+ module Factory
5
+ #
6
+ # SendGrid Web API v3 MailFactory implementation
7
+ #
8
+ module MailFactory
9
+ def self.create_params(
10
+ personalizations:, from:, subject:, content:
11
+ )
12
+ SendGrid4r::REST::Mail::Params.new(
13
+ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil,
14
+ nil, nil, nil, nil, nil, nil, nil
15
+ ).tap do |params|
16
+ params.personalizations = personalizations
17
+ params.from = from
18
+ params.content = content
19
+ params.subject = subject
20
+ end
21
+ end
22
+
23
+ def self.create_address(email:, name: nil)
24
+ SendGrid4r::REST::Mail::Address.new(email, name)
25
+ end
26
+
27
+ def self.create_personalization(to:)
28
+ SendGrid4r::REST::Mail::Personalization.new(
29
+ nil, nil, nil, nil, nil, nil, nil, nil
30
+ ).tap do |personalization|
31
+ personalization.to = to
32
+ end
33
+ end
34
+
35
+ def self.create_attachment(content:, filename:)
36
+ SendGrid4r::REST::Mail::Attachment.new(
37
+ nil, nil, nil, nil, nil
38
+ ).tap do |attachment|
39
+ attachment.content = content
40
+ attachment.filename = filename
41
+ end
42
+ end
43
+
44
+ def self.create_mail_settings
45
+ SendGrid4r::REST::Mail::MailSettings.new(nil, nil, nil, nil, nil)
46
+ end
47
+
48
+ def self.create_tracking_settings
49
+ SendGrid4r::REST::Mail::TrackingSettings.new(nil, nil, nil, nil)
50
+ end
51
+
52
+ def self.create_content(type:, value:)
53
+ SendGrid4r::REST::Mail::Content.new(type, value)
54
+ end
55
+ end
56
+ end
57
+ end
@@ -7,17 +7,14 @@ module SendGrid4r
7
7
  #
8
8
  class SegmentFactory
9
9
  def create(name: nil, list_id: nil, conditions:)
10
- segment = SendGrid4r::REST::Contacts::Segments::Segment.new(
10
+ segment = REST::MarketingCampaigns::Contacts::Segments::Segment.new(
11
11
  nil,
12
12
  name,
13
13
  list_id,
14
14
  conditions,
15
15
  nil
16
16
  )
17
- hash = segment.to_h
18
- hash.delete(:id)
19
- hash.delete(:list_id) if list_id.nil?
20
- hash
17
+ segment.to_h.reject { |_key, value| value.nil? }
21
18
  end
22
19
  end
23
20
  end
@@ -9,7 +9,7 @@ module SendGrid4r
9
9
  def create(
10
10
  name:, subject: '<%subject%>',
11
11
  html_content: '<%body%>', plain_content: '<%body%>', active: 1)
12
- SendGrid4r::REST::Templates::Versions::Version.new(
12
+ REST::TransactionalTemplates::Versions::Version.new(
13
13
  nil,
14
14
  nil,
15
15
  nil,
@@ -1,53 +1,52 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
 
3
- module SendGrid4r
4
- module REST
5
- #
6
- # SendGrid Web API v3
7
- #
8
- module API
9
- include SendGrid4r::REST::Templates
10
- include SendGrid4r::REST::Templates::Versions
11
- include SendGrid4r::REST::Sm
12
- include SendGrid4r::REST::Sm::Groups
13
- include SendGrid4r::REST::Sm::Suppressions
14
- include SendGrid4r::REST::Sm::GlobalUnsubscribes
15
- include SendGrid4r::REST::Settings
16
- include SendGrid4r::REST::Settings::EnforcedTls
17
- include SendGrid4r::REST::Settings::Mail
18
- include SendGrid4r::REST::Settings::Partner
19
- include SendGrid4r::REST::Settings::Tracking
20
- include SendGrid4r::REST::Ips::Addresses
21
- include SendGrid4r::REST::Ips::Warmup
22
- include SendGrid4r::REST::Ips::Pools
23
- include SendGrid4r::REST::Categories::Categories
24
- include SendGrid4r::REST::Stats::Global
25
- include SendGrid4r::REST::Stats::Category
26
- include SendGrid4r::REST::Stats::Subuser
27
- include SendGrid4r::REST::Stats::Advanced
28
- include SendGrid4r::REST::Stats::Parse
29
- include SendGrid4r::REST::Contacts::CustomFields
30
- include SendGrid4r::REST::Contacts::Lists
31
- include SendGrid4r::REST::Contacts::Recipients
32
- include SendGrid4r::REST::Contacts::ReservedFields
33
- include SendGrid4r::REST::Contacts::Segments
34
- include SendGrid4r::REST::Campaigns::Campaigns
35
- include SendGrid4r::REST::ApiKeys
36
- include SendGrid4r::REST::ApiKeys::Permissions
37
- include SendGrid4r::REST::Subusers
38
- include SendGrid4r::REST::EmailActivity
39
- include SendGrid4r::REST::Whitelabel::Domains
40
- include SendGrid4r::REST::Whitelabel::Ips
41
- include SendGrid4r::REST::Whitelabel::Links
42
- include SendGrid4r::REST::Users
43
- include SendGrid4r::REST::Bounces
44
- include SendGrid4r::REST::Blocks
45
- include SendGrid4r::REST::InvalidEmails
46
- include SendGrid4r::REST::SpamReports
47
- include SendGrid4r::REST::CancelScheduledSends
48
- include SendGrid4r::REST::Webhooks::Event
49
- include SendGrid4r::REST::Webhooks::Parse
50
- include SendGrid4r::REST::IpAccessManagement
51
- end
3
+ module SendGrid4r::REST
4
+ #
5
+ # SendGrid Web API v3
6
+ #
7
+ module API
8
+ include SendGrid4r::REST::TransactionalTemplates
9
+ include SendGrid4r::REST::TransactionalTemplates::Versions
10
+ include SendGrid4r::REST::Sm
11
+ include SendGrid4r::REST::Sm::Groups
12
+ include SendGrid4r::REST::Sm::Suppressions
13
+ include SendGrid4r::REST::Sm::GlobalUnsubscribes
14
+ include SendGrid4r::REST::Settings
15
+ include SendGrid4r::REST::Settings::EnforcedTls
16
+ include SendGrid4r::REST::Settings::Mail
17
+ include SendGrid4r::REST::Settings::Partner
18
+ include SendGrid4r::REST::Settings::Tracking
19
+ include SendGrid4r::REST::Ips::Addresses
20
+ include SendGrid4r::REST::Ips::Warmup
21
+ include SendGrid4r::REST::Ips::Pools
22
+ include SendGrid4r::REST::Categories
23
+ include SendGrid4r::REST::Stats::Global
24
+ include SendGrid4r::REST::Stats::Category
25
+ include SendGrid4r::REST::Stats::Subuser
26
+ include SendGrid4r::REST::Stats::Advanced
27
+ include SendGrid4r::REST::Stats::Parse
28
+ include SendGrid4r::REST::MarketingCampaigns
29
+ include SendGrid4r::REST::MarketingCampaigns::Contacts::CustomFields
30
+ include SendGrid4r::REST::MarketingCampaigns::Contacts::Lists
31
+ include SendGrid4r::REST::MarketingCampaigns::Contacts::Recipients
32
+ include SendGrid4r::REST::MarketingCampaigns::Contacts::ReservedFields
33
+ include SendGrid4r::REST::MarketingCampaigns::Contacts::Segments
34
+ include SendGrid4r::REST::ApiKeysManagement
35
+ include SendGrid4r::REST::ApiKeysManagement::Permissions
36
+ include SendGrid4r::REST::Subusers
37
+ include SendGrid4r::REST::EmailActivity
38
+ include SendGrid4r::REST::Whitelabel::Domains
39
+ include SendGrid4r::REST::Whitelabel::Ips
40
+ include SendGrid4r::REST::Whitelabel::Links
41
+ include SendGrid4r::REST::Users
42
+ include SendGrid4r::REST::Bounces
43
+ include SendGrid4r::REST::Blocks
44
+ include SendGrid4r::REST::InvalidEmails
45
+ include SendGrid4r::REST::SpamReports
46
+ include SendGrid4r::REST::CancelScheduledSends
47
+ include SendGrid4r::REST::Webhooks::Event
48
+ include SendGrid4r::REST::Webhooks::Parse
49
+ include SendGrid4r::REST::IpAccessManagement
50
+ include SendGrid4r::REST::Mail
52
51
  end
53
52
  end
@@ -0,0 +1,75 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ module SendGrid4r::REST
4
+ #
5
+ # SendGrid Web API v3 ApiKeysManagement
6
+ #
7
+ module ApiKeysManagement
8
+ include Request
9
+
10
+ ApiKeys = Struct.new(:result)
11
+ ApiKey = Struct.new(:name, :api_key_id, :api_key, :scopes)
12
+
13
+ def self.url(api_key_id = nil)
14
+ url = "#{BASE_URL}/api_keys"
15
+ url = "#{url}/#{api_key_id}" unless api_key_id.nil?
16
+ url
17
+ end
18
+
19
+ def self.create_api_keys(resp)
20
+ return resp if resp.nil?
21
+ api_keys = resp['result'].map do |api_key|
22
+ ApiKeysManagement.create_api_key(api_key)
23
+ end
24
+ ApiKeys.new(api_keys)
25
+ end
26
+
27
+ def self.create_api_key(resp)
28
+ return resp if resp.nil?
29
+ ApiKey.new(
30
+ resp['name'],
31
+ resp['api_key_id'],
32
+ resp['api_key'],
33
+ resp['scopes']
34
+ )
35
+ end
36
+
37
+ def get_api_keys(&block)
38
+ resp = get(@auth, ApiKeysManagement.url, &block)
39
+ ApiKeysManagement.create_api_keys(resp)
40
+ end
41
+
42
+ def post_api_key(name:, scopes: nil, &block)
43
+ params = { name: name }
44
+ params[:scopes] = scopes unless scopes.nil?
45
+ resp = post(@auth, ApiKeysManagement.url, params, &block)
46
+ ApiKeysManagement.create_api_key(resp)
47
+ end
48
+
49
+ def get_api_key(api_key_id:, &block)
50
+ endpoint = ApiKeysManagement.url(api_key_id)
51
+ resp = get(@auth, endpoint, &block)
52
+ ApiKeysManagement.create_api_key(resp)
53
+ end
54
+
55
+ def delete_api_key(api_key_id:, &block)
56
+ delete(@auth, ApiKeysManagement.url(api_key_id), &block)
57
+ end
58
+
59
+ def patch_api_key(api_key_id:, name:, &block)
60
+ params = { name: name }
61
+ endpoint = ApiKeysManagement.url(api_key_id)
62
+ resp = patch(@auth, endpoint, params, &block)
63
+ ApiKeysManagement.create_api_key(resp)
64
+ end
65
+
66
+ def put_api_key(api_key_id:, name:, scopes:, &block)
67
+ params = {}
68
+ params[:name] = name unless name.nil?
69
+ params[:scopes] = scopes unless scopes.nil?
70
+ endpoint = ApiKeysManagement.url(api_key_id)
71
+ resp = put(@auth, endpoint, params, &block)
72
+ ApiKeysManagement.create_api_key(resp)
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,31 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ module SendGrid4r::REST
4
+ #
5
+ # SendGrid Web API v3 ApiKeysManagement
6
+ #
7
+ module ApiKeysManagement
8
+ #
9
+ # SendGrid Web API v3 ApiKeysManagement Permissions
10
+ #
11
+ module Permissions
12
+ include Request
13
+
14
+ Permissions = Struct.new(:scopes)
15
+
16
+ def self.url
17
+ "#{BASE_URL}/scopes"
18
+ end
19
+
20
+ def self.create_permissions(resp)
21
+ return resp if resp.nil?
22
+ Permissions.new(resp['scopes'])
23
+ end
24
+
25
+ def get_permissions(&block)
26
+ resp = get(@auth, ApiKeysManagement::Permissions.url, &block)
27
+ ApiKeysManagement::Permissions.create_permissions(resp)
28
+ end
29
+ end
30
+ end
31
+ end
@@ -1,80 +1,61 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
 
3
- module SendGrid4r
4
- module REST
5
- #
6
- # SendGrid Web API v3 Blocks
7
- #
8
- module Blocks
9
- include SendGrid4r::REST::Request
10
-
11
- Block = Struct.new(
12
- :created, :email, :reason, :status
13
- )
14
-
15
- def self.url(email = nil)
16
- url = "#{BASE_URL}/suppression/blocks"
17
- url = "#{url}/#{email}" unless email.nil?
18
- url
19
- end
3
+ module SendGrid4r::REST
4
+ #
5
+ # SendGrid Web API v3 Blocks
6
+ #
7
+ module Blocks
8
+ include Request
9
+
10
+ Block = Struct.new(:created, :email, :reason, :status)
11
+
12
+ def self.url(email = nil)
13
+ url = "#{BASE_URL}/suppression/blocks"
14
+ url = "#{url}/#{email}" unless email.nil?
15
+ url
16
+ end
20
17
 
21
- def self.create_blocks(resp)
22
- return resp if resp.nil?
23
- blocks = []
24
- resp.each do |block|
25
- blocks.push(SendGrid4r::REST::Blocks.create_block(block))
26
- end
27
- blocks
28
- end
18
+ def self.create_blocks(resp)
19
+ return resp if resp.nil?
20
+ resp.map { |block| Blocks.create_block(block) }
21
+ end
29
22
 
30
- def self.create_block(resp)
31
- return resp if resp.nil?
32
- created = Time.at(resp['created']) unless resp['created'].nil?
33
- Block.new(
34
- created,
35
- resp['email'],
36
- resp['reason'],
37
- resp['status']
38
- )
39
- end
23
+ def self.create_block(resp)
24
+ return resp if resp.nil?
25
+ created = Time.at(resp['created']) unless resp['created'].nil?
26
+ Block.new(created, resp['email'], resp['reason'], resp['status'])
27
+ end
40
28
 
41
- def get_blocks(
42
- start_time: nil, end_time: nil, limit: nil, offset: nil, &block
43
- )
44
- params = {}
45
- params['start_time'] = start_time.to_i unless start_time.nil?
46
- params['end_time'] = end_time.to_i unless end_time.nil?
47
- params['limit'] = limit.to_i unless limit.nil?
48
- params['offset'] = offset.to_i unless offset.nil?
49
- resp = get(@auth, SendGrid4r::REST::Blocks.url, params, &block)
50
- SendGrid4r::REST::Blocks.create_blocks(resp)
51
- end
29
+ def get_blocks(
30
+ start_time: nil, end_time: nil, limit: nil, offset: nil, &block
31
+ )
32
+ params = {}
33
+ params[:start_time] = start_time.to_i unless start_time.nil?
34
+ params[:end_time] = end_time.to_i unless end_time.nil?
35
+ params[:limit] = limit.to_i unless limit.nil?
36
+ params[:offset] = offset.to_i unless offset.nil?
37
+ resp = get(@auth, Blocks.url, params, &block)
38
+ Blocks.create_blocks(resp)
39
+ end
52
40
 
53
- def delete_blocks(delete_all: nil, emails: nil, &block)
54
- endpoint = SendGrid4r::REST::Blocks.url
55
- payload = {}
56
- if delete_all == true
57
- payload['delete_all'] = delete_all
58
- else
59
- payload['emails'] = emails
60
- end
61
- delete(@auth, endpoint, nil, payload, &block)
41
+ def delete_blocks(delete_all: nil, emails: nil, &block)
42
+ if delete_all
43
+ payload = { delete_all: delete_all }
44
+ else
45
+ payload = { emails: emails }
62
46
  end
47
+ delete(@auth, Blocks.url, nil, payload, &block)
48
+ end
63
49
 
64
- def get_block(email:, &block)
65
- endpoint = SendGrid4r::REST::Blocks.url(email)
66
- params = {}
67
- params['email'] = email
68
- resp = get(@auth, endpoint, params, &block)
69
- SendGrid4r::REST::Blocks.create_blocks(resp)
70
- end
50
+ def get_block(email:, &block)
51
+ params = { email: email }
52
+ resp = get(@auth, Blocks.url(email), params, &block)
53
+ Blocks.create_blocks(resp)
54
+ end
71
55
 
72
- def delete_block(email:, &block)
73
- endpoint = SendGrid4r::REST::Blocks.url(email)
74
- params = {}
75
- params['email'] = email
76
- delete(@auth, endpoint, params, &block)
77
- end
56
+ def delete_block(email:, &block)
57
+ params = { email: email }
58
+ delete(@auth, Blocks.url(email), params, &block)
78
59
  end
79
60
  end
80
61
  end
@@ -1,76 +1,57 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
 
3
- module SendGrid4r
4
- module REST
5
- #
6
- # SendGrid Web API v3 Subusers
7
- #
8
- module Bounces
9
- include SendGrid4r::REST::Request
10
-
11
- Bounce = Struct.new(
12
- :created, :email, :reason, :status
13
- )
14
-
15
- def self.url(email = nil)
16
- url = "#{BASE_URL}/suppression/bounces"
17
- url = "#{url}/#{email}" unless email.nil?
18
- url
19
- end
3
+ module SendGrid4r::REST
4
+ #
5
+ # SendGrid Web API v3 Subusers
6
+ #
7
+ module Bounces
8
+ include Request
9
+
10
+ Bounce = Struct.new(:created, :email, :reason, :status)
11
+
12
+ def self.url(email = nil)
13
+ url = "#{BASE_URL}/suppression/bounces"
14
+ url = "#{url}/#{email}" unless email.nil?
15
+ url
16
+ end
20
17
 
21
- def self.create_bounces(resp)
22
- return resp if resp.nil?
23
- bounces = []
24
- resp.each do |bounce|
25
- bounces.push(SendGrid4r::REST::Bounces.create_bounce(bounce))
26
- end
27
- bounces
28
- end
18
+ def self.create_bounces(resp)
19
+ return resp if resp.nil?
20
+ resp.map { |bounce| Bounces.create_bounce(bounce) }
21
+ end
29
22
 
30
- def self.create_bounce(resp)
31
- return resp if resp.nil?
32
- created = Time.at(resp['created']) unless resp['created'].nil?
33
- Bounce.new(
34
- created,
35
- resp['email'],
36
- resp['reason'],
37
- resp['status']
38
- )
39
- end
23
+ def self.create_bounce(resp)
24
+ return resp if resp.nil?
25
+ created = Time.at(resp['created']) unless resp['created'].nil?
26
+ Bounce.new(created, resp['email'], resp['reason'], resp['status'])
27
+ end
40
28
 
41
- def get_bounces(start_time: nil, end_time: nil, &block)
42
- params = {}
43
- params['start_time'] = start_time.to_i unless start_time.nil?
44
- params['end_time'] = end_time.to_i unless end_time.nil?
45
- resp = get(@auth, SendGrid4r::REST::Bounces.url, params, &block)
46
- SendGrid4r::REST::Bounces.create_bounces(resp)
47
- end
29
+ def get_bounces(start_time: nil, end_time: nil, &block)
30
+ params = {}
31
+ params[:start_time] = start_time.to_i unless start_time.nil?
32
+ params[:end_time] = end_time.to_i unless end_time.nil?
33
+ resp = get(@auth, Bounces.url, params, &block)
34
+ Bounces.create_bounces(resp)
35
+ end
48
36
 
49
- def delete_bounces(delete_all: nil, emails: nil, &block)
50
- endpoint = SendGrid4r::REST::Bounces.url
51
- payload = {}
52
- if delete_all == true
53
- payload['delete_all'] = delete_all
54
- else
55
- payload['emails'] = emails
56
- end
57
- delete(@auth, endpoint, nil, payload, &block)
37
+ def delete_bounces(delete_all: nil, emails: nil, &block)
38
+ if delete_all
39
+ payload = { delete_all: delete_all }
40
+ else
41
+ payload = { emails: emails }
58
42
  end
43
+ delete(@auth, Bounces.url, nil, payload, &block)
44
+ end
59
45
 
60
- def get_bounce(email:, &block)
61
- endpoint = SendGrid4r::REST::Bounces.url(email)
62
- params = {}
63
- params['email'] = email
64
- resp = get(@auth, endpoint, params, &block)
65
- SendGrid4r::REST::Bounces.create_bounces(resp)
66
- end
46
+ def get_bounce(email:, &block)
47
+ params = { email: email }
48
+ resp = get(@auth, Bounces.url(email), params, &block)
49
+ Bounces.create_bounces(resp)
50
+ end
67
51
 
68
- def delete_bounce(email:, &block)
69
- endpoint = SendGrid4r::REST::Bounces.url(email)
70
- params = {}
71
- params['email'] = email
72
- delete(@auth, endpoint, params, &block)
73
- end
52
+ def delete_bounce(email:, &block)
53
+ params = { email: email }
54
+ delete(@auth, Bounces.url(email), params, &block)
74
55
  end
75
56
  end
76
57
  end