sendgrid4r 0.0.5 → 0.1.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/.rubocop.yml +21 -0
  3. data/.travis.yml +2 -3
  4. data/README.md +3 -373
  5. data/Rakefile +1 -1
  6. data/lib/auth.rb +7 -9
  7. data/lib/client.rb +8 -9
  8. data/lib/sendgrid4r/factory/version_factory.rb +20 -10
  9. data/lib/sendgrid4r/rest/api.rb +28 -9
  10. data/lib/sendgrid4r/rest/asm/global_suppressions.rb +46 -0
  11. data/lib/sendgrid4r/rest/asm/groups.rb +69 -0
  12. data/lib/sendgrid4r/rest/asm/suppressions.rb +68 -0
  13. data/lib/sendgrid4r/rest/categories/categories.rb +38 -0
  14. data/lib/sendgrid4r/rest/ips/addresses.rb +74 -0
  15. data/lib/sendgrid4r/rest/ips/pools.rb +63 -0
  16. data/lib/sendgrid4r/rest/ips/warmup.rb +55 -0
  17. data/lib/sendgrid4r/rest/request.rb +34 -19
  18. data/lib/sendgrid4r/rest/settings/enforced_tls.rb +39 -0
  19. data/lib/sendgrid4r/rest/stats/advanced.rb +91 -0
  20. data/lib/sendgrid4r/rest/stats/category.rb +47 -0
  21. data/lib/sendgrid4r/rest/stats/global.rb +26 -0
  22. data/lib/sendgrid4r/rest/stats/parse.rb +26 -0
  23. data/lib/sendgrid4r/rest/stats/stats.rb +89 -0
  24. data/lib/sendgrid4r/rest/stats/subuser.rb +47 -0
  25. data/lib/sendgrid4r/rest/templates/templates.rb +61 -0
  26. data/lib/sendgrid4r/rest/templates/versions.rb +92 -0
  27. data/lib/sendgrid4r/version.rb +4 -1
  28. data/lib/sendgrid4r.rb +5 -2
  29. data/sendgrid4r.gemspec +13 -12
  30. data/spec/{global_suppressions_spec.rb → asm/global_suppressions_spec.rb} +25 -17
  31. data/spec/asm/groups_spec.rb +58 -0
  32. data/spec/{suppressions_spec.rb → asm/suppressions_spec.rb} +24 -22
  33. data/spec/categories/categories_spec.rb +39 -0
  34. data/spec/client_spec.rb +65 -50
  35. data/spec/ips/addresses_spec.rb +116 -0
  36. data/spec/ips/pools_spec.rb +43 -0
  37. data/spec/ips/warmup_spec.rb +52 -0
  38. data/spec/{enforced_tls_spec.rb → settings/enforced_tls_spec.rb} +12 -11
  39. data/spec/stats/advanced_spec.rb +243 -0
  40. data/spec/stats/category_spec.rb +112 -0
  41. data/spec/stats/global_spec.rb +64 -0
  42. data/spec/stats/parse_spec.rb +49 -0
  43. data/spec/stats/subuser_spec.rb +105 -0
  44. data/spec/templates/templates_spec.rb +66 -0
  45. data/spec/templates/versions_spec.rb +89 -0
  46. data/spec/version_factory_spec.rb +20 -15
  47. metadata +94 -42
  48. data/lib/sendgrid4r/rest/addresses.rb +0 -62
  49. data/lib/sendgrid4r/rest/enforced_tls.rb +0 -46
  50. data/lib/sendgrid4r/rest/global_suppressions.rb +0 -35
  51. data/lib/sendgrid4r/rest/groups.rb +0 -68
  52. data/lib/sendgrid4r/rest/pools.rb +0 -53
  53. data/lib/sendgrid4r/rest/suppressions.rb +0 -57
  54. data/lib/sendgrid4r/rest/templates.rb +0 -64
  55. data/lib/sendgrid4r/rest/versions.rb +0 -65
  56. data/lib/sendgrid4r/rest/warmup.rb +0 -53
  57. data/spec/addresses_spec.rb +0 -80
  58. data/spec/groups_spec.rb +0 -54
  59. data/spec/pools_spec.rb +0 -62
  60. data/spec/templates_spec.rb +0 -38
  61. data/spec/versions_spec.rb +0 -75
  62. data/spec/warmup_spec.rb +0 -52
@@ -1,53 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
- $:.unshift File.dirname(__FILE__)
3
-
4
- require "sendgrid4r/rest/request"
5
-
6
- module SendGrid4r
7
- module REST
8
- module Ips
9
- module Warmup
10
-
11
- include SendGrid4r::REST::Request
12
-
13
- def get_warmup_ips
14
- response = get(@auth, "#{SendGrid4r::Client::BASE_URL}/ips/warmup")
15
- ips = Array.new
16
- response.each{|ip|
17
- ip_address = WarmupIp.create(ip)
18
- ips.push(ip_address)
19
- } if response.length > 0
20
- ips
21
- end
22
-
23
- def get_warmup_ip(ip_address)
24
- WarmupIp.create(get(@auth, "#{SendGrid4r::Client::BASE_URL}/ips/warmup/#{ip_address}"))
25
- end
26
-
27
- def post_warmup_ip(ip_address)
28
- params = Hash.new
29
- params["ip"] = ip_address
30
- WarmupIp.create(post(@auth, "#{SendGrid4r::Client::BASE_URL}/ips/warmup", params))
31
- end
32
-
33
- def delete_warmup_ip(ip_address)
34
- delete(@auth, "#{SendGrid4r::Client::BASE_URL}/ips/warmup/#{ip_address}")
35
- end
36
-
37
- class WarmupIp
38
-
39
- attr_accessor :ip, :start_date
40
-
41
- def self.create(value)
42
- obj = WarmupIp.new
43
- obj.ip = value["ip"]
44
- obj.start_date = value["start_date"]
45
- obj
46
- end
47
-
48
- end
49
- end
50
- end
51
-
52
- end
53
- end
@@ -1,80 +0,0 @@
1
- # encoding: utf-8
2
- require File.dirname(__FILE__) + '/spec_helper'
3
-
4
- describe "SendGrid4r::REST::Ips::Addresses" do
5
-
6
- before :all do
7
- Dotenv.load
8
- end
9
-
10
- context "if account is free" do
11
- before :all do
12
- @client = SendGrid4r::Client.new(ENV["SENDGRID_USERNAME"], ENV["SENDGRID_PASSWORD"])
13
- end
14
-
15
- describe "#get_ips" do
16
- it "raise error" do
17
- expect{@client.get_ips}.to raise_error(RestClient::Forbidden)
18
- end
19
- end
20
-
21
- describe "#get_ip" do
22
- it "raise error" do
23
- expect{@client.get_ip("10.10.10.10").to raise_error(RestClient::Forbidden)}
24
- end
25
- end
26
- end
27
-
28
- context "if account is silver" do
29
- TEST_POOL = "test_pool"
30
- before :all do
31
- @client = SendGrid4r::Client.new(ENV["SILVER_SENDGRID_USERNAME"], ENV["SILVER_SENDGRID_PASSWORD"])
32
- # refresh the pool
33
- pools = @client.get_pools
34
- pools.each {|pool|
35
- @client.delete_pool(TEST_POOL) if pool == TEST_POOL
36
- }
37
- @client.post_pool(TEST_POOL)
38
- #ips = @client.get_ips
39
- #@client.delete_ip_from_pool(TEST_POOL, ips[0].ip)
40
- end
41
-
42
- describe "#get_ips" do
43
- it "returns Array of Address instance" do
44
- ips = @client.get_ips
45
- expect(ips.length > 0).to be(true)
46
- expect(ips[0].class).to be(SendGrid4r::REST::Ips::Address)
47
- end
48
- end
49
-
50
- describe "#get_ip" do
51
- it "returns Address instance" do
52
- ips = @client.get_ips
53
- expect(@client.get_ip(ips[0].ip).class).to be(SendGrid4r::REST::Ips::Address)
54
- end
55
- end
56
-
57
- describe "#post_ip_to_pool" do
58
- it "add ip to pool successfully" do
59
- ips = @client.get_ips
60
- actual = @client.post_ip_to_pool(TEST_POOL, ips[0].ip)
61
- expect(actual.ip).to eq(ips[0].ip)
62
- expect(actual.pool_name).to eq(TEST_POOL)
63
- end
64
- end
65
-
66
- # Could not test because POST an IP to a pool takes 60 sec
67
- # describe "#delete_ip_from_pool" do
68
- # it "delete ip from pool successfully" do
69
- # begin
70
- # ips = @client.get_ips
71
- # @client.post_ip_to_pool(TEST_POOL, ips[0].ip)
72
- # @client.delete_ip_from_pool(TEST_POOL, ips[0].ip)
73
- # rescue => e
74
- # puts e.inspect
75
- # raise e
76
- # end
77
- # end
78
- # end
79
- end
80
- end
data/spec/groups_spec.rb DELETED
@@ -1,54 +0,0 @@
1
- # encoding: utf-8
2
- require File.dirname(__FILE__) + '/spec_helper'
3
-
4
- describe "SendGrid4r::REST::Asm::Groups" do
5
-
6
- before :all do
7
- Dotenv.load
8
- @client = SendGrid4r::Client.new(ENV["SENDGRID_USERNAME"], ENV["SENDGRID_PASSWORD"])
9
- @group_name = "group_test"
10
- @group_edit = "group_edit"
11
- @group_desc = "group_desc"
12
- @group_desc_edit = "group_desc_edit"
13
- end
14
-
15
- context "always" do
16
- it "is normal" do
17
- # celan up test env
18
- grps = @client.get_groups
19
- expect(grps.length >= 0).to eq(true)
20
- grps.each{|grp|
21
- if grp.name == @group_name || grp.name == @group_edit then
22
- @client.delete_group(grp.id)
23
- end
24
- }
25
- # post a group
26
- new_group = @client.post_group(@group_name, @group_desc)
27
- expect(@group_name).to eq(new_group.name)
28
- expect(@group_desc).to eq(new_group.description)
29
- # patch the group
30
- new_group.name = @group_edit
31
- new_group.description = @group_desc_edit
32
- @client.patch_group(new_group.id, new_group)
33
- # get the group
34
- edit_group = @client.get_group(new_group.id)
35
- expect(edit_group.respond_to?("id")).to eq(true)
36
- expect(edit_group.respond_to?("name")).to eq(true)
37
- expect(edit_group.respond_to?("description")).to eq(true)
38
- expect(edit_group.respond_to?("last_email_sent_at")).to eq(true)
39
- expect(edit_group.respond_to?("unsubscribes")).to eq(true)
40
- expect(new_group.id).to eq(edit_group.id)
41
- expect(@group_edit).to eq(edit_group.name)
42
- expect(@group_desc_edit).to eq(edit_group.description)
43
- # delete the group
44
- @client.delete_group(edit_group.id)
45
- expect{@client.get_group(edit_group.id)}.to raise_error(RestClient::ResourceNotFound)
46
- end
47
- end
48
-
49
- context "abnormal" do
50
- it "raise resource not found for none existance id" do
51
- expect{@client.get_group("notexistid")}.to raise_error(RestClient::ResourceNotFound)
52
- end
53
- end
54
- end
data/spec/pools_spec.rb DELETED
@@ -1,62 +0,0 @@
1
- # encoding: utf-8
2
- require File.dirname(__FILE__) + '/spec_helper'
3
-
4
- describe "SendGrid4r::REST::Ips::Pools" do
5
-
6
- before :all do
7
- Dotenv.load
8
- @client = SendGrid4r::Client.new(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 free" do
14
- it "raise error" do
15
- begin
16
- #client = SendGrid4r::Client.new(ENV["SENDGRID_USERNAME"], ENV["SENDGRID_PASSWORD"])
17
- # get ip pools
18
- #expect{client.get_pools}.to raise_error(RestClient::Forbidden)
19
- # post an ip pool
20
- #expect{client.post_pool("test")}.to raise_error(RestClient::Forbidden)
21
- # get the ip pool
22
- #expect{client.get_pool("test")}.to raise_error(RestClient::Forbidden)
23
- # put the ip pool
24
- #expect{client.put_pool("test", "new_test")}.to raise_error(RestClient::Forbidden)
25
- # delete the ip pool
26
- #expect{client.delete_pool("test")}.to raise_error(RestClient::Forbidden)
27
- rescue => ex
28
- puts ex.inspect
29
- raise ex
30
- end
31
- end
32
- end
33
-
34
- context "if account is silver" do
35
- it "is normal" do
36
- # clean up test env
37
- pools = @client.get_pools
38
- expect(pools.length >= 0).to eq(true)
39
- pools.each{|pool|
40
- if pool == @pool_name || pool == @pool_edit then
41
- @client.delete_pool(pool)
42
- end
43
- }
44
- # post a pool
45
- new_pool = @client.post_pool(@pool_name)
46
- expect(@pool_name).to eq(new_pool.name)
47
- # put the pool
48
- edit_pool = @client.put_pool(@pool_name, @pool_edit)
49
- expect(@pool_edit).to eq(edit_pool.name)
50
- # get the pool
51
- pool = @client.get_pool(@pool_edit)
52
- expect(SendGrid4r::REST::Ips::Pool).to be(pool.class)
53
- # delete the pool
54
- @client.delete_pool(pool.name)
55
- expect{@client.get_pool(pool.name)}
56
- ips = @client.get_ips
57
- expect(ips.length).to be(1)
58
- expect(ips[0].class).to be(SendGrid4r::REST::Ips::Address)
59
- expect(@client.get_ip(ips[0].ip).class).to be(SendGrid4r::REST::Ips::Address)
60
- end
61
- end
62
- end
@@ -1,38 +0,0 @@
1
- # encoding: utf-8
2
- require File.dirname(__FILE__) + '/spec_helper'
3
-
4
- describe "SendGrid4r::REST::Templates" do
5
-
6
- before :all do
7
- Dotenv.load
8
- @client = SendGrid4r::Client.new(ENV["SENDGRID_USERNAME"], ENV["SENDGRID_PASSWORD"])
9
- @template_name = "template_test"
10
- @template_edit = "template_edit"
11
- end
12
-
13
- context "always" do
14
- it "is normal" do
15
- # celan up test env
16
- tmps = @client.get_templates
17
- expect(tmps.length >= 0).to eq(true)
18
- tmps.each{|tmp|
19
- if tmp.name == @template_name || tmp.name == @template_edit then
20
- @client.delete_template(tmp.id)
21
- end
22
- }
23
- # post a template
24
- new_template = @client.post_template(@template_name)
25
- expect(@template_name).to eq(new_template.name)
26
- # pach the template
27
- @client.patch_template(new_template.id, @template_edit)
28
- # get the template
29
- edit_template = @client.get_template(new_template.id)
30
- expect(new_template.id).to eq(edit_template.id)
31
- expect(@template_edit).to eq(edit_template.name)
32
- expect(new_template.versions).to eq(edit_template.versions)
33
- # delete the template
34
- @client.delete_template(edit_template.id)
35
- expect{@client.get_template(edit_template.id)}.to raise_error(RestClient::ResourceNotFound)
36
- end
37
- end
38
- end
@@ -1,75 +0,0 @@
1
- # encoding: utf-8
2
- require File.dirname(__FILE__) + '/spec_helper'
3
-
4
- describe "SendGrid4r::REST::Templates::Versions" do
5
-
6
- before :all do
7
- Dotenv.load
8
- @client = SendGrid4r::Client.new(ENV["SENDGRID_USERNAME"], ENV["SENDGRID_PASSWORD"])
9
- @template_edit = "version_test"
10
- @version1_name = "version1_test"
11
- @version2_name = "version2_test"
12
- end
13
-
14
- context "always" do
15
- it "is normal" do
16
- # celan up test env
17
- tmps = @client.get_templates
18
- tmps.each{|tmp|
19
- if tmp.name == @template_edit then
20
- tmp.versions.each{|ver|
21
- @client.delete_version(tmp.id, ver.id)
22
- }
23
- @client.delete_template(tmp.id)
24
- end
25
- }
26
- # post a template
27
- new_template = @client.post_template(@template_edit)
28
- expect(@template_edit).to eq(new_template.name)
29
- # post a version
30
- factory = SendGrid4r::VersionFactory.new
31
- ver1 = factory.create(@version1_name)
32
- ver1 = @client.post_version(new_template.id, ver1)
33
- # get the version
34
- actual = @client.get_version(new_template.id, ver1.id)
35
- expect(ver1.template_id).to eq(actual.template_id)
36
- expect(ver1.active).to eq(actual.active)
37
- expect(ver1.name).to eq(actual.name)
38
- expect(ver1.html_content).to eq(actual.html_content)
39
- expect(ver1.plain_content).to eq(actual.plain_content)
40
- expect(ver1.subject).to eq(actual.subject)
41
- # edit the version
42
- edit_ver1 = actual.dup
43
- edit_ver1.name = "edit_version"
44
- edit_ver1.subject = "edit<%subject%>edit"
45
- edit_ver1.html_content = "edit<%body%>edit"
46
- edit_ver1.plain_content = "edit<%body%>edit"
47
- edit_ver1.active = 0
48
- @client.patch_version(new_template.id, ver1.id, edit_ver1)
49
- # get the version
50
- actual = @client.get_version(new_template.id, ver1.id)
51
- expect(new_template.id).to eq(actual.template_id)
52
- expect(edit_ver1.active).to eq(actual.active)
53
- expect(edit_ver1.name).to eq(actual.name)
54
- expect(edit_ver1.html_content).to eq(actual.html_content)
55
- expect(edit_ver1.plain_content).to eq(actual.plain_content)
56
- expect(edit_ver1.subject).to eq(actual.subject)
57
- # post a version 2
58
- ver2 = factory.create(@version2_name, "<%subject%>", "<%body%>", "<%body%>")
59
- ver2 = @client.post_version(new_template.id, ver2)
60
- # activate version 2
61
- @client.activate_version(new_template.id, ver2.id)
62
- actual_ver1 = @client.get_version(new_template.id, ver1.id)
63
- actual_ver2 = @client.get_version(new_template.id, ver2.id)
64
- expect(0).to eq(actual_ver1.active)
65
- expect(1).to eq(actual_ver2.active)
66
- # delete the version
67
- @client.delete_version(new_template.id, actual_ver1.id)
68
- @client.delete_version(new_template.id, actual_ver2.id)
69
- expect{@client.get_version(new_template.id, actual_ver1.id)}.to raise_error(RestClient::ResourceNotFound)
70
- expect{@client.get_version(new_template.id, actual_ver2.id)}.to raise_error(RestClient::ResourceNotFound)
71
- # delete the template
72
- @client.delete_template(new_template.id)
73
- end
74
- end
75
- end
data/spec/warmup_spec.rb DELETED
@@ -1,52 +0,0 @@
1
- # encoding: utf-8
2
- require File.dirname(__FILE__) + '/spec_helper'
3
-
4
- describe "SendGrid4r::REST::Ips::WarmUp" do
5
-
6
- before :all do
7
- Dotenv.load
8
- end
9
-
10
- # context "normal" do
11
- # it "is normal" do
12
- #
13
- # begin
14
- # client = SendGrid::Client.new(ENV["SENDGRID_USERNAME"], ENV["SENDGRID_PASSWORD"])
15
- # # celan up test env
16
- # warmup_ips = client.get_warmup_ips
17
- # expect(warmup_ips.length >= 0).to eq(true)
18
- # if warmup_ips.length > 0 then
19
- # warmup_ips.each{|warmup_ip|
20
- # client.delete_warmup_ip(warmup_ip.ip)
21
- # }
22
- # end
23
- # # get warmup ip
24
- # warmup_ips = client.get_warmup_ips
25
- # expect(warmup_ips.length).to eq(0)
26
- # # post warmup ip
27
- # ips = client.get_ips
28
- # if ips.length > 0 then
29
- # warmup_ip = client.post_warmup_ip(ips[0].ip)
30
- # expect(warmup_ip.ip).to eq(ips[0].ip)
31
- # end
32
- # warmup_ip = client.get_warmup_ip(warmup_ip.ip)
33
- # expect(warmup_ip.ip).to eq(ips[0].ip)
34
- # # delete the warmup ip
35
- # client.delete_warmup_ip(warmup_ip.ip)
36
- # expect{client.get_warmup_ip(warmup_ip.ip)}.to raise_error(RestClient::ResourceNotFound)
37
- # rescue => ex
38
- # puts ex.inspect
39
- # raise ex
40
- # end
41
- #
42
- # end
43
- # end
44
-
45
- context "abnormal" do
46
- it "raise forbidden for free account" do
47
- client = SendGrid4r::Client.new(ENV["SENDGRID_USERNAME"], ENV["SENDGRID_PASSWORD"])
48
- expect{client.get_warmup_ips}.to raise_error(RestClient::Forbidden)
49
- end
50
- end
51
-
52
- end