sendgrid-ruby 4.0.8 → 6.0.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.
- checksums.yaml +4 -4
- data/.codeclimate.yml +21 -0
- data/.env_sample +1 -0
- data/.github/PULL_REQUEST_TEMPLATE +26 -0
- data/.gitignore +1 -0
- data/.travis.yml +11 -2
- data/CHANGELOG.md +119 -3
- data/CODE_OF_CONDUCT.md +41 -0
- data/CONTRIBUTING.md +34 -30
- data/Gemfile +4 -1
- data/LICENSE.txt +1 -1
- data/README.md +53 -24
- data/Rakefile +7 -2
- data/TROUBLESHOOTING.md +41 -15
- data/UPGRADE.md +5 -0
- data/USAGE.md +1130 -1129
- data/USE_CASES.md +280 -16
- data/config.ru +4 -0
- data/docker/Dockerfile +12 -0
- data/docker/README.md +30 -0
- data/examples/helpers/mail/example.rb +62 -45
- data/examples/helpers/settings/example.rb +23 -0
- data/examples/helpers/stats/example.rb +42 -0
- data/examples/ips/ips.rb +13 -0
- data/examples/mail/mail.rb +2 -2
- data/examples/scopes/scopes.rb +49 -3
- data/examples/{whitelabel/whitelabel.rb → senderauthentication/senderauthentication.rb} +27 -27
- data/examples/suppression/suppression.rb +10 -10
- data/gemfiles/Sinatra_1.gemfile +6 -0
- data/gemfiles/Sinatra_2.gemfile +6 -0
- data/lib/sendgrid-ruby.rb +27 -1
- data/lib/sendgrid/client.rb +12 -9
- data/lib/sendgrid/helpers/inbound/README.md +98 -0
- data/lib/sendgrid/helpers/inbound/app.rb +32 -0
- data/lib/sendgrid/helpers/inbound/config.yml +26 -0
- data/lib/sendgrid/helpers/inbound/public/index.html +10 -0
- data/lib/sendgrid/helpers/inbound/sample_data/default_data.txt +58 -0
- data/lib/sendgrid/helpers/inbound/sample_data/raw_data.txt +57 -0
- data/lib/sendgrid/helpers/inbound/sample_data/raw_data_with_attachments.txt +298 -0
- data/lib/sendgrid/helpers/inbound/send.rb +26 -0
- data/lib/sendgrid/helpers/ip_management/ip_management.rb +17 -0
- data/lib/sendgrid/helpers/mail/README.md +1 -1
- data/lib/sendgrid/helpers/mail/asm.rb +33 -0
- data/lib/sendgrid/helpers/mail/attachment.rb +86 -0
- data/lib/sendgrid/helpers/mail/bcc_settings.rb +33 -0
- data/lib/sendgrid/helpers/mail/bypass_list_management.rb +43 -0
- data/lib/sendgrid/helpers/mail/category.rb +20 -0
- data/lib/sendgrid/helpers/mail/click_tracking.rb +33 -0
- data/lib/sendgrid/helpers/mail/content.rb +20 -0
- data/lib/sendgrid/helpers/mail/custom_arg.rb +24 -0
- data/lib/sendgrid/helpers/mail/email.rb +29 -0
- data/lib/sendgrid/helpers/mail/footer.rb +43 -0
- data/lib/sendgrid/helpers/mail/ganalytics.rb +74 -0
- data/lib/sendgrid/helpers/mail/header.rb +24 -0
- data/lib/sendgrid/helpers/mail/mail.rb +36 -895
- data/lib/sendgrid/helpers/mail/mail_settings.rb +63 -0
- data/lib/sendgrid/helpers/mail/open_tracking.rb +33 -0
- data/lib/sendgrid/helpers/mail/personalization.rb +82 -0
- data/lib/sendgrid/helpers/mail/section.rb +24 -0
- data/lib/sendgrid/helpers/mail/spam_check.rb +43 -0
- data/lib/sendgrid/helpers/mail/subscription_tracking.rb +53 -0
- data/lib/sendgrid/helpers/mail/substitution.rb +24 -0
- data/lib/sendgrid/helpers/mail/tracking_settings.rb +53 -0
- data/lib/sendgrid/helpers/permissions/scope.rb +28 -0
- data/lib/sendgrid/helpers/permissions/scopes.yml +309 -0
- data/lib/sendgrid/helpers/settings/README.md +14 -0
- data/lib/sendgrid/helpers/settings/mail_settings_dto.rb +13 -0
- data/lib/sendgrid/helpers/settings/partner_settings_dto.rb +13 -0
- data/lib/sendgrid/helpers/settings/settings.rb +28 -0
- data/lib/sendgrid/helpers/settings/tracking_settings_dto.rb +24 -0
- data/lib/sendgrid/helpers/settings/user_settings_dto.rb +13 -0
- data/lib/sendgrid/helpers/stats/email_stats.rb +46 -0
- data/lib/sendgrid/helpers/stats/metrics.rb +35 -0
- data/lib/sendgrid/helpers/stats/stats_response.rb +31 -0
- data/lib/sendgrid/version.rb +2 -2
- data/mail_helper_v3.md +390 -0
- data/sendgrid-ruby.gemspec +12 -5
- data/spec/sendgrid/helpers/ip_management/ip_management_spec.rb +12 -0
- data/spec/sendgrid/helpers/settings/mail_settings_dto_spec.rb +32 -0
- data/spec/sendgrid/helpers/settings/partner_settings_dto_spec.rb +24 -0
- data/spec/sendgrid/helpers/settings/settings_spec.rb +25 -0
- data/spec/sendgrid/helpers/settings/tracking_settings_dto_spec.rb +27 -0
- data/spec/sendgrid/helpers/settings/user_settings_dto_spec.rb +24 -0
- data/spec/sendgrid/helpers/stats/email_stats_spec.rb +112 -0
- data/spec/sendgrid/helpers/stats/metrics_spec.rb +46 -0
- data/spec/sendgrid/helpers/stats/stats_response_spec.rb +76 -0
- data/spec/spec_helper.rb +10 -0
- data/test/sendgrid/helpers/mail/test_attachment.rb +35 -0
- data/test/sendgrid/helpers/mail/test_category.rb +27 -0
- data/test/sendgrid/helpers/mail/test_email.rb +34 -0
- data/test/sendgrid/helpers/mail/test_mail.rb +198 -59
- data/test/sendgrid/helpers/mail/test_personalizations.rb +161 -0
- data/test/sendgrid/permissions/test_scopes.rb +38 -0
- data/test/sendgrid/test_sendgrid-ruby.rb +90 -9
- metadata +170 -10
data/sendgrid-ruby.gemspec
CHANGED
|
@@ -8,16 +8,23 @@ Gem::Specification.new do |spec|
|
|
|
8
8
|
spec.version = SendGrid::VERSION
|
|
9
9
|
spec.authors = ['Elmer Thomas', 'Robin Johnson', 'Eddie Zaneski']
|
|
10
10
|
spec.email = 'dx@sendgrid.com'
|
|
11
|
-
spec.summary = 'Official SendGrid Gem'
|
|
12
|
-
spec.description = 'Interact with SendGrids API in native Ruby'
|
|
11
|
+
spec.summary = 'Official Twilio SendGrid Gem'
|
|
12
|
+
spec.description = 'Official Twilio SendGrid Gem to Interact with Twilio SendGrids API in native Ruby'
|
|
13
13
|
spec.homepage = 'http://github.com/sendgrid/sendgrid-ruby'
|
|
14
|
+
|
|
15
|
+
spec.required_ruby_version = '>= 2.2'
|
|
16
|
+
|
|
14
17
|
spec.license = 'MIT'
|
|
15
18
|
spec.files = `git ls-files -z`.split("\x0")
|
|
16
19
|
spec.executables = spec.files.grep(/^bin/) { |f| File.basename(f) }
|
|
17
20
|
spec.test_files = spec.files.grep(/^(test|spec|features)/)
|
|
18
21
|
spec.require_paths = ['lib']
|
|
19
|
-
|
|
20
|
-
spec.
|
|
22
|
+
spec.add_dependency 'ruby_http_client', '~> 3.3.0'
|
|
23
|
+
spec.add_development_dependency 'sinatra', '>= 1.4.7', '< 3'
|
|
21
24
|
spec.add_development_dependency 'rake', '~> 0'
|
|
22
|
-
spec.add_development_dependency '
|
|
25
|
+
spec.add_development_dependency 'rspec'
|
|
26
|
+
spec.add_development_dependency 'pry'
|
|
27
|
+
spec.add_development_dependency 'faker'
|
|
28
|
+
spec.add_development_dependency 'rubocop'
|
|
29
|
+
spec.add_development_dependency 'minitest', '~> 5.9'
|
|
23
30
|
end
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe SendGrid::IpManagement do
|
|
4
|
+
let(:sendgrid_client) { SendGrid::API.new(api_key: 'fake_key').client }
|
|
5
|
+
let(:ip_management) { SendGrid::IpManagement.new(sendgrid_client: sendgrid_client) }
|
|
6
|
+
|
|
7
|
+
describe '.new' do
|
|
8
|
+
it 'initializes correctly' do
|
|
9
|
+
expect(ip_management).to be_a SendGrid::IpManagement
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe SendGrid::MailSettingsDto do
|
|
4
|
+
let(:sendgrid_client) { SendGrid::API.new(api_key: 'fake_key').client }
|
|
5
|
+
let(:mail_settings) { SendGrid::MailSettingsDto }
|
|
6
|
+
let(:setting_name) { 'bcc' }
|
|
7
|
+
let(:setting_params) { {email: Faker::Internet.email, enabled: rand(1..100).even?} }
|
|
8
|
+
|
|
9
|
+
it { should respond_to :bcc }
|
|
10
|
+
it { should respond_to :address_whitelist }
|
|
11
|
+
it { should respond_to :bounce_purge }
|
|
12
|
+
it { should respond_to :footer }
|
|
13
|
+
it { should respond_to :forward_spam }
|
|
14
|
+
it { should respond_to :forward_bounce }
|
|
15
|
+
it { should respond_to :plain_content }
|
|
16
|
+
it { should respond_to :spam_check }
|
|
17
|
+
it { should respond_to :template }
|
|
18
|
+
|
|
19
|
+
describe '.fetch' do
|
|
20
|
+
it 'calls get on sendgrid_client' do
|
|
21
|
+
args = { sendgrid_client: sendgrid_client, name: setting_name, query_params: {} }
|
|
22
|
+
expect(mail_settings.fetch(args)).to be_a SendGrid::Response
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
describe '.update' do
|
|
27
|
+
it 'calls patch on sendgrid_client' do
|
|
28
|
+
args = { sendgrid_client: sendgrid_client, name: setting_name, request_body: setting_params }
|
|
29
|
+
expect(mail_settings.update(args)).to be_a SendGrid::Response
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe SendGrid::PartnerSettingsDto do
|
|
4
|
+
let(:sendgrid_client) { SendGrid::API.new(api_key: 'fake_key').client }
|
|
5
|
+
let(:partner_settings) { SendGrid::PartnerSettingsDto }
|
|
6
|
+
let(:setting_name) { 'new_relic' }
|
|
7
|
+
let(:setting_params) { {license_key: 'key', enabled: rand(1..100).even?} }
|
|
8
|
+
|
|
9
|
+
it { should respond_to :new_relic }
|
|
10
|
+
|
|
11
|
+
describe '.fetch' do
|
|
12
|
+
it 'calls get on sendgrid_client' do
|
|
13
|
+
args = { sendgrid_client: sendgrid_client, name: setting_name, query_params: {} }
|
|
14
|
+
expect(partner_settings.fetch(args)).to be_a SendGrid::Response
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
describe '.update' do
|
|
19
|
+
it 'calls patch on sendgrid_client' do
|
|
20
|
+
args = { sendgrid_client: sendgrid_client, name: setting_name, request_body: setting_params }
|
|
21
|
+
expect(partner_settings.update(args)).to be_a SendGrid::Response
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe SendGrid::Settings do
|
|
4
|
+
let(:sendgrid_client) { SendGrid::API.new(api_key: 'fake_key').client }
|
|
5
|
+
let(:settings) { SendGrid::Settings.new(sendgrid_client: sendgrid_client) }
|
|
6
|
+
|
|
7
|
+
describe '.new' do
|
|
8
|
+
it 'initializes correctly' do
|
|
9
|
+
expect(settings).to be_a SendGrid::Settings
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
describe '.bcc' do
|
|
14
|
+
it 'fetches bcc data' do
|
|
15
|
+
expect(settings.bcc).to be_a SendGrid::Response
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
describe '.update_bcc' do
|
|
20
|
+
it 'updates bcc' do
|
|
21
|
+
bcc_response = settings.update_bcc(enabled: true, email: "email@example.com")
|
|
22
|
+
expect(bcc_response).to be_a SendGrid::Response
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe SendGrid::TrackingSettingsDto do
|
|
4
|
+
let(:sendgrid_client) { SendGrid::API.new(api_key: 'fake_key').client }
|
|
5
|
+
let(:tracking_settings) { SendGrid::TrackingSettingsDto }
|
|
6
|
+
let(:setting_name) { 'open_tracking' }
|
|
7
|
+
let(:setting_params) { {enabled: rand(1..100).even?} }
|
|
8
|
+
|
|
9
|
+
it { should respond_to :open_tracking }
|
|
10
|
+
it { should respond_to :click_tracking }
|
|
11
|
+
it { should respond_to :google_analytics }
|
|
12
|
+
it { should respond_to :subscription_tracking }
|
|
13
|
+
|
|
14
|
+
describe '.fetch' do
|
|
15
|
+
it 'calls get on sendgrid_client' do
|
|
16
|
+
args = { sendgrid_client: sendgrid_client, name: setting_name, query_params: {} }
|
|
17
|
+
expect(tracking_settings.fetch(args)).to be_a SendGrid::Response
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
describe '.update' do
|
|
22
|
+
it 'calls patch on sendgrid_client' do
|
|
23
|
+
args = { sendgrid_client: sendgrid_client, name: setting_name, request_body: setting_params }
|
|
24
|
+
expect(tracking_settings.update(args)).to be_a SendGrid::Response
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe SendGrid::UserSettingsDto do
|
|
4
|
+
let(:sendgrid_client) { SendGrid::API.new(api_key: 'fake_key').client }
|
|
5
|
+
let(:user_settings) { SendGrid::UserSettingsDto }
|
|
6
|
+
let(:setting_name) { 'enforced_tls' }
|
|
7
|
+
let(:setting_params) { {require_tls: rand(1..100).even?} }
|
|
8
|
+
|
|
9
|
+
it { should respond_to :enforced_tls }
|
|
10
|
+
|
|
11
|
+
describe '.fetch' do
|
|
12
|
+
it 'calls get on sendgrid_client' do
|
|
13
|
+
args = { sendgrid_client: sendgrid_client, name: setting_name, query_params: {} }
|
|
14
|
+
expect(user_settings.fetch(args)).to be_a SendGrid::Response
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
describe '.update' do
|
|
19
|
+
it 'calls patch on sendgrid_client' do
|
|
20
|
+
args = { sendgrid_client: sendgrid_client, name: setting_name, request_body: setting_params }
|
|
21
|
+
expect(user_settings.update(args)).to be_a SendGrid::Response
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe SendGrid::EmailStats do
|
|
4
|
+
let(:sg_client) { SendGrid::API.new(api_key: 'abcd').client }
|
|
5
|
+
let(:stats) { SendGrid::EmailStats.new(sendgrid_client: sg_client) }
|
|
6
|
+
let(:sg_response) { double('SendGrid::Response') }
|
|
7
|
+
|
|
8
|
+
let(:sample_response) do
|
|
9
|
+
[{
|
|
10
|
+
"date" => "2017-10-01",
|
|
11
|
+
"stats" => [
|
|
12
|
+
{"metrics" =>
|
|
13
|
+
{
|
|
14
|
+
"blocks" => 101,
|
|
15
|
+
"bounce_drops" => 102,
|
|
16
|
+
"bounces" => 103,
|
|
17
|
+
"clicks" => 104,
|
|
18
|
+
"deferred" => 105,
|
|
19
|
+
"delivered" => 106,
|
|
20
|
+
"invalid_emails" => 107,
|
|
21
|
+
"opens" => 108,
|
|
22
|
+
"processed" => 109,
|
|
23
|
+
"requests" => 110,
|
|
24
|
+
"spam_report_drops" => 111,
|
|
25
|
+
"spam_reports" => 112,
|
|
26
|
+
"unique_clicks" => 113,
|
|
27
|
+
"unique_opens" => 114,
|
|
28
|
+
"unsubscribe_drops" => 115,
|
|
29
|
+
"unsubscribes" => 116
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
]
|
|
33
|
+
}]
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
let(:error_response) do
|
|
37
|
+
{
|
|
38
|
+
"errors" => [
|
|
39
|
+
{
|
|
40
|
+
"message" => "end_date should be a YYYY-MM-DD formatted date"
|
|
41
|
+
}
|
|
42
|
+
]
|
|
43
|
+
}
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
describe '.new' do
|
|
47
|
+
it 'initializes with SendGrid::Client' do
|
|
48
|
+
expect(stats).to be_a SendGrid::EmailStats
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
describe 'successful response' do
|
|
53
|
+
before do
|
|
54
|
+
allow_any_instance_of(SendGrid::Response).to receive(:body) { sample_response.to_json }
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
describe '#by_day' do
|
|
58
|
+
it 'fetches data aggregated by day' do
|
|
59
|
+
day_stats = stats.by_day('2017-10-01', '2017-10-02')
|
|
60
|
+
day_metrics = day_stats.metrics.first
|
|
61
|
+
|
|
62
|
+
expect(day_metrics).to be_a SendGrid::Metrics
|
|
63
|
+
expect(day_metrics.date.to_s).to eq('2017-10-01')
|
|
64
|
+
expect(day_metrics.requests).to eq(110)
|
|
65
|
+
expect(day_metrics.clicks).to eq(104)
|
|
66
|
+
expect(day_metrics.bounces).to eq(103)
|
|
67
|
+
expect(day_metrics.opens).to eq(108)
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
describe '#by_week' do
|
|
72
|
+
it 'fetches data aggregated by week' do
|
|
73
|
+
day_stats = stats.by_week('2017-10-01', '2017-10-12')
|
|
74
|
+
day_metrics = day_stats.metrics.first
|
|
75
|
+
|
|
76
|
+
expect(day_metrics).to be_a SendGrid::Metrics
|
|
77
|
+
expect(day_metrics.date.to_s).to eq('2017-10-01')
|
|
78
|
+
expect(day_metrics.requests).to eq(110)
|
|
79
|
+
expect(day_metrics.clicks).to eq(104)
|
|
80
|
+
expect(day_metrics.bounces).to eq(103)
|
|
81
|
+
expect(day_metrics.opens).to eq(108)
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
describe '#by_month' do
|
|
86
|
+
it 'fetches data aggregated by month' do
|
|
87
|
+
day_stats = stats.by_month('2017-10-01', '2017-11-01')
|
|
88
|
+
day_metrics = day_stats.metrics.first
|
|
89
|
+
|
|
90
|
+
expect(day_metrics).to be_a SendGrid::Metrics
|
|
91
|
+
expect(day_metrics.date.to_s).to eq('2017-10-01')
|
|
92
|
+
expect(day_metrics.requests).to eq(110)
|
|
93
|
+
expect(day_metrics.clicks).to eq(104)
|
|
94
|
+
expect(day_metrics.bounces).to eq(103)
|
|
95
|
+
expect(day_metrics.opens).to eq(108)
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
describe 'error response' do
|
|
101
|
+
before do
|
|
102
|
+
allow_any_instance_of(SendGrid::Response).to receive(:body) { error_response.to_json }
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
it 'fetches data aggregated by month' do
|
|
106
|
+
day_stats = stats.by_month('2017-10-01', '2017-10-02')
|
|
107
|
+
|
|
108
|
+
expect(day_stats.errors).to include('end_date should be a YYYY-MM-DD formatted date')
|
|
109
|
+
expect(day_stats.error?).to be_truthy
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
end
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe SendGrid::Metrics do
|
|
4
|
+
let(:params) do
|
|
5
|
+
{
|
|
6
|
+
"date" => "2017-10-01",
|
|
7
|
+
"blocks" => 101,
|
|
8
|
+
"bounce_drops" => 102,
|
|
9
|
+
"bounces" => 103,
|
|
10
|
+
"clicks" => 104,
|
|
11
|
+
"deferred" => 105,
|
|
12
|
+
"delivered" => 106,
|
|
13
|
+
"invalid_emails" => 107,
|
|
14
|
+
"opens" => 108,
|
|
15
|
+
"processed" => 109,
|
|
16
|
+
"requests" => 110,
|
|
17
|
+
"spam_report_drops" => 111,
|
|
18
|
+
"spam_reports" => 112,
|
|
19
|
+
"unique_clicks" => 113,
|
|
20
|
+
"unique_opens" => 114,
|
|
21
|
+
"unsubscribe_drops" => 115,
|
|
22
|
+
"unsubscribes" => 116
|
|
23
|
+
}
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
subject { described_class.new(params) }
|
|
27
|
+
|
|
28
|
+
it 'initializes with metric parameters' do
|
|
29
|
+
expect(subject).to be_a SendGrid::Metrics
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
it 'returns date as object' do
|
|
33
|
+
expect(subject.date).to be_a Date
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
%w(
|
|
37
|
+
blocks bounce_drops bounces clicks deferred delivered invalid_emails
|
|
38
|
+
opens processed requests spam_report_drops spam_reports unique_clicks
|
|
39
|
+
unique_opens unsubscribe_drops unsubscribes
|
|
40
|
+
).each do |attribute|
|
|
41
|
+
it "responds to #{attribute}" do
|
|
42
|
+
expect(subject).to respond_to(attribute.to_sym)
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
end
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe SendGrid::StatsResponse do
|
|
4
|
+
let(:params) do
|
|
5
|
+
[{
|
|
6
|
+
"date" => "2017-10-01",
|
|
7
|
+
"stats" => [
|
|
8
|
+
{"metrics" =>
|
|
9
|
+
{
|
|
10
|
+
"blocks" => 101,
|
|
11
|
+
"bounce_drops" => 102,
|
|
12
|
+
"bounces" => 103,
|
|
13
|
+
"clicks" => 104,
|
|
14
|
+
"deferred" => 105,
|
|
15
|
+
"delivered" => 106,
|
|
16
|
+
"invalid_emails" => 107,
|
|
17
|
+
"opens" => 108,
|
|
18
|
+
"processed" => 109,
|
|
19
|
+
"requests" => 110,
|
|
20
|
+
"spam_report_drops" => 111,
|
|
21
|
+
"spam_reports" => 112,
|
|
22
|
+
"unique_clicks" => 113,
|
|
23
|
+
"unique_opens" => 114,
|
|
24
|
+
"unsubscribe_drops" => 115,
|
|
25
|
+
"unsubscribes" => 116
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
]
|
|
29
|
+
}]
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
subject { described_class.new(params) }
|
|
33
|
+
|
|
34
|
+
it 'initialized with JSON response body' do
|
|
35
|
+
expect(subject).to be_a SendGrid::StatsResponse
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
describe '#metrics' do
|
|
39
|
+
it 'returns an array of metrics' do
|
|
40
|
+
metric = subject.metrics.first
|
|
41
|
+
|
|
42
|
+
expect(subject.metrics).to be_a Array
|
|
43
|
+
expect(metric.date.to_s).to eq('2017-10-01')
|
|
44
|
+
expect(metric.requests).to eq(110)
|
|
45
|
+
expect(metric.clicks).to eq(104)
|
|
46
|
+
expect(metric.bounces).to eq(103)
|
|
47
|
+
expect(metric.opens).to eq(108)
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
context 'errors' do
|
|
52
|
+
let(:error_params) do
|
|
53
|
+
{
|
|
54
|
+
"errors" => [
|
|
55
|
+
{
|
|
56
|
+
"message" => "end_date should be a YYYY-MM-DD formatted date"
|
|
57
|
+
}
|
|
58
|
+
]
|
|
59
|
+
}
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
subject { described_class.new(error_params) }
|
|
63
|
+
|
|
64
|
+
describe '#errors' do
|
|
65
|
+
it 'shows a list of errors' do
|
|
66
|
+
expect(subject.errors).to include('end_date should be a YYYY-MM-DD formatted date')
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
describe '#error?' do
|
|
71
|
+
it 'returns true if there is an error' do
|
|
72
|
+
expect(subject.error?).to be_truthy
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
end
|
data/spec/spec_helper.rb
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
require_relative "../../../../lib/sendgrid/helpers/mail/attachment"
|
|
3
|
+
include SendGrid
|
|
4
|
+
require "json"
|
|
5
|
+
require "minitest/autorun"
|
|
6
|
+
|
|
7
|
+
class TestAttachment < Minitest::Test
|
|
8
|
+
SAMPLE_INPUT = """Es blüht so grün wie Blüten blüh'n im Frühling
|
|
9
|
+
Es blüht so grün wie Blüten blüh'n im Frühling
|
|
10
|
+
Es blüht so grün wie Blüten blüh'n im Frühling
|
|
11
|
+
Es blüht so grün wie Blüten blüh'n im Frühling
|
|
12
|
+
Es blüht so grün wie Blüten blüh'n im Frühling
|
|
13
|
+
""".force_encoding('UTF-8').encode
|
|
14
|
+
|
|
15
|
+
def setup
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def test_io_enocding
|
|
19
|
+
attachment = Attachment.new
|
|
20
|
+
attachment.content = StringIO.new(SAMPLE_INPUT)
|
|
21
|
+
|
|
22
|
+
expected = {
|
|
23
|
+
"content" => "RXMgYmzDvGh0IHNvIGdyw7xuIHdpZSBCbMO8dGVuIGJsw7xoJ24gaW0gRnLD\nvGhsaW5nCkVzIGJsw7xodCBzbyBncsO8biB3aWUgQmzDvHRlbiBibMO8aCdu\nIGltIEZyw7xobGluZwpFcyBibMO8aHQgc28gZ3LDvG4gd2llIEJsw7x0ZW4g\nYmzDvGgnbiBpbSBGcsO8aGxpbmcKRXMgYmzDvGh0IHNvIGdyw7xuIHdpZSBC\nbMO8dGVuIGJsw7xoJ24gaW0gRnLDvGhsaW5nCkVzIGJsw7xodCBzbyBncsO8\nbiB3aWUgQmzDvHRlbiBibMO8aCduIGltIEZyw7xobGluZwo=\n"
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
json = attachment.to_json
|
|
27
|
+
|
|
28
|
+
# Double check that the decoded json matches original input.
|
|
29
|
+
decoded = Base64.decode64(json["content"]).force_encoding('UTF-8').encode
|
|
30
|
+
|
|
31
|
+
assert_equal(decoded, SAMPLE_INPUT)
|
|
32
|
+
|
|
33
|
+
assert_equal(json, expected)
|
|
34
|
+
end
|
|
35
|
+
end
|