Class: LinkIO::ReferralData

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

Overview

A referral relationship between a referrer and a referee. timestamp is epoch milliseconds, matching the Node.js backend.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(referrer_id:, referee_id:, referral_code:, timestamp:, metadata: nil) ⇒ ReferralData

Returns a new instance of ReferralData.

Parameters:

  • referrer_id (String)
  • referee_id (String)
  • referral_code (String)
  • timestamp (Integer)

    epoch milliseconds

  • metadata (Hash, nil) (defaults to: nil)


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

def initialize(referrer_id:, referee_id:, referral_code:, timestamp:, metadata: nil)
  @referrer_id = referrer_id
  @referee_id = referee_id
  @referral_code = referral_code
  @timestamp = timestamp
  @metadata = 
end

Instance Attribute Details

#metadataObject (readonly)

Returns the value of attribute metadata.



7
8
9
# File 'lib/linkio/referral_data.rb', line 7

def 
  @metadata
end

#referee_idObject (readonly)

Returns the value of attribute referee_id.



7
8
9
# File 'lib/linkio/referral_data.rb', line 7

def referee_id
  @referee_id
end

#referral_codeObject (readonly)

Returns the value of attribute referral_code.



7
8
9
# File 'lib/linkio/referral_data.rb', line 7

def referral_code
  @referral_code
end

#referrer_idObject (readonly)

Returns the value of attribute referrer_id.



7
8
9
# File 'lib/linkio/referral_data.rb', line 7

def referrer_id
  @referrer_id
end

#timestampObject (readonly)

Returns the value of attribute timestamp.



7
8
9
# File 'lib/linkio/referral_data.rb', line 7

def timestamp
  @timestamp
end

Class Method Details

.from_h(hash) ⇒ ReferralData

Build from a hash using either camelCase or snake_case keys.

Parameters:

  • hash (Hash)

Returns:



37
38
39
40
41
42
43
44
45
46
# File 'lib/linkio/referral_data.rb', line 37

def self.from_h(hash)
  h = hash.each_with_object({}) { |(k, v), acc| acc[k.to_s] = v }
  new(
    referrer_id: h["referrerId"] || h["referrer_id"],
    referee_id: h["refereeId"] || h["referee_id"],
    referral_code: h["referralCode"] || h["referral_code"],
    timestamp: h["timestamp"],
    metadata: h["metadata"]
  )
end

Instance Method Details

#to_hHash

Returns:

  • (Hash)


23
24
25
26
27
28
29
30
31
# File 'lib/linkio/referral_data.rb', line 23

def to_h
  {
    "referrerId" => referrer_id,
    "refereeId" => referee_id,
    "referralCode" => referral_code,
    "timestamp" => timestamp,
    "metadata" => 
  }
end