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,64 +1,132 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
 
3
- module SendGrid4r
4
- module REST
5
- #
6
- # SendGrid Web API v3 Users
7
- #
8
- module Users
9
- include SendGrid4r::REST::Request
10
-
11
- Profile = Struct.new(
12
- :address, :city, :company, :country, :first_name, :last_name,
13
- :phone, :state, :website, :zip
3
+ module SendGrid4r::REST
4
+ #
5
+ # SendGrid Web API v3 Users
6
+ #
7
+ module Users
8
+ include Request
9
+
10
+ Profile = Struct.new(
11
+ :address, :city, :company, :country, :first_name, :last_name,
12
+ :phone, :state, :website, :zip
13
+ )
14
+
15
+ Account = Struct.new(:type, :reputation)
16
+
17
+ Email = Struct.new(:email)
18
+
19
+ Username = Struct.new(:username, :user_id)
20
+
21
+ Credits = Struct.new(
22
+ :remain, :total, :overage, :used, :last_reset, :next_reset,
23
+ :reset_frequency
24
+ )
25
+
26
+ Password = Struct.new(:new_password, :old_password)
27
+
28
+ def self.url(path)
29
+ "#{BASE_URL}/user/#{path}"
30
+ end
31
+
32
+ def self.create_profile(resp)
33
+ return resp if resp.nil?
34
+ Profile.new(
35
+ resp['address'],
36
+ resp['city'],
37
+ resp['company'],
38
+ resp['country'],
39
+ resp['first_name'],
40
+ resp['last_name'],
41
+ resp['phone'],
42
+ resp['state'],
43
+ resp['website'],
44
+ resp['zip']
14
45
  )
46
+ end
47
+
48
+ def self.create_account(resp)
49
+ return resp if resp.nil?
50
+ Account.new(resp['type'], resp['reputation'])
51
+ end
52
+
53
+ def self.create_email(resp)
54
+ return resp if resp.nil?
55
+ Email.new(resp['email'])
56
+ end
57
+
58
+ def self.create_username(resp)
59
+ return resp if resp.nil?
60
+ Username.new(resp['username'], resp['user_id'])
61
+ end
62
+
63
+ def self.create_credits(resp)
64
+ return resp if resp.nil?
65
+ Credits.new(
66
+ resp['remain'],
67
+ resp['total'],
68
+ resp['overage'],
69
+ resp['used'],
70
+ resp['last_reset'],
71
+ resp['next_reset'],
72
+ resp['reset_frequency']
73
+ )
74
+ end
75
+
76
+ def self.create_password(resp)
77
+ return resp if resp.nil?
78
+ Password.new(resp['new_password'], resp['old_password'])
79
+ end
80
+
81
+ def get_user_profile(&block)
82
+ resp = get(@auth, Users.url(:profile), nil, &block)
83
+ Users.create_profile(resp)
84
+ end
85
+
86
+ def patch_user_profile(params:, &block)
87
+ resp = patch(@auth, Users.url(:profile), params, &block)
88
+ Users.create_profile(resp)
89
+ end
90
+
91
+ def get_user_account(&block)
92
+ resp = get(@auth, Users.url(:account), nil, &block)
93
+ Users.create_account(resp)
94
+ end
95
+
96
+ def get_user_email(&block)
97
+ resp = get(@auth, Users.url(:email), nil, &block)
98
+ Users.create_email(resp)
99
+ end
100
+
101
+ def put_user_email(email:, &block)
102
+ params = { email: email }
103
+ resp = put(@auth, Users.url(:email), params, &block)
104
+ Users.create_email(resp)
105
+ end
106
+
107
+ def get_user_username(&block)
108
+ resp = get(@auth, Users.url(:username), nil, &block)
109
+ Users.create_username(resp)
110
+ end
111
+
112
+ def put_user_username(username:, &block)
113
+ params = { username: username }
114
+ resp = put(@auth, Users.url(:username), params, &block)
115
+ Users.create_username(resp)
116
+ end
117
+
118
+ def get_user_credits(&block)
119
+ resp = get(@auth, Users.url(:credits), &block)
120
+ Users.create_credits(resp)
121
+ end
15
122
 
16
- Account = Struct.new(:type, :reputation)
17
-
18
- def self.url(path)
19
- url = "#{BASE_URL}/user/#{path}"
20
- url
21
- end
22
-
23
- def self.create_profile(resp)
24
- return resp if resp.nil?
25
- Profile.new(
26
- resp['address'],
27
- resp['city'],
28
- resp['company'],
29
- resp['country'],
30
- resp['first_name'],
31
- resp['last_name'],
32
- resp['phone'],
33
- resp['state'],
34
- resp['website'],
35
- resp['zip']
36
- )
37
- end
38
-
39
- def self.create_account(resp)
40
- return resp if resp.nil?
41
- Account.new(
42
- resp['type'],
43
- resp['reputation']
44
- )
45
- end
46
-
47
- def get_user_profile(&block)
48
- resp = get(@auth, SendGrid4r::REST::Users.url('profile'), nil, &block)
49
- SendGrid4r::REST::Users.create_profile(resp)
50
- end
51
-
52
- def patch_user_profile(params:, &block)
53
- endpoint = SendGrid4r::REST::Users.url('profile')
54
- resp = patch(@auth, endpoint, params, &block)
55
- SendGrid4r::REST::Users.create_profile(resp)
56
- end
57
-
58
- def get_user_account(&block)
59
- resp = get(@auth, SendGrid4r::REST::Users.url('account'), nil, &block)
60
- SendGrid4r::REST::Users.create_account(resp)
61
- end
123
+ def put_user_password(new_password:, old_password:, &block)
124
+ params = {
125
+ new_password: new_password,
126
+ old_password: old_password
127
+ }
128
+ resp = put(@auth, Users.url(:password), params, &block)
129
+ Users.create_password(resp)
62
130
  end
63
131
  end
64
132
  end
@@ -1,55 +1,49 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
 
3
- module SendGrid4r
4
- module REST
3
+ module SendGrid4r::REST
4
+ #
5
+ # SendGrid Web API v3 Webhooks
6
+ #
7
+ module Webhooks
5
8
  #
6
- # SendGrid Web API v3 Webhooks
9
+ # SendGrid Web API v3 Webhooks ParseApi
7
10
  #
8
- module Webhooks
9
- #
10
- # SendGrid Web API v3 Webhooks ParseApi
11
- #
12
- module Event
13
- include SendGrid4r::REST::Request
11
+ module Event
12
+ include Request
14
13
 
15
- def self.url_event(path)
16
- "#{BASE_URL}/user/webhooks/event/#{path}"
17
- end
14
+ def self.url_event(path)
15
+ "#{BASE_URL}/user/webhooks/event/#{path}"
16
+ end
18
17
 
19
- EventNotification = Struct.new(
20
- :enabled, :url, :group_resubscribe, :delivered, :group_unsubscribe,
21
- :spam_report, :bounce, :deferred, :unsubscribe, :processed, :open,
22
- :click, :dropped
23
- )
18
+ EventNotification = Struct.new(
19
+ :enabled, :url, :group_resubscribe, :delivered, :group_unsubscribe,
20
+ :spam_report, :bounce, :deferred, :unsubscribe, :processed, :open,
21
+ :click, :dropped
22
+ )
24
23
 
25
- def self.create_event_notification(resp)
26
- return resp if resp.nil?
27
- EventNotification.new(
28
- resp['enabled'], resp['url'], resp['group_resubscribe'],
29
- resp['delivered'], resp['group_unsubscribe'], resp['spam_report'],
30
- resp['bounce'], resp['deferred'], resp['unsubscribe'],
31
- resp['processed'], resp['open'], resp['click'], resp['dropped']
32
- )
33
- end
24
+ def self.create_event_notification(resp)
25
+ return resp if resp.nil?
26
+ EventNotification.new(
27
+ resp['enabled'], resp['url'], resp['group_resubscribe'],
28
+ resp['delivered'], resp['group_unsubscribe'], resp['spam_report'],
29
+ resp['bounce'], resp['deferred'], resp['unsubscribe'],
30
+ resp['processed'], resp['open'], resp['click'], resp['dropped']
31
+ )
32
+ end
34
33
 
35
- def get_settings_event_notification(&block)
36
- endpoint = SendGrid4r::REST::Webhooks::Event.url_event('settings')
37
- resp = get(@auth, endpoint, &block)
38
- SendGrid4r::REST::Webhooks::Event.create_event_notification(resp)
39
- end
34
+ def get_settings_event_notification(&block)
35
+ resp = get(@auth, Event.url_event(:settings), &block)
36
+ Event.create_event_notification(resp)
37
+ end
40
38
 
41
- def patch_settings_event_notification(params:, &block)
42
- endpoint = SendGrid4r::REST::Webhooks::Event.url_event('settings')
43
- resp = patch(@auth, endpoint, params.to_h, &block)
44
- SendGrid4r::REST::Webhooks::Event.create_event_notification(resp)
45
- end
39
+ def patch_settings_event_notification(params:, &block)
40
+ resp = patch(@auth, Event.url_event(:settings), params.to_h, &block)
41
+ Event.create_event_notification(resp)
42
+ end
46
43
 
47
- def test_settings_event_notification(url:, &block)
48
- params = {}
49
- params['url'] = url
50
- endpoint = SendGrid4r::REST::Webhooks::Event.url_event('test')
51
- post(@auth, endpoint, params, &block)
52
- end
44
+ def test_settings_event_notification(url:, &block)
45
+ params = { url: url }
46
+ post(@auth, Event.url_event(:test), params, &block)
53
47
  end
54
48
  end
55
49
  end
@@ -1,50 +1,41 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
 
3
- module SendGrid4r
4
- module REST
3
+ module SendGrid4r::REST
4
+ #
5
+ # SendGrid Web API v3 Webhooks
6
+ #
7
+ module Webhooks
5
8
  #
6
- # SendGrid Web API v3 Webhooks
9
+ # SendGrid Web API v3 Webhooks Parse
7
10
  #
8
- module Webhooks
9
- #
10
- # SendGrid Web API v3 Webhooks Parse
11
- #
12
- module Parse
13
- include SendGrid4r::REST::Request
11
+ module Parse
12
+ include Request
14
13
 
15
- ParseSettings = Struct.new(:result)
16
- ParseSetting = Struct.new(:url, :hostname, :spam_check_outgoing)
14
+ ParseSettings = Struct.new(:result)
15
+ ParseSetting = Struct.new(:url, :hostname, :spam_check_outgoing)
17
16
 
18
- def self.url
19
- "#{BASE_URL}/user/webhooks/parse/settings"
20
- end
17
+ def self.url
18
+ "#{BASE_URL}/user/webhooks/parse/settings"
19
+ end
21
20
 
22
- def self.create_parse_settings(resp)
23
- return resp if resp.nil?
24
- parse_settings = []
25
- resp['result'].each do |setting|
26
- parse_settings.push(
27
- SendGrid4r::REST::Webhooks::Parse.create_parse_setting(
28
- setting
29
- )
30
- )
31
- end
32
- ParseSettings.new(parse_settings)
21
+ def self.create_parse_settings(resp)
22
+ return resp if resp.nil?
23
+ parse_settings = resp['result'].map do |setting|
24
+ Parse.create_parse_setting(setting)
33
25
  end
26
+ ParseSettings.new(parse_settings)
27
+ end
34
28
 
35
- def self.create_parse_setting(resp)
36
- return resp if resp.nil?
37
- ParseSetting.new(
38
- resp['url'],
39
- resp['hostname'],
40
- resp['spam_check_outgoing']
41
- )
42
- end
29
+ def self.create_parse_setting(resp)
30
+ return resp if resp.nil?
31
+ ParseSetting.new(
32
+ resp['url'], resp['hostname'], resp['spam_check_outgoing']
33
+ )
34
+ end
43
35
 
44
- def get_parse_settings(&block)
45
- resp = get(@auth, SendGrid4r::REST::Webhooks::Parse.url, &block)
46
- SendGrid4r::REST::Webhooks::Parse.create_parse_settings(resp)
47
- end
36
+ def get_parse_settings(&block)
37
+ resp = get(@auth, Parse.url, &block)
38
+ Parse.create_parse_settings(resp)
48
39
  end
49
40
  end
50
41
  end