Class: Pinnacle::Action

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

Constant Summary collapse

OMIT =
Object.new

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(title: OMIT, type: OMIT, payload: OMIT, metadata: OMIT, event_start_time: OMIT, event_end_time: OMIT, event_title: OMIT, event_description: OMIT, lat_long: OMIT, additional_properties: nil) ⇒ Pinnacle::Action

Parameters:

  • title (String) (defaults to: OMIT)

    Title of the action (must be less than 25 characters).

  • type (Pinnacle::ActionType) (defaults to: OMIT)

    Type of action for the button. ‘openUrl’ opens a URL, ‘call’ dials a phone number, ‘trigger’ sends the predefined payload to the webhook when pressed, ‘requestUserLocation’ requests the user’s location, ‘scheduleEvent’ creates a calendar event, ‘sendLocation’ sends a location.

  • payload (String) (defaults to: OMIT)

    Optional payload associated with the action. This payload encodes the respective fields for the action type and is required. For ‘openUrl’, the payload is the URL to open. For ‘call’, the payload is the phone number to dial. For ‘trigger’, the payload is the predefined payload to send to the webhook.

  • metadata (String) (defaults to: OMIT)

    Optional metadata. Only used for type ‘trigger’ ignored for other action types. When the user presses the action, the metadata is sent to the webhook alongside the payload.

  • event_start_time (String) (defaults to: OMIT)

    Start time for events in ISO 8601 format. For example, ‘2022-01-01T12:00:00Z’. Required for ‘scheduleEvent’.

  • event_end_time (String) (defaults to: OMIT)

    End time for events in ISO 8601 format. For example, ‘2022-01-01T12:00:00Z’. Required for ‘scheduleEvent’.

  • event_title (String) (defaults to: OMIT)

    Event title. Required for ‘scheduleEvent’.

  • event_description (String) (defaults to: OMIT)

    Optional event description.

  • lat_long (Pinnacle::ActionLatLong) (defaults to: OMIT)

    Latitude and longitude coordinates. Required for ‘sendLocation’.

  • additional_properties (OpenStruct) (defaults to: nil)

    Additional properties unmapped to the current class definition



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/rcs/types/action.rb', line 67

def initialize(title: OMIT, type: OMIT, payload: OMIT, metadata: OMIT, event_start_time: OMIT,
               event_end_time: OMIT, event_title: OMIT, event_description: OMIT, lat_long: OMIT, additional_properties: nil)
  @title = title if title != OMIT
  @type = type if type != OMIT
  @payload = payload if payload != OMIT
  @metadata =  if  != OMIT
  @event_start_time = event_start_time if event_start_time != OMIT
  @event_end_time = event_end_time if event_end_time != OMIT
  @event_title = event_title if event_title != OMIT
  @event_description = event_description if event_description != OMIT
  @lat_long = lat_long if lat_long != OMIT
  @additional_properties = additional_properties
  @_field_set = {
    "title": title,
    "type": type,
    "payload": payload,
    "metadata": ,
    "eventStartTime": event_start_time,
    "eventEndTime": event_end_time,
    "eventTitle": event_title,
    "eventDescription": event_description,
    "latLong": lat_long
  }.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



39
40
41
# File 'lib/rcs/types/action.rb', line 39

def additional_properties
  @additional_properties
end

#event_descriptionString (readonly)

Returns Optional event description.

Returns:

  • (String)

    Optional event description.



35
36
37
# File 'lib/rcs/types/action.rb', line 35

def event_description
  @event_description
end

#event_end_timeString (readonly)

Returns End time for events in ISO 8601 format. For example, ‘2022-01-01T12:00:00Z’. Required for ‘scheduleEvent’.

Returns:

  • (String)

    End time for events in ISO 8601 format. For example, ‘2022-01-01T12:00:00Z’. Required for ‘scheduleEvent’.



31
32
33
# File 'lib/rcs/types/action.rb', line 31

def event_end_time
  @event_end_time
end

#event_start_timeString (readonly)

Returns Start time for events in ISO 8601 format. For example, ‘2022-01-01T12:00:00Z’. Required for ‘scheduleEvent’.

Returns:

  • (String)

    Start time for events in ISO 8601 format. For example, ‘2022-01-01T12:00:00Z’. Required for ‘scheduleEvent’.



28
29
30
# File 'lib/rcs/types/action.rb', line 28

def event_start_time
  @event_start_time
end

#event_titleString (readonly)

Returns Event title. Required for ‘scheduleEvent’.

Returns:

  • (String)

    Event title. Required for ‘scheduleEvent’.



33
34
35
# File 'lib/rcs/types/action.rb', line 33

def event_title
  @event_title
end

#lat_longPinnacle::ActionLatLong (readonly)

Returns Latitude and longitude coordinates. Required for ‘sendLocation’.

Returns:



37
38
39
# File 'lib/rcs/types/action.rb', line 37

def lat_long
  @lat_long
end

#metadataString (readonly)

Returns Optional metadata. Only used for type ‘trigger’ ignored for other action types. When the user presses the action, the metadata is sent to the webhook alongside the payload.

Returns:

  • (String)

    Optional metadata. Only used for type ‘trigger’ ignored for other action types. When the user presses the action, the metadata is sent to the webhook alongside the payload.



25
26
27
# File 'lib/rcs/types/action.rb', line 25

def 
  @metadata
end

#payloadString (readonly)

Returns Optional payload associated with the action. This payload encodes the respective fields for the action type and is required. For ‘openUrl’, the payload is the URL to open. For ‘call’, the payload is the phone number to dial. For ‘trigger’, the payload is the predefined payload to send to the webhook.

Returns:

  • (String)

    Optional payload associated with the action. This payload encodes the respective fields for the action type and is required. For ‘openUrl’, the payload is the URL to open. For ‘call’, the payload is the phone number to dial. For ‘trigger’, the payload is the predefined payload to send to the webhook.



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

def payload
  @payload
end

#titleString (readonly)

Returns Title of the action (must be less than 25 characters).

Returns:

  • (String)

    Title of the action (must be less than 25 characters).



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

def title
  @title
end

#typePinnacle::ActionType (readonly)

Returns Type of action for the button. ‘openUrl’ opens a URL, ‘call’ dials a phone number, ‘trigger’ sends the predefined payload to the webhook when pressed, ‘requestUserLocation’ requests the user’s location, ‘scheduleEvent’ creates a calendar event, ‘sendLocation’ sends a location.

Returns:

  • (Pinnacle::ActionType)

    Type of action for the button. ‘openUrl’ opens a URL, ‘call’ dials a phone number, ‘trigger’ sends the predefined payload to the webhook when pressed, ‘requestUserLocation’ requests the user’s location, ‘scheduleEvent’ creates a calendar event, ‘sendLocation’ sends a location.



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

def type
  @type
end

Class Method Details

.from_json(json_object:) ⇒ Pinnacle::Action

Deserialize a JSON object to an instance of Action

Parameters:

  • json_object (String)

Returns:



98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/rcs/types/action.rb', line 98

def self.from_json(json_object:)
  struct = JSON.parse(json_object, object_class: OpenStruct)
  parsed_json = JSON.parse(json_object)
  title = parsed_json["title"]
  type = parsed_json["type"]
  payload = parsed_json["payload"]
   = parsed_json["metadata"]
  event_start_time = parsed_json["eventStartTime"]
  event_end_time = parsed_json["eventEndTime"]
  event_title = parsed_json["eventTitle"]
  event_description = parsed_json["eventDescription"]
  if parsed_json["latLong"].nil?
    lat_long = nil
  else
    lat_long = parsed_json["latLong"].to_json
    lat_long = Pinnacle::ActionLatLong.from_json(json_object: lat_long)
  end
  new(
    title: title,
    type: type,
    payload: payload,
    metadata: ,
    event_start_time: event_start_time,
    event_end_time: event_end_time,
    event_title: event_title,
    event_description: event_description,
    lat_long: lat_long,
    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)


142
143
144
145
146
147
148
149
150
151
152
# File 'lib/rcs/types/action.rb', line 142

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.type&.is_a?(Pinnacle::ActionType) != false || raise("Passed value for field obj.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.&.is_a?(String) != false || raise("Passed value for field obj.metadata is not the expected type, validation failed.")
  obj.event_start_time&.is_a?(String) != false || raise("Passed value for field obj.event_start_time is not the expected type, validation failed.")
  obj.event_end_time&.is_a?(String) != false || raise("Passed value for field obj.event_end_time is not the expected type, validation failed.")
  obj.event_title&.is_a?(String) != false || raise("Passed value for field obj.event_title is not the expected type, validation failed.")
  obj.event_description&.is_a?(String) != false || raise("Passed value for field obj.event_description is not the expected type, validation failed.")
  obj.lat_long.nil? || Pinnacle::ActionLatLong.validate_raw(obj: obj.lat_long)
end

Instance Method Details

#to_json(*_args) ⇒ String

Serialize an instance of Action to a JSON object

Returns:

  • (String)


132
133
134
# File 'lib/rcs/types/action.rb', line 132

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