Class: Ey::Core::Client::Address

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

Instance Method Summary collapse

Methods included from Associations

assoc_accessor, assoc_coverage, assoc_reader, assoc_writer, associations, collection_reader

Methods inherited from Model

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

Instance Method Details

#attach(server) ⇒ Object



24
25
26
27
28
29
30
31
# File 'lib/ey-core/models/address.rb', line 24

def attach(server)
  params = {
    "id"     => self.identity,
    "server" => server.identity,
  }

  self.connection.requests.new(self.connection.attach_address(params).body["request"])
end

#detachObject



16
17
18
19
20
21
22
# File 'lib/ey-core/models/address.rb', line 16

def detach
  params = {
    "id" => self.identity,
  }

  self.connection.requests.new(self.connection.detach_address(params).body["request"])
end

#save!Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/ey-core/models/address.rb', line 33

def save!
  if new_record?
    requires :provider_id, :location

    params = {
      "provider" => self.provider_id,
      "address"  => {
        "location"       => self.location,
        "scope"          => self.scope,
      },
    }

    self.connection.requests.new(self.connection.create_address(params).body["request"])
  else
    requires :identity

    params = {
      "id" => self.identity,
      "address" => {
        "disappeared_at" => self.disappeared_at,
      }
    }

    merge_attributes(self.connection.update_address(params).body["address"])
  end
end