lib/emites/resources/base.rb in emites-client-0.1.1 vs lib/emites/resources/base.rb in emites-client-0.1.2
- old
+ new
@@ -10,28 +10,18 @@
def initialize(http)
@http = http
end
- def parsed_body(response)
- MultiJson.load(response.body)
- rescue MultiJson::ParseError
- {}
- end
-
protected
def respond_with_collection(response, naked_klass = entity_klass)
- hash = parsed_body(response)
- hash["collection"].map do |item|
- naked_klass.new(item)
- end
+ Emites::Entities::Collection.build(response, naked_klass)
end
def respond_with_entity(response, naked_klass = entity_klass)
- item = parsed_body(response)
- naked_klass.new(item)
+ naked_klass.new(response.parsed_body)
end
def base_klass
@base_klass ||= self.class.name.split("::").last
end
@@ -40,6 +30,6 @@
@entity_klass ||= Emites::Entities.const_get(base_klass.to_sym)
end
end
end
-end
\ No newline at end of file
+end