Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/sugarcrm/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ module SugarCRM; class Base
# Contains a list of attributes
attr :attributes, true
attr :modified_attributes, true
attr :relate, true
attr :associations, true
attr :debug, true
attr :errors, true
Expand Down Expand Up @@ -128,6 +129,7 @@ def create(attributes = nil, &block)
# Creates an instance of a Module Class, i.e. Account, User, Contact, etc.
def initialize(attributes={}, &block)
attributes.delete('id')
@relate = {}
@errors = {}
@modified_attributes = {}
merge_attributes(attributes.with_indifferent_access)
Expand Down Expand Up @@ -305,4 +307,4 @@ def superclasses
include AssociationCache
end

end; end
end; end
19 changes: 17 additions & 2 deletions lib/sugarcrm/connection/response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class << self
# It tries to convert the response into an object such as User
# or an object collection. If it fails, it just returns the response hash
def handle(json, session)
#puts "returned json: #{json.inspect}"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like a commented-out debugging line made into the commit.

r = new(json, session)
begin
return r.to_obj
Expand Down Expand Up @@ -39,16 +40,30 @@ def to_obj
return @response unless @response && @response["entry_list"]

objects = []
@response["entry_list"].each do |object|
@response["entry_list"].each_index do |index|
object = @response["entry_list"][index]
attributes = []
related_attributes = {}
_module = resolve_module(object)
attributes = flatten_name_value_list(object)
namespace = @session.namespace_const
if namespace.const_get(_module)
if attributes.length == 0
raise AttributeParsingError, "response contains objects without attributes!"
end
objects << namespace.const_get(_module).new(attributes)
obj = namespace.const_get(_module).new(attributes)
# Check to see if there is a relationship for this object
if @response["relationship_list"][index]
@response["relationship_list"][index].each do |list|
relate = list["name"]
related_attributes[relate] = []
list["records"].each do |record|
related_attributes[relate] << flatten_name_value_list({ "name_value_list" => record })
end
obj.relate = related_attributes
end
end
objects << obj
else
raise InvalidModule, "#{_module} does not exist, or is not accessible"
end
Expand Down