From 07a43d916acd52b50381f780893e991e476bc8ab Mon Sep 17 00:00:00 2001 From: Sam Knight Date: Mon, 28 Apr 2014 16:39:14 +0100 Subject: [PATCH] Add callbacks for create and update --- lib/parse_resource/base.rb | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/lib/parse_resource/base.rb b/lib/parse_resource/base.rb index 7db3c40..c34b6a4 100644 --- a/lib/parse_resource/base.rb +++ b/lib/parse_resource/base.rb @@ -430,23 +430,26 @@ def save end def create - attrs = attributes_for_saving.to_json - opts = {:content_type => "application/json"} - result = self.resource.post(attrs, opts) do |resp, req, res, &block| - return post_result(resp, req, res, &block) + run_callbacks :create do + attrs = attributes_for_saving.to_json + opts = {:content_type => "application/json"} + result = self.resource.post(attrs, opts) do |resp, req, res, &block| + return post_result(resp, req, res, &block) + end end end def update(attributes = {}) + run_callbacks :update do + attributes = HashWithIndifferentAccess.new(attributes) - attributes = HashWithIndifferentAccess.new(attributes) - - @unsaved_attributes.merge!(attributes) - put_attrs = attributes_for_saving.to_json + @unsaved_attributes.merge!(attributes) + put_attrs = attributes_for_saving.to_json - opts = {:content_type => "application/json"} - result = self.instance_resource.put(put_attrs, opts) do |resp, req, res, &block| - return post_result(resp, req, res, &block) + opts = {:content_type => "application/json"} + result = self.instance_resource.put(put_attrs, opts) do |resp, req, res, &block| + return post_result(resp, req, res, &block) + end end end