Class: Trophonius::Record
- Inherits:
-
Hash
- Object
- Hash
- Trophonius::Record
- Defined in:
- lib/trophonius_record.rb
Overview
This class will hold a singular record
A Record is contained in a RecordSet and has methods to retrieve data from the fields inside the Record-hash
Instance Attribute Summary collapse
-
#layout_name ⇒ Object
Returns the value of attribute layout_name.
-
#modifiable_fields ⇒ Object
Returns the value of attribute modifiable_fields.
-
#modified_fields ⇒ Object
Returns the value of attribute modified_fields.
-
#record_id ⇒ Object
Returns the value of attribute record_id.
Instance Method Summary collapse
- #[]=(field, new_val) ⇒ Object
-
#delete ⇒ True
Deletes the corresponding record from FileMaker Throws a FileMaker error if save failed.
-
#initialize ⇒ Record
constructor
Initializes a new Record.
-
#save ⇒ True
Saves the last changes made to the Record to FileMaker.
-
#update(fieldData) ⇒ True
Changes and saves the corresponding record in FileMaker Throws a FileMaker error if save failed.
Constructor Details
#initialize ⇒ Record
Initializes a new Record
13 14 15 16 |
# File 'lib/trophonius_record.rb', line 13 def initialize @modifiable_fields = {} @modified_fields = {} end |
Instance Attribute Details
#layout_name ⇒ Object
Returns the value of attribute layout_name.
9 10 11 |
# File 'lib/trophonius_record.rb', line 9 def layout_name @layout_name end |
#modifiable_fields ⇒ Object
Returns the value of attribute modifiable_fields.
9 10 11 |
# File 'lib/trophonius_record.rb', line 9 def modifiable_fields @modifiable_fields end |
#modified_fields ⇒ Object
Returns the value of attribute modified_fields.
9 10 11 |
# File 'lib/trophonius_record.rb', line 9 def modified_fields @modified_fields end |
#record_id ⇒ Object
Returns the value of attribute record_id.
9 10 11 |
# File 'lib/trophonius_record.rb', line 9 def record_id @record_id end |
Instance Method Details
#[]=(field, new_val) ⇒ Object
18 19 20 21 |
# File 'lib/trophonius_record.rb', line 18 def []=(field, new_val) modifiable_fields[field] = new_val super end |
#delete ⇒ True
Deletes the corresponding record from FileMaker Throws a FileMaker error if save failed
44 45 46 47 48 49 50 51 52 |
# File 'lib/trophonius_record.rb', line 44 def delete url = URI("http#{Trophonius.config.ssl == true ? 's' : ''}://#{Trophonius.config.host}/fmi/data/v1/databases/#{Trophonius.config.database}/layouts/#{layout_name}/records/#{record_id}") response = Request.make_request(url, "Bearer #{Request.get_token}", 'delete', '{}') if response['messages'][0]['code'] != '0' Error.throw_error(response['messages'][0]['code']) else return true end end |
#save ⇒ True
Saves the last changes made to the Record to FileMaker. Throws a FileMaker error if save failed
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/trophonius_record.rb', line 28 def save url = URI("http#{Trophonius.config.ssl == true ? 's' : ''}://#{Trophonius.config.host}/fmi/data/v1/databases/#{Trophonius.config.database}/layouts/#{layout_name}/records/#{record_id}") body = "{\"fieldData\": #{modified_fields.to_json}}" response = Request.make_request(url, "Bearer #{Request.get_token}", 'patch', body) if response['messages'][0]['code'] != '0' Error.throw_error(response['messages'][0]['code']) else return true end end |
#update(fieldData) ⇒ True
Changes and saves the corresponding record in FileMaker Throws a FileMaker error if save failed
61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/trophonius_record.rb', line 61 def update(fieldData) url = URI("http#{Trophonius.config.ssl == true ? 's' : ''}://#{Trophonius.config.host}/fmi/data/v1/databases/#{Trophonius.config.database}/layouts/#{layout_name}/records/#{record_id}") fieldData.keys.each do |field| modifiable_fields[field] = fieldData[field] end body = "{\"fieldData\": #{fieldData.to_json}}" response = Request.make_request(url, "Bearer #{Request.get_token}", 'patch', body) if response['messages'][0]['code'] != '0' Error.throw_error(response['messages'][0]['code']) else return true end end |