Class: Pinnacle::Postback

Inherits:
Object
  • Object
show all
Defined in:
lib/rcs/types/postback.rb

Constant Summary collapse

OMIT =
Object.new

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(action_type:, payload:, execute: OMIT, additional_properties: nil) ⇒ Pinnacle::Postback

Parameters:

  • action_type (String)

    The type of action being sent

  • payload (String)

    The postback payload. Maximum length is 1000 characters.

  • execute (String) (defaults to: OMIT)

    The action to execute. Optional additional data sent when the button is tapped.

  • additional_properties (OpenStruct) (defaults to: nil)

    Additional properties unmapped to the current class definition



27
28
29
30
31
32
33
34
35
# File 'lib/rcs/types/postback.rb', line 27

def initialize(action_type:, payload:, execute: OMIT, additional_properties: nil)
  @action_type = action_type
  @payload = payload
  @execute = execute if execute != OMIT
  @additional_properties = additional_properties
  @_field_set = { "action_type": action_type, "payload": payload, "execute": execute }.reject do |_k, v|
    v == OMIT
  end
end

Instance Attribute Details

#action_typeString (readonly)

Returns The type of action being sent.

Returns:

  • (String)

    The type of action being sent



9
10
11
# File 'lib/rcs/types/postback.rb', line 9

def action_type
  @action_type
end

#additional_propertiesOpenStruct (readonly)

Returns Additional properties unmapped to the current class definition.

Returns:

  • (OpenStruct)

    Additional properties unmapped to the current class definition



15
16
17
# File 'lib/rcs/types/postback.rb', line 15

def additional_properties
  @additional_properties
end

#executeString (readonly)

Returns The action to execute. Optional additional data sent when the button is tapped.

Returns:

  • (String)

    The action to execute. Optional additional data sent when the button is tapped.



13
14
15
# File 'lib/rcs/types/postback.rb', line 13

def execute
  @execute
end

#payloadString (readonly)

Returns The postback payload. Maximum length is 1000 characters.

Returns:

  • (String)

    The postback payload. Maximum length is 1000 characters.



11
12
13
# File 'lib/rcs/types/postback.rb', line 11

def payload
  @payload
end

Class Method Details

.from_json(json_object:) ⇒ Pinnacle::Postback

Deserialize a JSON object to an instance of Postback

Parameters:

  • json_object (String)

Returns:



41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/rcs/types/postback.rb', line 41

def self.from_json(json_object:)
  struct = JSON.parse(json_object, object_class: OpenStruct)
  parsed_json = JSON.parse(json_object)
  action_type = parsed_json["action_type"]
  payload = parsed_json["payload"]
  execute = parsed_json["execute"]
  new(
    action_type: action_type,
    payload: payload,
    execute: execute,
    additional_properties: struct
  )
end

.validate_raw(obj:) ⇒ Void

Leveraged for Union-type generation, validate_raw attempts to parse the given

hash and check each fields type against the current object's property
definitions.

Parameters:

  • obj (Object)

Returns:

  • (Void)


68
69
70
71
72
# File 'lib/rcs/types/postback.rb', line 68

def self.validate_raw(obj:)
  obj.action_type.is_a?(String) != false || raise("Passed value for field obj.action_type is not the expected type, validation failed.")
  obj.payload.is_a?(String) != false || raise("Passed value for field obj.payload is not the expected type, validation failed.")
  obj.execute&.is_a?(String) != false || raise("Passed value for field obj.execute is not the expected type, validation failed.")
end

Instance Method Details

#to_json(*_args) ⇒ String

Serialize an instance of Postback to a JSON object

Returns:

  • (String)


58
59
60
# File 'lib/rcs/types/postback.rb', line 58

def to_json(*_args)
  @_field_set&.to_json
end