diff --git a/lib/hubspot/contact.rb b/lib/hubspot/contact.rb index 31b1611f..e198345e 100644 --- a/lib/hubspot/contact.rb +++ b/lib/hubspot/contact.rb @@ -106,6 +106,14 @@ def batch_update(contacts, opts = {}) end end + def [](name) + return @changes[name] if changes.key? name + + name_property = @properties[name] + + name_property.is_a?(Hash) ? name_property['value'] : name_property + end + def name [firstname, lastname].compact.join(' ') end diff --git a/lib/hubspot/resource.rb b/lib/hubspot/resource.rb index 75480d36..d762a33f 100644 --- a/lib/hubspot/resource.rb +++ b/lib/hubspot/resource.rb @@ -230,11 +230,11 @@ def add_accessors(keys) singleton_class.instance_eval do keys.each do |k| # Define a getter - define_method(k) { @changes[k.to_sym] || @properties.dig(k, 'value') } + define_method(k) { self[k] } # Define a setter define_method("#{k}=") do |v| - @changes[k.to_sym] = v + @changes[k] = v end end end @@ -247,9 +247,9 @@ def method_missing(method_name, *arguments, &block) add_accessors([attr]) # Call the new setter - return send(method_name, arguments[0]) + send(method_name, arguments[0]) elsif @properties.key?(method_name) - return @properties[method_name]['value'] + self[method_name] else super end