lib/sugarcrm/response.rb in sugarcrm-0.7.9 vs lib/sugarcrm/response.rb in sugarcrm-0.8.0
- old
+ new
@@ -6,11 +6,16 @@
# or an object collection. If it fails, it just returns the response hash
def handle(json)
r = new(json)
begin
return r.to_obj
- rescue
+ rescue => e
+ if SugarCRM.connection.debug?
+ puts "Failed to process JSON:"
+ pp json
+ puts e
+ end
return json
end
end
end
@@ -21,22 +26,21 @@
end
# Tries to instantiate and return an object with the values
# populated from the response
def to_obj
+ # If this is not a "entry_list" response, just return
+ return @response unless @response["entry_list"]
+
objects = []
@response["entry_list"].each do |object|
attributes = []
_module = resolve_module(object)
id = object["id"]
- begin
- attributes = flatten_name_value_list(object)
- rescue ArgumentError => e
- end
+ attributes = flatten_name_value_list(object)
if SugarCRM.const_get(_module)
if attributes.length == 0
- pp object
raise AttributeParsingError, "response contains objects without attributes!"
end
objects << SugarCRM.const_get(_module).new(id, attributes)
else
raise InvalidModule, "#{_module} does not exist, or is not accessible"
@@ -51,10 +55,10 @@
end
def to_json
@response.to_json
end
-
+
def resolve_module(list)
list["module_name"].classify
end
def flatten_name_value_list(list)