sendgrid4r 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,53 @@
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
+ @template_name = "template_test"
9
+ @template_edit = "template_edit"
10
+ end
11
+
12
+ context "normal" do
13
+ it "is normal" do
14
+
15
+ begin
16
+ client = SendGrid4r::Client.new(ENV["SENDGRID_USERNAME"], ENV["SENDGRID_PASSWORD"])
17
+ # celan up test env
18
+ tmps = client.get_templates
19
+ expect(tmps.length >= 0).to eq(true)
20
+ tmps.each{|tmp|
21
+ if tmp.name == @template_name || tmp.name == @template_edit then
22
+ client.delete_template(tmp.id)
23
+ end
24
+ }
25
+ # post a template
26
+ new_template = client.post_template(@template_name)
27
+ expect(@template_name).to eq(new_template.name)
28
+ # pach the template
29
+ client.patch_template(new_template.id, @template_edit)
30
+ # get the template
31
+ edit_template = client.get_template(new_template.id)
32
+ expect(new_template.id).to eq(edit_template.id)
33
+ expect(@template_edit).to eq(edit_template.name)
34
+ expect(new_template.versions).to eq(edit_template.versions)
35
+ # delete the template
36
+ client.delete_template(edit_template.id)
37
+ expect{client.get_template(edit_template.id)}.to raise_error(RestClient::ResourceNotFound)
38
+ rescue => ex
39
+ puts ex.inspect
40
+ raise ex
41
+ end
42
+
43
+ end
44
+ end
45
+
46
+ context "abnormal" do
47
+ it "raise resource not found for none existance id" do
48
+ client = SendGrid4r::Client.new(ENV["SENDGRID_USERNAME"], ENV["SENDGRID_PASSWORD"])
49
+ expect{client.get_template("notexistid")}.to raise_error(RestClient::ResourceNotFound)
50
+ end
51
+ end
52
+
53
+ end
@@ -0,0 +1,37 @@
1
+ # encoding: utf-8
2
+ require File.dirname(__FILE__) + '/spec_helper'
3
+
4
+ describe "SendGrid4r::VersionFactory" do
5
+
6
+ before :all do
7
+ Dotenv.load
8
+ end
9
+
10
+ context "normal" do
11
+ it "is simple case" do
12
+
13
+ factory = SendGrid4r::VersionFactory.new
14
+ version = factory.create("version_name")
15
+ expect(version.name).to eq("version_name")
16
+ expect(version.subject).to eq("<%subject%>")
17
+ expect(version.html_content).to eq("<%body%>")
18
+ expect(version.plain_content).to eq("<%body%>")
19
+ expect(version.active).to eq(1)
20
+
21
+ end
22
+
23
+ it "is full params case" do
24
+
25
+ factory = SendGrid4r::VersionFactory.new
26
+ version = factory.create("version_name", "This is subject <%subject%>", "This is html content <%body%>", "This is plain content <%body%>", 0)
27
+ expect(version.name).to eq("version_name")
28
+ expect(version.subject).to eq("This is subject <%subject%>")
29
+ expect(version.html_content).to eq("This is html content <%body%>")
30
+ expect(version.plain_content).to eq("This is plain content <%body%>")
31
+ expect(version.active).to eq(0)
32
+
33
+ end
34
+
35
+ end
36
+
37
+ end
@@ -0,0 +1,90 @@
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
+ @template_name = "version_test"
9
+ @version1_name = "version1_test"
10
+ @version2_name = "version2_test"
11
+ end
12
+
13
+ context "normal" do
14
+
15
+ it "is normal" do
16
+ begin
17
+ client = SendGrid4r::Client.new(ENV["SENDGRID_USERNAME"], ENV["SENDGRID_PASSWORD"])
18
+ # celan up test env
19
+ tmps = client.get_templates
20
+ tmps.each{|tmp|
21
+ if tmp.name == @template_name then
22
+ tmp.versions.each{|ver|
23
+ client.delete_version(tmp.id, ver.id)
24
+ }
25
+ client.delete_template(tmp.id)
26
+ end
27
+ }
28
+ # post a template
29
+ new_template = client.post_template(@template_name)
30
+ expect(@template_name).to eq(new_template.name)
31
+ # post a version
32
+ factory = SendGrid4r::VersionFactory.new
33
+ ver1 = factory.create(@version1_name)
34
+ ver1 = client.post_version(new_template.id, ver1)
35
+ # get the version
36
+ actual = client.get_version(new_template.id, ver1.id)
37
+ expect(ver1.template_id).to eq(actual.template_id)
38
+ expect(ver1.active).to eq(actual.active)
39
+ expect(ver1.name).to eq(actual.name)
40
+ expect(ver1.html_content).to eq(actual.html_content)
41
+ expect(ver1.plain_content).to eq(actual.plain_content)
42
+ expect(ver1.subject).to eq(actual.subject)
43
+ # edit the version
44
+ edit_ver1 = actual.dup
45
+ edit_ver1.name = "edit_version"
46
+ edit_ver1.subject = "edit<%subject%>edit"
47
+ edit_ver1.html_content = "edit<%body%>edit"
48
+ edit_ver1.plain_content = "edit<%body%>edit"
49
+ edit_ver1.active = 0
50
+ client.patch_version(new_template.id, ver1.id, edit_ver1)
51
+ # get the version
52
+ actual = client.get_version(new_template.id, ver1.id)
53
+ expect(new_template.id).to eq(actual.template_id)
54
+ expect(edit_ver1.active).to eq(actual.active)
55
+ expect(edit_ver1.name).to eq(actual.name)
56
+ expect(edit_ver1.html_content).to eq(actual.html_content)
57
+ expect(edit_ver1.plain_content).to eq(actual.plain_content)
58
+ expect(edit_ver1.subject).to eq(actual.subject)
59
+ # post a version 2
60
+ ver2 = factory.create(@version2_name, "<%subject%>", "<%body%>", "<%body%>")
61
+ ver2 = client.post_version(new_template.id, ver2)
62
+ # activate version 2
63
+ client.activate_version(new_template.id, ver2.id)
64
+ actual_ver1 = client.get_version(new_template.id, ver1.id)
65
+ actual_ver2 = client.get_version(new_template.id, ver2.id)
66
+ expect(0).to eq(actual_ver1.active)
67
+ expect(1).to eq(actual_ver2.active)
68
+ # delete the version
69
+ client.delete_version(new_template.id, actual_ver1.id)
70
+ client.delete_version(new_template.id, actual_ver2.id)
71
+ expect{client.get_version(new_template.id, actual_ver1.id)}.to raise_error(RestClient::ResourceNotFound)
72
+ expect{client.get_version(new_template.id, actual_ver2.id)}.to raise_error(RestClient::ResourceNotFound)
73
+ # delete the template
74
+ client.delete_template(new_template.id)
75
+ rescue => ex
76
+ puts ex.inspect
77
+ raise ex
78
+ end
79
+ end
80
+ end
81
+
82
+ context "abnormal" do
83
+
84
+ it "raise resource not found for none existance id" do
85
+ client = SendGrid4r::Client.new(ENV["SENDGRID_USERNAME"], ENV["SENDGRID_PASSWORD"])
86
+ expect{client.get_version("notexistid", "notexistid")}.to raise_error(RestClient::ResourceNotFound)
87
+ end
88
+ end
89
+
90
+ 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
+
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
metadata ADDED
@@ -0,0 +1,146 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sendgrid4r
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - awwa500@gmail.com
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-09-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rest-client
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.6'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.6'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: dotenv
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: SendGrid Web API v3 module
70
+ email:
71
+ - awwa500@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".env.example"
77
+ - ".gitignore"
78
+ - ".travis.yml"
79
+ - Gemfile
80
+ - LICENSE.txt
81
+ - README.md
82
+ - Rakefile
83
+ - lib/auth.rb
84
+ - lib/client.rb
85
+ - lib/sendgrid4r.rb
86
+ - lib/sendgrid4r/factory/version_factory.rb
87
+ - lib/sendgrid4r/rest/api.rb
88
+ - lib/sendgrid4r/rest/enforced_tls.rb
89
+ - lib/sendgrid4r/rest/global_suppressions.rb
90
+ - lib/sendgrid4r/rest/groups.rb
91
+ - lib/sendgrid4r/rest/ip_addresses.rb
92
+ - lib/sendgrid4r/rest/request.rb
93
+ - lib/sendgrid4r/rest/suppressions.rb
94
+ - lib/sendgrid4r/rest/templates.rb
95
+ - lib/sendgrid4r/rest/versions.rb
96
+ - lib/sendgrid4r/rest/warmup.rb
97
+ - lib/sendgrid4r/version.rb
98
+ - sendgrid4r.gemspec
99
+ - spec/client_spec.rb
100
+ - spec/enforced_tls_spec.rb
101
+ - spec/global_suppressions_spec.rb
102
+ - spec/groups_spec.rb
103
+ - spec/ip_addresses_spec.rb
104
+ - spec/spec_helper.rb
105
+ - spec/suppressions_spec.rb
106
+ - spec/templates_spec.rb
107
+ - spec/version_factory_spec.rb
108
+ - spec/versions_spec.rb
109
+ - spec/warmup_spec.rb
110
+ homepage: ''
111
+ licenses:
112
+ - MIT
113
+ metadata: {}
114
+ post_install_message:
115
+ rdoc_options: []
116
+ require_paths:
117
+ - lib
118
+ required_ruby_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ required_rubygems_version: !ruby/object:Gem::Requirement
124
+ requirements:
125
+ - - ">="
126
+ - !ruby/object:Gem::Version
127
+ version: '0'
128
+ requirements: []
129
+ rubyforge_project:
130
+ rubygems_version: 2.2.2
131
+ signing_key:
132
+ specification_version: 4
133
+ summary: SendGrid Web API v3 module
134
+ test_files:
135
+ - spec/client_spec.rb
136
+ - spec/enforced_tls_spec.rb
137
+ - spec/global_suppressions_spec.rb
138
+ - spec/groups_spec.rb
139
+ - spec/ip_addresses_spec.rb
140
+ - spec/spec_helper.rb
141
+ - spec/suppressions_spec.rb
142
+ - spec/templates_spec.rb
143
+ - spec/version_factory_spec.rb
144
+ - spec/versions_spec.rb
145
+ - spec/warmup_spec.rb
146
+ has_rdoc: