Skip to content
This repository has been archived by the owner on Aug 1, 2023. It is now read-only.

Commit

Permalink
Merge pull request tumblr#124 from tumblr/dallas-collins-client-state…
Browse files Browse the repository at this point in the history
…-delete

accept collins asset state objects as arguments for state_update! and state_delete!
  • Loading branch information
dallasmarlow committed Mar 4, 2014
2 parents 3b2fc24 + ce56b6e commit 94045a7
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions support/ruby/collins-client/lib/collins/api/asset_state.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,41 @@ def state_create! name, label, description, status = nil
:description => description,
:status => status
}

if not ::Collins::Api::AssetState.state_test then
parameters = select_non_empty_parameters parameters
end

logger.debug("Creating state with name #{name}")
http_put("/api/state/#{name}", parameters) do |r|
parse_response r, :expects => 201, :as => :status, :raise => strict?, :default => false
end
end
def state_delete! name
name = validate_state_name name

def state_delete! state
name = validate_state_name case state.class
when ::Collins::AssetState
state.name
else
state
end

logger.debug("Deleting state with name #{name}")
http_delete("/api/state/#{name}") do |r|
parse_response r, :expects => 202, :as => :data, :raise => strict?, :default => 0 do |js|
js["DELETED"].to_s.to_i
end
end
end
def state_update! name, options = {}
name = validate_state_name name

def state_update! state, options = {}
name = validate_state_name case state.class
when ::Collins::AssetState
state.name
else
state
end

parameters = {
:label => options[:label],
:description => options[:description],
Expand All @@ -45,6 +61,7 @@ def state_update! name, options = {}
parse_response r, :expects => 200, :as => :status, :raise => strict?, :default => false
end
end

def state_get name
name = validate_state_name name
logger.debug("Fetching state with name #{name}")
Expand All @@ -55,6 +72,7 @@ def state_get name
end
end
end

def state_get_all
http_get("/api/states") do |r|
parse_response r, :expects => 200, :as => :data, :default => [], :raise => false do |js|
Expand Down

0 comments on commit 94045a7

Please sign in to comment.