sendgrid-ruby 1.1.6 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. checksums.yaml +4 -4
  2. data/.github/ISSUE_TEMPLATE +17 -0
  3. data/.travis.yml +1 -6
  4. data/CHANGELOG.md +6 -0
  5. data/CONTRIBUTING.md +202 -0
  6. data/Gemfile +3 -5
  7. data/LICENSE.txt +1 -1
  8. data/README.md +74 -248
  9. data/Rakefile +8 -6
  10. data/USAGE.md +4645 -0
  11. data/examples/accesssettings/accesssettings.rb +89 -0
  12. data/examples/apikeys/apikeys.rb +95 -0
  13. data/examples/asm/asm.rb +169 -0
  14. data/examples/browsers/browsers.rb +29 -0
  15. data/examples/campaigns/campaigns.rb +166 -0
  16. data/examples/categories/categories.rb +49 -0
  17. data/examples/clients/clients.rb +40 -0
  18. data/examples/contactdb/contactdb.rb +398 -0
  19. data/examples/devices/devices.rb +29 -0
  20. data/examples/geo/geo.rb +29 -0
  21. data/examples/helpers/mail/example.rb +130 -0
  22. data/examples/ips/ips.rb +167 -0
  23. data/examples/mail/mail.rb +191 -0
  24. data/examples/mailboxproviders/mailboxproviders.rb +29 -0
  25. data/examples/mailsettings/mailsettings.rb +232 -0
  26. data/examples/partnersettings/partnersettings.rb +52 -0
  27. data/examples/scopes/scopes.rb +28 -0
  28. data/examples/stats/stats.rb +29 -0
  29. data/examples/subusers/subusers.rb +182 -0
  30. data/examples/suppression/suppression.rb +186 -0
  31. data/examples/templates/templates.rb +142 -0
  32. data/examples/trackingsettings/trackingsettings.rb +123 -0
  33. data/examples/user/user.rb +256 -0
  34. data/examples/whitelabel/whitelabel.rb +323 -0
  35. data/lib/helpers/mail/README.md +14 -0
  36. data/lib/helpers/mail/mail.rb +999 -0
  37. data/lib/sendgrid-ruby.rb +33 -8
  38. data/sendgrid-ruby.gemspec +5 -17
  39. data/test/helpers/mail/test_mail.rb +122 -0
  40. data/test/test_sendgrid-ruby.rb +2016 -0
  41. metadata +42 -190
  42. data/.env_sample +0 -3
  43. data/.rspec +0 -2
  44. data/.rubocop.yml +0 -30
  45. data/FETCH_HEAD +0 -0
  46. data/Guardfile +0 -10
  47. data/example.rb +0 -41
  48. data/lib/sendgrid/client.rb +0 -62
  49. data/lib/sendgrid/exceptions.rb +0 -7
  50. data/lib/sendgrid/mail.rb +0 -182
  51. data/lib/sendgrid/recipient.rb +0 -29
  52. data/lib/sendgrid/response.rb +0 -14
  53. data/lib/sendgrid/template.rb +0 -26
  54. data/lib/sendgrid/template_mailer.rb +0 -59
  55. data/lib/sendgrid/version.rb +0 -3
  56. data/spec/lib/sendgrid/client_spec.rb +0 -87
  57. data/spec/lib/sendgrid/mail_spec.rb +0 -151
  58. data/spec/lib/sendgrid/recipient_spec.rb +0 -91
  59. data/spec/lib/sendgrid/template_mailer_spec.rb +0 -86
  60. data/spec/lib/sendgrid/template_spec.rb +0 -61
  61. data/spec/lib/sendgrid_spec.rb +0 -7
  62. data/spec/spec_helper.rb +0 -1
@@ -1,91 +0,0 @@
1
- require_relative '../../../lib/sendgrid/recipient'
2
-
3
- module SendGrid
4
- describe Recipient do
5
- subject { described_class.new(anything) }
6
-
7
- describe '#initialize' do
8
- it 'sets the address instance var' do
9
- expect(subject.instance_variable_get(:@address)).to_not be_nil
10
- end
11
-
12
- it 'sets substitutions to an empty hash' do
13
- expect(subject.instance_variable_get(:@substitutions)).to eq({})
14
- end
15
-
16
- context 'initialized with nil' do
17
- it 'raises an error' do
18
- expect do
19
- described_class.new(nil)
20
- end.to raise_error(Recipient::NoAddress, 'Recipient address cannot be nil')
21
- end
22
- end
23
- end
24
-
25
- describe '#add_substitution' do
26
- it 'adds the key and value to the substitutions hash' do
27
- subject.add_substitution(:foo, :bar)
28
- expect(subject.substitutions).to have_key(:foo)
29
- expect(subject.substitutions[:foo]).to eq(:bar)
30
- end
31
-
32
- context 'the same substiution key already exists' do
33
- before do
34
- subject.add_substitution(:foo, :bar)
35
- end
36
-
37
- it 'replaces the value' do
38
- subject.add_substitution(:foo, :baz)
39
- expect(subject.substitutions).to have_key(:foo)
40
- expect(subject.substitutions[:foo]).to eq(:baz)
41
- end
42
- end
43
- end
44
-
45
- describe '#add_to_smtpapi' do
46
- let(:substitutions) { { foo: :bar, baz: :qux } }
47
- let(:smtp_api) { Smtpapi::Header.new }
48
- before do
49
- substitutions.each do |key, value|
50
- subject.add_substitution(key, value)
51
- end
52
- end
53
-
54
- it 'adds the address' do
55
- expect(smtp_api).to receive(:add_to)
56
- subject.add_to_smtpapi(smtp_api)
57
- end
58
-
59
- it 'calls add_substitution as many times as there are substitution keys' do
60
- substitutions.each do |key, value|
61
- expect(smtp_api).to receive(:add_substitution).with(key, [value])
62
- end
63
-
64
- subject.add_to_smtpapi(smtp_api)
65
- end
66
-
67
- context 'a substitution for the same key already exists' do
68
- let(:substitutions) { { foo: :bar } }
69
- let(:added_value) { [:bar, :rab] }
70
-
71
- before do
72
- smtp_api.add_substitution(:foo, [:rab])
73
- end
74
-
75
- it 'adds to it' do
76
- expect(smtp_api).to receive(:add_substitution).with(:foo, array_including(added_value))
77
- subject.add_to_smtpapi(smtp_api)
78
- end
79
- end
80
-
81
- context 'substitutions is empty' do
82
- let(:substitutions) { {} }
83
-
84
- it 'does nothing' do
85
- expect(smtp_api).to_not receive(:add_substitution)
86
- subject.add_to_smtpapi(smtp_api)
87
- end
88
- end
89
- end
90
- end
91
- end
@@ -1,86 +0,0 @@
1
- require_relative '../../../lib/sendgrid/template_mailer'
2
-
3
- module SendGrid
4
- describe TemplateMailer do
5
- let(:client) { anything }
6
- let(:template) { Template.new(anything) }
7
- let(:recipients) { [Recipient.new(anything)] }
8
-
9
- describe '#initialize' do
10
- let(:client) { anything }
11
- let(:template) { Template.new(anything) }
12
- let(:recipients) { [anything] }
13
-
14
- subject { described_class.new(client, template, recipients) }
15
-
16
- it 'sets the instance variables' do
17
- expect(subject.instance_variable_get(:@client)).to_not be_nil
18
- expect(subject.instance_variable_get(:@template)).to_not be_nil
19
- expect(subject.instance_variable_get(:@recipients)).to_not be_nil
20
- end
21
-
22
- context 'nil variables' do
23
- context 'template is nil' do
24
- let(:template) { nil }
25
-
26
- it 'raises error' do
27
- expect do
28
- subject
29
- end.to raise_error(InvalidTemplate, 'Template must be present')
30
- end
31
- end
32
-
33
- context 'client is nil' do
34
- let(:client) { nil }
35
-
36
- it 'raises error' do
37
- expect do
38
- subject
39
- end.to raise_error(InvalidClient, 'Client must be present')
40
- end
41
- end
42
- end
43
-
44
- context 'recipients' do
45
- let(:first_recipient) { Recipient.new('someone@anything.com') }
46
- let(:second_recipient) { Recipient.new('test@test.com') }
47
- let(:recipients) { [first_recipient, second_recipient] }
48
-
49
- it 'adds them to the template' do
50
- expect(template).to receive(:add_recipient).with(first_recipient)
51
- expect(template).to receive(:add_recipient).with(second_recipient)
52
-
53
- subject
54
- end
55
- end
56
- end
57
-
58
- describe '#mail' do
59
- subject { described_class.new(client, template, recipients) }
60
-
61
- let(:mail_params) { {} }
62
- let(:mail_to_h) { '' }
63
-
64
- before do
65
- allow(subject).to receive(:mail_params) { mail_params }
66
- allow_any_instance_of(Mail).to receive(:to_h) { mail_to_h }
67
- allow(client).to receive(:send)
68
- end
69
-
70
- it 'creates a new mail object' do
71
- expect(Mail).to receive(:new).with(mail_params).and_call_original
72
- subject.mail
73
- end
74
-
75
- it 'adds the template to the mail object' do
76
- expect_any_instance_of(Mail).to receive(:template=).with(template)
77
- subject.mail
78
- end
79
-
80
- it 'calls send on the client with the mail object' do
81
- expect(client).to receive(:send).with(mail_to_h)
82
- subject.mail
83
- end
84
- end
85
- end
86
- end
@@ -1,61 +0,0 @@
1
- require_relative '../../../lib/sendgrid/template'
2
-
3
- module SendGrid
4
- describe Template do
5
- let(:id) { anything }
6
- subject { described_class.new(id) }
7
-
8
- describe '#initialize' do
9
- it 'sets the id instance var' do
10
- expect(subject.instance_variable_get(:@id)).to_not be_nil
11
- end
12
- end
13
-
14
- describe '#add_to_smtpapi' do
15
- let(:id) { rand(8999) }
16
- let(:smtpapi) { Smtpapi::Header.new }
17
-
18
- it 'adds enabled and the templates id' do
19
- expect(smtpapi).to receive(:add_filter).with(:templates, :enable, 1)
20
- expect(smtpapi).to receive(:add_filter).with(:templates, :template_id, id)
21
- subject.add_to_smtpapi(smtpapi)
22
- end
23
-
24
- context 'smtpapi is nil' do
25
- it 'does not error' do
26
- expect do
27
- subject.add_to_smtpapi(nil)
28
- end.to_not raise_error
29
- end
30
- end
31
-
32
- context 'with recipients' do
33
- let(:substitution_key) { :foo }
34
- let(:substitution_value) { :bar }
35
- let(:recipients) do
36
- [].tap do |recipients|
37
- 3.times.each do
38
- r = Recipient.new("test+#{ rand(100) }@example.com")
39
- r.add_substitution(substitution_key, substitution_value)
40
- recipients << r
41
- end
42
- end
43
- end
44
-
45
- before do
46
- recipients.each do |r|
47
- subject.add_recipient(r)
48
- end
49
- end
50
-
51
- it 'calls the recipients call to add to smtpapi' do
52
- recipients.each do |recipient|
53
- expect(recipient).to receive(:add_to_smtpapi).with(smtpapi)
54
- end
55
-
56
- subject.add_to_smtpapi(smtpapi)
57
- end
58
- end
59
- end
60
- end
61
- end
@@ -1,7 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe 'SendGrid' do
4
- it 'should have a version' do
5
- expect(SendGrid::VERSION).to eq('1.1.6')
6
- end
7
- end
data/spec/spec_helper.rb DELETED
@@ -1 +0,0 @@
1
- require_relative '../lib/sendgrid-ruby'