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
@@ -1,16 +1,16 @@
1
1
  # encoding: utf-8
2
2
  require File.dirname(__FILE__) + '/../../spec_helper'
3
3
 
4
- describe SendGrid4r::REST::Ips::Warmup do
5
- describe 'integration test', :it do
6
- before do
7
- Dotenv.load
8
- @client = SendGrid4r::Client.new(api_key: ENV['SILVER_API_KEY'])
9
- end
10
-
11
- context 'account is silver' do
4
+ module SendGrid4r::REST::Ips
5
+ describe Warmup do
6
+ describe 'integration test', :it do
12
7
  before do
13
- begin
8
+ Dotenv.load
9
+ @client = SendGrid4r::Client.new(api_key: ENV['SILVER_API_KEY'])
10
+ end
11
+
12
+ context 'account is silver' do
13
+ before do
14
14
  # celan up test env
15
15
  warmup_ips = @client.get_warmup_ips
16
16
  if warmup_ips.length > 0
@@ -18,15 +18,10 @@ describe SendGrid4r::REST::Ips::Warmup do
18
18
  @client.delete_warmup_ip(ip: warmup_ip.ip)
19
19
  end
20
20
  end
21
- rescue RestClient::ExceptionWithResponse => e
22
- puts e.inspect
23
- raise e
24
21
  end
25
- end
26
22
 
27
- context 'without block call' do
28
- it 'warmup_ip spec' do
29
- begin
23
+ context 'without block call' do
24
+ it 'warmup_ip spec' do
30
25
  # get warmup ip
31
26
  warmup_ips = @client.get_warmup_ips
32
27
  expect(warmup_ips.length).to eq(0)
@@ -42,74 +37,71 @@ describe SendGrid4r::REST::Ips::Warmup do
42
37
  expect do
43
38
  @client.get_warmup_ip(ip: warmup_ip.ip)
44
39
  end.to raise_error(RestClient::ResourceNotFound)
45
- rescue RestClient::ExceptionWithResponse => ex
46
- puts ex.inspect
47
- raise ex
48
40
  end
49
41
  end
50
42
  end
51
43
  end
52
- end
53
-
54
- describe 'unit test', :ut do
55
- let(:client) do
56
- SendGrid4r::Client.new(api_key: '')
57
- end
58
44
 
59
- let(:warmup_ip) do
60
- JSON.parse(
61
- '{'\
62
- '"ip":"0.0.0.0",'\
63
- '"start_date":1409616000'\
64
- '}'
65
- )
66
- end
45
+ describe 'unit test', :ut do
46
+ let(:client) do
47
+ SendGrid4r::Client.new(api_key: '')
48
+ end
67
49
 
68
- let(:warmup_ips) do
69
- JSON.parse(
70
- '['\
50
+ let(:warmup_ip) do
51
+ JSON.parse(
71
52
  '{'\
72
- '"ip": "0.0.0.0",'\
73
- '"start_date": 1409616000'\
74
- '}'\
75
- ']'
76
- )
77
- end
53
+ '"ip":"0.0.0.0",'\
54
+ '"start_date":1409616000'\
55
+ '}'
56
+ )
57
+ end
78
58
 
79
- it '#get_warmup_ips' do
80
- allow(client).to receive(:execute).and_return(warmup_ips)
81
- actual = client.get_warmup_ips
82
- expect(actual).to be_a(Array)
83
- actual.each do |warmup_ip|
84
- expect(warmup_ip).to be_a(SendGrid4r::REST::Ips::Warmup::WarmupIp)
59
+ let(:warmup_ips) do
60
+ JSON.parse(
61
+ '['\
62
+ '{'\
63
+ '"ip": "0.0.0.0",'\
64
+ '"start_date": 1409616000'\
65
+ '}'\
66
+ ']'
67
+ )
85
68
  end
86
- end
87
69
 
88
- it '#get_warmup_ip' do
89
- allow(client).to receive(:execute).and_return(warmup_ip)
90
- actual = client.get_warmup_ip(ip: '')
91
- expect(actual).to be_a(SendGrid4r::REST::Ips::Warmup::WarmupIp)
92
- end
70
+ it '#get_warmup_ips' do
71
+ allow(client).to receive(:execute).and_return(warmup_ips)
72
+ actual = client.get_warmup_ips
73
+ expect(actual).to be_a(Array)
74
+ actual.each do |warmup_ip|
75
+ expect(warmup_ip).to be_a(Warmup::WarmupIp)
76
+ end
77
+ end
93
78
 
94
- it '#post_warmup_ip' do
95
- allow(client).to receive(:execute).and_return(warmup_ip)
96
- actual = client.post_warmup_ip(ip: '')
97
- expect(actual).to be_a(SendGrid4r::REST::Ips::Warmup::WarmupIp)
98
- end
79
+ it '#get_warmup_ip' do
80
+ allow(client).to receive(:execute).and_return(warmup_ip)
81
+ actual = client.get_warmup_ip(ip: '')
82
+ expect(actual).to be_a(Warmup::WarmupIp)
83
+ end
99
84
 
100
- it '#delete_warmup_ip' do
101
- allow(client).to receive(:execute).and_return('')
102
- actual = client.delete_warmup_ip(ip: '')
103
- expect(actual).to eq('')
104
- end
85
+ it '#post_warmup_ip' do
86
+ allow(client).to receive(:execute).and_return(warmup_ip)
87
+ actual = client.post_warmup_ip(ip: '')
88
+ expect(actual).to be_a(Warmup::WarmupIp)
89
+ end
105
90
 
106
- it 'creates warmup_ips instance' do
107
- actual = SendGrid4r::REST::Ips::Warmup.create_warmup_ips(warmup_ips)
108
- expect(actual).to be_a(Array)
109
- actual.each do |warmup_ip|
110
- expect(warmup_ip).to be_a(SendGrid4r::REST::Ips::Warmup::WarmupIp)
111
- expect(warmup_ip.ip).to eq('0.0.0.0')
112
- expect(warmup_ip.start_date).to eq(Time.at(1409616000))
91
+ it '#delete_warmup_ip' do
92
+ allow(client).to receive(:execute).and_return('')
93
+ actual = client.delete_warmup_ip(ip: '')
94
+ expect(actual).to eq('')
95
+ end
96
+
97
+ it 'creates warmup_ips instance' do
98
+ actual = Warmup.create_warmup_ips(warmup_ips)
99
+ expect(actual).to be_a(Array)
100
+ actual.each do |warmup_ip|
101
+ expect(warmup_ip).to be_a(Warmup::WarmupIp)
102
+ expect(warmup_ip.ip).to eq('0.0.0.0')
103
+ expect(warmup_ip.start_date).to eq(Time.at(1409616000))
104
+ end
113
105
  end
114
106
  end
115
107
  end
@@ -0,0 +1,28 @@
1
+ # encoding: utf-8
2
+ require File.dirname(__FILE__) + '/../../spec_helper'
3
+
4
+ module SendGrid4r::REST
5
+ describe Mail do
6
+ describe 'unit test', :ut do
7
+ before do
8
+ Dotenv.load
9
+ end
10
+
11
+ it '#to_h with mandatory parameters' do
12
+ em = SendGrid4r::Factory::MailFactory.create_address(
13
+ email: 'test@example.com'
14
+ )
15
+ expect(em.to_h).to eq(email: 'test@example.com')
16
+ end
17
+
18
+ it '#to_h with full parameters' do
19
+ em = SendGrid4r::Factory::MailFactory.create_address(
20
+ email: 'test@example.com', name: 'To name'
21
+ )
22
+ em.email = 'from@example.com'
23
+ em.name = 'To name2'
24
+ expect(em.to_h).to eq(email: 'from@example.com', name: 'To name2')
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,48 @@
1
+ # encoding: utf-8
2
+ require File.dirname(__FILE__) + '/../../spec_helper'
3
+
4
+ module SendGrid4r::REST
5
+ describe Mail do
6
+ describe 'unit test', :ut do
7
+ before do
8
+ Dotenv.load
9
+ end
10
+
11
+ it '#to_h with mandatory parameters' do
12
+ attachment = SendGrid4r::Factory::MailFactory.create_attachment(
13
+ content: 'Hello', filename: 'example.txt'
14
+ )
15
+ expect(attachment.to_h).to eq(
16
+ content: 'SGVsbG8=', filename: 'example.txt'
17
+ )
18
+ end
19
+
20
+ it '#to_h with full parameters' do
21
+ attachment = SendGrid4r::Factory::MailFactory.create_attachment(
22
+ content: 'Hello', filename: 'example.txt'
23
+ )
24
+ attachment.content = 'MoMoMo'
25
+ attachment.filename = 'new.txt'
26
+ attachment.type = 'text/csv'
27
+ attachment.disposition = 'inline'
28
+ attachment.content_id = 'ii_139db99fdb5c3704'
29
+ expect(attachment.to_h).to eq(
30
+ content: 'TW9Nb01v',
31
+ filename: 'new.txt',
32
+ type: 'text/csv',
33
+ disposition: 'inline',
34
+ content_id: 'ii_139db99fdb5c3704'
35
+ )
36
+ end
37
+
38
+ it '#to_h with File' do
39
+ path = File.dirname(__FILE__) + '/../../photo.jpg'
40
+ binary = File.binread(path)
41
+ attachment = SendGrid4r::Factory::MailFactory.create_attachment(
42
+ content: binary, filename: 'photo.jpg'
43
+ )
44
+ expect(attachment.filename).to eq('photo.jpg')
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,32 @@
1
+ # encoding: utf-8
2
+ require File.dirname(__FILE__) + '/../../spec_helper'
3
+
4
+ module SendGrid4r::REST
5
+ describe Mail do
6
+ describe 'unit test', :ut do
7
+ before do
8
+ Dotenv.load
9
+ end
10
+
11
+ it '#to_h with mandatory parameters' do
12
+ content = SendGrid4r::Factory::MailFactory.create_content(
13
+ type: 'text/plain', value: 'This is text part.'
14
+ )
15
+ expect(content.to_h).to eq(
16
+ type: 'text/plain', value: 'This is text part.'
17
+ )
18
+ end
19
+
20
+ it '#to_h with full parameters' do
21
+ content = SendGrid4r::Factory::MailFactory.create_content(
22
+ type: 'text/plain', value: 'This is text part.'
23
+ )
24
+ content.type = 'text/html'
25
+ content.value = '<div>This is html part.</div>'
26
+ expect(content.to_h).to eq(
27
+ type: 'text/html', value: '<div>This is html part.</div>'
28
+ )
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,51 @@
1
+ # encoding: utf-8
2
+ require File.dirname(__FILE__) + '/../../spec_helper'
3
+
4
+ module SendGrid4r::REST
5
+ describe Mail do
6
+ describe 'unit test', :ut do
7
+ before do
8
+ Dotenv.load
9
+ end
10
+
11
+ it '#to_h with mandatory parameters' do
12
+ settings = SendGrid4r::Factory::MailFactory.create_mail_settings
13
+ expect(settings.to_h).to eq({})
14
+ end
15
+
16
+ it '#to_h with full parameters enable' do
17
+ settings = SendGrid4r::Factory::MailFactory.create_mail_settings
18
+ settings.enable_bcc('bcc@example.com')
19
+ settings.enable_bypass_list_management
20
+ settings.enable_footer('text', 'html')
21
+ settings.enable_sandbox_mode
22
+ settings.enable_spam_check(5, 'http://post.url')
23
+ expect(settings.to_h).to eq(
24
+ bcc: { enable: true, email: 'bcc@example.com' },
25
+ bypass_list_management: { enable: true },
26
+ footer: { enable: true, text: 'text', html: 'html' },
27
+ sandbox_mode: { enable: true },
28
+ spam_check: {
29
+ enable: true, threshold: 5, post_to_url: 'http://post.url'
30
+ }
31
+ )
32
+ end
33
+
34
+ it '#to_h with full parameters disable' do
35
+ settings = SendGrid4r::Factory::MailFactory.create_mail_settings
36
+ settings.disable_bcc
37
+ settings.disable_bypass_list_management
38
+ settings.disable_footer
39
+ settings.disable_sandbox_mode
40
+ settings.disable_spam_check
41
+ expect(settings.to_h).to eq(
42
+ bcc: { enable: false },
43
+ bypass_list_management: { enable: false },
44
+ footer: { enable: false },
45
+ sandbox_mode: { enable: false },
46
+ spam_check: { enable: false }
47
+ )
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,136 @@
1
+ # encoding: utf-8
2
+ require File.dirname(__FILE__) + '/../../spec_helper'
3
+
4
+ module SendGrid4r::REST
5
+ describe Mail do
6
+ describe 'integration test', :it do
7
+ before do
8
+ Dotenv.load
9
+ @client = SendGrid4r::Client.new(api_key: ENV['API_KEY'])
10
+ end
11
+
12
+ context 'without block call' do
13
+ it '#send with mandatory params' do
14
+ # Create Personalization
15
+ to = SendGrid4r::Factory::MailFactory.create_address(
16
+ email: ENV['MAIL']
17
+ )
18
+ per = SendGrid4r::Factory::MailFactory.create_personalization(
19
+ to: [to]
20
+ )
21
+ # Create Params
22
+ from = SendGrid4r::Factory::MailFactory.create_address(
23
+ email: ENV['FROM']
24
+ )
25
+ plain = SendGrid4r::Factory::MailFactory.create_content(
26
+ type: 'text/plain',
27
+ value: 'Hello! TEXT'
28
+ )
29
+ params = SendGrid4r::Factory::MailFactory.create_params(
30
+ personalizations: [per], from: from, content: [plain],
31
+ subject: 'Hello v3 Mail'
32
+ )
33
+ begin
34
+ @client.send(params: params)
35
+ rescue RestClient::ExceptionWithResponse => e
36
+ puts e.inspect
37
+ raise
38
+ end
39
+ end
40
+
41
+ it '#send with full params' do
42
+ # Create Personalization
43
+ to = SendGrid4r::Factory::MailFactory.create_address(
44
+ email: ENV['MAIL'], name: 'To name'
45
+ )
46
+ cc = SendGrid4r::Factory::MailFactory.create_address(
47
+ email: ENV['CC'], name: 'Cc name'
48
+ )
49
+ bcc = SendGrid4r::Factory::MailFactory.create_address(
50
+ email: ENV['BCC'], name: 'Bcc name'
51
+ )
52
+ per = SendGrid4r::Factory::MailFactory.create_personalization(
53
+ to: [to]
54
+ )
55
+ per.bcc = [bcc]
56
+ per.cc = [cc]
57
+ per.headers = { 'X-CUSTOM' => 'X-VALUE' }
58
+ per.substitutions = {
59
+ 'subkey' => 'subvalue', 'sectionkey' => 'sectionkey'
60
+ }
61
+ per.custom_args = { 'CUSTOM' => 'value' }
62
+ per.send_at = Time.utc(2016)
63
+ # Create Params
64
+ from = SendGrid4r::Factory::MailFactory.create_address(
65
+ email: ENV['FROM'], name: 'From Name'
66
+ )
67
+ plain = SendGrid4r::Factory::MailFactory.create_content(
68
+ type: 'text/plain',
69
+ value: 'Hello! TEXT subkey'\
70
+ 'sectionkey\nhttps://www.google.com'
71
+ )
72
+ html = SendGrid4r::Factory::MailFactory.create_content(
73
+ type: 'text/html',
74
+ value: '<h1>Hello! HTML subkey sectionkey</h1><br />'\
75
+ '<a href="https://www.google.com">Google</a>'
76
+ )
77
+ params = SendGrid4r::Factory::MailFactory.create_params(
78
+ personalizations: [per], from: from, content: [plain, html],
79
+ subject: 'Hello v3 Mail'
80
+ )
81
+ reply_to = SendGrid4r::Factory::MailFactory.create_address(
82
+ email: ENV['MAIL']
83
+ )
84
+ params.reply_to = reply_to
85
+ attachment0 = SendGrid4r::Factory::MailFactory.create_attachment(
86
+ content: 'XXX', filename: 'text.txt'
87
+ )
88
+ binary = File.binread(File.dirname(__FILE__) + '/../../photo.jpg')
89
+ attachment1 = SendGrid4r::Factory::MailFactory.create_attachment(
90
+ content: binary, filename: 'photo.jpg'
91
+ )
92
+ params.attachments = [attachment0, attachment1]
93
+ params.template_id = '8481d009-d1a6-4e1b-adae-22d2426da9fe'
94
+ params.sections = { 'sectionkey' => 'sectionvalue' }
95
+ params.headers = { 'X-GLOBAL' => 'GLOBAL_VALUE' }
96
+ params.categories = %w(CAT1 CAT2)
97
+ params.custom_args = { 'CUSTOM1' => 'CUSTOM_VALUE1' }
98
+ params.send_at = Time.local(2016)
99
+ params.asm = 3581
100
+ # Create MailSettings
101
+ mail_settings =
102
+ SendGrid4r::Factory::MailFactory.create_mail_settings
103
+ mail_settings.enable_bcc(ENV['MAIL'])
104
+ mail_settings.disable_bcc
105
+ mail_settings.enable_bypass_list_management
106
+ mail_settings.disable_bypass_list_management
107
+ mail_settings.enable_footer('text footer', '<p>html footer</p>')
108
+ mail_settings.disable_footer
109
+ mail_settings.enable_sandbox_mode
110
+ mail_settings.disable_sandbox_mode
111
+ mail_settings.enable_spam_check(10, 'http://www.kke.co.jp')
112
+ mail_settings.disable_spam_check
113
+ params.mail_settings = mail_settings
114
+ # Create TrackingSettings
115
+ tracking =
116
+ SendGrid4r::Factory::MailFactory.create_tracking_settings
117
+ tracking.enable_click_tracking(true)
118
+ tracking.disable_click_tracking
119
+ tracking.enable_open_tracking('open_tag')
120
+ tracking.disable_open_tracking
121
+ tracking.enable_subscription_tracking('', '', 'tag')
122
+ tracking.disable_subscription_tracking
123
+ tracking.enable_ganalytics('', '', '', '', '')
124
+ tracking.disable_ganalytics
125
+ params.tracking_settings = tracking
126
+ begin
127
+ @client.send(params: params)
128
+ rescue RestClient::ExceptionWithResponse => e
129
+ puts e.inspect
130
+ raise
131
+ end
132
+ end
133
+ end
134
+ end
135
+ end
136
+ end
@@ -0,0 +1,152 @@
1
+ # encoding: utf-8
2
+ require File.dirname(__FILE__) + '/../../spec_helper'
3
+
4
+ module SendGrid4r::REST
5
+ describe Mail do
6
+ describe 'unit test', :ut do
7
+ before do
8
+ Dotenv.load
9
+ end
10
+
11
+ let(:to) do
12
+ SendGrid4r::Factory::MailFactory.create_address(
13
+ email: 'to@example.com'
14
+ )
15
+ end
16
+
17
+ let(:from) do
18
+ SendGrid4r::Factory::MailFactory.create_address(
19
+ email: 'from@example.com'
20
+ )
21
+ end
22
+
23
+ let(:per) do
24
+ SendGrid4r::Factory::MailFactory.create_personalization(to: [to])
25
+ end
26
+
27
+ let(:plain) do
28
+ SendGrid4r::Factory::MailFactory.create_content(
29
+ type: 'text/plain',
30
+ value: 'Hello! TEXT subkey '\
31
+ 'sectionkey\nhttps://www.google.com'
32
+ )
33
+ end
34
+
35
+ let(:html) do
36
+ SendGrid4r::Factory::MailFactory.create_content(
37
+ type: 'text/html',
38
+ value: '<h1>Hello! HTML subkey sectionkey</h1><br />'\
39
+ '<a href="https://www.google.com">Google</a>'
40
+ )
41
+ end
42
+
43
+ let(:reply_to) do
44
+ SendGrid4r::Factory::MailFactory.create_address(
45
+ email: 'reply_to@example.com'
46
+ )
47
+ end
48
+
49
+ let(:attachment) do
50
+ SendGrid4r::Factory::MailFactory.create_attachment(
51
+ content: 'Hello', filename: 'text.txt'
52
+ )
53
+ end
54
+
55
+ let(:mail_settings) do
56
+ SendGrid4r::Factory::MailFactory.create_mail_settings
57
+ end
58
+
59
+ let(:tracking_settings) do
60
+ SendGrid4r::Factory::MailFactory.create_tracking_settings
61
+ end
62
+
63
+ it '#to_h with mandatory parameters' do
64
+ params = SendGrid4r::Factory::MailFactory.create_params(
65
+ personalizations: [per], from: from, content: [plain, html],
66
+ subject: 'This is the subject'
67
+ )
68
+ expect(params.to_h).to eq(
69
+ personalizations: [
70
+ {
71
+ to: [{ email: 'to@example.com' }]
72
+ }
73
+ ],
74
+ from: { email: 'from@example.com' },
75
+ content: [
76
+ {
77
+ type: 'text/plain',
78
+ value: 'Hello! TEXT subkey '\
79
+ 'sectionkey\nhttps://www.google.com'
80
+ },
81
+ {
82
+ type: 'text/html',
83
+ value: '<h1>Hello! HTML subkey sectionkey</h1><br />'\
84
+ '<a href="https://www.google.com">Google</a>'
85
+ }
86
+ ],
87
+ subject: 'This is the subject'
88
+ )
89
+ end
90
+
91
+ it '#to_h with full parameters' do
92
+ params = SendGrid4r::Factory::MailFactory.create_params(
93
+ personalizations: [per], from: from, content: [plain, html],
94
+ subject: 'This is the subject'
95
+ )
96
+ params.reply_to = reply_to
97
+ params.attachments = [attachment]
98
+ params.template_id = 'XXX-YYY-ZZZ'
99
+ params.sections = { 'sectionkey' => 'sectionvalue' }
100
+ params.headers = { 'X-GLOBAL' => 'GLOBAL_VALUE' }
101
+ params.categories = %w(CAT1 CAT2)
102
+ params.custom_args = { 'CUSTOM1' => 'CUSTOM_VALUE1' }
103
+ params.send_at = Time.utc(2016)
104
+ params.batch_id = '1234567890'
105
+ params.asm = 3581, [12, 34]
106
+ params.ip_pool_name = 'pool_name'
107
+ params.mail_settings = mail_settings
108
+ params.tracking_settings = tracking_settings
109
+
110
+ expect(params.to_h).to eq(
111
+ personalizations: [
112
+ {
113
+ to: [{ email: 'to@example.com' }]
114
+ }
115
+ ],
116
+ from: { email: 'from@example.com' },
117
+ content: [
118
+ {
119
+ type: 'text/plain',
120
+ value: 'Hello! TEXT subkey '\
121
+ 'sectionkey\nhttps://www.google.com'
122
+ },
123
+ {
124
+ type: 'text/html',
125
+ value: '<h1>Hello! HTML subkey sectionkey</h1><br />'\
126
+ '<a href="https://www.google.com">Google</a>'
127
+ }
128
+ ],
129
+ reply_to: { email: 'reply_to@example.com' },
130
+ attachments: [
131
+ {
132
+ content: 'SGVsbG8=',
133
+ filename: 'text.txt'
134
+ }
135
+ ],
136
+ template_id: 'XXX-YYY-ZZZ',
137
+ sections: { 'sectionkey' => 'sectionvalue' },
138
+ headers: { 'X-GLOBAL' => 'GLOBAL_VALUE' },
139
+ categories: %w(CAT1 CAT2),
140
+ custom_args: { 'CUSTOM1' => 'CUSTOM_VALUE1' },
141
+ send_at: 1451606400,
142
+ batch_id: '1234567890',
143
+ asm: { group_id: 3581, groups_to_display: [12, 34] },
144
+ ip_pool_name: 'pool_name',
145
+ mail_settings: {},
146
+ tracking_settings: {},
147
+ subject: 'This is the subject'
148
+ )
149
+ end
150
+ end
151
+ end
152
+ end
@@ -0,0 +1,66 @@
1
+ # encoding: utf-8
2
+ require File.dirname(__FILE__) + '/../../spec_helper'
3
+
4
+ module SendGrid4r::REST
5
+ describe Mail do
6
+ describe 'unit test', :ut do
7
+ before do
8
+ Dotenv.load
9
+ end
10
+
11
+ let(:to) do
12
+ SendGrid4r::Factory::MailFactory.create_address(
13
+ email: 'to@example.com'
14
+ )
15
+ end
16
+
17
+ let(:cc) do
18
+ SendGrid4r::Factory::MailFactory.create_address(
19
+ email: 'cc@example.com'
20
+ )
21
+ end
22
+
23
+ let(:bcc) do
24
+ SendGrid4r::Factory::MailFactory.create_address(
25
+ email: 'bcc@example.com'
26
+ )
27
+ end
28
+
29
+ it '#to_h with mandatory parameters' do
30
+ per = SendGrid4r::Factory::MailFactory.create_personalization(
31
+ to: [to]
32
+ )
33
+ expect(per.to_h).to eq(
34
+ to: [{ email: 'to@example.com' }]
35
+ )
36
+ end
37
+
38
+ it '#to_h with full parameters' do
39
+ per = SendGrid4r::Factory::MailFactory.create_personalization(
40
+ to: [to]
41
+ )
42
+ per.subject = 'This is subject.'
43
+ per.cc = [cc]
44
+ per.bcc = [bcc]
45
+ per.headers = { 'X-CUSTOM' => 'X-VALUE' }
46
+ per.substitutions = {
47
+ 'subkey' => 'subval', 'sectionkey' => 'sectionkey'
48
+ }
49
+ per.custom_args = { 'CUSTOM' => 'value' }
50
+ per.send_at = Time.utc(2016)
51
+ expect(per.to_h).to eq(
52
+ to: [{ email: 'to@example.com' }],
53
+ subject: 'This is subject.',
54
+ cc: [{ email: 'cc@example.com' }],
55
+ bcc: [{ email: 'bcc@example.com' }],
56
+ headers: { 'X-CUSTOM' => 'X-VALUE' },
57
+ substitutions: {
58
+ 'subkey' => 'subval', 'sectionkey' => 'sectionkey'
59
+ },
60
+ custom_args: { 'CUSTOM' => 'value' },
61
+ send_at: 1451606400
62
+ )
63
+ end
64
+ end
65
+ end
66
+ end