sendgrid4r 0.2.0 → 0.3.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 (61) hide show
  1. checksums.yaml +4 -4
  2. data/.env.example +5 -0
  3. data/.rubocop.yml +8 -8
  4. data/README.md +2 -0
  5. data/lib/auth.rb +5 -2
  6. data/lib/client.rb +4 -2
  7. data/lib/sendgrid4r/factory/version_factory.rb +1 -1
  8. data/lib/sendgrid4r/rest/api.rb +4 -0
  9. data/lib/sendgrid4r/rest/api_keys/api_keys.rb +73 -0
  10. data/lib/sendgrid4r/rest/asm/asm.rb +28 -0
  11. data/lib/sendgrid4r/rest/asm/global_suppressions.rb +12 -8
  12. data/lib/sendgrid4r/rest/asm/groups.rb +29 -22
  13. data/lib/sendgrid4r/rest/asm/suppressions.rb +25 -15
  14. data/lib/sendgrid4r/rest/categories/categories.rb +19 -9
  15. data/lib/sendgrid4r/rest/contacts/custom_fields.rb +14 -8
  16. data/lib/sendgrid4r/rest/contacts/lists.rb +32 -20
  17. data/lib/sendgrid4r/rest/contacts/recipients.rb +42 -31
  18. data/lib/sendgrid4r/rest/contacts/reserved_fields.rb +6 -2
  19. data/lib/sendgrid4r/rest/contacts/segments.rb +22 -12
  20. data/lib/sendgrid4r/rest/ips/addresses.rb +36 -22
  21. data/lib/sendgrid4r/rest/ips/pools.rb +31 -16
  22. data/lib/sendgrid4r/rest/ips/warmup.rb +34 -15
  23. data/lib/sendgrid4r/rest/request.rb +33 -19
  24. data/lib/sendgrid4r/rest/settings/enforced_tls.rb +12 -5
  25. data/lib/sendgrid4r/rest/stats/advanced.rb +73 -25
  26. data/lib/sendgrid4r/rest/stats/category.rb +11 -6
  27. data/lib/sendgrid4r/rest/stats/global.rb +6 -4
  28. data/lib/sendgrid4r/rest/stats/parse.rb +10 -4
  29. data/lib/sendgrid4r/rest/stats/stats.rb +13 -18
  30. data/lib/sendgrid4r/rest/stats/subuser.rb +10 -6
  31. data/lib/sendgrid4r/rest/templates/templates.rb +23 -16
  32. data/lib/sendgrid4r/rest/templates/versions.rb +39 -36
  33. data/lib/sendgrid4r/version.rb +1 -1
  34. data/spec/api_keys/api_keys_spec.rb +152 -0
  35. data/spec/asm/asm_spec.rb +33 -0
  36. data/spec/asm/global_suppressions_spec.rb +111 -45
  37. data/spec/asm/groups_spec.rb +172 -48
  38. data/spec/asm/suppressions_spec.rb +180 -54
  39. data/spec/categories/categories_spec.rb +81 -25
  40. data/spec/client_spec.rb +11 -4
  41. data/spec/contacts/custom_fields_spec.rb +135 -44
  42. data/spec/contacts/lists_spec.rb +314 -84
  43. data/spec/contacts/recipients_spec.rb +337 -92
  44. data/spec/contacts/reserved_fields_spec.rb +80 -60
  45. data/spec/contacts/segments_spec.rb +219 -88
  46. data/spec/factory/condition_factory_spec.rb +12 -12
  47. data/spec/factory/segment_factory_spec.rb +19 -19
  48. data/spec/factory/version_factory_spec.rb +6 -6
  49. data/spec/ips/addresses_spec.rb +177 -84
  50. data/spec/ips/pools_spec.rb +190 -34
  51. data/spec/ips/warmup_spec.rb +106 -38
  52. data/spec/settings/enforced_tls_spec.rb +76 -18
  53. data/spec/stats/advanced_spec.rb +373 -196
  54. data/spec/stats/category_spec.rb +133 -71
  55. data/spec/stats/global_spec.rb +74 -47
  56. data/spec/stats/parse_spec.rb +46 -29
  57. data/spec/stats/stats_spec.rb +246 -0
  58. data/spec/stats/subuser_spec.rb +99 -54
  59. data/spec/templates/templates_spec.rb +219 -54
  60. data/spec/templates/versions_spec.rb +171 -67
  61. metadata +10 -2
@@ -1,29 +1,87 @@
1
1
  # encoding: utf-8
2
2
  require File.dirname(__FILE__) + '/../spec_helper'
3
3
 
4
- describe 'SendGrid4r::REST::Stats::Cateogry' do
5
- before :all do
6
- Dotenv.load
7
- @client = SendGrid4r::Client.new(
8
- ENV['SENDGRID_USERNAME'], ENV['SENDGRID_PASSWORD'])
9
- end
4
+ describe SendGrid4r::REST::Stats::Category do
5
+ describe 'integration test' do
6
+ before do
7
+ Dotenv.load
8
+ @client = SendGrid4r::Client.new(
9
+ username: ENV['SENDGRID_USERNAME'],
10
+ password: ENV['SENDGRID_PASSWORD'])
11
+ end
10
12
 
11
- context 'always' do
12
- describe '#get_categories_stats' do
13
- it 'returns categories stats if specify mandatory params' do
14
- actual = @client.get_categories_stats(
15
- start_date: '2015-01-01',
16
- categories: 'yui'
17
- )
18
- expect(actual.class).to be(Array)
19
- expect(actual.length > 0).to be(true)
20
- actual.each do |global_stat|
21
- expect(global_stat.class).to be(SendGrid4r::REST::Stats::TopStat)
22
- stats = global_stat.stats
23
- expect(stats.length).to eq(1)
24
- stats.each do |stat|
25
- expect(stat.class).to be(SendGrid4r::REST::Stats::Stat)
26
- expect(stat.metrics.class).to be(SendGrid4r::REST::Stats::Metric)
13
+ context 'without block call' do
14
+ it '#get_categories_stats with mandatory params' do
15
+ begin
16
+ top_stats = @client.get_categories_stats(
17
+ start_date: '2015-01-01',
18
+ categories: 'yui'
19
+ )
20
+ expect(top_stats).to be_a(Array)
21
+ top_stats.each do |top_stat|
22
+ expect(top_stat).to be_a(SendGrid4r::REST::Stats::TopStat)
23
+ expect(top_stat.stats.length).to eq(1)
24
+ top_stat.stats.each do |stat|
25
+ expect(stat).to be_a(SendGrid4r::REST::Stats::Stat)
26
+ expect(stat.metrics).to be_a(SendGrid4r::REST::Stats::Metric)
27
+ expect(stat.metrics.blocks.nil?).to be(false)
28
+ expect(stat.metrics.bounce_drops.nil?).to be(false)
29
+ expect(stat.metrics.bounces.nil?).to be(false)
30
+ expect(stat.metrics.clicks.nil?).to be(false)
31
+ expect(stat.metrics.deferred.nil?).to be(false)
32
+ expect(stat.metrics.delivered.nil?).to be(false)
33
+ expect(stat.metrics.invalid_emails.nil?).to be(false)
34
+ expect(stat.metrics.opens.nil?).to be(false)
35
+ expect(stat.metrics.processed.nil?).to be(false)
36
+ expect(stat.metrics.requests.nil?).to be(false)
37
+ expect(stat.metrics.spam_report_drops.nil?).to be(false)
38
+ expect(stat.metrics.spam_reports.nil?).to be(false)
39
+ expect(stat.metrics.unique_clicks.nil?).to be(false)
40
+ expect(stat.metrics.unique_opens.nil?).to be(false)
41
+ expect(stat.metrics.unsubscribe_drops.nil?).to be(false)
42
+ expect(stat.metrics.unsubscribes.nil?).to be(false)
43
+ expect(stat.name).to be_a(String)
44
+ expect(stat.type).to eq('category')
45
+ end
46
+ end
47
+ rescue => e
48
+ puts e.inspect
49
+ raise e
50
+ end
51
+ end
52
+
53
+ it '#get_category_stats with all params' do
54
+ begin
55
+ top_stats = @client.get_categories_stats(
56
+ start_date: '2015-01-01',
57
+ end_date: '2015-01-02',
58
+ aggregated_by: SendGrid4r::REST::Stats::AggregatedBy::WEEK,
59
+ categories: 'yui'
60
+ )
61
+ expect(top_stats).to be_a(Array)
62
+ top_stats.each do |top_stat|
63
+ expect(top_stat).to be_a(SendGrid4r::REST::Stats::TopStat)
64
+ expect(top_stat.stats.length).to eq(1)
65
+ top_stat.stats.each do |stat|
66
+ expect(stat).to be_a(SendGrid4r::REST::Stats::Stat)
67
+ expect(stat.metrics).to be_a(SendGrid4r::REST::Stats::Metric)
68
+ end
69
+ end
70
+ rescue => e
71
+ puts e.inspect
72
+ raise e
73
+ end
74
+ end
75
+
76
+ it '#get_categories_stats_sums with mandatory params' do
77
+ begin
78
+ top_stat =
79
+ @client.get_categories_stats_sums(start_date: '2015-01-01')
80
+ expect(top_stat).to be_a(SendGrid4r::REST::Stats::TopStat)
81
+ expect(top_stat.date).to eq('2015-01-01')
82
+ top_stat.stats.each do |stat|
83
+ expect(stat).to be_a(SendGrid4r::REST::Stats::Stat)
84
+ expect(stat.metrics).to be_a(SendGrid4r::REST::Stats::Metric)
27
85
  expect(stat.metrics.blocks.nil?).to be(false)
28
86
  expect(stat.metrics.bounce_drops.nil?).to be(false)
29
87
  expect(stat.metrics.bounces.nil?).to be(false)
@@ -40,71 +98,75 @@ describe 'SendGrid4r::REST::Stats::Cateogry' do
40
98
  expect(stat.metrics.unique_opens.nil?).to be(false)
41
99
  expect(stat.metrics.unsubscribe_drops.nil?).to be(false)
42
100
  expect(stat.metrics.unsubscribes.nil?).to be(false)
101
+ expect(stat.name).to be_a(String)
102
+ expect(stat.type).to eq('category')
103
+ end
104
+ rescue => e
105
+ puts e.inspect
106
+ raise e
107
+ end
108
+ end
109
+
110
+ it '#get_categories_stats_sums with all params' do
111
+ begin
112
+ top_stat = @client.get_categories_stats_sums(
113
+ start_date: '2015-01-01',
114
+ end_date: '2015-01-02',
115
+ sort_by_metric: 'opens',
116
+ sort_by_direction: 'desc',
117
+ limit: 5,
118
+ offset: 0
119
+ )
120
+ expect(top_stat).to be_a(SendGrid4r::REST::Stats::TopStat)
121
+ expect(top_stat.stats.length).to eq(0)
122
+ top_stat.stats.each do |stat|
123
+ expect(stat).to be_a(SendGrid4r::REST::Stats::Stat)
124
+ expect(stat.metrics_a).to be(SendGrid4r::REST::Stats::Metric)
43
125
  end
126
+ rescue => e
127
+ puts e.inspect
128
+ raise e
44
129
  end
45
130
  end
46
- it 'returns categories stats if specify all params' do
47
- actual = @client.get_categories_stats(
131
+ end
132
+
133
+ context 'with block call' do
134
+ it '#get_category_stats with all params' do
135
+ @client.get_categories_stats(
48
136
  start_date: '2015-01-01',
49
137
  end_date: '2015-01-02',
50
138
  aggregated_by: SendGrid4r::REST::Stats::AggregatedBy::WEEK,
51
139
  categories: 'yui'
52
- )
53
- expect(actual.class).to be(Array)
54
- expect(actual.length > 0).to be(true)
55
- actual.each do |global_stat|
56
- expect(global_stat.class).to be(SendGrid4r::REST::Stats::TopStat)
57
- stats = global_stat.stats
58
- expect(stats.length).to eq(1)
59
- stats.each do |stat|
60
- expect(stat.class).to be(SendGrid4r::REST::Stats::Stat)
61
- expect(stat.metrics.class).to be(SendGrid4r::REST::Stats::Metric)
140
+ ) do |resp, req, res|
141
+ resp =
142
+ SendGrid4r::REST::Stats.create_top_stats(
143
+ JSON.parse(resp)
144
+ )
145
+ expect(resp).to be_a(Array)
146
+ resp.each do |stat|
147
+ expect(stat).to be_a(SendGrid4r::REST::Stats::TopStat)
62
148
  end
149
+ expect(req).to be_a(RestClient::Request)
150
+ expect(res).to be_a(Net::HTTPOK)
63
151
  end
64
152
  end
65
- end
66
- describe '#get_categories_stats_sums' do
67
- it 'returns categories stats sums if specify mandatory params' do
68
- actual = @client.get_categories_stats_sums(start_date: '2015-01-01')
69
- expect(actual.class).to be(SendGrid4r::REST::Stats::TopStat)
70
- stats = actual.stats
71
- expect(stats.length > 0).to eq(true)
72
- stats.each do |stat|
73
- expect(stat.class).to be(SendGrid4r::REST::Stats::Stat)
74
- expect(stat.metrics.class).to be(SendGrid4r::REST::Stats::Metric)
75
- expect(stat.metrics.blocks.nil?).to be(false)
76
- expect(stat.metrics.bounce_drops.nil?).to be(false)
77
- expect(stat.metrics.bounces.nil?).to be(false)
78
- expect(stat.metrics.clicks.nil?).to be(false)
79
- expect(stat.metrics.deferred.nil?).to be(false)
80
- expect(stat.metrics.delivered.nil?).to be(false)
81
- expect(stat.metrics.invalid_emails.nil?).to be(false)
82
- expect(stat.metrics.opens.nil?).to be(false)
83
- expect(stat.metrics.processed.nil?).to be(false)
84
- expect(stat.metrics.requests.nil?).to be(false)
85
- expect(stat.metrics.spam_report_drops.nil?).to be(false)
86
- expect(stat.metrics.spam_reports.nil?).to be(false)
87
- expect(stat.metrics.unique_clicks.nil?).to be(false)
88
- expect(stat.metrics.unique_opens.nil?).to be(false)
89
- expect(stat.metrics.unsubscribe_drops.nil?).to be(false)
90
- expect(stat.metrics.unsubscribes.nil?).to be(false)
91
- end
92
- end
93
- it 'returns categories stats sums if specify all params' do
94
- actual = @client.get_categories_stats_sums(
153
+
154
+ it '#get_categories_stats_sums with all params' do
155
+ @client.get_categories_stats_sums(
95
156
  start_date: '2015-01-01',
96
157
  end_date: '2015-01-02',
97
158
  sort_by_metric: 'opens',
98
159
  sort_by_direction: 'desc',
99
160
  limit: 5,
100
161
  offset: 0
101
- )
102
- expect(actual.class).to be(SendGrid4r::REST::Stats::TopStat)
103
- stats = actual.stats
104
- expect(stats.length).to eq(0)
105
- stats.each do |stat|
106
- expect(stat.class).to be(SendGrid4r::REST::Stats::Stat)
107
- expect(stat.metrics.class).to be(SendGrid4r::REST::Stats::Metric)
162
+ ) do |resp, req, res|
163
+ resp =
164
+ SendGrid4r::REST::Stats.create_top_stat(
165
+ JSON.parse(resp)
166
+ )
167
+ expect(resp).to be_a(SendGrid4r::REST::Stats::TopStat)
168
+ expect(req).to be_a(RestClient::Request)
169
+ expect(res).to be_a(Net::HTTPOK)
108
170
  end
109
171
  end
110
172
  end
@@ -1,62 +1,89 @@
1
1
  # encoding: utf-8
2
2
  require File.dirname(__FILE__) + '/../spec_helper'
3
3
 
4
- describe 'SendGrid4r::REST::Stats::Global' do
5
- before :all do
6
- Dotenv.load
7
- @client = SendGrid4r::Client.new(
8
- ENV['SENDGRID_USERNAME'], ENV['SENDGRID_PASSWORD'])
9
- end
4
+ describe SendGrid4r::REST::Stats::Global do
5
+ describe 'integration test' do
6
+ before do
7
+ Dotenv.load
8
+ @client = SendGrid4r::Client.new(
9
+ username: ENV['SENDGRID_USERNAME'],
10
+ password: ENV['SENDGRID_PASSWORD'])
11
+ end
10
12
 
11
- context 'always' do
12
- describe '#get_global_stats' do
13
- it 'returns global stats if specify mandatory params' do
14
- actual = @client.get_global_stats(start_date: '2015-01-01')
15
- expect(actual.class).to be(Array)
16
- expect(actual.length > 0).to be(true)
17
- actual.each do |global_stat|
18
- expect(global_stat.class).to be(SendGrid4r::REST::Stats::TopStat)
19
- stats = global_stat.stats
20
- expect(stats.length).to eq(1)
21
- stats.each do |stat|
22
- expect(stat.class).to be(SendGrid4r::REST::Stats::Stat)
23
- expect(stat.metrics.class).to be(SendGrid4r::REST::Stats::Metric)
24
- expect(stat.metrics.blocks.nil?).to be(false)
25
- expect(stat.metrics.bounce_drops.nil?).to be(false)
26
- expect(stat.metrics.bounces.nil?).to be(false)
27
- expect(stat.metrics.clicks.nil?).to be(false)
28
- expect(stat.metrics.deferred.nil?).to be(false)
29
- expect(stat.metrics.delivered.nil?).to be(false)
30
- expect(stat.metrics.invalid_emails.nil?).to be(false)
31
- expect(stat.metrics.opens.nil?).to be(false)
32
- expect(stat.metrics.processed.nil?).to be(false)
33
- expect(stat.metrics.requests.nil?).to be(false)
34
- expect(stat.metrics.spam_report_drops.nil?).to be(false)
35
- expect(stat.metrics.spam_reports.nil?).to be(false)
36
- expect(stat.metrics.unique_clicks.nil?).to be(false)
37
- expect(stat.metrics.unique_opens.nil?).to be(false)
38
- expect(stat.metrics.unsubscribe_drops.nil?).to be(false)
39
- expect(stat.metrics.unsubscribes.nil?).to be(false)
13
+ context 'without block call' do
14
+ it '#get_global_stats with mandatory params' do
15
+ begin
16
+ top_stats = @client.get_global_stats(start_date: '2015-01-01')
17
+ expect(top_stats).to be_a(Array)
18
+ top_stats.each do |top_stat|
19
+ expect(top_stat).to be_a(SendGrid4r::REST::Stats::TopStat)
20
+ top_stat.stats.each do |stat|
21
+ expect(stat).to be_a(SendGrid4r::REST::Stats::Stat)
22
+ expect(stat.metrics).to be_a(SendGrid4r::REST::Stats::Metric)
23
+ expect(stat.metrics.blocks.nil?).to be(false)
24
+ expect(stat.metrics.bounce_drops.nil?).to be(false)
25
+ expect(stat.metrics.bounces.nil?).to be(false)
26
+ expect(stat.metrics.clicks.nil?).to be(false)
27
+ expect(stat.metrics.deferred.nil?).to be(false)
28
+ expect(stat.metrics.delivered.nil?).to be(false)
29
+ expect(stat.metrics.invalid_emails.nil?).to be(false)
30
+ expect(stat.metrics.opens.nil?).to be(false)
31
+ expect(stat.metrics.processed.nil?).to be(false)
32
+ expect(stat.metrics.requests.nil?).to be(false)
33
+ expect(stat.metrics.spam_report_drops.nil?).to be(false)
34
+ expect(stat.metrics.spam_reports.nil?).to be(false)
35
+ expect(stat.metrics.unique_clicks.nil?).to be(false)
36
+ expect(stat.metrics.unique_opens.nil?).to be(false)
37
+ expect(stat.metrics.unsubscribe_drops.nil?).to be(false)
38
+ expect(stat.metrics.unsubscribes.nil?).to be(false)
39
+ end
40
40
  end
41
+ rescue => e
42
+ puts e.inspect
43
+ raise e
41
44
  end
42
45
  end
43
46
 
44
- it 'returns global stats if specify all params' do
45
- actual = @client.get_global_stats(
47
+ it '#get_global_stats with all params' do
48
+ begin
49
+ top_stats = @client.get_global_stats(
50
+ start_date: '2015-01-01',
51
+ end_date: '2015-01-01',
52
+ aggregated_by: SendGrid4r::REST::Stats::AggregatedBy::WEEK
53
+ )
54
+ expect(top_stats).to be_a(Array)
55
+ top_stats.each do |top_stat|
56
+ expect(top_stat).to be_a(SendGrid4r::REST::Stats::TopStat)
57
+ stats = top_stat.stats
58
+ stats.each do |stat|
59
+ expect(stat).to be_a(SendGrid4r::REST::Stats::Stat)
60
+ expect(stat.metrics).to be_a(SendGrid4r::REST::Stats::Metric)
61
+ end
62
+ end
63
+ rescue => e
64
+ puts e.inspect
65
+ raise e
66
+ end
67
+ end
68
+ end
69
+
70
+ context 'with block call' do
71
+ it '#get_global_stats with all params' do
72
+ @client.get_global_stats(
46
73
  start_date: '2015-01-01',
47
74
  end_date: '2015-01-01',
48
75
  aggregated_by: SendGrid4r::REST::Stats::AggregatedBy::WEEK
49
- )
50
- expect(actual.class).to be(Array)
51
- expect(actual.length).to eq(2)
52
- actual.each do |global_stat|
53
- expect(global_stat.class).to be(SendGrid4r::REST::Stats::TopStat)
54
- stats = global_stat.stats
55
- expect(stats.length).to eq(1)
56
- stats.each do |stat|
57
- expect(stat.class).to be(SendGrid4r::REST::Stats::Stat)
58
- expect(stat.metrics.class).to be(SendGrid4r::REST::Stats::Metric)
76
+ ) do |resp, req, res|
77
+ resp =
78
+ SendGrid4r::REST::Stats.create_top_stats(
79
+ JSON.parse(resp)
80
+ )
81
+ expect(resp).to be_a(Array)
82
+ resp.each do |stat|
83
+ expect(stat).to be_a(SendGrid4r::REST::Stats::TopStat)
59
84
  end
85
+ expect(req).to be_a(RestClient::Request)
86
+ expect(res).to be_a(Net::HTTPOK)
60
87
  end
61
88
  end
62
89
  end
@@ -1,47 +1,64 @@
1
1
  # encoding: utf-8
2
2
  require File.dirname(__FILE__) + '/../spec_helper'
3
3
 
4
- describe 'SendGrid4r::REST::Stats::Parse' do
5
- before :all do
6
- Dotenv.load
7
- @client = SendGrid4r::Client.new(
8
- ENV['SENDGRID_USERNAME'], ENV['SENDGRID_PASSWORD'])
9
- end
4
+ describe SendGrid4r::REST::Stats::Parse do
5
+ describe 'integration test' do
6
+ before do
7
+ Dotenv.load
8
+ @client = SendGrid4r::Client.new(
9
+ username: ENV['SENDGRID_USERNAME'],
10
+ password: ENV['SENDGRID_PASSWORD'])
11
+ end
10
12
 
11
- context 'always' do
12
- describe '#get_parse_stats' do
13
- it 'returns parse stats if specify mandatory params' do
14
- actual = @client.get_parse_stats(start_date: '2015-01-01')
15
- expect(actual.class).to be(Array)
16
- expect(actual.length > 0).to be(true)
17
- actual.each do |global_stat|
18
- expect(global_stat.class).to be(SendGrid4r::REST::Stats::TopStat)
19
- stats = global_stat.stats
20
- expect(stats.length).to eq(1)
21
- stats.each do |stat|
22
- expect(stat.class).to be(SendGrid4r::REST::Stats::Stat)
13
+ context 'without block call' do
14
+ it '#get_parse_stats with mandatory params' do
15
+ top_stats = @client.get_parse_stats(start_date: '2015-01-01')
16
+ expect(top_stats).to be_a(Array)
17
+ top_stats.each do |top_stat|
18
+ expect(top_stat).to be_a(SendGrid4r::REST::Stats::TopStat)
19
+ top_stat.stats.each do |stat|
20
+ expect(stat).to be_a(SendGrid4r::REST::Stats::Stat)
23
21
  expect(stat.metrics.class).to be(SendGrid4r::REST::Stats::Metric)
24
22
  expect(stat.metrics.received.nil?).to be(false)
25
23
  expect(stat.metrics.blocks.nil?).to be(true)
26
24
  end
27
25
  end
28
26
  end
29
- it 'returns parse stats if specify all params' do
30
- actual = @client.get_parse_stats(
27
+
28
+ it '#get_parse_stats with all params' do
29
+ top_stats = @client.get_parse_stats(
31
30
  start_date: '2015-01-01',
32
31
  end_date: '2015-01-02',
33
32
  aggregated_by: SendGrid4r::REST::Stats::AggregatedBy::WEEK
34
33
  )
35
- expect(actual.class).to be(Array)
36
- expect(actual.length > 0).to be(true)
37
- actual.each do |global_stat|
38
- expect(global_stat.class).to be(SendGrid4r::REST::Stats::TopStat)
39
- stats = global_stat.stats
40
- expect(stats.length).to eq(1)
41
- stats.each do |stat|
42
- expect(stat.class).to be(SendGrid4r::REST::Stats::Stat)
43
- expect(stat.metrics.class).to be(SendGrid4r::REST::Stats::Metric)
34
+ expect(top_stats).to be_a(Array)
35
+ top_stats.each do |top_stat|
36
+ expect(top_stat).to be_a(SendGrid4r::REST::Stats::TopStat)
37
+ top_stat.stats.each do |stat|
38
+ expect(stat).to be_a(SendGrid4r::REST::Stats::Stat)
39
+ expect(stat.metrics).to be_a(SendGrid4r::REST::Stats::Metric)
40
+ end
41
+ end
42
+ end
43
+ end
44
+
45
+ context 'with block call' do
46
+ it '#get_parse_stats with all params' do
47
+ @client.get_parse_stats(
48
+ start_date: '2015-01-01',
49
+ end_date: '2015-01-02',
50
+ aggregated_by: SendGrid4r::REST::Stats::AggregatedBy::WEEK
51
+ ) do |resp, req, res|
52
+ resp =
53
+ SendGrid4r::REST::Stats.create_top_stats(
54
+ JSON.parse(resp)
55
+ )
56
+ expect(resp).to be_a(Array)
57
+ resp.each do |stat|
58
+ expect(stat).to be_a(SendGrid4r::REST::Stats::TopStat)
44
59
  end
60
+ expect(req).to be_a(RestClient::Request)
61
+ expect(res).to be_a(Net::HTTPOK)
45
62
  end
46
63
  end
47
64
  end