Class: FellowshipOne::ApiWriter
- Inherits:
-
Object
- Object
- FellowshipOne::ApiWriter
- Defined in:
- lib/writers/api_writer.rb
Overview
This adapter is the standard for all saving objects.
Direct Known Subclasses
CommunicationWriter, ContributionWriter, HouseholdWriter, PersonWriter
Instance Attribute Summary collapse
-
#error_messages ⇒ Object
readonly
Returns the value of attribute error_messages.
-
#response_code ⇒ Object
readonly
Returns the value of attribute response_code.
Instance Method Summary collapse
-
#delete_object ⇒ Object
Deletes this object.
-
#save_object ⇒ Object
Saves this object.
Instance Attribute Details
#error_messages ⇒ Object (readonly)
Returns the value of attribute error_messages.
5 6 7 |
# File 'lib/writers/api_writer.rb', line 5 def end |
#response_code ⇒ Object (readonly)
Returns the value of attribute response_code.
5 6 7 |
# File 'lib/writers/api_writer.rb', line 5 def response_code @response_code end |
Instance Method Details
#delete_object ⇒ Object
Deletes this object.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/writers/api_writer.rb', line 41 def delete_object success = true if @url_data_delete_path.nil? = ["DELETE not implemented for #{self.class.to_s}"] return false end begin # @url_data_path should be the same as :put if this object is already # setup and mapped to an object that exists response = FellowshipOne::api_request(:delete, @url_data_delete_path) success = response.code == 204 ? true : false # No content but is a success rescue Exception => e = e..split(',') success = false end return success end |
#save_object ⇒ Object
Saves this object.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/writers/api_writer.rb', line 10 def save_object @url_data_params ||= {} success = true if @url_data_path.nil? = ["#{@url_action.to_s.upcase} not implemented for #{self.class.to_s}"] return false end if @updatable_fields and !@updatable_fields.empty? # fields_to_remove = @url_data_params.keys - @updatable_fields # fields_to_remove.each { |ftr| @url_data_params.delete(ftr) } end begin response = FellowshipOne::api_request(@url_action, @url_data_path, [], @url_data_params.to_json) @response_code = response.code # No content but is a success success = response.code == 204 ? {'success' => true} : JSON.parse(response.body) rescue Exception => e = e..split(',') success = false end return success end |