Class: Ey::Core::Client::Request

Inherits:
Model
  • Object
show all
Extended by:
Associations
Includes:
Subscribable
Defined in:
lib/ey-core/models/request.rb

Instance Method Summary collapse

Methods included from Associations

assoc_accessor, assoc_coverage, assoc_reader, assoc_writer, associations, collection_reader

Methods included from Subscribable

included, #read_channel_uri, #subscribe

Methods inherited from Model

#destroy, range_parser, #save, #to_s, #update!, #url

Instance Method Details

#callbackObject



21
22
23
24
25
# File 'lib/ey-core/models/request.rb', line 21

def callback
  requires :callback_url

  merge_attributes(connection.request_callback("url" => self.callback_url).body["request"])
end

#ready!(timeout = self.service.timeout, interval = self.service.poll_interval, raise_on_failure = true, &block) ⇒ Object



27
28
29
30
31
32
33
34
35
36
# File 'lib/ey-core/models/request.rb', line 27

def ready!(timeout = self.service.timeout, interval = self.service.poll_interval, raise_on_failure = true, &block)
  wait_for!(timeout, interval) do
    yield self if block_given?
    ready?
  end
  if raise_on_failure && !successful?
    raise Ey::Core::RequestFailure.new(self)
  end
  self
end

#ready?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/ey-core/models/request.rb', line 38

def ready?
  !!self.finished_at
end

#resourceObject



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/ey-core/models/request.rb', line 50

def resource
  return nil unless resource_url
  resource_id = resource_url.split("/").last
  case type
  when /address/
    self.connection.addresses.get!(resource_id)
  when /auto_scaling_group/
    self.connection.auto_scaling_groups.get!(resource_id)
  when /auto_scaling_policy/
    self.connection.auto_scaling_policies.get(resource_id)
  when /auto_scaling_alarm/
    self.connection.auto_scaling_alarms.get(resource_id)
  when /cluster_update/
    self.connection.cluster_updates.get!(resource_id)
  when /database_server_snapshot/
    collection, id = resource_url.split('/')[-3..-2]
    if collection == "providers"
      connection.providers.get!(id).database_server_snapshots
    elsif collection == "database-servers"
      connection.database_servers.get!(id).snapshots
    else
      connection.database_server_snapshots.get!(resource_id)
    end
  when /database_server/
    self.connection.database_servers.get!(resource_id)
  when /database_service/
    self.connection.database_services.get!(resource_id)
  when /deployment/
    self.connection.deployments.get!(resource_id)
  when /firewall(?!_rule)/
    self.connection.firewalls.get!(resource_id)
  when /firewall_rule/
    self.connection.firewall_rules.get!(resource_id)
  when /logical_database/
    self.connection.logical_databases.get!(resource_id)
  when /provider_location/
    self.connection.provider_locations.get!(resource_id)
  when /provider_storage_credential/
    self.connection.storage_users.get!(resource_id)
  when /provider_storage/
    self.connection.storages.get!(resource_id)
  when /provider/
    self.connection.providers.get!(resource_id)
  when /server/
    self.connection.servers.get!(resource_id)
  when /snapshot/
    self.connection.snapshots.get!(resource_id)
  when /task/
    self.connection.tasks.get!(resource_id)
  when /volume/
    self.connection.volumes.get!(resource_id)
  when /load_balancer/
    self.connection.load_balancers.get!(resource_id)
  when /ssl_certificate/
    self.connection.ssl_certificates.get!(resource_id)
  else
    nil # has no coresponding resource
  end
end

#resource!(timeout = self.service.timeout, interval = self.service.poll_interval) ⇒ Object



46
47
48
# File 'lib/ey-core/models/request.rb', line 46

def resource!(timeout = self.service.timeout, interval = self.service.poll_interval)
  ready!(timeout, interval); resource
end

#successful?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/ey-core/models/request.rb', line 42

def successful?
  self.successful
end