sendgrid4r 0.0.5 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +21 -0
- data/.travis.yml +2 -3
- data/README.md +3 -373
- data/Rakefile +1 -1
- data/lib/auth.rb +7 -9
- data/lib/client.rb +8 -9
- data/lib/sendgrid4r/factory/version_factory.rb +20 -10
- data/lib/sendgrid4r/rest/api.rb +28 -9
- data/lib/sendgrid4r/rest/asm/global_suppressions.rb +46 -0
- data/lib/sendgrid4r/rest/asm/groups.rb +69 -0
- data/lib/sendgrid4r/rest/asm/suppressions.rb +68 -0
- data/lib/sendgrid4r/rest/categories/categories.rb +38 -0
- data/lib/sendgrid4r/rest/ips/addresses.rb +74 -0
- data/lib/sendgrid4r/rest/ips/pools.rb +63 -0
- data/lib/sendgrid4r/rest/ips/warmup.rb +55 -0
- data/lib/sendgrid4r/rest/request.rb +34 -19
- data/lib/sendgrid4r/rest/settings/enforced_tls.rb +39 -0
- data/lib/sendgrid4r/rest/stats/advanced.rb +91 -0
- data/lib/sendgrid4r/rest/stats/category.rb +47 -0
- data/lib/sendgrid4r/rest/stats/global.rb +26 -0
- data/lib/sendgrid4r/rest/stats/parse.rb +26 -0
- data/lib/sendgrid4r/rest/stats/stats.rb +89 -0
- data/lib/sendgrid4r/rest/stats/subuser.rb +47 -0
- data/lib/sendgrid4r/rest/templates/templates.rb +61 -0
- data/lib/sendgrid4r/rest/templates/versions.rb +92 -0
- data/lib/sendgrid4r/version.rb +4 -1
- data/lib/sendgrid4r.rb +5 -2
- data/sendgrid4r.gemspec +13 -12
- data/spec/{global_suppressions_spec.rb → asm/global_suppressions_spec.rb} +25 -17
- data/spec/asm/groups_spec.rb +58 -0
- data/spec/{suppressions_spec.rb → asm/suppressions_spec.rb} +24 -22
- data/spec/categories/categories_spec.rb +39 -0
- data/spec/client_spec.rb +65 -50
- data/spec/ips/addresses_spec.rb +116 -0
- data/spec/ips/pools_spec.rb +43 -0
- data/spec/ips/warmup_spec.rb +52 -0
- data/spec/{enforced_tls_spec.rb → settings/enforced_tls_spec.rb} +12 -11
- data/spec/stats/advanced_spec.rb +243 -0
- data/spec/stats/category_spec.rb +112 -0
- data/spec/stats/global_spec.rb +64 -0
- data/spec/stats/parse_spec.rb +49 -0
- data/spec/stats/subuser_spec.rb +105 -0
- data/spec/templates/templates_spec.rb +66 -0
- data/spec/templates/versions_spec.rb +89 -0
- data/spec/version_factory_spec.rb +20 -15
- metadata +94 -42
- data/lib/sendgrid4r/rest/addresses.rb +0 -62
- data/lib/sendgrid4r/rest/enforced_tls.rb +0 -46
- data/lib/sendgrid4r/rest/global_suppressions.rb +0 -35
- data/lib/sendgrid4r/rest/groups.rb +0 -68
- data/lib/sendgrid4r/rest/pools.rb +0 -53
- data/lib/sendgrid4r/rest/suppressions.rb +0 -57
- data/lib/sendgrid4r/rest/templates.rb +0 -64
- data/lib/sendgrid4r/rest/versions.rb +0 -65
- data/lib/sendgrid4r/rest/warmup.rb +0 -53
- data/spec/addresses_spec.rb +0 -80
- data/spec/groups_spec.rb +0 -54
- data/spec/pools_spec.rb +0 -62
- data/spec/templates_spec.rb +0 -38
- data/spec/versions_spec.rb +0 -75
- data/spec/warmup_spec.rb +0 -52
data/spec/client_spec.rb
CHANGED
@@ -1,84 +1,99 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
require File.dirname(__FILE__) + '/spec_helper'
|
3
3
|
|
4
|
-
describe
|
5
|
-
|
4
|
+
describe 'SendGrid4r::Client' do
|
6
5
|
before :all do
|
7
6
|
Dotenv.load
|
8
7
|
end
|
9
8
|
|
10
|
-
context
|
11
|
-
|
9
|
+
context 'always' do
|
12
10
|
before :all do
|
13
|
-
@client = SendGrid4r::Client.new(
|
11
|
+
@client = SendGrid4r::Client.new('username', 'password')
|
14
12
|
end
|
15
13
|
|
16
|
-
describe
|
17
|
-
it
|
14
|
+
describe '#initialize' do
|
15
|
+
it 'create instance' do
|
18
16
|
expect(@client.class).to eq(SendGrid4r::Client)
|
19
17
|
end
|
20
18
|
end
|
21
19
|
|
22
|
-
describe
|
23
|
-
it
|
20
|
+
describe 'methods' do
|
21
|
+
it 'available' do
|
24
22
|
# Advanced Suppression Manager
|
25
23
|
# groups
|
26
|
-
expect(@client.respond_to?(
|
27
|
-
expect(@client.respond_to?(
|
28
|
-
expect(@client.respond_to?(
|
29
|
-
expect(@client.respond_to?(
|
30
|
-
expect(@client.respond_to?(
|
24
|
+
expect(@client.respond_to?('get_groups')).to eq(true)
|
25
|
+
expect(@client.respond_to?('get_group')).to eq(true)
|
26
|
+
expect(@client.respond_to?('post_group')).to eq(true)
|
27
|
+
expect(@client.respond_to?('patch_group')).to eq(true)
|
28
|
+
expect(@client.respond_to?('delete_group')).to eq(true)
|
31
29
|
# suppressions
|
32
|
-
expect(@client.respond_to?(
|
33
|
-
expect(@client.respond_to?(
|
34
|
-
expect(@client.respond_to?(
|
35
|
-
expect(@client.respond_to?(
|
30
|
+
expect(@client.respond_to?('post_suppressed_emails')).to eq(true)
|
31
|
+
expect(@client.respond_to?('get_suppressions')).to eq(true)
|
32
|
+
expect(@client.respond_to?('get_suppressed_emails')).to eq(true)
|
33
|
+
expect(@client.respond_to?('delete_suppressed_email')).to eq(true)
|
36
34
|
# global suppressions
|
37
|
-
expect(@client.respond_to?(
|
38
|
-
expect(@client.respond_to?(
|
39
|
-
expect(
|
35
|
+
expect(@client.respond_to?('post_global_suppressed_emails')).to eq(true)
|
36
|
+
expect(@client.respond_to?('get_global_suppressed_email')).to eq(true)
|
37
|
+
expect(
|
38
|
+
@client.respond_to?('delete_global_suppressed_email')
|
39
|
+
).to eq(true)
|
40
40
|
# IP Management
|
41
41
|
# ip addresses
|
42
|
-
expect(@client.respond_to?(
|
43
|
-
expect(@client.respond_to?(
|
44
|
-
expect(@client.respond_to?(
|
45
|
-
expect(@client.respond_to?(
|
42
|
+
expect(@client.respond_to?('get_ips')).to eq(true)
|
43
|
+
expect(@client.respond_to?('get_ips_assigned')).to eq(true)
|
44
|
+
expect(@client.respond_to?('get_ip')).to eq(true)
|
45
|
+
expect(@client.respond_to?('post_ip_to_pool')).to eq(true)
|
46
|
+
expect(@client.respond_to?('delete_ip_from_pool')).to eq(true)
|
46
47
|
# pool
|
47
|
-
expect(@client.respond_to?(
|
48
|
-
expect(@client.respond_to?(
|
49
|
-
expect(@client.respond_to?(
|
50
|
-
expect(@client.respond_to?(
|
51
|
-
expect(@client.respond_to?(
|
48
|
+
expect(@client.respond_to?('get_pools')).to eq(true)
|
49
|
+
expect(@client.respond_to?('post_pool')).to eq(true)
|
50
|
+
expect(@client.respond_to?('get_pool')).to eq(true)
|
51
|
+
expect(@client.respond_to?('put_pool')).to eq(true)
|
52
|
+
expect(@client.respond_to?('delete_pool')).to eq(true)
|
52
53
|
# warmup
|
53
|
-
expect(@client.respond_to?(
|
54
|
-
expect(@client.respond_to?(
|
55
|
-
expect(@client.respond_to?(
|
56
|
-
expect(@client.respond_to?(
|
54
|
+
expect(@client.respond_to?('get_warmup_ips')).to eq(true)
|
55
|
+
expect(@client.respond_to?('get_warmup_ip')).to eq(true)
|
56
|
+
expect(@client.respond_to?('post_warmup_ip')).to eq(true)
|
57
|
+
expect(@client.respond_to?('delete_warmup_ip')).to eq(true)
|
57
58
|
# Settings
|
58
59
|
# enforced_tls
|
59
|
-
expect(@client.respond_to?(
|
60
|
-
expect(@client.respond_to?(
|
60
|
+
expect(@client.respond_to?('get_enforced_tls')).to eq(true)
|
61
|
+
expect(@client.respond_to?('patch_enforced_tls')).to eq(true)
|
61
62
|
# Template Engine
|
62
63
|
# templates
|
63
|
-
expect(@client.respond_to?(
|
64
|
-
expect(@client.respond_to?(
|
65
|
-
expect(@client.respond_to?(
|
66
|
-
expect(@client.respond_to?(
|
67
|
-
expect(@client.respond_to?(
|
64
|
+
expect(@client.respond_to?('get_templates')).to eq(true)
|
65
|
+
expect(@client.respond_to?('get_template')).to eq(true)
|
66
|
+
expect(@client.respond_to?('post_template')).to eq(true)
|
67
|
+
expect(@client.respond_to?('patch_template')).to eq(true)
|
68
|
+
expect(@client.respond_to?('delete_template')).to eq(true)
|
68
69
|
# versions
|
69
|
-
expect(@client.respond_to?(
|
70
|
-
expect(@client.respond_to?(
|
71
|
-
expect(@client.respond_to?(
|
72
|
-
expect(@client.respond_to?(
|
73
|
-
expect(@client.respond_to?(
|
70
|
+
expect(@client.respond_to?('get_version')).to eq(true)
|
71
|
+
expect(@client.respond_to?('post_version')).to eq(true)
|
72
|
+
expect(@client.respond_to?('activate_version')).to eq(true)
|
73
|
+
expect(@client.respond_to?('patch_version')).to eq(true)
|
74
|
+
expect(@client.respond_to?('delete_version')).to eq(true)
|
75
|
+
# Categories
|
76
|
+
expect(@client.respond_to?('get_categories')).to eq(true)
|
77
|
+
# Stats
|
78
|
+
expect(@client.respond_to?('get_global_stats')).to eq(true)
|
79
|
+
expect(@client.respond_to?('get_categories_stats')).to eq(true)
|
80
|
+
expect(@client.respond_to?('get_categories_stats_sums')).to eq(true)
|
81
|
+
expect(@client.respond_to?('get_subusers_stats')).to eq(true)
|
82
|
+
expect(@client.respond_to?('get_subusers_stats_sums')).to eq(true)
|
83
|
+
expect(@client.respond_to?('get_geo_stats')).to eq(true)
|
84
|
+
expect(@client.respond_to?('get_devices_stats')).to eq(true)
|
85
|
+
expect(@client.respond_to?('get_clients_stats')).to eq(true)
|
86
|
+
expect(@client.respond_to?('get_clients_type_stats')).to eq(true)
|
87
|
+
expect(@client.respond_to?('get_esp_stats')).to eq(true)
|
88
|
+
expect(@client.respond_to?('get_browsers_stats')).to eq(true)
|
89
|
+
expect(@client.respond_to?('get_parse_stats')).to eq(true)
|
74
90
|
end
|
75
91
|
end
|
76
92
|
|
77
|
-
describe
|
78
|
-
it
|
79
|
-
expect(SendGrid4r::VERSION).to eq(
|
93
|
+
describe 'VERSION' do
|
94
|
+
it 'returns VERSION value' do
|
95
|
+
expect(SendGrid4r::VERSION).to eq('0.1.0')
|
80
96
|
end
|
81
97
|
end
|
82
|
-
|
83
98
|
end
|
84
99
|
end
|
@@ -0,0 +1,116 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
3
|
+
|
4
|
+
describe 'SendGrid4r::REST::Ips::Addresses' do
|
5
|
+
before :all do
|
6
|
+
Dotenv.load
|
7
|
+
end
|
8
|
+
|
9
|
+
context 'if account is free' do
|
10
|
+
before :all do
|
11
|
+
@client = SendGrid4r::Client.new(
|
12
|
+
ENV['SENDGRID_USERNAME'], ENV['SENDGRID_PASSWORD'])
|
13
|
+
end
|
14
|
+
|
15
|
+
describe '#get_ips_assigned' do
|
16
|
+
it 'raise error' do
|
17
|
+
expect do
|
18
|
+
@client.get_ips_assigned
|
19
|
+
end.to raise_error(RestClient::Forbidden)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe '#get_ip' do
|
24
|
+
it 'raise error' do
|
25
|
+
begin
|
26
|
+
expect do
|
27
|
+
@client.get_ip('10.10.10.10').to raise_error(RestClient::Forbidden)
|
28
|
+
end
|
29
|
+
rescue => e
|
30
|
+
puts e.inspect
|
31
|
+
raise e
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
context 'if account is silver' do
|
38
|
+
TEST_POOL = 'test_pool'
|
39
|
+
before :all do
|
40
|
+
begin
|
41
|
+
@client = SendGrid4r::Client.new(
|
42
|
+
ENV['SILVER_SENDGRID_USERNAME'], ENV['SILVER_SENDGRID_PASSWORD'])
|
43
|
+
# refresh the pool
|
44
|
+
pools = @client.get_pools
|
45
|
+
pools.each do |pool|
|
46
|
+
@client.delete_pool(TEST_POOL) if pool.name == TEST_POOL
|
47
|
+
end
|
48
|
+
@client.post_pool(TEST_POOL)
|
49
|
+
# ips = @client.get_ips
|
50
|
+
# @client.delete_ip_from_pool(TEST_POOL, ips[0].ip)
|
51
|
+
rescue => e
|
52
|
+
puts e.inspect
|
53
|
+
raise e
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe '#get_ips' do
|
58
|
+
it 'returns Array of Address instance' do
|
59
|
+
ips = @client.get_ips
|
60
|
+
expect(ips.length > 0).to be(true)
|
61
|
+
ip = ips[0]
|
62
|
+
expect(ip.class).to be(SendGrid4r::REST::Ips::Addresses::Address)
|
63
|
+
expect(ip.ip.nil?).to be(false)
|
64
|
+
# expect(ip.pools.nil?).to be(false)
|
65
|
+
# expect(ip.start_date.nil?).to be(false)
|
66
|
+
expect(ip.warmup.nil?).to be(false)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
describe '#get_ips_assigned' do
|
71
|
+
it 'returns Array of Address instance' do
|
72
|
+
ips = @client.get_ips_assigned
|
73
|
+
expect(ips.length > 0).to be(true)
|
74
|
+
expect(ips[0].class).to be(SendGrid4r::REST::Ips::Addresses::Address)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
describe '#get_ip' do
|
79
|
+
it 'returns Address instance' do
|
80
|
+
begin
|
81
|
+
ips = @client.get_ips_assigned
|
82
|
+
expect(
|
83
|
+
@client.get_ip(ips[0].ip).class
|
84
|
+
).to be(SendGrid4r::REST::Ips::Addresses::Address)
|
85
|
+
rescue => e
|
86
|
+
puts e.inspect
|
87
|
+
raise e
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
describe '#post_ip_to_pool' do
|
93
|
+
it 'add ip to pool successfully' do
|
94
|
+
ips = @client.get_ips_assigned
|
95
|
+
actual = @client.post_ip_to_pool(TEST_POOL, ips[0].ip)
|
96
|
+
expect(actual.ip).to eq(ips[0].ip)
|
97
|
+
expect(actual.pools).to include(TEST_POOL)
|
98
|
+
expect(actual.pools.class).to be(Array)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
# Could not test because POST an IP to a pool takes 60 sec
|
103
|
+
# describe '#delete_ip_from_pool' do
|
104
|
+
# it 'delete ip from pool successfully' do
|
105
|
+
# begin
|
106
|
+
# ips = @client.get_ips
|
107
|
+
# @client.post_ip_to_pool(TEST_POOL, ips[0].ip)
|
108
|
+
# @client.delete_ip_from_pool(TEST_POOL, ips[0].ip)
|
109
|
+
# rescue => e
|
110
|
+
# puts e.inspect
|
111
|
+
# raise e
|
112
|
+
# end
|
113
|
+
# end
|
114
|
+
# end
|
115
|
+
end
|
116
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
3
|
+
|
4
|
+
describe 'SendGrid4r::REST::Ips::Pools' do
|
5
|
+
before :all do
|
6
|
+
Dotenv.load
|
7
|
+
@client = SendGrid4r::Client.new(
|
8
|
+
ENV['SILVER_SENDGRID_USERNAME'], ENV['SILVER_SENDGRID_PASSWORD'])
|
9
|
+
@pool_name = 'pool_test'
|
10
|
+
@pool_edit = 'pool_edit'
|
11
|
+
end
|
12
|
+
|
13
|
+
context 'if account is silver' do
|
14
|
+
it 'is normal' do
|
15
|
+
# clean up test env
|
16
|
+
pools = @client.get_pools
|
17
|
+
expect(pools.length >= 0).to eq(true)
|
18
|
+
pools.each do |pool|
|
19
|
+
if pool.name == @pool_name || pool.name == @pool_edit
|
20
|
+
@client.delete_pool(pool.name)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
# post a pool
|
24
|
+
new_pool = @client.post_pool(@pool_name)
|
25
|
+
expect(@pool_name).to eq(new_pool.name)
|
26
|
+
# put the pool
|
27
|
+
edit_pool = @client.put_pool(@pool_name, @pool_edit)
|
28
|
+
expect(@pool_edit).to eq(edit_pool.name)
|
29
|
+
# get the pool
|
30
|
+
pool = @client.get_pool(@pool_edit)
|
31
|
+
expect(SendGrid4r::REST::Ips::Pools::Pool).to be(pool.class)
|
32
|
+
# delete the pool
|
33
|
+
@client.delete_pool(pool.pool_name)
|
34
|
+
expect { @client.get_pool(pool.name) }
|
35
|
+
ips = @client.get_ips
|
36
|
+
expect(ips.length).to be(1)
|
37
|
+
expect(ips[0].class).to be(SendGrid4r::REST::Ips::Addresses::Address)
|
38
|
+
expect(
|
39
|
+
@client.get_ip(ips[0].ip).class
|
40
|
+
).to be(SendGrid4r::REST::Ips::Addresses::Address)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
3
|
+
|
4
|
+
describe 'SendGrid4r::REST::Ips::WarmUp' do
|
5
|
+
before :all do
|
6
|
+
Dotenv.load
|
7
|
+
end
|
8
|
+
|
9
|
+
context 'normal' do
|
10
|
+
it 'is normal' do
|
11
|
+
begin
|
12
|
+
client = SendGrid4r::Client.new(
|
13
|
+
ENV['SILVER_SENDGRID_USERNAME'], ENV['SILVER_SENDGRID_PASSWORD'])
|
14
|
+
# celan up test env
|
15
|
+
warmup_ips = client.get_warmup_ips
|
16
|
+
expect(warmup_ips.length >= 0).to eq(true)
|
17
|
+
if warmup_ips.length > 0
|
18
|
+
warmup_ips.each do |warmup_ip|
|
19
|
+
client.delete_warmup_ip(warmup_ip.ip)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
# get warmup ip
|
23
|
+
warmup_ips = client.get_warmup_ips
|
24
|
+
expect(warmup_ips.length).to eq(0)
|
25
|
+
# post warmup ip
|
26
|
+
ips = client.get_ips
|
27
|
+
if ips.length > 0
|
28
|
+
warmup_ip = client.post_warmup_ip(ips[0].ip)
|
29
|
+
expect(warmup_ip.ip).to eq(ips[0].ip)
|
30
|
+
end
|
31
|
+
warmup_ip = client.get_warmup_ip(warmup_ip.ip)
|
32
|
+
expect(warmup_ip.ip).to eq(ips[0].ip)
|
33
|
+
# delete the warmup ip
|
34
|
+
client.delete_warmup_ip(warmup_ip.ip)
|
35
|
+
expect do
|
36
|
+
client.get_warmup_ip(warmup_ip.ip)
|
37
|
+
end.to raise_error(RestClient::ResourceNotFound)
|
38
|
+
rescue => ex
|
39
|
+
puts ex.inspect
|
40
|
+
raise ex
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
context 'abnormal' do
|
46
|
+
it 'raise forbidden for free account' do
|
47
|
+
client = SendGrid4r::Client.new(
|
48
|
+
ENV['SENDGRID_USERNAME'], ENV['SENDGRID_PASSWORD'])
|
49
|
+
expect { client.get_warmup_ips }.to raise_error(RestClient::Forbidden)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -1,24 +1,25 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
-
require File.dirname(__FILE__) + '
|
3
|
-
|
4
|
-
describe "SendGrid4r::REST::Settings::EnforcedTls" do
|
2
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
5
3
|
|
4
|
+
describe 'SendGrid4r::REST::Settings::EnforcedTls' do
|
6
5
|
before :all do
|
7
6
|
Dotenv.load
|
8
|
-
@client = SendGrid4r::Client.new(
|
7
|
+
@client = SendGrid4r::Client.new(
|
8
|
+
ENV['SENDGRID_USERNAME'], ENV['SENDGRID_PASSWORD'])
|
9
9
|
end
|
10
10
|
|
11
|
-
context
|
12
|
-
|
13
|
-
|
14
|
-
it "returns EnforcedTls instance" do
|
11
|
+
context 'always' do
|
12
|
+
describe '#get_enforced_tls' do
|
13
|
+
it 'returns EnforcedTls instance' do
|
15
14
|
actual = @client.get_enforced_tls
|
16
|
-
expect(
|
15
|
+
expect(
|
16
|
+
actual.class
|
17
|
+
).to be(SendGrid4r::REST::Settings::EnforcedTls::EnforcedTls)
|
17
18
|
end
|
18
19
|
end
|
19
20
|
|
20
|
-
describe
|
21
|
-
it
|
21
|
+
describe '#patch_enforced_tls' do
|
22
|
+
it 'update EnforcedTls values' do
|
22
23
|
# get original enforced_tls settings
|
23
24
|
actual = @client.get_enforced_tls
|
24
25
|
# patch both value
|
@@ -0,0 +1,243 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
3
|
+
|
4
|
+
describe 'SendGrid4r::REST::Stats::Advanced' do
|
5
|
+
before :all do
|
6
|
+
Dotenv.load
|
7
|
+
@client = SendGrid4r::Client.new(
|
8
|
+
ENV['SENDGRID_USERNAME'], ENV['SENDGRID_PASSWORD'])
|
9
|
+
end
|
10
|
+
|
11
|
+
context 'always' do
|
12
|
+
describe '#get_geo_stats' do
|
13
|
+
it 'returns geo stats if specify mandatory params' do
|
14
|
+
actual = @client.get_geo_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(14)
|
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.clicks.nil?).to be(false)
|
25
|
+
expect(stat.metrics.opens.nil?).to be(false)
|
26
|
+
expect(stat.metrics.unique_clicks.nil?).to be(false)
|
27
|
+
expect(stat.metrics.unique_opens.nil?).to be(false)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
it 'returns geo stats if specify all params' do
|
32
|
+
actual = @client.get_geo_stats(
|
33
|
+
start_date: '2015-01-01',
|
34
|
+
end_date: '2015-01-02',
|
35
|
+
aggregated_by: SendGrid4r::REST::Stats::AggregatedBy::WEEK,
|
36
|
+
country: 'US'
|
37
|
+
)
|
38
|
+
expect(actual.class).to be(Array)
|
39
|
+
expect(actual.length > 0).to be(true)
|
40
|
+
actual.each do |global_stat|
|
41
|
+
expect(global_stat.class).to be(SendGrid4r::REST::Stats::TopStat)
|
42
|
+
stats = global_stat.stats
|
43
|
+
expect(stats.length).to eq(1)
|
44
|
+
stats.each do |stat|
|
45
|
+
expect(stat.class).to be(SendGrid4r::REST::Stats::Stat)
|
46
|
+
expect(stat.metrics.class).to be(SendGrid4r::REST::Stats::Metric)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
describe '#get_devices_stats' do
|
52
|
+
it 'returns devices stats if specify mandatory params' do
|
53
|
+
actual = @client.get_devices_stats(start_date: '2015-01-01')
|
54
|
+
expect(actual.class).to be(Array)
|
55
|
+
expect(actual.length > 0).to be(true)
|
56
|
+
actual.each do |global_stat|
|
57
|
+
expect(global_stat.class).to be(SendGrid4r::REST::Stats::TopStat)
|
58
|
+
stats = global_stat.stats
|
59
|
+
expect(stats.length).to eq(5)
|
60
|
+
stats.each do |stat|
|
61
|
+
expect(stat.class).to be(SendGrid4r::REST::Stats::Stat)
|
62
|
+
expect(stat.metrics.class).to be(SendGrid4r::REST::Stats::Metric)
|
63
|
+
expect(stat.metrics.opens.nil?).to be(false)
|
64
|
+
expect(stat.metrics.unique_opens.nil?).to be(false)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
it 'returns devices stats if specify all params' do
|
69
|
+
actual = @client.get_devices_stats(
|
70
|
+
start_date: '2015-01-01',
|
71
|
+
end_date: '2015-01-02',
|
72
|
+
aggregated_by: SendGrid4r::REST::Stats::AggregatedBy::WEEK
|
73
|
+
)
|
74
|
+
expect(actual.class).to be(Array)
|
75
|
+
expect(actual.length > 0).to be(true)
|
76
|
+
actual.each do |global_stat|
|
77
|
+
expect(global_stat.class).to be(SendGrid4r::REST::Stats::TopStat)
|
78
|
+
stats = global_stat.stats
|
79
|
+
expect(stats.length).to eq(1)
|
80
|
+
stats.each do |stat|
|
81
|
+
expect(stat.class).to be(SendGrid4r::REST::Stats::Stat)
|
82
|
+
expect(stat.metrics.class).to be(SendGrid4r::REST::Stats::Metric)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
describe '#get_clients_stats' do
|
88
|
+
it 'returns clients stats if specify mandatory params' do
|
89
|
+
actual = @client.get_clients_stats(start_date: '2015-01-01')
|
90
|
+
expect(actual.class).to be(Array)
|
91
|
+
expect(actual.length > 0).to be(true)
|
92
|
+
actual.each do |global_stat|
|
93
|
+
expect(global_stat.class).to be(SendGrid4r::REST::Stats::TopStat)
|
94
|
+
stats = global_stat.stats
|
95
|
+
expect(stats.length).to eq(17)
|
96
|
+
stats.each do |stat|
|
97
|
+
expect(stat.class).to be(SendGrid4r::REST::Stats::Stat)
|
98
|
+
expect(stat.metrics.class).to be(SendGrid4r::REST::Stats::Metric)
|
99
|
+
expect(stat.metrics.opens.nil?).to be(false)
|
100
|
+
expect(stat.metrics.unique_opens.nil?).to be(false)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
it 'returns clients stats if specify all params' do
|
105
|
+
actual = @client.get_clients_stats(
|
106
|
+
start_date: '2015-01-01',
|
107
|
+
end_date: '2015-01-02',
|
108
|
+
aggregated_by: SendGrid4r::REST::Stats::AggregatedBy::WEEK
|
109
|
+
)
|
110
|
+
expect(actual.class).to be(Array)
|
111
|
+
expect(actual.length > 0).to be(true)
|
112
|
+
actual.each do |global_stat|
|
113
|
+
expect(global_stat.class).to be(SendGrid4r::REST::Stats::TopStat)
|
114
|
+
stats = global_stat.stats
|
115
|
+
expect(stats.length).to eq(1)
|
116
|
+
stats.each do |stat|
|
117
|
+
expect(stat.class).to be(SendGrid4r::REST::Stats::Stat)
|
118
|
+
expect(stat.metrics.class).to be(SendGrid4r::REST::Stats::Metric)
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
describe '#get_clients_type_stats' do
|
124
|
+
it 'returns clients type stats if specify mandatory params' do
|
125
|
+
actual = @client.get_clients_type_stats(
|
126
|
+
start_date: '2015-01-01', client_type: 'webmail'
|
127
|
+
)
|
128
|
+
expect(actual.class).to be(Array)
|
129
|
+
expect(actual.length > 0).to be(true)
|
130
|
+
actual.each do |global_stat|
|
131
|
+
expect(global_stat.class).to be(SendGrid4r::REST::Stats::TopStat)
|
132
|
+
stats = global_stat.stats
|
133
|
+
expect(stats.length).to eq(5)
|
134
|
+
stats.each do |stat|
|
135
|
+
expect(stat.class).to be(SendGrid4r::REST::Stats::Stat)
|
136
|
+
expect(stat.metrics.class).to be(SendGrid4r::REST::Stats::Metric)
|
137
|
+
expect(stat.metrics.opens.nil?).to be(false)
|
138
|
+
expect(stat.metrics.unique_opens.nil?).to be(false)
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
it 'returns clients type stats if specify all params' do
|
143
|
+
actual = @client.get_clients_type_stats(
|
144
|
+
start_date: '2015-01-01',
|
145
|
+
end_date: '2015-01-02',
|
146
|
+
aggregated_by: SendGrid4r::REST::Stats::AggregatedBy::WEEK,
|
147
|
+
client_type: 'webmail'
|
148
|
+
)
|
149
|
+
expect(actual.class).to be(Array)
|
150
|
+
expect(actual.length > 0).to be(true)
|
151
|
+
actual.each do |global_stat|
|
152
|
+
expect(global_stat.class).to be(SendGrid4r::REST::Stats::TopStat)
|
153
|
+
stats = global_stat.stats
|
154
|
+
expect(stats.length).to eq(1)
|
155
|
+
stats.each do |stat|
|
156
|
+
expect(stat.class).to be(SendGrid4r::REST::Stats::Stat)
|
157
|
+
expect(stat.metrics.class).to be(SendGrid4r::REST::Stats::Metric)
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
162
|
+
describe '#get_esp_stats' do
|
163
|
+
it 'returns esp stats if specify mandatory params' do
|
164
|
+
actual = @client.get_esp_stats(start_date: '2015-01-01')
|
165
|
+
expect(actual.class).to be(Array)
|
166
|
+
expect(actual.length > 0).to be(true)
|
167
|
+
actual.each do |global_stat|
|
168
|
+
expect(global_stat.class).to be(SendGrid4r::REST::Stats::TopStat)
|
169
|
+
stats = global_stat.stats
|
170
|
+
expect(stats.length).to eq(1)
|
171
|
+
stats.each do |stat|
|
172
|
+
expect(stat.class).to be(SendGrid4r::REST::Stats::Stat)
|
173
|
+
expect(stat.metrics.class).to be(SendGrid4r::REST::Stats::Metric)
|
174
|
+
expect(stat.metrics.blocks.nil?).to be(false)
|
175
|
+
expect(stat.metrics.bounces.nil?).to be(false)
|
176
|
+
expect(stat.metrics.clicks.nil?).to be(false)
|
177
|
+
expect(stat.metrics.deferred.nil?).to be(false)
|
178
|
+
expect(stat.metrics.delivered.nil?).to be(false)
|
179
|
+
expect(stat.metrics.drops.nil?).to be(false)
|
180
|
+
expect(stat.metrics.opens.nil?).to be(false)
|
181
|
+
expect(stat.metrics.spam_reports.nil?).to be(false)
|
182
|
+
expect(stat.metrics.unique_clicks.nil?).to be(false)
|
183
|
+
expect(stat.metrics.unique_opens.nil?).to be(false)
|
184
|
+
end
|
185
|
+
end
|
186
|
+
end
|
187
|
+
it 'returns esp stats if specify all params' do
|
188
|
+
actual = @client.get_esp_stats(
|
189
|
+
start_date: '2015-01-01',
|
190
|
+
end_date: '2015-01-02',
|
191
|
+
aggregated_by: SendGrid4r::REST::Stats::AggregatedBy::WEEK,
|
192
|
+
esps: 'sss'
|
193
|
+
)
|
194
|
+
expect(actual.class).to be(Array)
|
195
|
+
expect(actual.length > 0).to be(true)
|
196
|
+
actual.each do |global_stat|
|
197
|
+
expect(global_stat.class).to be(SendGrid4r::REST::Stats::TopStat)
|
198
|
+
stats = global_stat.stats
|
199
|
+
stats.each do |stat|
|
200
|
+
expect(stat.class).to be(SendGrid4r::REST::Stats::Stat)
|
201
|
+
expect(stat.metrics.class).to be(SendGrid4r::REST::Stats::Metric)
|
202
|
+
end
|
203
|
+
end
|
204
|
+
end
|
205
|
+
end
|
206
|
+
describe '#get_browsers_stats' do
|
207
|
+
it 'returns browsers stats if specify mandatory params' do
|
208
|
+
actual = @client.get_browsers_stats(start_date: '2015-01-01')
|
209
|
+
expect(actual.class).to be(Array)
|
210
|
+
expect(actual.length > 0).to be(true)
|
211
|
+
actual.each do |global_stat|
|
212
|
+
expect(global_stat.class).to be(SendGrid4r::REST::Stats::TopStat)
|
213
|
+
stats = global_stat.stats
|
214
|
+
expect(stats.length).to eq(1)
|
215
|
+
stats.each do |stat|
|
216
|
+
expect(stat.class).to be(SendGrid4r::REST::Stats::Stat)
|
217
|
+
expect(stat.metrics.class).to be(SendGrid4r::REST::Stats::Metric)
|
218
|
+
expect(stat.metrics.clicks.nil?).to be(false)
|
219
|
+
expect(stat.metrics.unique_clicks.nil?).to be(false)
|
220
|
+
end
|
221
|
+
end
|
222
|
+
end
|
223
|
+
it 'returns browsers stats if specify all params' do
|
224
|
+
actual = @client.get_browsers_stats(
|
225
|
+
start_date: '2015-01-01',
|
226
|
+
end_date: '2015-01-02',
|
227
|
+
aggregated_by: SendGrid4r::REST::Stats::AggregatedBy::WEEK,
|
228
|
+
browsers: 'chrome'
|
229
|
+
)
|
230
|
+
expect(actual.class).to be(Array)
|
231
|
+
expect(actual.length > 0).to be(false)
|
232
|
+
actual.each do |global_stat|
|
233
|
+
expect(global_stat.class).to be(SendGrid4r::REST::Stats::TopStat)
|
234
|
+
stats = global_stat.stats
|
235
|
+
stats.each do |stat|
|
236
|
+
expect(stat.class).to be(SendGrid4r::REST::Stats::Stat)
|
237
|
+
expect(stat.metrics.class).to be(SendGrid4r::REST::Stats::Metric)
|
238
|
+
end
|
239
|
+
end
|
240
|
+
end
|
241
|
+
end
|
242
|
+
end
|
243
|
+
end
|