Class: Hookd::Interaction

Inherits:
Object
  • Object
show all
Defined in:
lib/hookd/interaction.rb

Overview

Represents a captured DNS or HTTP interaction

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type:, timestamp:, source_ip:, data:) ⇒ Interaction

Returns a new instance of Interaction.



8
9
10
11
12
13
# File 'lib/hookd/interaction.rb', line 8

def initialize(type:, timestamp:, source_ip:, data:)
  @type = type
  @timestamp = timestamp
  @source_ip = source_ip
  @data = data
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



6
7
8
# File 'lib/hookd/interaction.rb', line 6

def data
  @data
end

#source_ipObject (readonly)

Returns the value of attribute source_ip.



6
7
8
# File 'lib/hookd/interaction.rb', line 6

def source_ip
  @source_ip
end

#timestampObject (readonly)

Returns the value of attribute timestamp.



6
7
8
# File 'lib/hookd/interaction.rb', line 6

def timestamp
  @timestamp
end

#typeObject (readonly)

Returns the value of attribute type.



6
7
8
# File 'lib/hookd/interaction.rb', line 6

def type
  @type
end

Class Method Details

.from_hash(hash) ⇒ Object

Create an Interaction from API response hash



16
17
18
19
20
21
22
23
# File 'lib/hookd/interaction.rb', line 16

def self.from_hash(hash)
  new(
    type: hash['type'],
    timestamp: hash['timestamp'],
    source_ip: hash['source_ip'],
    data: hash['data']
  )
end

Instance Method Details

#dns?Boolean

Check if this is a DNS interaction

Returns:

  • (Boolean)


26
27
28
# File 'lib/hookd/interaction.rb', line 26

def dns?
  type == 'dns'
end

#http?Boolean

Check if this is an HTTP interaction

Returns:

  • (Boolean)


31
32
33
# File 'lib/hookd/interaction.rb', line 31

def http?
  type == 'http'
end

#inspectObject



39
40
41
42
# File 'lib/hookd/interaction.rb', line 39

def inspect
  "#<Hookd::Interaction:#{object_id.to_s(16)} @type=#{type.inspect}, @timestamp=#{timestamp.inspect}, " \
    "@source_ip=#{source_ip.inspect}, @data=#{data.inspect}>"
end

#to_sObject



35
36
37
# File 'lib/hookd/interaction.rb', line 35

def to_s
  "#<Hookd::Interaction type=#{type} timestamp=#{timestamp} source_ip=#{source_ip}>"
end