Class: Pdm::Template

Inherits:
Resource show all
Defined in:
lib/pdm/template.rb

Instance Attribute Summary collapse

Attributes inherited from Resource

#options

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Resource

#api_request, #check_opts, #with_exceptions

Constructor Details

#initialize(name, description = nil, html = nil, options = {}) ⇒ Template

Returns a new instance of Template.



17
18
19
20
21
22
# File 'lib/pdm/template.rb', line 17

def initialize(name, description = nil, html = nil, options = {})
  self.name = name
  self.description = description
  self.html = html
  super(options)
end

Instance Attribute Details

#descriptionObject

Returns the value of attribute description.



15
16
17
# File 'lib/pdm/template.rb', line 15

def description
  @description
end

#htmlObject

Returns the value of attribute html.



15
16
17
# File 'lib/pdm/template.rb', line 15

def html
  @html
end

#nameObject

Returns the value of attribute name.



15
16
17
# File 'lib/pdm/template.rb', line 15

def name
  @name
end

Class Method Details

.exists?(name) ⇒ Boolean

Returns:

  • (Boolean)


9
10
11
# File 'lib/pdm/template.rb', line 9

def exists?(name)
  Template.new(name).exists?
end

Instance Method Details

#createObject



54
55
56
57
58
59
# File 'lib/pdm/template.rb', line 54

def create
  params = create_params
  with_exceptions do
    api_request.multipart_post(:templates, params)
  end
end

#create_paramsObject Also known as: update_params



46
47
48
49
50
51
52
# File 'lib/pdm/template.rb', line 46

def create_params
  {
    "template[name]" => self.name,
    "template[description]" => self.description,
    "template[html]" => self.html,
  }
end

#exists?Boolean

Returns:

  • (Boolean)


38
39
40
41
42
43
44
# File 'lib/pdm/template.rb', line 38

def exists?
  params = show_params
  res = with_exceptions do
    api_request.get(:templates, params)
  end
  res.is_a?(Net::HTTPSuccess)
end

#showObject



31
32
33
34
35
36
# File 'lib/pdm/template.rb', line 31

def show
  params = show_params
  with_exceptions do
    api_request.get(:templates, params)
  end
end

#show_paramsObject



25
26
27
28
29
# File 'lib/pdm/template.rb', line 25

def show_params
  {
    "template[name]" => self.name,
  }
end

#updateObject



65
66
67
68
69
70
# File 'lib/pdm/template.rb', line 65

def update
  params = update_params
  with_exceptions do
    api_request.multipart_put(:templates, params)
  end
end