sendgrid-ruby 1.1.6 → 6.0.4

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 (136) hide show
  1. checksums.yaml +5 -5
  2. data/.codeclimate.yml +21 -0
  3. data/.env_sample +1 -3
  4. data/.gitignore +1 -0
  5. data/.travis.yml +28 -17
  6. data/CHANGELOG.md +231 -1
  7. data/CODE_OF_CONDUCT.md +73 -0
  8. data/CONTRIBUTING.md +214 -0
  9. data/Gemfile +5 -4
  10. data/ISSUE_TEMPLATE.md +26 -0
  11. data/LICENSE.md +21 -0
  12. data/Makefile +7 -0
  13. data/PULL_REQUEST_TEMPLATE.md +31 -0
  14. data/README.md +161 -225
  15. data/Rakefile +9 -2
  16. data/TROUBLESHOOTING.md +137 -0
  17. data/UPGRADE.md +5 -0
  18. data/USAGE.md +5037 -0
  19. data/USE_CASES.md +377 -0
  20. data/config.ru +4 -0
  21. data/docker/Dockerfile +12 -0
  22. data/docker/README.md +30 -0
  23. data/examples/accesssettings/accesssettings.rb +83 -0
  24. data/examples/alerts/alerts.rb +62 -0
  25. data/examples/apikeys/apikeys.rb +84 -0
  26. data/examples/asm/asm.rb +173 -0
  27. data/examples/browsers/browsers.rb +16 -0
  28. data/examples/campaigns/campaigns.rb +153 -0
  29. data/examples/categories/categories.rb +36 -0
  30. data/examples/clients/clients.rb +27 -0
  31. data/examples/contactdb/contactdb.rb +395 -0
  32. data/examples/devices/devices.rb +16 -0
  33. data/examples/geo/geo.rb +16 -0
  34. data/examples/helpers/mail/example.rb +147 -0
  35. data/examples/helpers/settings/example.rb +23 -0
  36. data/examples/helpers/stats/example.rb +42 -0
  37. data/examples/ips/ips.rb +167 -0
  38. data/examples/mail/mail.rb +173 -0
  39. data/examples/mailboxproviders/mailboxproviders.rb +16 -0
  40. data/examples/mailsettings/mailsettings.rb +219 -0
  41. data/examples/partnersettings/partnersettings.rb +39 -0
  42. data/examples/scopes/scopes.rb +61 -0
  43. data/examples/senderauthentication/senderauthentication.rb +310 -0
  44. data/examples/senders/senders.rb +98 -0
  45. data/examples/stats/stats.rb +16 -0
  46. data/examples/subusers/subusers.rb +169 -0
  47. data/examples/suppression/suppression.rb +201 -0
  48. data/examples/templates/templates.rb +129 -0
  49. data/examples/trackingsettings/trackingsettings.rb +110 -0
  50. data/examples/user/user.rb +293 -0
  51. data/gemfiles/Sinatra_1.gemfile +6 -0
  52. data/gemfiles/Sinatra_2.gemfile +6 -0
  53. data/lib/sendgrid/client.rb +33 -57
  54. data/lib/sendgrid/helpers/inbound/README.md +98 -0
  55. data/lib/sendgrid/helpers/inbound/app.rb +32 -0
  56. data/lib/sendgrid/helpers/inbound/config.yml +26 -0
  57. data/lib/sendgrid/helpers/inbound/public/index.html +10 -0
  58. data/lib/sendgrid/helpers/inbound/sample_data/default_data.txt +58 -0
  59. data/lib/sendgrid/helpers/inbound/sample_data/raw_data.txt +57 -0
  60. data/lib/sendgrid/helpers/inbound/sample_data/raw_data_with_attachments.txt +298 -0
  61. data/lib/sendgrid/helpers/inbound/send.rb +26 -0
  62. data/lib/sendgrid/helpers/ip_management/ip_management.rb +17 -0
  63. data/lib/sendgrid/helpers/mail/README.md +14 -0
  64. data/lib/sendgrid/helpers/mail/asm.rb +33 -0
  65. data/lib/sendgrid/helpers/mail/attachment.rb +86 -0
  66. data/lib/sendgrid/helpers/mail/bcc_settings.rb +33 -0
  67. data/lib/sendgrid/helpers/mail/bypass_list_management.rb +43 -0
  68. data/lib/sendgrid/helpers/mail/category.rb +20 -0
  69. data/lib/sendgrid/helpers/mail/click_tracking.rb +33 -0
  70. data/lib/sendgrid/helpers/mail/content.rb +20 -0
  71. data/lib/sendgrid/helpers/mail/custom_arg.rb +24 -0
  72. data/lib/sendgrid/helpers/mail/email.rb +29 -0
  73. data/lib/sendgrid/helpers/mail/footer.rb +43 -0
  74. data/lib/sendgrid/helpers/mail/ganalytics.rb +74 -0
  75. data/lib/sendgrid/helpers/mail/header.rb +24 -0
  76. data/lib/sendgrid/helpers/mail/mail.rb +140 -0
  77. data/lib/sendgrid/helpers/mail/mail_settings.rb +63 -0
  78. data/lib/sendgrid/helpers/mail/open_tracking.rb +33 -0
  79. data/lib/sendgrid/helpers/mail/personalization.rb +82 -0
  80. data/lib/sendgrid/helpers/mail/section.rb +24 -0
  81. data/lib/sendgrid/helpers/mail/spam_check.rb +43 -0
  82. data/lib/sendgrid/helpers/mail/subscription_tracking.rb +53 -0
  83. data/lib/sendgrid/helpers/mail/substitution.rb +24 -0
  84. data/lib/sendgrid/helpers/mail/tracking_settings.rb +53 -0
  85. data/lib/sendgrid/helpers/permissions/scope.rb +28 -0
  86. data/lib/sendgrid/helpers/permissions/scopes.yml +309 -0
  87. data/lib/sendgrid/helpers/settings/README.md +14 -0
  88. data/lib/sendgrid/helpers/settings/mail_settings_dto.rb +13 -0
  89. data/lib/sendgrid/helpers/settings/partner_settings_dto.rb +13 -0
  90. data/lib/sendgrid/helpers/settings/settings.rb +28 -0
  91. data/lib/sendgrid/helpers/settings/tracking_settings_dto.rb +24 -0
  92. data/lib/sendgrid/helpers/settings/user_settings_dto.rb +13 -0
  93. data/lib/sendgrid/helpers/stats/email_stats.rb +46 -0
  94. data/lib/sendgrid/helpers/stats/metrics.rb +35 -0
  95. data/lib/sendgrid/helpers/stats/stats_response.rb +31 -0
  96. data/lib/sendgrid/version.rb +1 -1
  97. data/lib/sendgrid-ruby.rb +27 -6
  98. data/mail_helper_v3.md +390 -0
  99. data/sendgrid-ruby.gemspec +13 -17
  100. data/spec/sendgrid/helpers/ip_management/ip_management_spec.rb +12 -0
  101. data/spec/sendgrid/helpers/settings/mail_settings_dto_spec.rb +32 -0
  102. data/spec/sendgrid/helpers/settings/partner_settings_dto_spec.rb +24 -0
  103. data/spec/sendgrid/helpers/settings/settings_spec.rb +25 -0
  104. data/spec/sendgrid/helpers/settings/tracking_settings_dto_spec.rb +27 -0
  105. data/spec/sendgrid/helpers/settings/user_settings_dto_spec.rb +24 -0
  106. data/spec/sendgrid/helpers/stats/email_stats_spec.rb +112 -0
  107. data/spec/sendgrid/helpers/stats/metrics_spec.rb +46 -0
  108. data/spec/sendgrid/helpers/stats/stats_response_spec.rb +76 -0
  109. data/spec/spec_helper.rb +10 -1
  110. data/test/prism.sh +42 -0
  111. data/test/sendgrid/helpers/mail/test_attachment.rb +35 -0
  112. data/test/sendgrid/helpers/mail/test_category.rb +27 -0
  113. data/test/sendgrid/helpers/mail/test_email.rb +34 -0
  114. data/test/sendgrid/helpers/mail/test_mail.rb +261 -0
  115. data/test/sendgrid/helpers/mail/test_personalizations.rb +161 -0
  116. data/test/sendgrid/permissions/test_scopes.rb +38 -0
  117. data/test/sendgrid/test_sendgrid-ruby.rb +2751 -0
  118. metadata +149 -115
  119. data/.rspec +0 -2
  120. data/.rubocop.yml +0 -30
  121. data/FETCH_HEAD +0 -0
  122. data/Guardfile +0 -10
  123. data/LICENSE.txt +0 -22
  124. data/example.rb +0 -41
  125. data/lib/sendgrid/exceptions.rb +0 -7
  126. data/lib/sendgrid/mail.rb +0 -182
  127. data/lib/sendgrid/recipient.rb +0 -29
  128. data/lib/sendgrid/response.rb +0 -14
  129. data/lib/sendgrid/template.rb +0 -26
  130. data/lib/sendgrid/template_mailer.rb +0 -59
  131. data/spec/lib/sendgrid/client_spec.rb +0 -87
  132. data/spec/lib/sendgrid/mail_spec.rb +0 -151
  133. data/spec/lib/sendgrid/recipient_spec.rb +0 -91
  134. data/spec/lib/sendgrid/template_mailer_spec.rb +0 -86
  135. data/spec/lib/sendgrid/template_spec.rb +0 -61
  136. data/spec/lib/sendgrid_spec.rb +0 -7
@@ -0,0 +1,161 @@
1
+ require_relative '../../../../lib/sendgrid/helpers/mail/personalization'
2
+ require 'minitest/autorun'
3
+
4
+ class TestPersonalization < Minitest::Test
5
+
6
+ include SendGrid
7
+
8
+ def test_add_to
9
+ @personalization = Personalization.new()
10
+ @personalization.add_to(Email.new(email: 'test1@example.com', name: 'Example User'))
11
+ expected_json = {
12
+ "to"=>[
13
+ {
14
+ "email"=>"test1@example.com",
15
+ "name"=>"Example User"
16
+ }
17
+ ]
18
+ }
19
+ @personalization.add_to(Email.new(email: 'test2@example.com', name: 'Example User 2'))
20
+ expected_json = {
21
+ "to"=>[
22
+ {
23
+ "email"=>"test1@example.com",
24
+ "name"=>"Example User"
25
+ },
26
+ {
27
+ "email"=>"test2@example.com",
28
+ "name"=>"Example User 2"
29
+ }
30
+ ]
31
+ }
32
+ assert_equal @personalization.to_json, expected_json
33
+ end
34
+
35
+ def test_add_cc
36
+ @personalization = Personalization.new()
37
+ @personalization.add_cc(Email.new(email: 'test1@example.com', name: 'Example User'))
38
+ expected_json = {
39
+ "cc"=>[
40
+ {
41
+ "email"=>"test1@example.com",
42
+ "name"=>"Example User"
43
+ }
44
+ ]
45
+ }
46
+ @personalization.add_cc(Email.new(email: 'test2@example.com', name: 'Example User 2'))
47
+ expected_json = {
48
+ "cc"=>[
49
+ {
50
+ "email"=>"test1@example.com",
51
+ "name"=>"Example User"
52
+ },
53
+ {
54
+ "email"=>"test2@example.com",
55
+ "name"=>"Example User 2"
56
+ }
57
+ ]
58
+ }
59
+ assert_equal @personalization.to_json, expected_json
60
+ end
61
+
62
+ def test_add_bcc
63
+ @personalization = Personalization.new()
64
+ @personalization.add_bcc(Email.new(email: 'test1@example.com', name: 'Example User'))
65
+ expected_json = {
66
+ "bcc"=>[
67
+ {
68
+ "email"=>"test1@example.com",
69
+ "name"=>"Example User"
70
+ }
71
+ ]
72
+ }
73
+ @personalization.add_bcc(Email.new(email: 'test2@example.com', name: 'Example User 2'))
74
+ expected_json = {
75
+ "bcc"=>[
76
+ {
77
+ "email"=>"test1@example.com",
78
+ "name"=>"Example User"
79
+ },
80
+ {
81
+ "email"=>"test2@example.com",
82
+ "name"=>"Example User 2"
83
+ }
84
+ ]
85
+ }
86
+ assert_equal @personalization.to_json, expected_json
87
+ end
88
+
89
+ def test_add_header
90
+ @personalization = Personalization.new()
91
+ @personalization.add_header(Header.new(key: 'X-Test', value: 'True'))
92
+ expected_json = {
93
+ "headers"=>{
94
+ "X-Test"=>"True"
95
+ }
96
+ }
97
+ assert_equal @personalization.to_json, expected_json
98
+ @personalization.add_header(Header.new(key: 'X-Test 1', value: 'False'))
99
+ expected_json = {
100
+ "headers"=>{
101
+ "X-Test"=>"True",
102
+ "X-Test 1"=>"False"
103
+ }
104
+ }
105
+ assert_equal @personalization.to_json, expected_json
106
+ end
107
+
108
+ def test_add_substitution
109
+ @personalization = Personalization.new()
110
+ @personalization.add_substitution(Substitution.new(key: '%name%', value: 'Example User'))
111
+ expected_json = {
112
+ "substitutions"=>{
113
+ "%name%"=>"Example User"
114
+ }
115
+ }
116
+ assert_equal @personalization.to_json, expected_json
117
+ @personalization.add_substitution(Substitution.new(key: '%name 1%', value: 'Example User 1'))
118
+ expected_json = {
119
+ "substitutions"=>{
120
+ "%name%"=>"Example User",
121
+ "%name 1%"=>"Example User 1"
122
+ }
123
+ }
124
+ assert_equal @personalization.to_json, expected_json
125
+ end
126
+
127
+ def test_add_custom_arg
128
+ @personalization = Personalization.new()
129
+ @personalization.add_custom_arg(CustomArg.new(key: 'user_id', value: '343'))
130
+ expected_json = {
131
+ "custom_args"=>{
132
+ "user_id"=>"343"
133
+ }
134
+ }
135
+ assert_equal @personalization.to_json, expected_json
136
+ @personalization.add_custom_arg(CustomArg.new(key: 'city', value: 'denver'))
137
+ expected_json = {
138
+ "custom_args"=>{
139
+ "user_id"=>"343",
140
+ "city"=>"denver"
141
+ }
142
+ }
143
+ assert_equal @personalization.to_json, expected_json
144
+ end
145
+
146
+ def test_add_dynamic_template_data
147
+ @personalization = Personalization.new()
148
+ @personalization.add_dynamic_template_data({
149
+ "name"=>"Example User",
150
+ "city"=> "Denver"
151
+ })
152
+ expected_json = {
153
+ "dynamic_template_data"=>{
154
+ "name"=>"Example User",
155
+ "city"=>"Denver"
156
+ }
157
+ }
158
+ assert_equal @personalization.to_json, expected_json
159
+ end
160
+
161
+ end
@@ -0,0 +1,38 @@
1
+ require_relative '../../../lib/sendgrid/helpers/permissions/scope'
2
+ require 'minitest/autorun'
3
+
4
+ class TestCategory < Minitest::Test
5
+
6
+ include SendGrid
7
+
8
+ # usecases
9
+ # 1. test admin scopes
10
+ # 2. test read only scopes
11
+ # 3. test read only and full access scopes for a method by hardcoding
12
+ # 4. test read only and full access scopes by loading scopes.yaml
13
+
14
+ def setup
15
+ @scopes_from_yaml = YAML.load_file(File.dirname(__FILE__) + '/../../../lib/sendgrid/helpers/permissions/scopes.yml').freeze
16
+ end
17
+
18
+ def test_admin_scopes
19
+ assert_equal Scope.admin_permissions, @scopes_from_yaml.values.map(&:values).flatten
20
+ end
21
+
22
+ def test_read_only_scopes
23
+ assert_equal Scope.read_only_permissions, @scopes_from_yaml.map { |_, v| v[:read] }.flatten
24
+ end
25
+
26
+ def test_read_only_and_full_access_for_mail_hardcoded
27
+ assert_equal Scope.mail_read_only_permissions, ["mail.batch.read"]
28
+ assert_equal Scope.mail_full_access_permissions, ["mail.send", "mail.batch.create", "mail.batch.delete", "mail.batch.read", "mail.batch.update"]
29
+ end
30
+
31
+ def test_read_only_and_full_access_from_file
32
+ @scopes_from_yaml.each_key do |endpoint|
33
+ assert_equal Scope.send("#{endpoint}_read_only_permissions"), @scopes_from_yaml[endpoint][:read]
34
+ assert_equal Scope.send("#{endpoint}_full_access_permissions"), @scopes_from_yaml[endpoint].values.flatten
35
+ end
36
+ end
37
+
38
+ end