Class: RubyPhpipam::Address

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_phpipam/address.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(json) ⇒ Address

Returns a new instance of Address.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/ruby_phpipam/address.rb', line 7

def initialize(json)
  @id = RubyPhpipam::Helper.to_type(json[:id], :int)
  @subnetId = RubyPhpipam::Helper.to_type(json[:subnetId], :int)
  @ip = json[:ip]
  @is_gateway = RubyPhpipam::Helper.to_type(json[:is_gateway], :binary)
  @description = json[:description]
  @hostname = json[:hostname]
  @mac = json[:mac]
  @owner = json[:owner]
  @tag = RubyPhpipam::Helper.to_type(json[:tag], :int)
  @PTRignore = RubyPhpipam::Helper.to_type(json[:PTRignore], :binary)
  @PTR = RubyPhpipam::Helper.to_type(json[:PTR], :int)
  @deviceId = RubyPhpipam::Helper.to_type(json[:deviceId], :int)
  @port = json[:port]
  @note = json[:note]
  @lastSeen = RubyPhpipam::Helper.to_type(json[:lastSeen], :date)
  @excludePing = RubyPhpipam::Helper.to_type(json[:excludePing], :binary)
  @editDate = RubyPhpipam::Helper.to_type(json[:editDate], :date)
end

Instance Attribute Details

#descriptionObject (readonly)

Returns the value of attribute description.



3
4
5
# File 'lib/ruby_phpipam/address.rb', line 3

def description
  @description
end

#deviceIdObject (readonly)

Returns the value of attribute deviceId.



3
4
5
# File 'lib/ruby_phpipam/address.rb', line 3

def deviceId
  @deviceId
end

#editDateObject (readonly)

Returns the value of attribute editDate.



3
4
5
# File 'lib/ruby_phpipam/address.rb', line 3

def editDate
  @editDate
end

#excludePingObject (readonly)

Returns the value of attribute excludePing.



3
4
5
# File 'lib/ruby_phpipam/address.rb', line 3

def excludePing
  @excludePing
end

#hostnameObject (readonly)

Returns the value of attribute hostname.



3
4
5
# File 'lib/ruby_phpipam/address.rb', line 3

def hostname
  @hostname
end

#idObject (readonly)

Returns the value of attribute id.



3
4
5
# File 'lib/ruby_phpipam/address.rb', line 3

def id
  @id
end

#ipObject (readonly)

Returns the value of attribute ip.



3
4
5
# File 'lib/ruby_phpipam/address.rb', line 3

def ip
  @ip
end

#is_gatewayObject (readonly)

Returns the value of attribute is_gateway.



3
4
5
# File 'lib/ruby_phpipam/address.rb', line 3

def is_gateway
  @is_gateway
end

#lastSeenObject (readonly)

Returns the value of attribute lastSeen.



3
4
5
# File 'lib/ruby_phpipam/address.rb', line 3

def lastSeen
  @lastSeen
end

#macObject (readonly)

Returns the value of attribute mac.



3
4
5
# File 'lib/ruby_phpipam/address.rb', line 3

def mac
  @mac
end

#noteObject (readonly)

Returns the value of attribute note.



3
4
5
# File 'lib/ruby_phpipam/address.rb', line 3

def note
  @note
end

#ownerObject (readonly)

Returns the value of attribute owner.



3
4
5
# File 'lib/ruby_phpipam/address.rb', line 3

def owner
  @owner
end

#portObject (readonly)

Returns the value of attribute port.



3
4
5
# File 'lib/ruby_phpipam/address.rb', line 3

def port
  @port
end

#PTRObject (readonly)

Returns the value of attribute PTR.



3
4
5
# File 'lib/ruby_phpipam/address.rb', line 3

def PTR
  @PTR
end

#PTRignoreObject (readonly)

Returns the value of attribute PTRignore.



3
4
5
# File 'lib/ruby_phpipam/address.rb', line 3

def PTRignore
  @PTRignore
end

#subnetIdObject (readonly)

Returns the value of attribute subnetId.



3
4
5
# File 'lib/ruby_phpipam/address.rb', line 3

def subnetId
  @subnetId
end

#tagObject (readonly)

Returns the value of attribute tag.



3
4
5
# File 'lib/ruby_phpipam/address.rb', line 3

def tag
  @tag
end

Class Method Details

.first_free(subnetId) ⇒ Object



66
67
68
# File 'lib/ruby_phpipam/address.rb', line 66

def self.first_free(subnetId)
  RubyPhpipam::Query.get("/addresses/first_free/#{subnetId}/")
end

.get(id) ⇒ Object



27
28
29
# File 'lib/ruby_phpipam/address.rb', line 27

def self.get(id)
  Address.new(RubyPhpipam::Query.get("/addresses/#{id}/"))
end

.get_by_tag(tagId) ⇒ Object



31
32
33
34
35
36
# File 'lib/ruby_phpipam/address.rb', line 31

def self.get_by_tag(tagId)
  addresses = RubyPhpipam::Query.get_array("/addresses/tags/#{tagId}/addresses/")
  addresses.map do |address|
    self.new(address)
  end
end

.ping(id) ⇒ Object



38
39
40
41
42
43
44
45
46
# File 'lib/ruby_phpipam/address.rb', line 38

def self.ping(id)
  response = RubyPhpipam::Query.get("/addresses/#{id}/ping/")

  if response[:exit_code] == 0
    return true
  else
    return false
  end
end

.search(ip: nil, hostname: nil, subnetId: nil) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/ruby_phpipam/address.rb', line 48

def self.search(ip:nil, hostname:nil, subnetId:nil)
  if !ip.nil?
    if subnetId.nil?
      addresses = RubyPhpipam::Query.get_array("/addresses/search/#{ip}/")
    else
      address = RubyPhpipam::Query.get("/addresses/#{ip}/#{subnetId}/")
    end
  else
    addresses = RubyPhpipam::Query.get_array("/addresses/search_hostname/#{hostname}/")
  end

  return (address ? self.new(address) : nil) if subnetId

  addresses.map do |address|
    self.new(address)
  end
end

Instance Method Details

#online?Boolean

Returns:

  • (Boolean)


70
71
72
# File 'lib/ruby_phpipam/address.rb', line 70

def online?
  RubyPhpipam::Address.ping(@id)
end