module HyperTrack::ApiOperations::Common::Update

Public Instance Methods

update(path, params, required_params=[]) click to toggle source
# File lib/hypertrack/api_operations/common/update.rb, line 6
def update(path, params, required_params=[])
  if HyperTrack::ParamsValidator.valid_args?(params, required_params, self.class::VALID_ATTRIBUTE_VALUES)
    api_path = "#{self.class::API_BASE_PATH}#{self.id}/" + path
    result = HyperTrack::ApiClient.update(api_path, params)
    update_attributes_in_object(result)
  end
end

Private Instance Methods

update_attributes_in_object(result) click to toggle source
# File lib/hypertrack/api_operations/common/update.rb, line 16
def update_attributes_in_object(result)
  result = Util.symbolize_keys(result)

  self_keys = self.keys

  result.each do |key, value|
    if self_keys.include?(key) && self[key] != value
      self[key] = value
    end
  end

  self
end