Class: REIformslive::Form

Inherits:
Object
  • Object
show all
Defined in:
lib/reiformslive/form.rb

Constant Summary collapse

PATH =
'/forms'.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data: {}) ⇒ Form

Returns a new instance of Form.



7
8
9
# File 'lib/reiformslive/form.rb', line 7

def initialize data: {}
  @data = data
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



5
6
7
# File 'lib/reiformslive/form.rb', line 5

def data
  @data
end

Class Method Details

.all(path: PATH) ⇒ Object



91
92
93
94
95
96
# File 'lib/reiformslive/form.rb', line 91

def self.all path: PATH
  REIformslive::Session
    .get(path: path)
    .parse_json
    .map{|data| self.new data: data }
end

.find(id, path: "#{PATH}/#{id}") ⇒ Object



98
99
100
101
102
103
# File 'lib/reiformslive/form.rb', line 98

def self.find id, path: "#{PATH}/#{id}"
  self.new data:
    REIformslive::Session
      .get(path: path)
      .parse_json
end

Instance Method Details

#agency_idObject



19
20
21
# File 'lib/reiformslive/form.rb', line 19

def agency_id
  data['agency_id'].to_i
end

#created_atObject



43
44
45
# File 'lib/reiformslive/form.rb', line 43

def created_at
  Time.at data['created'].to_i
end

#finalised?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/reiformslive/form.rb', line 35

def finalised?
  data['finalised'].to_s == 'true'
end

#full_nameObject



59
60
61
# File 'lib/reiformslive/form.rb', line 59

def full_name
  "#{given_name} #{surname}"
end

#given_nameObject



51
52
53
# File 'lib/reiformslive/form.rb', line 51

def given_name
  data['given_name']
end

#idObject



11
12
13
# File 'lib/reiformslive/form.rb', line 11

def id
  data['id'].to_i
end

#nameObject



27
28
29
# File 'lib/reiformslive/form.rb', line 27

def name
  data['name']
end

#private?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/reiformslive/form.rb', line 39

def private?
  data['private'].to_s == 'true'
end

#surnameObject



55
56
57
# File 'lib/reiformslive/form.rb', line 55

def surname
  data['surname']
end

#template?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/reiformslive/form.rb', line 31

def template?
  data['template'].to_s == 'true'
end

#template_codeObject



75
76
77
# File 'lib/reiformslive/form.rb', line 75

def template_code
  data['template_code']
end

#template_costObject



63
64
65
# File 'lib/reiformslive/form.rb', line 63

def template_cost
  data['template_cost'].to_i
end

#template_idObject



67
68
69
# File 'lib/reiformslive/form.rb', line 67

def template_id
  data['template_id'].to_i
end

#template_instruction_pagesObject



79
80
81
# File 'lib/reiformslive/form.rb', line 79

def template_instruction_pages
  data['template_instruction_pages'].to_i
end

#template_nameObject



71
72
73
# File 'lib/reiformslive/form.rb', line 71

def template_name
  data['template_name']
end

#template_version_idObject



15
16
17
# File 'lib/reiformslive/form.rb', line 15

def template_version_id
  data['template_version_id'].to_i
end

#update(data = {}, path: "#{PATH}/#{id}/save") ⇒ Object



83
84
85
86
87
88
89
# File 'lib/reiformslive/form.rb', line 83

def update data={}, path: "#{PATH}/#{id}/save"
  REIformslive::Session
    .put(path: path, data: data)
    .parse_json['message']
    .send(:==, 'The form has been saved.')
    .tap{|ok| @data = self.class.find(id).data if ok }
end

#updated_atObject



47
48
49
# File 'lib/reiformslive/form.rb', line 47

def updated_at
  Time.at data['updated'].to_i
end

#user_idObject



23
24
25
# File 'lib/reiformslive/form.rb', line 23

def user_id
  data['user_id'].to_i
end