Sha256: 7fbac4e587edc1f6ea71ffc9cd8ed53c1cff36292f90af43ec93dec0a2da2d09
Contents?: true
Size: 1.48 KB
Versions: 9
Compression:
Stored size: 1.48 KB
Contents
module TheCity # This adapter is the standard for all saving objects. class ApiWriter attr_reader :error_messages, :response_code # Saves this object. # # @return True or ID on success, otherwise false. def save_object @url_data_params ||= {} success = true 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 = TheCity::admin_request(@url_action, @url_data_path, @url_data_params) @response_code = response.code # No content but is a success success = response.code == 204 ? {'success' => true} : JSON.parse(response.body) rescue Exception => e @error_messages = e.message.split(',') success = false end return success end # Deletes this object. # # @return True or ID on success, otherwise false. def delete_object success = true begin # @url_data_path should be the same as :put if this object is already # setup and mapped to an object that exists response = TheCity::admin_request(:delete, @url_data_delete_path) success = response.code == 204 ? true : false # No content but is a success rescue Exception => e @error_messages = e.message.split(',') success = false end return success end end end
Version data entries
9 entries across 9 versions & 1 rubygems