lib/octobat/api_operations/update.rb in octobat-0.0.8 vs lib/octobat/api_operations/update.rb in octobat-0.0.9
- old
+ new
@@ -9,11 +9,11 @@
end
if values.length > 0
values.delete(:id)
- response, api_key = Octobat.request(:patch, url, @api_key, values)
+ response, api_key = Octobat.request(save_method, save_url, @api_key, values)
refresh_from(response, api_key)
end
self
end
@@ -50,8 +50,25 @@
update_hash
else
obj
end
end
+
+ private
+ def save_url
+ if self[:id] == nil && self.class.respond_to?(:create)
+ self.class.url
+ else
+ url
+ end
+ end
+
+ def save_method
+ if self[:id] == nil && self.class.respond_to?(:create)
+ :post
+ else
+ :patch
+ end
+ end
end
end
end