Class: LinkIO::PendingLinkData

Inherits:
Object
  • Object
show all
Defined in:
lib/linkio/pending_link_data.rb

Overview

A deep link stored for later retrieval (deferred deep linking). Timestamps are epoch milliseconds, matching the Node.js backend so that data is interchangeable between the two implementations.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url:, params:, created_at:, expires_at:) ⇒ PendingLinkData

Returns a new instance of PendingLinkData.

Parameters:

  • url (String)

    the full URL that produced this pending link

  • params (Hash)

    parsed query/path parameters

  • created_at (Integer)

    epoch milliseconds

  • expires_at (Integer)

    epoch milliseconds



14
15
16
17
18
19
# File 'lib/linkio/pending_link_data.rb', line 14

def initialize(url:, params:, created_at:, expires_at:)
  @url = url
  @params = params || {}
  @created_at = created_at
  @expires_at = expires_at
end

Instance Attribute Details

#created_atObject (readonly)

Returns the value of attribute created_at.



8
9
10
# File 'lib/linkio/pending_link_data.rb', line 8

def created_at
  @created_at
end

#expires_atObject (readonly)

Returns the value of attribute expires_at.



8
9
10
# File 'lib/linkio/pending_link_data.rb', line 8

def expires_at
  @expires_at
end

#paramsObject (readonly)

Returns the value of attribute params.



8
9
10
# File 'lib/linkio/pending_link_data.rb', line 8

def params
  @params
end

#urlObject (readonly)

Returns the value of attribute url.



8
9
10
# File 'lib/linkio/pending_link_data.rb', line 8

def url
  @url
end

Class Method Details

.from_h(hash) ⇒ PendingLinkData

Build from a hash using either camelCase (JSON/Node-compatible) or snake_case keys.

Parameters:

  • hash (Hash)

Returns:



42
43
44
45
46
47
48
49
50
# File 'lib/linkio/pending_link_data.rb', line 42

def self.from_h(hash)
  h = stringify(hash)
  new(
    url: h["url"],
    params: h["params"] || {},
    created_at: h["createdAt"] || h["created_at"],
    expires_at: h["expiresAt"] || h["expires_at"]
  )
end

Instance Method Details

#expired?(now_ms = (Time.now.to_f * 1000).to_i) ⇒ Boolean

Parameters:

  • now_ms (Integer) (defaults to: (Time.now.to_f * 1000).to_i)

    current time in epoch milliseconds

Returns:

  • (Boolean)


23
24
25
# File 'lib/linkio/pending_link_data.rb', line 23

def expired?(now_ms = (Time.now.to_f * 1000).to_i)
  now_ms > expires_at
end

#to_hHash

Returns:

  • (Hash)


28
29
30
31
32
33
34
35
# File 'lib/linkio/pending_link_data.rb', line 28

def to_h
  {
    "url" => url,
    "params" => params,
    "createdAt" => created_at,
    "expiresAt" => expires_at
  }
end