Class: EPC::Command::UnbindServiceCommand

Inherits:
BaseCommand show all
Defined in:
lib/epc/command/unbind_service_command.rb

Constant Summary

Constants inherited from BaseCommand

BaseCommand::GIVEUP_TICKS, BaseCommand::SLEEP_TIME, BaseCommand::TICKER_TICKS

Instance Attribute Summary

Attributes inherited from BaseCommand

#client, #options

Instance Method Summary collapse

Methods inherited from BaseCommand

#go, inherited, #initialize, required_options

Methods included from PersistentAttributes

#auth_token, #caller_id, #target_url

Constructor Details

This class inherits a constructor from EPC::Command::BaseCommand

Instance Method Details

#execute(version = nil) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/epc/command/unbind_service_command.rb', line 4

def execute(version = nil)
  if version.nil?
    say("You must specify the service version to be unbound.")
    say(EPC::Help::COMMAND_USAGES[:unbind_service])
    return 1
  end 

  path = File.expand_path(".")

  solution_name = @options[:solution_name]
  project_name = @options[:project_name]

  solution_id, solution_name = infer_solution_context(solution_name, path)
  project_id, project_name = infer_project_context(project_name, path, solution_id)

  if numeric?(version)
    service_version_id = version.to_i 
  else
    service_version_id = get_resource_id(EPC::Config::SERVICE_VERSIONS_PATH, :label, version)
  end

  if service_version_id.nil? || project_id.nil?
    say("Project or service incorrectly specified.")
    say(EPC::Help::COMMAND_USAGES[:unbind_service])
    return 1
  end

  status, response, headers = client.delete(EPC::Config::PROJECTS_PATH + "/#{project_id}/remove_service_version/#{service_version_id}")

  if status.successful?
    say("Service version unbound.")
  else
    say("Request failed: [#{response[:message]}]")
  end
  return status

end