Class: Pinnacle::Card

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

Constant Summary collapse

OMIT =
Object.new

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(title:, subtitle: OMIT, media_url: OMIT, buttons: OMIT, additional_properties: nil) ⇒ Pinnacle::Card

Parameters:

  • title (String)

    The title of the card.

  • subtitle (String) (defaults to: OMIT)

    Optional subtitle for the card.

  • media_url (String) (defaults to: OMIT)

    Optional media URL displayed with the card.

  • buttons (Array<Pinnacle::Action>) (defaults to: OMIT)

    Optional list of buttons on the card (max 4).

  • additional_properties (OpenStruct) (defaults to: nil)

    Additional properties unmapped to the current class definition



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/rcs/types/card.rb', line 31

def initialize(title:, subtitle: OMIT, media_url: OMIT, buttons: OMIT, additional_properties: nil)
  @title = title
  @subtitle = subtitle if subtitle != OMIT
  @media_url = media_url if media_url != OMIT
  @buttons = buttons if buttons != OMIT
  @additional_properties = additional_properties
  @_field_set = {
    "title": title,
    "subtitle": subtitle,
    "mediaUrl": media_url,
    "buttons": buttons
  }.reject do |_k, v|
    v == OMIT
  end
end

Instance Attribute Details

#additional_propertiesOpenStruct (readonly)

Returns Additional properties unmapped to the current class definition.

Returns:

  • (OpenStruct)

    Additional properties unmapped to the current class definition



18
19
20
# File 'lib/rcs/types/card.rb', line 18

def additional_properties
  @additional_properties
end

#buttonsArray<Pinnacle::Action> (readonly)

Returns Optional list of buttons on the card (max 4).

Returns:



16
17
18
# File 'lib/rcs/types/card.rb', line 16

def buttons
  @buttons
end

#media_urlString (readonly)

Returns Optional media URL displayed with the card.

Returns:

  • (String)

    Optional media URL displayed with the card.



14
15
16
# File 'lib/rcs/types/card.rb', line 14

def media_url
  @media_url
end

#subtitleString (readonly)

Returns Optional subtitle for the card.

Returns:

  • (String)

    Optional subtitle for the card.



12
13
14
# File 'lib/rcs/types/card.rb', line 12

def subtitle
  @subtitle
end

#titleString (readonly)

Returns The title of the card.

Returns:

  • (String)

    The title of the card.



10
11
12
# File 'lib/rcs/types/card.rb', line 10

def title
  @title
end

Class Method Details

.from_json(json_object:) ⇒ Pinnacle::Card

Deserialize a JSON object to an instance of Card

Parameters:

  • json_object (String)

Returns:



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/rcs/types/card.rb', line 51

def self.from_json(json_object:)
  struct = JSON.parse(json_object, object_class: OpenStruct)
  parsed_json = JSON.parse(json_object)
  title = parsed_json["title"]
  subtitle = parsed_json["subtitle"]
  media_url = parsed_json["mediaUrl"]
  buttons = parsed_json["buttons"]&.map do |item|
    item = item.to_json
    Pinnacle::Action.from_json(json_object: item)
  end
  new(
    title: title,
    subtitle: subtitle,
    media_url: media_url,
    buttons: buttons,
    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)


83
84
85
86
87
88
# File 'lib/rcs/types/card.rb', line 83

def self.validate_raw(obj:)
  obj.title.is_a?(String) != false || raise("Passed value for field obj.title is not the expected type, validation failed.")
  obj.subtitle&.is_a?(String) != false || raise("Passed value for field obj.subtitle is not the expected type, validation failed.")
  obj.media_url&.is_a?(String) != false || raise("Passed value for field obj.media_url is not the expected type, validation failed.")
  obj.buttons&.is_a?(Array) != false || raise("Passed value for field obj.buttons is not the expected type, validation failed.")
end

Instance Method Details

#to_json(*_args) ⇒ String

Serialize an instance of Card to a JSON object

Returns:

  • (String)


73
74
75
# File 'lib/rcs/types/card.rb', line 73

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