Class: Hookd::Hook

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

Overview

Represents a registered hook with DNS and HTTP endpoints. expires_at and metadata are populated for long-lived hooks (registered with a ttl) and nil otherwise.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id:, dns:, http:, https:, created_at:, expires_at: nil, metadata: nil) ⇒ Hook

Returns a new instance of Hook.



10
11
12
13
14
15
16
17
18
# File 'lib/hookd/hook.rb', line 10

def initialize(id:, dns:, http:, https:, created_at:, expires_at: nil, metadata: nil)
  @id = id
  @dns = dns
  @http = http
  @https = https
  @created_at = created_at
  @expires_at = expires_at
  @metadata = 
end

Instance Attribute Details

#created_atObject (readonly)

Returns the value of attribute created_at.



8
9
10
# File 'lib/hookd/hook.rb', line 8

def created_at
  @created_at
end

#dnsObject (readonly)

Returns the value of attribute dns.



8
9
10
# File 'lib/hookd/hook.rb', line 8

def dns
  @dns
end

#expires_atObject (readonly)

Returns the value of attribute expires_at.



8
9
10
# File 'lib/hookd/hook.rb', line 8

def expires_at
  @expires_at
end

#httpObject (readonly)

Returns the value of attribute http.



8
9
10
# File 'lib/hookd/hook.rb', line 8

def http
  @http
end

#httpsObject (readonly)

Returns the value of attribute https.



8
9
10
# File 'lib/hookd/hook.rb', line 8

def https
  @https
end

#idObject (readonly)

Returns the value of attribute id.



8
9
10
# File 'lib/hookd/hook.rb', line 8

def id
  @id
end

#metadataObject (readonly)

Returns the value of attribute metadata.



8
9
10
# File 'lib/hookd/hook.rb', line 8

def 
  @metadata
end

Class Method Details

.from_hash(hash) ⇒ Object

Create a Hook from API response hash

Raises:

  • (ArgumentError)


21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/hookd/hook.rb', line 21

def self.from_hash(hash)
  raise ArgumentError, "Invalid hash: expected Hash, got #{hash.class}" unless hash.is_a?(Hash)

  new(
    id: hash['id'],
    dns: hash['dns'],
    http: hash['http'],
    https: hash['https'],
    created_at: hash['created_at'],
    expires_at: hash['expires_at'],
    metadata: hash['metadata']
  )
end

Instance Method Details

#to_sObject



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

def to_s
  "#<Hookd::Hook id=#{id} dns=#{dns}>"
end