lib/arrest/transport/http_source.rb in arrest-0.0.83.1 vs lib/arrest/transport/http_source.rb in arrest-0.0.84
- old
+ new
@@ -82,23 +82,24 @@
end
end
def put(context, rest_resource)
raise "To change an object it must have an id" unless rest_resource.respond_to?(:id) && rest_resource.id != nil
- hash = rest_resource.to_jhash
- insert_nulls!(rest_resource,hash)
+ hash = rest_resource.to_jhash(:update)
hash.delete(:id)
hash.delete("id")
body = JSON.generate(hash)
internal_put(rest_resource, rest_resource.resource_location, body)
end
def internal_put(rest_resource, location, body)
profiler_status_str = ""
::ActiveSupport::Notifications.instrument("http.sgdb",
- :method => :delete, :url => rest_resource.resource_location, :status => profiler_status_str) do
+ :method => :delete,
+ :url => rest_resource.resource_location,
+ :status => profiler_status_str) do
headers = nil
response = self.connection().put do |req|
req.url(location)
headers = add_headers(rest_resource.context, req.headers)
req.body = body
@@ -112,29 +113,20 @@
profiler_status_str << response.env[:status].to_s
response.env[:status] == 200
end
end
- def insert_nulls!(rest_resource, hash)
- rest_resource.class.all_fields.each do |field|
- changed = (!rest_resource.respond_to?("#{field.name}_changed?" || rest_resource.send("#{field}_changed?")))
- if !field.read_only && hash[field.json_name] == nil && changed
- hash[field.json_name] = Null.singleton
- end
- end
- end
-
def post(context, rest_resource)
profiler_status_str = ""
::ActiveSupport::Notifications.instrument("http.sgdb",
- :method => :post, :url => rest_resource.resource_path, :status => profiler_status_str) do
+ :method => :post,
+ :url => rest_resource.resource_path,
+ :status => profiler_status_str) do
raise "new object must have setter for id" unless rest_resource.respond_to?(:id=)
raise "new object must not have id" if rest_resource.respond_to?(:id) && rest_resource.id != nil
- hash = rest_resource.to_jhash
+ hash = rest_resource.to_jhash(:create)
hash.delete(:id)
hash.delete('id')
-
- insert_nulls!(rest_resource,hash)
body = JSON.generate(hash)
headers = nil
response = self.connection().post do |req|
req.url rest_resource.resource_path