Class: EPC::Command::BindServiceCommand

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

Constant Summary

Constants inherited from BaseCommand

EPC::Command::BaseCommand::GIVEUP_TICKS, EPC::Command::BaseCommand::SLEEP_TIME, EPC::Command::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(service = nil) ⇒ Object

Raises:



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
# File 'lib/epc/command/bind_service_command.rb', line 4

def execute(service = nil)
  path = File.expand_path(".")

  raise FatalError, "You must specify the service to be bound" if service.blank?

  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?(service)
    service_version_id = service.to_i
  else
    service_version_id = get_resource_id(EPC::Config::SERVICE_VERSIONS_PATH, :label, service)
  end

  raise FatalError, "Project or service incorrectly specified" if service.nil? || service == 0 || project_id.nil?

  status, response, headers = client.post(EPC::Config::PROJECTS_PATH + "/#{project_id}/add_service_version", {:version_id => service_version_id})

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

  return status
end