sendgrid_template_engine 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +0 -1
- data/lib/resources.rb +6 -2
- data/lib/sendgrid_template_engine/version.rb +1 -1
- data/lib/templates.rb +10 -6
- data/lib/versions.rb +10 -5
- data/test/sendgrid_template_engine_test.rb +1 -1
- data/test/templates_test.rb +91 -109
- data/test/versions_test.rb +166 -134
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 949d6eb203bec2e5ccc36831323ed8ef94fd1df7
|
4
|
+
data.tar.gz: ae8f61d89ce4702632b300c0d0fd1ab7455188d4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0cc70a568f834267d47bc72084bca57f9318247805dc2d1c1892ddf65ea518fcc401eeec5b2f4f8cca6cd15690be4bef8e73ea047c58cdb64a52868f25000835
|
7
|
+
data.tar.gz: 5549eed7705dd1ffd157b8e7d8e248abb25de6ed9bc49b8b42b08a115e2970ebc59df4f61d5dd341b0239d162d524b38a4aeb8a56bdda90a0d80a52de1c24268
|
data/.travis.yml
CHANGED
data/lib/resources.rb
CHANGED
@@ -9,12 +9,16 @@ module SendgridTemplateEngine
|
|
9
9
|
|
10
10
|
class Resources
|
11
11
|
|
12
|
+
attr_reader :url_base, :username, :password
|
13
|
+
|
12
14
|
def initialize(username, password)
|
13
15
|
raise ArgumentError.new("username should not be nil") if username == nil
|
14
16
|
raise ArgumentError.new("password should not be nil") if password == nil
|
15
|
-
@
|
17
|
+
@username = username
|
18
|
+
@password = password
|
19
|
+
@url_base = URI.escape("https://api.sendgrid.com/v3")
|
16
20
|
end
|
17
|
-
|
21
|
+
|
18
22
|
end
|
19
23
|
|
20
24
|
end
|
data/lib/templates.rb
CHANGED
@@ -3,7 +3,6 @@ $:.unshift File.dirname(__FILE__)
|
|
3
3
|
|
4
4
|
require "sendgrid_template_engine/version"
|
5
5
|
require "rest-client"
|
6
|
-
require "uri"
|
7
6
|
require "resources"
|
8
7
|
require "versions"
|
9
8
|
|
@@ -13,7 +12,8 @@ module SendgridTemplateEngine
|
|
13
12
|
|
14
13
|
def get_all
|
15
14
|
endpoint = "#{@url_base}/templates"
|
16
|
-
|
15
|
+
resource = RestClient::Resource.new(endpoint, @username, @password)
|
16
|
+
body = resource.get.body
|
17
17
|
response = JSON.parse(body)
|
18
18
|
temps = []
|
19
19
|
response["templates"].each{|template|
|
@@ -26,16 +26,18 @@ module SendgridTemplateEngine
|
|
26
26
|
def get(template_id)
|
27
27
|
raise ArgumentError.new("template_id should not be nil") if template_id == nil
|
28
28
|
endpoint = "#{@url_base}/templates/#{template_id}"
|
29
|
-
|
29
|
+
resource = RestClient::Resource.new(endpoint, @username, @password)
|
30
|
+
body = resource.get.body
|
30
31
|
Template.create(JSON.parse(body))
|
31
32
|
end
|
32
33
|
|
33
34
|
def post(name)
|
34
35
|
raise ArgumentError.new("name should not be nil") if name == nil
|
35
36
|
endpoint = "#{@url_base}/templates"
|
37
|
+
resource = RestClient::Resource.new(endpoint, @username, @password)
|
36
38
|
params = Hash.new
|
37
39
|
params["name"] = name
|
38
|
-
body =
|
40
|
+
body = resource.post(params.to_json, :content_type => :json).body
|
39
41
|
Template.create(JSON.parse(body))
|
40
42
|
end
|
41
43
|
|
@@ -43,16 +45,18 @@ module SendgridTemplateEngine
|
|
43
45
|
raise ArgumentError.new("template_id should not be nil") if template_id == nil
|
44
46
|
raise ArgumentError.new("name should not be nil") if name == nil
|
45
47
|
endpoint = "#{@url_base}/templates/#{template_id}"
|
48
|
+
resource = RestClient::Resource.new(endpoint, @username, @password)
|
46
49
|
params = Hash.new
|
47
50
|
params["name"] = name
|
48
|
-
body =
|
51
|
+
body = resource.patch(params.to_json, :content_type => :json).body
|
49
52
|
Template.create(JSON.parse(body))
|
50
53
|
end
|
51
54
|
|
52
55
|
def delete(template_id)
|
53
56
|
raise ArgumentError.new("template_id should not be nil") if template_id == nil
|
54
57
|
endpoint = "#{@url_base}/templates/#{template_id}"
|
55
|
-
RestClient.
|
58
|
+
resource = RestClient::Resource.new(endpoint, @username, @password)
|
59
|
+
resource.delete
|
56
60
|
end
|
57
61
|
|
58
62
|
end
|
data/lib/versions.rb
CHANGED
@@ -14,7 +14,8 @@ module SendgridTemplateEngine
|
|
14
14
|
raise ArgumentError.new("template_id should not be nil") if template_id == nil
|
15
15
|
raise ArgumentError.new("version_id should not be nil") if version_id == nil
|
16
16
|
endpoint = "#{@url_base}/templates/#{template_id}/versions/#{version_id}"
|
17
|
-
|
17
|
+
resource = RestClient::Resource.new(endpoint, @username, @password)
|
18
|
+
body = resource.get.body
|
18
19
|
Version.create(JSON.parse(body))
|
19
20
|
end
|
20
21
|
|
@@ -22,7 +23,8 @@ module SendgridTemplateEngine
|
|
22
23
|
raise ArgumentError.new("template_id should not be nil") if template_id == nil
|
23
24
|
raise ArgumentError.new("version should not be nil") if version == nil
|
24
25
|
endpoint = "#{@url_base}/templates/#{template_id}/versions"
|
25
|
-
|
26
|
+
resource = RestClient::Resource.new(endpoint, @username, @password)
|
27
|
+
body = resource.post(version.to_hash.to_json, :content_type => :json).body
|
26
28
|
Version.create(JSON.parse(body))
|
27
29
|
end
|
28
30
|
|
@@ -30,7 +32,8 @@ module SendgridTemplateEngine
|
|
30
32
|
raise ArgumentError.new("template_id should not be nil") if template_id == nil
|
31
33
|
raise ArgumentError.new("version_id should not be nil") if version_id == nil
|
32
34
|
endpoint = "#{@url_base}/templates/#{template_id}/versions/#{version_id}/activate"
|
33
|
-
|
35
|
+
resource = RestClient::Resource.new(endpoint, @username, @password)
|
36
|
+
body = resource.post(:content_type => :json).body
|
34
37
|
Version.create(JSON.parse(body))
|
35
38
|
end
|
36
39
|
|
@@ -39,7 +42,8 @@ module SendgridTemplateEngine
|
|
39
42
|
raise ArgumentError.new("version_id should not be nil") if version_id == nil
|
40
43
|
raise ArgumentError.new("version should not be nil") if version == nil
|
41
44
|
endpoint = "#{@url_base}/templates/#{template_id}/versions/#{version_id}"
|
42
|
-
|
45
|
+
resource = RestClient::Resource.new(endpoint, @username, @password)
|
46
|
+
body = resource.patch(version.to_hash.to_json, :content_type => :json).body
|
43
47
|
Version.create(JSON.parse(body))
|
44
48
|
end
|
45
49
|
|
@@ -47,7 +51,8 @@ module SendgridTemplateEngine
|
|
47
51
|
raise ArgumentError.new("template_id should not be nil") if template_id == nil
|
48
52
|
raise ArgumentError.new("version_id should not be nil") if version_id == nil
|
49
53
|
endpoint = "#{@url_base}/templates/#{template_id}/versions/#{version_id}"
|
50
|
-
RestClient.
|
54
|
+
resource = RestClient::Resource.new(endpoint, @username, @password)
|
55
|
+
resource.delete
|
51
56
|
end
|
52
57
|
|
53
58
|
end
|
data/test/templates_test.rb
CHANGED
@@ -7,9 +7,10 @@ require "./lib/sendgrid_template_engine/version"
|
|
7
7
|
class TemplatesTest < Test::Unit::TestCase
|
8
8
|
|
9
9
|
def setup
|
10
|
-
|
11
|
-
|
12
|
-
|
10
|
+
Dotenv.load
|
11
|
+
@username = ENV["SENDGRID_USERNAME"]
|
12
|
+
@password = ENV["SENDGRID_PASSWORD"]
|
13
|
+
@template_name = "template_test"
|
13
14
|
end
|
14
15
|
|
15
16
|
def test_initialize
|
@@ -19,120 +20,101 @@ class TemplatesTest < Test::Unit::TestCase
|
|
19
20
|
|
20
21
|
def test_bad_username
|
21
22
|
assert_raise(ArgumentError) {
|
22
|
-
|
23
|
+
SendgridTemplateEngine::Templates.new(nil, nil)
|
23
24
|
}
|
24
25
|
end
|
25
26
|
|
26
27
|
def test_invalid_auth
|
27
28
|
templates = SendgridTemplateEngine::Templates.new("user", "pass")
|
28
29
|
assert_raise(RestClient::Unauthorized) {
|
29
|
-
|
30
|
+
templates.get_all()
|
30
31
|
}
|
31
32
|
end
|
32
33
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
#
|
119
|
-
# def test_delete_not_exist
|
120
|
-
# templates = SendgridTemplateEngine::Templates.new(@username, @password)
|
121
|
-
# assert_raise(RestClient::ResourceNotFound) {
|
122
|
-
# templates.delete("not_exist")
|
123
|
-
# }
|
124
|
-
# end
|
125
|
-
#
|
126
|
-
# def test_delete
|
127
|
-
# #-- prepare test
|
128
|
-
# templates = SendgridTemplateEngine::Templates.new(@username, @password)
|
129
|
-
# # Add template
|
130
|
-
# new_template = templates.post("new_template")
|
131
|
-
# # Delete template
|
132
|
-
# templates.delete(new_template.id)
|
133
|
-
# assert_raise(RestClient::ResourceNotFound) {
|
134
|
-
# templates.get(new_template.id)
|
135
|
-
# }
|
136
|
-
# end
|
34
|
+
def test_get_template_id_nil
|
35
|
+
templates = SendgridTemplateEngine::Templates.new(@username, @password)
|
36
|
+
assert_raise(ArgumentError) {
|
37
|
+
templates.get(nil)
|
38
|
+
}
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_get_template_id_not_exist
|
42
|
+
templates = SendgridTemplateEngine::Templates.new(@username, @password)
|
43
|
+
assert_raise(RestClient::ResourceNotFound) {
|
44
|
+
templates.get("not_exist")
|
45
|
+
}
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_post_name_nil
|
49
|
+
templates = SendgridTemplateEngine::Templates.new(@username, @password)
|
50
|
+
assert_raise(ArgumentError) {
|
51
|
+
templates.post(nil)
|
52
|
+
}
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_post_bad_request
|
56
|
+
templates = SendgridTemplateEngine::Templates.new(@username, @password)
|
57
|
+
expect = ""
|
58
|
+
assert_raise(RestClient::BadRequest) {
|
59
|
+
templates.post(expect)
|
60
|
+
}
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_patch_id_nil
|
64
|
+
templates = SendgridTemplateEngine::Templates.new(@username, @password)
|
65
|
+
new_name = "new_name"
|
66
|
+
assert_raise(ArgumentError) {
|
67
|
+
templates.patch(nil, new_name)
|
68
|
+
}
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_patch_name_nil
|
72
|
+
templates = SendgridTemplateEngine::Templates.new(@username, @password)
|
73
|
+
id = "some_id"
|
74
|
+
assert_raise(ArgumentError) {
|
75
|
+
templates.patch(id, nil)
|
76
|
+
}
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_delete_id_nil
|
80
|
+
templates = SendgridTemplateEngine::Templates.new(@username, @password)
|
81
|
+
assert_raise(ArgumentError) {
|
82
|
+
templates.delete(nil)
|
83
|
+
}
|
84
|
+
end
|
85
|
+
|
86
|
+
def test_delete_not_exist
|
87
|
+
templates = SendgridTemplateEngine::Templates.new(@username, @password)
|
88
|
+
assert_raise(RestClient::ResourceNotFound) {
|
89
|
+
templates.delete("not_exist")
|
90
|
+
}
|
91
|
+
end
|
92
|
+
|
93
|
+
def test_template
|
94
|
+
templates = SendgridTemplateEngine::Templates.new(@username, @password)
|
95
|
+
# celan up test env
|
96
|
+
resp_temps = templates.get_all()
|
97
|
+
assert_equal(true, resp_temps.length >= 0)
|
98
|
+
resp_temps.each{|temp|
|
99
|
+
if temp.name == @template_name then
|
100
|
+
templates.delete(temp.id)
|
101
|
+
end
|
102
|
+
}
|
103
|
+
# post a template
|
104
|
+
new_template = templates.post(@template_name)
|
105
|
+
assert_equal(@template_name, new_template.name)
|
106
|
+
# pach the template
|
107
|
+
templates.patch(new_template.id, "edit_template")
|
108
|
+
# get the template
|
109
|
+
edit_template = templates.get(new_template.id)
|
110
|
+
assert_equal(new_template.id, edit_template.id)
|
111
|
+
assert_equal("edit_template", edit_template.name)
|
112
|
+
assert_equal(new_template.versions, edit_template.versions)
|
113
|
+
# delete the template
|
114
|
+
templates.delete(edit_template.id)
|
115
|
+
assert_raise(RestClient::ResourceNotFound) {
|
116
|
+
templates.get(edit_template.id)
|
117
|
+
}
|
118
|
+
end
|
137
119
|
|
138
120
|
end
|
data/test/versions_test.rb
CHANGED
@@ -7,9 +7,11 @@ require "./lib/sendgrid_template_engine/version"
|
|
7
7
|
class VersionsTest < Test::Unit::TestCase
|
8
8
|
|
9
9
|
def setup
|
10
|
-
|
10
|
+
Dotenv.load
|
11
11
|
@username = ENV["SENDGRID_USERNAME"]
|
12
12
|
@password = ENV["SENDGRID_PASSWORD"]
|
13
|
+
@template_name = "version_test"
|
14
|
+
@version_name= "version_test"
|
13
15
|
end
|
14
16
|
|
15
17
|
def test_initialize
|
@@ -19,159 +21,189 @@ class VersionsTest < Test::Unit::TestCase
|
|
19
21
|
|
20
22
|
def test_bad_username
|
21
23
|
assert_raise(ArgumentError) {
|
22
|
-
|
24
|
+
SendgridTemplateEngine::Versions.new(nil, nil)
|
23
25
|
}
|
24
26
|
end
|
25
27
|
|
26
28
|
def test_invalid_auth
|
27
29
|
versions = SendgridTemplateEngine::Versions.new("user", "pass")
|
28
30
|
assert_raise(RestClient::Unauthorized) {
|
29
|
-
|
31
|
+
versions.get("template_id", "version_id")
|
30
32
|
}
|
31
33
|
end
|
32
34
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
# # Delete version
|
93
|
-
# versions.delete(actual.template_id, actual.id)
|
94
|
-
# assert_raise(RestClient::ResourceNotFound) {
|
95
|
-
# versions.get(new_template.id, new_version.id)
|
96
|
-
# }
|
97
|
-
# # Delete template
|
98
|
-
# templates.delete(actual.template_id)
|
99
|
-
# rescue => ex
|
100
|
-
# puts ex.inspect
|
101
|
-
# end
|
102
|
-
# end
|
103
|
-
|
104
|
-
def test_post_activate
|
35
|
+
def test_get_template_id_nil
|
36
|
+
versions = SendgridTemplateEngine::Versions.new(@username, @password)
|
37
|
+
assert_raise(ArgumentError) {
|
38
|
+
versions.get(nil, "version_id")
|
39
|
+
}
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_get_version_id_nil
|
43
|
+
versions = SendgridTemplateEngine::Versions.new(@username, @password)
|
44
|
+
assert_raise(ArgumentError) {
|
45
|
+
versions.get("template_id", nil)
|
46
|
+
}
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_get_not_exist
|
50
|
+
versions = SendgridTemplateEngine::Versions.new(@username, @password)
|
51
|
+
assert_raise(RestClient::ResourceNotFound) {
|
52
|
+
versions.get("not_exist", "not_exist")
|
53
|
+
}
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_post_name_nil
|
57
|
+
templates = SendgridTemplateEngine::Templates.new(@username, @password)
|
58
|
+
assert_raise(ArgumentError) {
|
59
|
+
templates.post(nil)
|
60
|
+
}
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_post_bad_request
|
64
|
+
templates = SendgridTemplateEngine::Templates.new(@username, @password)
|
65
|
+
expect = ""
|
66
|
+
assert_raise(RestClient::BadRequest) {
|
67
|
+
templates.post(expect)
|
68
|
+
}
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_patch_name_nil
|
72
|
+
templates = SendgridTemplateEngine::Templates.new(@username, @password)
|
73
|
+
id = "some_id"
|
74
|
+
assert_raise(ArgumentError) {
|
75
|
+
templates.patch(id, nil)
|
76
|
+
}
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_delete_id_nil
|
80
|
+
templates = SendgridTemplateEngine::Templates.new(@username, @password)
|
81
|
+
assert_raise(ArgumentError) {
|
82
|
+
templates.delete(nil)
|
83
|
+
}
|
84
|
+
end
|
85
|
+
|
86
|
+
def test_delete_not_exist
|
87
|
+
templates = SendgridTemplateEngine::Templates.new(@username, @password)
|
88
|
+
assert_raise(RestClient::ResourceNotFound) {
|
89
|
+
templates.delete("not_exist")
|
90
|
+
}
|
91
|
+
end
|
92
|
+
|
93
|
+
def test_version
|
105
94
|
begin
|
106
95
|
templates = SendgridTemplateEngine::Templates.new(@username, @password)
|
107
|
-
# Add template
|
108
|
-
new_template = templates.post("new_template")
|
109
|
-
# Add version
|
110
|
-
new_version = SendgridTemplateEngine::Version.new()
|
111
|
-
new_version.set_name("new_version")
|
112
|
-
new_version.set_subject("<%subject%>")
|
113
|
-
new_version.set_html_content("<%body%>")
|
114
|
-
new_version.set_plain_content("<%body%>")
|
115
|
-
new_version.set_active(0)
|
116
96
|
versions = SendgridTemplateEngine::Versions.new(@username, @password)
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
97
|
+
# celan up test env
|
98
|
+
resp_temps = templates.get_all()
|
99
|
+
resp_temps.each{|temp|
|
100
|
+
if temp.name == @template_name then
|
101
|
+
temp.versions.each{|ver|
|
102
|
+
versions.delete(temp.id, ver.id)
|
103
|
+
}
|
104
|
+
templates.delete(temp.id)
|
105
|
+
end
|
106
|
+
}
|
107
|
+
# post a template
|
108
|
+
new_template = templates.post(@template_name)
|
109
|
+
assert_equal(@template_name, new_template.name)
|
110
|
+
# post a version
|
111
|
+
version_1 = SendgridTemplateEngine::Version.new()
|
112
|
+
version_1.set_name(@version_name)
|
113
|
+
version_1.set_subject("<%subject%>")
|
114
|
+
version_1.set_html_content("<%body%>")
|
115
|
+
version_1.set_plain_content("<%body%>")
|
116
|
+
version_1.set_active(1)
|
117
|
+
version_1 = versions.post(new_template.id, version_1)
|
118
|
+
# get the version
|
119
|
+
actual = versions.get(new_template.id, version_1.id)
|
120
|
+
assert_equal(version_1.template_id, actual.template_id)
|
121
|
+
assert_equal(version_1.active, actual.active)
|
122
|
+
assert_equal(version_1.name, actual.name)
|
123
|
+
assert_equal(version_1.html_content, actual.html_content)
|
124
|
+
assert_equal(version_1.plain_content, actual.plain_content)
|
125
|
+
assert_equal(version_1.subject, actual.subject)
|
126
|
+
# edit the version
|
127
|
+
edit_version = SendgridTemplateEngine::Version.new()
|
128
|
+
edit_version.set_name("edit_version")
|
129
|
+
edit_version.set_subject("edit<%subject%>edit")
|
130
|
+
edit_version.set_html_content("edit<%body%>edit")
|
131
|
+
edit_version.set_plain_content("edit<%body%>edit")
|
132
|
+
edit_version.set_active(0)
|
133
|
+
versions.patch(new_template.id, version_1.id, edit_version)
|
134
|
+
# get the version
|
135
|
+
actual = versions.get(new_template.id, version_1.id)
|
136
|
+
assert_equal(new_template.id, actual.template_id)
|
137
|
+
assert_equal(edit_version.active, actual.active)
|
138
|
+
assert_equal(edit_version.name, actual.name)
|
139
|
+
assert_equal(edit_version.html_content, actual.html_content)
|
140
|
+
assert_equal(edit_version.plain_content, actual.plain_content)
|
141
|
+
assert_equal(edit_version.subject, actual.subject)
|
142
|
+
# post a version 2
|
143
|
+
version_2 = SendgridTemplateEngine::Version.new()
|
144
|
+
version_2.set_name("#{@version_name}-2")
|
145
|
+
version_2.set_subject("<%subject%>")
|
146
|
+
version_2.set_html_content("<%body%>")
|
147
|
+
version_2.set_plain_content("<%body%>")
|
148
|
+
version_2 = versions.post(new_template.id, version_2)
|
149
|
+
# activate version 2
|
150
|
+
versions.post_activate(new_template.id, version_2.id)
|
151
|
+
actual_version_1 = versions.get(new_template.id, version_1.id)
|
152
|
+
actual_version_2 = versions.get(new_template.id, version_2.id)
|
153
|
+
assert_equal(0, actual_version_1.active)
|
154
|
+
assert_equal(1, actual_version_2.active)
|
155
|
+
# delete the version
|
156
|
+
versions.delete(new_template.id, actual_version_1.id)
|
157
|
+
versions.delete(new_template.id, actual_version_2.id)
|
158
|
+
assert_raise(RestClient::ResourceNotFound) {
|
159
|
+
versions.get(new_template.id, actual_version_1.id)
|
160
|
+
}
|
161
|
+
assert_raise(RestClient::ResourceNotFound) {
|
162
|
+
versions.get(new_template.id, actual_version_2.id)
|
163
|
+
}
|
164
|
+
# delete the template
|
165
|
+
templates.delete(new_template.id)
|
130
166
|
rescue => ex
|
131
167
|
puts ex.inspect
|
132
168
|
end
|
133
169
|
end
|
134
170
|
|
171
|
+
# def test_post_activate
|
172
|
+
# begin
|
173
|
+
# templates = SendgridTemplateEngine::Templates.new(@username, @password)
|
174
|
+
# # Add template
|
175
|
+
# new_template = templates.post("new_template")
|
176
|
+
# # Add version
|
177
|
+
# new_version = SendgridTemplateEngine::Version.new()
|
178
|
+
# new_version.set_name("new_version")
|
179
|
+
# new_version.set_subject("<%subject%>")
|
180
|
+
# new_version.set_html_content("<%body%>")
|
181
|
+
# new_version.set_plain_content("<%body%>")
|
182
|
+
# new_version.set_active(0)
|
183
|
+
# versions = SendgridTemplateEngine::Versions.new(@username, @password)
|
184
|
+
# new_version = versions.post(new_template.id, new_version)
|
185
|
+
# # Get version
|
186
|
+
# actual = versions.get(new_template.id, new_version.id)
|
187
|
+
# assert_equal(new_version.active, actual.active)
|
188
|
+
# # Activate version
|
189
|
+
# versions.post_activate(new_template.id, new_version.id)
|
190
|
+
# # Get version
|
191
|
+
# actual = versions.get(new_template.id, new_version.id)
|
192
|
+
# assert_equal(1, actual.active)
|
193
|
+
# # Delete version
|
194
|
+
# versions.delete(actual.template_id, actual.id)
|
195
|
+
# # Delete template
|
196
|
+
# templates.delete(actual.template_id)
|
197
|
+
# rescue => ex
|
198
|
+
# puts ex.inspect
|
199
|
+
# end
|
200
|
+
# end
|
201
|
+
|
202
|
+
|
203
|
+
|
135
204
|
|
136
205
|
|
137
206
|
|
138
207
|
|
139
|
-
#
|
140
|
-
# def test_post_name_nil
|
141
|
-
# templates = SendgridTemplateEngine::Templates.new(@username, @password)
|
142
|
-
# assert_raise(ArgumentError) {
|
143
|
-
# resp = templates.post(nil)
|
144
|
-
# }
|
145
|
-
# end
|
146
|
-
#
|
147
|
-
# def test_post_bad_request
|
148
|
-
# templates = SendgridTemplateEngine::Templates.new(@username, @password)
|
149
|
-
# expect = ""
|
150
|
-
# assert_raise(RestClient::BadRequest) {
|
151
|
-
# resp = templates.post(expect)
|
152
|
-
# }
|
153
|
-
# end
|
154
|
-
#
|
155
|
-
# def test_patch_name_nil
|
156
|
-
# templates = SendgridTemplateEngine::Templates.new(@username, @password)
|
157
|
-
# id = "some_id"
|
158
|
-
# assert_raise(ArgumentError) {
|
159
|
-
# actual = templates.patch(id, nil)
|
160
|
-
# }
|
161
|
-
# end
|
162
|
-
#
|
163
|
-
# def test_delete_id_nil
|
164
|
-
# templates = SendgridTemplateEngine::Templates.new(@username, @password)
|
165
|
-
# assert_raise(ArgumentError) {
|
166
|
-
# templates.delete(nil)
|
167
|
-
# }
|
168
|
-
# end
|
169
|
-
#
|
170
|
-
# def test_delete_not_exist
|
171
|
-
# templates = SendgridTemplateEngine::Templates.new(@username, @password)
|
172
|
-
# assert_raise(RestClient::ResourceNotFound) {
|
173
|
-
# templates.delete("not_exist")
|
174
|
-
# }
|
175
|
-
# end
|
176
208
|
|
177
209
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sendgrid_template_engine
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- awwa500@gmail.com
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-09-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|