Class: Paubox::DynamicTemplates

Inherits:
Object
  • Object
show all
Defined in:
lib/paubox/dynamic_templates.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ DynamicTemplates

Returns a new instance of DynamicTemplates.



8
9
10
11
12
13
# File 'lib/paubox/dynamic_templates.rb', line 8

def initialize(args = {})
  @id = args['id']
  @name = args['name']
  @api_customer_id = args['api_customer_id']
  @body = args['body']
end

Instance Attribute Details

#api_customer_idObject

Returns the value of attribute api_customer_id.



6
7
8
# File 'lib/paubox/dynamic_templates.rb', line 6

def api_customer_id
  @api_customer_id
end

#bodyObject

Returns the value of attribute body.



6
7
8
# File 'lib/paubox/dynamic_templates.rb', line 6

def body
  @body
end

#idObject

Returns the value of attribute id.



6
7
8
# File 'lib/paubox/dynamic_templates.rb', line 6

def id
  @id
end

#nameObject

Returns the value of attribute name.



6
7
8
# File 'lib/paubox/dynamic_templates.rb', line 6

def name
  @name
end

Class Method Details

.create(template_name, template_file_path) ⇒ Object



33
34
35
36
37
38
39
40
41
42
# File 'lib/paubox/dynamic_templates.rb', line 33

def create(template_name, template_file_path)
  path = "dynamic_templates"
  payload = {
    data: {
      name: template_name,
      body: File.new(template_file_path) 
    }
  }
  Paubox::Client.new.send_request(method: :post, payload: payload, path: path)
end

.find(template_id) ⇒ Object



44
45
46
47
48
49
# File 'lib/paubox/dynamic_templates.rb', line 44

def find(template_id)
  path = "dynamic_templates/#{template_id.to_s}"
  response = Paubox::Client.new.send_request(method: :get, path: path)
  data = JSON.parse(response.body)
  Paubox::DynamicTemplates.new(data)
end

.listObject



51
52
53
54
55
# File 'lib/paubox/dynamic_templates.rb', line 51

def list
  path = "dynamic_templates"
  response = Paubox::Client.new.send_request(method: :get, path: path)
  JSON.parse(response.body)
end

Instance Method Details

#deleteObject



27
28
29
30
# File 'lib/paubox/dynamic_templates.rb', line 27

def delete
  path = "dynamic_templates/#{id}"
  Paubox::Client.new.send_request(method: :delete, path: path)
end

#update(template_file_path, template_name = nil) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/paubox/dynamic_templates.rb', line 15

def update(template_file_path, template_name = nil)
  path = "dynamic_templates/#{id}"
  payload = {
    data: {
      name: template_name,
      body: File.new(template_file_path) 
    }
    }

  Paubox::Client.new.send_request(method: :patch, payload: payload, path: path)
end