Class: LaunchDarkly::Interfaces::DataSystem::Payload

Inherits:
Object
  • Object
show all
Defined in:
lib/ldclient-rb/interfaces/data_system.rb

Overview

Payload represents a payload delivered in a streaming response.

This type is not stable, and not subject to any backwards compatibility guarantees or semantic versioning. It is not suitable for production usage.

Do not use it. You have been warned.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id:, target:, code:, reason:) ⇒ Payload

Returns a new instance of Payload.

Parameters:

  • id (String)

    The payload ID

  • target (Integer)

    The target

  • code (String)

    The intent code (IntentCode)

  • reason (String)

    The reason



345
346
347
348
349
350
# File 'lib/ldclient-rb/interfaces/data_system.rb', line 345

def initialize(id:, target:, code:, reason:)
  @id = id
  @target = target
  @code = code
  @reason = reason
end

Instance Attribute Details

#codeString (readonly)

Returns The intent code (IntentCode).

Returns:



334
335
336
# File 'lib/ldclient-rb/interfaces/data_system.rb', line 334

def code
  @code
end

#idString (readonly)

Returns The payload ID.

Returns:

  • (String)

    The payload ID



328
329
330
# File 'lib/ldclient-rb/interfaces/data_system.rb', line 328

def id
  @id
end

#reasonString (readonly)

Returns The reason.

Returns:

  • (String)

    The reason



337
338
339
# File 'lib/ldclient-rb/interfaces/data_system.rb', line 337

def reason
  @reason
end

#targetInteger (readonly)

Returns The target.

Returns:

  • (Integer)

    The target



331
332
333
# File 'lib/ldclient-rb/interfaces/data_system.rb', line 331

def target
  @target
end

Class Method Details

.from_h(data) ⇒ Payload

Deserializes a Payload from a Hash.

Parameters:

  • data (Hash)

    The hash representation

Returns:

Raises:

  • (ArgumentError)

    if required fields are missing or invalid



373
374
375
376
377
378
379
380
381
382
383
384
# File 'lib/ldclient-rb/interfaces/data_system.rb', line 373

def self.from_h(data)
  intent_code = data['intentCode'] || data[:intentCode]

  raise ArgumentError, "Invalid data for Payload: 'intentCode' key is missing or not a string" if intent_code.nil? || !intent_code.is_a?(String)

  Payload.new(
    id: data['id'] || data[:id] || "",
    target: data['target'] || data[:target] || 0,
    code: intent_code,
    reason: data['reason'] || data[:reason] || ""
  )
end

Instance Method Details

#to_hHash

Serializes the Payload to a Hash.

Returns:

  • (Hash)


357
358
359
360
361
362
363
364
# File 'lib/ldclient-rb/interfaces/data_system.rb', line 357

def to_h
  {
    id: @id,
    target: @target,
    intentCode: @code,
    reason: @reason,
  }
end