Class: SendgridTemplateEngine::Templates
Instance Method Summary
collapse
Methods inherited from Resources
#initialize
Instance Method Details
#delete(template_id) ⇒ Object
52
53
54
55
56
|
# File 'lib/templates.rb', line 52
def delete(template_id)
raise ArgumentError.new("template_id should not be nil") if template_id == nil
endpoint = "#{@url_base}/templates/#{template_id}"
RestClient.delete(endpoint)
end
|
#get(template_id) ⇒ Object
26
27
28
29
30
31
|
# File 'lib/templates.rb', line 26
def get(template_id)
raise ArgumentError.new("template_id should not be nil") if template_id == nil
endpoint = "#{@url_base}/templates/#{template_id}"
body = RestClient.get(endpoint).body
Template.create(JSON.parse(body))
end
|
#get_all ⇒ Object
14
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/templates.rb', line 14
def get_all
endpoint = "#{@url_base}/templates"
body = RestClient.get(endpoint).body
response = JSON.parse(body)
temps = []
response["templates"].each{|template|
temp = Template.create(template)
temps.push(temp)
} if response["templates"] != nil
temps
end
|
#patch(template_id, name) ⇒ Object
42
43
44
45
46
47
48
49
50
|
# File 'lib/templates.rb', line 42
def patch(template_id, name)
raise ArgumentError.new("template_id should not be nil") if template_id == nil
raise ArgumentError.new("name should not be nil") if name == nil
endpoint = "#{@url_base}/templates/#{template_id}"
params = Hash.new
params["name"] = name
body = RestClient.patch(endpoint, params.to_json, :content_type => :json).body
Template.create(JSON.parse(body))
end
|
#post(name) ⇒ Object
33
34
35
36
37
38
39
40
|
# File 'lib/templates.rb', line 33
def post(name)
raise ArgumentError.new("name should not be nil") if name == nil
endpoint = "#{@url_base}/templates"
params = Hash.new
params["name"] = name
body = RestClient.post(endpoint, params.to_json, :content_type => :json).body
Template.create(JSON.parse(body))
end
|