module UserEngage::Operation::UpdateAttributes
Public Instance Methods
update_attributes(attributes_hash)
click to toggle source
Public: Updates attributes of the resource
Params: attributes - A hash where the key is the name_std of the attribute to set and the value is the value to set
# File lib/user_engage/operation/update_attributes.rb, line 12 def update_attributes(attributes_hash) update_remote_attributes!(attributes_hash) && update_local_attributes!(attributes_hash) end
Private Instance Methods
update_local_attribute!(name, value)
click to toggle source
Private: Search for the resources attribute with the given name and set's it's attribute to the given value.
# File lib/user_engage/operation/update_attributes.rb, line 42 def update_local_attribute!(name, value) attribute = attributes[:attributes].find do |attr| attr.name_std.to_s.eql?(name.to_s) end if attribute.nil? new_attr = UserEngage::Attribute.new(value: value, name: name.to_s) attributes[:attributes] << new_attr else attribute.attributes[:value] = value end end
update_local_attributes!(attributes_hash)
click to toggle source
Private: Iterates through all attributes and sets it on the instance.
# File lib/user_engage/operation/update_attributes.rb, line 33 def update_local_attributes!(attributes_hash) attributes_hash.each_pair do |attr_name, attr_value| update_local_attribute!(attr_name, attr_value) end end
update_remote_attributes!(attributes_hash)
click to toggle source
Privates: Generates the destination endpoint and calls it with POST and given attributes.
# File lib/user_engage/operation/update_attributes.rb, line 25 def update_remote_attributes!(attributes_hash) path = "/#{resource_name}/#{id}/set_multiple_attributes/" UserEngage.client.post(path, attributes_hash) end