Module: FreshdeskAPI::Save
Instance Method Summary collapse
-
#save(options = {}, &block) ⇒ Object
Saves, returning false if it fails and attachibg the errors.
-
#save!(options = {}) ⇒ Resource
If this resource hasn’t been deleted, then create or save it.
Methods included from ResponseHandler
Instance Method Details
#save(options = {}, &block) ⇒ Object
Saves, returning false if it fails and attachibg the errors
68 69 70 71 72 73 74 75 |
# File 'lib/freshdesk_api/actions.rb', line 68 def save( = {}, &block) save!(, &block) rescue FreshdeskAPI::Error::RecordInvalid => e @errors = e.errors false rescue FreshdeskAPI::Error::ClientError false end |
#save!(options = {}) ⇒ Resource
If this resource hasn’t been deleted, then create or save it. Executes a POST if it is a Data#new_record?, otherwise a PUT.
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/freshdesk_api/actions.rb', line 48 def save!( = {}) return false if respond_to?(:destroyed?) && destroyed? = { request_namespace => attributes } if new_record? method = :post req_path = api_url() else method = :put req_path = api_url() + "/#{id}" end response = @client.make_request!(req_path, method, ) handle_response(response) return self end |