lib/utils/serializer.rb in sk-api-1.0.6 vs lib/utils/serializer.rb in sk-api-1.1.0
- old
+ new
@@ -4,11 +4,11 @@
# SKApi Resources.
# Inside SalesKing this serialising is used to render the output.
# f.ex. in the clients api controller
# => SKApi::Resources::Client.to_json(a_client)
# This way you can keep your API client up to date by using the resources and
- # relying on SKApi::Resources::Client.api_fields
+ # relying on SKApi::Resources::Client.schema
module Serializer
def self.included(base)
base.extend ClassMethods
end
@@ -40,20 +40,20 @@
if rel_obj = obj.send( field )
klass = "SKApi::Resources::#{rel_obj.class}".constantize
# ex: data['invoice']['client'] = SKApi::Models::Client.to_hash_from_schema(client)
data[obj_class_name][field] = klass.to_hash_from_schema(rel_obj)
end
- else # a simple field which can be directly called
- data[obj_class_name][field] = obj.send(field)
+ else # a simple field which can be directly called, only added of objects know its
+ data[obj_class_name][field] = obj.send(field) if obj.respond_to?(field.to_sym)
end
end
data
end
def to_json(obj)
data = self.to_hash_from_schema(obj)
# data[:links] = self.api_links
- Rufus::Json.encode(data)
+ ActiveSupport::JSON.encode(data)
end
end #ClassMethods
end #mixin
\ No newline at end of file