sendgrid_template_engine 0.0.1 → 0.0.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3e7d6e78791493a76386165219f8877d6989f162
4
- data.tar.gz: d2a98bee7dc2d73969aaf4e6d22fa5a8babdfce8
3
+ metadata.gz: 949d6eb203bec2e5ccc36831323ed8ef94fd1df7
4
+ data.tar.gz: ae8f61d89ce4702632b300c0d0fd1ab7455188d4
5
5
  SHA512:
6
- metadata.gz: c4633934f1eb5a274ab33f7f1a93c039fedf975743f78842cf9b9cfa052a936b1308549d385d11329d397cbef67a7d6ced281ab06daf85be9ce46f16a4d7ffaf
7
- data.tar.gz: 26006969a24dcc7fe5c06fd8dff93277adc666ca8bffacfe1a1e7d80df941aa57ddeb07cf069335baeec3fe75bef0ede6b7f7dea06e3a1da8b6f24772de49e52
6
+ metadata.gz: 0cc70a568f834267d47bc72084bca57f9318247805dc2d1c1892ddf65ea518fcc401eeec5b2f4f8cca6cd15690be4bef8e73ea047c58cdb64a52868f25000835
7
+ data.tar.gz: 5549eed7705dd1ffd157b8e7d8e248abb25de6ed9bc49b8b42b08a115e2970ebc59df4f61d5dd341b0239d162d524b38a4aeb8a56bdda90a0d80a52de1c24268
@@ -1,6 +1,5 @@
1
1
  language: ruby
2
2
  rvm:
3
- - "1.9.2"
4
3
  - "1.9.3"
5
4
  - "2.0.0"
6
5
  - "2.1.0"
@@ -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
- @url_base = "https://#{username}:#{password}@api.sendgrid.com/v3"
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
@@ -1,3 +1,3 @@
1
1
  module SendgridTemplateEngine
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -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
- body = RestClient.get(endpoint).body
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
- body = RestClient.get(endpoint).body
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 = RestClient.post(endpoint, params.to_json, :content_type => :json).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 = RestClient.patch(endpoint, params.to_json, :content_type => :json).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.delete(endpoint)
58
+ resource = RestClient::Resource.new(endpoint, @username, @password)
59
+ resource.delete
56
60
  end
57
61
 
58
62
  end
@@ -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
- body = RestClient.get(endpoint).body
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
- body = RestClient.post(endpoint, version.to_hash.to_json, :content_type => :json).body
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
- body = RestClient.post(endpoint, :content_type => :json).body
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
- body = RestClient.patch(endpoint, version.to_hash.to_json, :content_type => :json).body
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.delete(endpoint)
54
+ resource = RestClient::Resource.new(endpoint, @username, @password)
55
+ resource.delete
51
56
  end
52
57
 
53
58
  end
@@ -8,7 +8,7 @@ require "./lib/sendgrid_template_engine/version"
8
8
  class SendgridTemplateEngineTest < Test::Unit::TestCase
9
9
 
10
10
  def test_version
11
- assert_equal("0.0.1", SendgridTemplateEngine::VERSION)
11
+ assert_equal("0.0.2", SendgridTemplateEngine::VERSION)
12
12
  end
13
13
 
14
14
  end
@@ -7,9 +7,10 @@ require "./lib/sendgrid_template_engine/version"
7
7
  class TemplatesTest < Test::Unit::TestCase
8
8
 
9
9
  def setup
10
- config = Dotenv.load
11
- @username = ENV["SENDGRID_USERNAME"]
12
- @password = ENV["SENDGRID_PASSWORD"]
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
- templates = SendgridTemplateEngine::Templates.new(nil, nil)
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
- response = templates.get_all()
30
+ templates.get_all()
30
31
  }
31
32
  end
32
33
 
33
- # def test_get_all
34
- # templates = SendgridTemplateEngine::Templates.new(@username, @password)
35
- # resp_temps = templates.get_all()
36
- # assert_equal(true, resp_temps.length >= 0)
37
- # end
38
- #
39
- # def test_get_template_id_nil
40
- # templates = SendgridTemplateEngine::Templates.new(@username, @password)
41
- # assert_raise(ArgumentError) {
42
- # response = templates.get(nil)
43
- # }
44
- # end
45
- #
46
- # def test_get_template_id_not_exist
47
- # templates = SendgridTemplateEngine::Templates.new(@username, @password)
48
- # assert_raise(RestClient::ResourceNotFound) {
49
- # response = templates.get("not_exist")
50
- # }
51
- # end
52
- #
53
- # def test_get_template_id_exist
54
- # templates = SendgridTemplateEngine::Templates.new(@username, @password)
55
- # # Add template
56
- # new_template = templates.post("new_template")
57
- # # Get template
58
- # actual = templates.get(new_template.id)
59
- # assert_equal(new_template.id, actual.id)
60
- # assert_equal(new_template.name, actual.name)
61
- # assert_equal(new_template.versions, actual.versions)
62
- # # Delete template
63
- # templates.delete(actual.id)
64
- # end
65
- #
66
- # def test_post_name_nil
67
- # templates = SendgridTemplateEngine::Templates.new(@username, @password)
68
- # assert_raise(ArgumentError) {
69
- # resp = templates.post(nil)
70
- # }
71
- # end
72
- #
73
- # def test_post_bad_request
74
- # templates = SendgridTemplateEngine::Templates.new(@username, @password)
75
- # expect = ""
76
- # assert_raise(RestClient::BadRequest) {
77
- # resp = templates.post(expect)
78
- # }
79
- # end
80
- #
81
- # def test_patch_id_nil
82
- # templates = SendgridTemplateEngine::Templates.new(@username, @password)
83
- # new_name = "new_name"
84
- # assert_raise(ArgumentError) {
85
- # actual = templates.patch(nil, new_name)
86
- # }
87
- # end
88
- #
89
- # def test_patch_name_nil
90
- # templates = SendgridTemplateEngine::Templates.new(@username, @password)
91
- # id = "some_id"
92
- # assert_raise(ArgumentError) {
93
- # actual = templates.patch(id, nil)
94
- # }
95
- # end
96
- #
97
- # def test_patch
98
- # templates = SendgridTemplateEngine::Templates.new(@username, @password)
99
- # # Add template
100
- # new_template = templates.post("new_template")
101
- # # Edit template
102
- # templates.patch(new_template.id, "edit_template")
103
- # # Get template
104
- # actual = templates.get(new_template.id)
105
- # assert_equal(new_template.id, actual.id)
106
- # assert_equal("edit_template", actual.name)
107
- # assert_equal(new_template.versions, actual.versions)
108
- # # Delete template
109
- # templates.delete(actual.id)
110
- # end
111
- #
112
- # def test_delete_id_nil
113
- # templates = SendgridTemplateEngine::Templates.new(@username, @password)
114
- # assert_raise(ArgumentError) {
115
- # templates.delete(nil)
116
- # }
117
- # end
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
@@ -7,9 +7,11 @@ require "./lib/sendgrid_template_engine/version"
7
7
  class VersionsTest < Test::Unit::TestCase
8
8
 
9
9
  def setup
10
- config = Dotenv.load
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
- versions = SendgridTemplateEngine::Versions.new(nil, nil)
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
- response = versions.get("template_id", "version_id")
31
+ versions.get("template_id", "version_id")
30
32
  }
31
33
  end
32
34
 
33
- # def test_get_template_id_nil
34
- # versions = SendgridTemplateEngine::Versions.new(@username, @password)
35
- # assert_raise(ArgumentError) {
36
- # response = versions.get(nil, "version_id")
37
- # }
38
- # end
39
- #
40
- # def test_get_version_id_nil
41
- # versions = SendgridTemplateEngine::Versions.new(@username, @password)
42
- # assert_raise(ArgumentError) {
43
- # response = versions.get("template_id", nil)
44
- # }
45
- # end
46
- #
47
- # def test_get_not_exist
48
- # versions = SendgridTemplateEngine::Versions.new(@username, @password)
49
- # assert_raise(RestClient::ResourceNotFound) {
50
- # response = versions.get("not_exist", "not_exist")
51
- # }
52
- # end
53
- #
54
- # def test_get
55
- # begin
56
- # templates = SendgridTemplateEngine::Templates.new(@username, @password)
57
- # # Add template
58
- # new_template = templates.post("new_template")
59
- # # Add version
60
- # new_version = SendgridTemplateEngine::Version.new()
61
- # new_version.set_name("new_version")
62
- # new_version.set_subject("<%subject%>")
63
- # new_version.set_html_content("<%body%>")
64
- # new_version.set_plain_content("<%body%>")
65
- # new_version.set_active(1)
66
- # versions = SendgridTemplateEngine::Versions.new(@username, @password)
67
- # new_version = versions.post(new_template.id, new_version)
68
- # # Get version
69
- # actual = versions.get(new_template.id, new_version.id)
70
- # assert_equal(new_version.template_id, actual.template_id)
71
- # assert_equal(new_version.active, actual.active)
72
- # assert_equal(new_version.name, actual.name)
73
- # assert_equal(new_version.html_content, actual.html_content)
74
- # assert_equal(new_version.plain_content, actual.plain_content)
75
- # assert_equal(new_version.subject, actual.subject)
76
- # # Edit version
77
- # edit_version = SendgridTemplateEngine::Version.new()
78
- # edit_version.set_name("edit_version")
79
- # edit_version.set_subject("edit<%subject%>edit")
80
- # edit_version.set_html_content("edit<%body%>edit")
81
- # edit_version.set_plain_content("edit<%body%>edit")
82
- # edit_version.set_active(0)
83
- # versions.patch(new_template.id, new_version.id, edit_version)
84
- # # Get version
85
- # actual = versions.get(new_template.id, new_version.id)
86
- # assert_equal(new_template.id, actual.template_id)
87
- # assert_equal(edit_version.active, actual.active)
88
- # assert_equal(edit_version.name, actual.name)
89
- # assert_equal(edit_version.html_content, actual.html_content)
90
- # assert_equal(edit_version.plain_content, actual.plain_content)
91
- # assert_equal(edit_version.subject, actual.subject)
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
- new_version = versions.post(new_template.id, new_version)
118
- # Get version
119
- actual = versions.get(new_template.id, new_version.id)
120
- assert_equal(new_version.active, actual.active)
121
- # Activate version
122
- versions.post_activate(new_template.id, new_version.id)
123
- # Get version
124
- actual = versions.get(new_template.id, new_version.id)
125
- assert_equal(1, actual.active)
126
- # Delete version
127
- versions.delete(actual.template_id, actual.id)
128
- # Delete template
129
- templates.delete(actual.template_id)
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.1
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-07-14 00:00:00.000000000 Z
11
+ date: 2014-09-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client