sendgrid-ruby 5.1.0 → 5.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -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
@@ -0,0 +1,34 @@
1
+ require_relative '../../../../lib/sendgrid/helpers/mail/email'
2
+ require 'minitest/autorun'
3
+
4
+ class TestEmail < Minitest::Test
5
+
6
+ include SendGrid
7
+
8
+ def test_split_email_full_email
9
+ @email = Email.new(email: "Example User <test1@example.com>")
10
+ expected_json = {
11
+ "email"=>"test1@example.com",
12
+ "name"=>"Example User"
13
+ }
14
+ assert_equal @email.to_json, expected_json
15
+ end
16
+
17
+ def test_split_email_only_email
18
+ @email = Email.new(email: "test1@example.com")
19
+ expected_json = {
20
+ "email"=>"test1@example.com",
21
+ }
22
+ assert_equal @email.to_json, expected_json
23
+ end
24
+
25
+ def test_split_email_name_and_email
26
+ @email = Email.new(name: "Example User", email: "test1@example.com")
27
+ expected_json = {
28
+ "email"=>"test1@example.com",
29
+ "name"=>"Example User"
30
+ }
31
+ assert_equal @email.to_json, expected_json
32
+ end
33
+
34
+ end
@@ -55,7 +55,7 @@ class TestAPI < MiniTest::Test
55
55
  ')
56
56
  assert_equal(test_headers, sg.request_headers)
57
57
  assert_equal("v3", sg.version)
58
- assert_equal("5.1.0", SendGrid::VERSION)
58
+ assert_equal("5.2.0", SendGrid::VERSION)
59
59
  assert_instance_of(SendGrid::Client, sg.client)
60
60
  end
61
61
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sendgrid-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.1.0
4
+ version: 5.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Elmer Thomas
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2017-09-01 00:00:00.000000000 Z
13
+ date: 2017-10-31 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: ruby_http_client
@@ -122,10 +122,13 @@ executables: []
122
122
  extensions: []
123
123
  extra_rdoc_files: []
124
124
  files:
125
+ - ".env_sample"
125
126
  - ".github/ISSUE_TEMPLATE"
127
+ - ".github/PULL_REQUEST_TEMPLATE"
126
128
  - ".gitignore"
127
129
  - ".travis.yml"
128
130
  - CHANGELOG.md
131
+ - CODE_OF_CONDUCT.md
129
132
  - CONTRIBUTING.md
130
133
  - Gemfile
131
134
  - LICENSE.txt
@@ -148,6 +151,7 @@ files:
148
151
  - examples/geo/geo.rb
149
152
  - examples/helpers/mail/example.rb
150
153
  - examples/helpers/settings/example.rb
154
+ - examples/helpers/stats/example.rb
151
155
  - examples/ips/ips.rb
152
156
  - examples/mail/mail.rb
153
157
  - examples/mailboxproviders/mailboxproviders.rb
@@ -202,6 +206,9 @@ files:
202
206
  - lib/sendgrid/helpers/settings/settings.rb
203
207
  - lib/sendgrid/helpers/settings/tracking_settings_dto.rb
204
208
  - lib/sendgrid/helpers/settings/user_settings_dto.rb
209
+ - lib/sendgrid/helpers/stats/email_stats.rb
210
+ - lib/sendgrid/helpers/stats/metrics.rb
211
+ - lib/sendgrid/helpers/stats/stats_response.rb
205
212
  - lib/sendgrid/version.rb
206
213
  - mail_helper_v3.md
207
214
  - sendgrid-ruby.gemspec
@@ -210,9 +217,13 @@ files:
210
217
  - spec/sendgrid/helpers/settings/settings_spec.rb
211
218
  - spec/sendgrid/helpers/settings/tracking_settings_dto_spec.rb
212
219
  - spec/sendgrid/helpers/settings/user_settings_dto_spec.rb
220
+ - spec/sendgrid/helpers/stats/email_stats_spec.rb
221
+ - spec/sendgrid/helpers/stats/metrics_spec.rb
222
+ - spec/sendgrid/helpers/stats/stats_response_spec.rb
213
223
  - spec/spec_helper.rb
214
224
  - test/prism.sh
215
225
  - test/sendgrid/helpers/mail/test_category.rb
226
+ - test/sendgrid/helpers/mail/test_email.rb
216
227
  - test/sendgrid/helpers/mail/test_mail.rb
217
228
  - test/sendgrid/helpers/mail/test_personalizations.rb
218
229
  - test/sendgrid/test_sendgrid-ruby.rb
@@ -246,9 +257,13 @@ test_files:
246
257
  - spec/sendgrid/helpers/settings/settings_spec.rb
247
258
  - spec/sendgrid/helpers/settings/tracking_settings_dto_spec.rb
248
259
  - spec/sendgrid/helpers/settings/user_settings_dto_spec.rb
260
+ - spec/sendgrid/helpers/stats/email_stats_spec.rb
261
+ - spec/sendgrid/helpers/stats/metrics_spec.rb
262
+ - spec/sendgrid/helpers/stats/stats_response_spec.rb
249
263
  - spec/spec_helper.rb
250
264
  - test/prism.sh
251
265
  - test/sendgrid/helpers/mail/test_category.rb
266
+ - test/sendgrid/helpers/mail/test_email.rb
252
267
  - test/sendgrid/helpers/mail/test_mail.rb
253
268
  - test/sendgrid/helpers/mail/test_personalizations.rb
254
269
  - test/sendgrid/test_sendgrid-ruby.rb