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:, image_url:, subtitle: OMIT, buttons: OMIT, card_style: OMIT, additional_properties: nil) ⇒ Pinnacle::Card

Parameters:

  • title (String)

    The title of the card

  • subtitle (String) (defaults to: OMIT)

    The subtitle of the card

  • image_url (String)

    The URL of the image to be displayed on the card

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

    Array of buttons attached to the card. Maximum of 4 buttons.

  • card_style (Pinnacle::CardStyle) (defaults to: OMIT)

    The style of the card

  • additional_properties (OpenStruct) (defaults to: nil)

    Additional properties unmapped to the current class definition



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/rcs/types/card.rb', line 35

def initialize(title:, image_url:, subtitle: OMIT, buttons: OMIT, card_style: OMIT, additional_properties: nil)
  @title = title
  @subtitle = subtitle if subtitle != OMIT
  @image_url = image_url
  @buttons = buttons if buttons != OMIT
  @card_style = card_style if card_style != OMIT
  @additional_properties = additional_properties
  @_field_set = {
    "title": title,
    "subtitle": subtitle,
    "image_url": image_url,
    "buttons": buttons,
    "card_style": card_style
  }.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



21
22
23
# File 'lib/rcs/types/card.rb', line 21

def additional_properties
  @additional_properties
end

#buttonsArray<Pinnacle::Action> (readonly)

Returns Array of buttons attached to the card. Maximum of 4 buttons.

Returns:

  • (Array<Pinnacle::Action>)

    Array of buttons attached to the card. Maximum of 4 buttons.



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

def buttons
  @buttons
end

#card_stylePinnacle::CardStyle (readonly)

Returns The style of the card.

Returns:



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

def card_style
  @card_style
end

#image_urlString (readonly)

Returns The URL of the image to be displayed on the card.

Returns:

  • (String)

    The URL of the image to be displayed on the card



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

def image_url
  @image_url
end

#subtitleString (readonly)

Returns The subtitle of the card.

Returns:

  • (String)

    The subtitle of the card



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

def subtitle
  @subtitle
end

#titleString (readonly)

Returns The title of the card.

Returns:

  • (String)

    The title of the card



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

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:



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/rcs/types/card.rb', line 57

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"]
  image_url = parsed_json["image_url"]
  buttons = parsed_json["buttons"]&.map do |item|
    item = item.to_json
    Pinnacle::Action.from_json(json_object: item)
  end
  if parsed_json["card_style"].nil?
    card_style = nil
  else
    card_style = parsed_json["card_style"].to_json
    card_style = Pinnacle::CardStyle.from_json(json_object: card_style)
  end
  new(
    title: title,
    subtitle: subtitle,
    image_url: image_url,
    buttons: buttons,
    card_style: card_style,
    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)


96
97
98
99
100
101
102
# File 'lib/rcs/types/card.rb', line 96

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.image_url.is_a?(String) != false || raise("Passed value for field obj.image_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.")
  obj.card_style.nil? || Pinnacle::CardStyle.validate_raw(obj: obj.card_style)
end

Instance Method Details

#to_json(*_args) ⇒ String

Serialize an instance of Card to a JSON object

Returns:

  • (String)


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

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