module Collins::Api::Attributes
Public Instance Methods
delete_attribute!(asset_or_tag, attribute, group_id = nil)
click to toggle source
# File lib/collins/api/attributes.rb, line 5 def delete_attribute! asset_or_tag, attribute, group_id = nil asset = get_asset_or_tag asset_or_tag parameters = { :groupId => group_id } parameters = select_non_empty_parameters parameters logger.debug("Deleting attribute #{attribute} on #{asset.tag} with params #{parameters.inspect}") http_delete("/api/asset/#{asset.tag}/attribute/#{attribute}", parameters, asset.location) do |response| parse_response response, :expects => 202, :as => :status, :raise => strict?, :default => false end end
set_attribute!(asset_or_tag, key, value, group_id = nil)
click to toggle source
# File lib/collins/api/attributes.rb, line 17 def set_attribute! asset_or_tag, key, value, group_id = nil set_multi_attribute! asset_or_tag, {key => value}, group_id end
set_multi_attribute!(asset_or_tag, kv_hash, group_id = nil)
click to toggle source
# File lib/collins/api/attributes.rb, line 21 def set_multi_attribute! asset_or_tag, kv_hash, group_id = nil asset = get_asset_or_tag asset_or_tag http_overrides = {} parameters = { :groupId => group_id, :attribute => [] } kv_hash.each do |key,value| if ::Collins::Asset::Update.is_attribute?(key) then parameters[:attribute] << "#{key};#{value}" else p = ::Collins::Asset::Update.get_param(key) parameters[p.to_sym] = ::Collins::Asset::Update.get_param_value(key, value) end end if parameters[:attribute].empty? then parameters[:attribute] = nil elsif parameters[:attribute].size == 1 then parameters[:attribute] = parameters[:attribute].first else http_overrides[:query_string_normalizer] = HTTParty::Request::NON_RAILS_QUERY_STRING_NORMALIZER end parameters = select_non_empty_parameters parameters logger.debug("Setting attributes #{parameters.inspect} on #{asset.tag}") parameters[:http_options] = http_overrides unless http_overrides.empty? http_post("/api/asset/#{asset.tag}", parameters, asset.location) do |response| parse_response response, :expects => 200, :as => :status, :raise => strict?, :default => false end end
set_status!(asset_or_tag, *varargs)
click to toggle source
Set the status of an asset @overload set_status!(asset_or_tag, status, reason = 'Set via API', state = nil)
Set the status, reason and optionally state of asset @param [String,Collins::Asset] asset_or_tag The asset or tag @param [String] status the status of the asset @param [String] reason the reason for the change @param [String] state the asset state
@overload set_status!(asset_or_tag, hash)
Set the status, reason, and optionally state of asset @param [String,Collins::Asset] asset_or_tag The asset or tag @param [Hash] hash the options to set @option hash [String] :status The asset status @option hash [String] :reason The reason for the change @option hash [String] :state The asset state
@return Boolean
# File lib/collins/api/attributes.rb, line 66 def set_status! asset_or_tag, *varargs status = state = nil reason = 'Set via ruby client' asset = get_asset_or_tag asset_or_tag if varargs.size == 0 then raise ::Collins::ExpectationFailedError.new("set_status! requires a status") elsif varargs.size == 1 and varargs[0].is_a?(Hash) then hash = symbolize_hash(varargs[0], :downcase => true) status = hash[:status] reason = hash.fetch(:reason, reason) state = hash[:state] elsif varargs.size == 1 and (varargs[0].is_a?(String) or varargs[0].is_a?(Symbol)) then status = varargs[0].to_s elsif varargs.size > 1 then status = varargs[0] reason = varargs[1] state = varargs[2] if varargs.size > 2 else raise ::Collins::ExpectationFailedError.new("set_status! called with invalid parameters") end parameters = { :status => status, :reason => reason, :state => state } parameters = select_non_empty_parameters parameters logger.debug("Setting status to #{status} on #{asset.tag}") http_post("/api/asset/#{asset.tag}/status", parameters, asset.location) do |response| parse_response response, :expects => 200, :as => :status, :raise => strict?, :default => false end end