Class: Pinnacle::Sms

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

Constant Summary collapse

OMIT =
Object.new

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message_type:, message:, phone_number: OMIT, additional_properties: nil) ⇒ Pinnacle::Sms

Parameters:

  • phone_number (String) (defaults to: OMIT)

    Phone number to send the SMS message to

  • message_type (String)

    The type of message being sent

  • message (Pinnacle::SmsMessage)

    The content of the message

  • additional_properties (OpenStruct) (defaults to: nil)

    Additional properties unmapped to the current class definition



28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/rcs/types/sms.rb', line 28

def initialize(message_type:, message:, phone_number: OMIT, additional_properties: nil)
  @phone_number = phone_number if phone_number != OMIT
  @message_type = message_type
  @message = message
  @additional_properties = additional_properties
  @_field_set = {
    "phone_number": phone_number,
    "message_type": message_type,
    "message": message
  }.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



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

def additional_properties
  @additional_properties
end

#messagePinnacle::SmsMessage (readonly)

Returns The content of the message.

Returns:



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

def message
  @message
end

#message_typeString (readonly)

Returns The type of message being sent.

Returns:

  • (String)

    The type of message being sent



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

def message_type
  @message_type
end

#phone_numberString (readonly)

Returns Phone number to send the SMS message to.

Returns:

  • (String)

    Phone number to send the SMS message to



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

def phone_number
  @phone_number
end

Class Method Details

.from_json(json_object:) ⇒ Pinnacle::Sms

Deserialize a JSON object to an instance of Sms

Parameters:

  • json_object (String)

Returns:



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/rcs/types/sms.rb', line 46

def self.from_json(json_object:)
  struct = JSON.parse(json_object, object_class: OpenStruct)
  parsed_json = JSON.parse(json_object)
  phone_number = parsed_json["phone_number"]
  message_type = parsed_json["message_type"]
  if parsed_json["message"].nil?
    message = nil
  else
    message = parsed_json["message"].to_json
    message = Pinnacle::SmsMessage.from_json(json_object: message)
  end
  new(
    phone_number: phone_number,
    message_type: message_type,
    message: message,
    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)


78
79
80
81
82
# File 'lib/rcs/types/sms.rb', line 78

def self.validate_raw(obj:)
  obj.phone_number&.is_a?(String) != false || raise("Passed value for field obj.phone_number is not the expected type, validation failed.")
  obj.message_type.is_a?(String) != false || raise("Passed value for field obj.message_type is not the expected type, validation failed.")
  Pinnacle::SmsMessage.validate_raw(obj: obj.message)
end

Instance Method Details

#to_json(*_args) ⇒ String

Serialize an instance of Sms to a JSON object

Returns:

  • (String)


68
69
70
# File 'lib/rcs/types/sms.rb', line 68

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