Class: Passtools::Template

Inherits:
Object
  • Object
show all
Extended by:
Request
Defined in:
lib/passtools/template.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Request

construct_url, delete_request, download_file, get, headers, post, put

Constructor Details

#initialize(raw_data) ⇒ Template

Returns a new instance of Template.



29
30
31
# File 'lib/passtools/template.rb', line 29

def initialize(raw_data)
  @raw_data = raw_data
end

Instance Attribute Details

#raw_dataObject

Returns the value of attribute raw_data.



4
5
6
# File 'lib/passtools/template.rb', line 4

def raw_data
  @raw_data
end

Class Method Details

.build_from_current(template_id) ⇒ Object



18
19
20
21
22
23
24
25
26
27
# File 'lib/passtools/template.rb', line 18

def self.build_from_current(template_id)
  begin
    response = show(template_id)
    new(response)
  rescue RestClient::Exception => e
    data = MultiJson.load(e.response)
    data['message'] = e.message
    new(data)
  end
end

.delete(template_id) ⇒ Object



14
15
16
# File 'lib/passtools/template.rb', line 14

def self.delete(template_id)
  delete_request("/template/#{template_id}")
end

.list(params = {}) ⇒ Object



6
7
8
# File 'lib/passtools/template.rb', line 6

def self.list(params={})
  get("/template/headers", params)
end

.show(template_id) ⇒ Object



10
11
12
# File 'lib/passtools/template.rb', line 10

def self.show(template_id)
  get("/template/#{template_id}")
end

Instance Method Details

#deleteObject



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

def delete
  return false unless self.id
  response = self.class.delete_pass(id)
  self.raw_data['id'] = nil if response['Status'] == 'Deleted'
  response
end

#field_namesObject

return array of field names



38
39
40
# File 'lib/passtools/template.rb', line 38

def field_names
  fetch_from_raw('fieldsModel').keys
end

#fieldsObject

return hash required for creating a Pass based on this template



43
44
45
# File 'lib/passtools/template.rb', line 43

def fields
  fetch_from_raw('fieldsModel')
end

#idObject



33
34
35
# File 'lib/passtools/template.rb', line 33

def id
  fetch_from_raw('templateHeader','id')
end

#valid?Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/passtools/template.rb', line 54

def valid?
  @raw_data.has_key?('fieldsModel')
end