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



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

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

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

#detachObject



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

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

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

#save!Object



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

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

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

    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