Class: Courier::Send::BaseMessage
- Inherits:
-
Object
- Object
- Courier::Send::BaseMessage
- Defined in:
- lib/trycourier/send/types/base_message.rb
Instance Attribute Summary collapse
-
#additional_properties ⇒ Object
readonly
Returns the value of attribute additional_properties.
-
#brand_id ⇒ Object
readonly
Returns the value of attribute brand_id.
-
#channels ⇒ Object
readonly
Returns the value of attribute channels.
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#delay ⇒ Object
readonly
Returns the value of attribute delay.
-
#expiry ⇒ Object
readonly
Returns the value of attribute expiry.
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
-
#providers ⇒ Object
readonly
Returns the value of attribute providers.
-
#routing ⇒ Object
readonly
Returns the value of attribute routing.
-
#timeout ⇒ Object
readonly
Returns the value of attribute timeout.
Class Method Summary collapse
-
.from_json(json_object:) ⇒ Send::BaseMessage
Deserialize a JSON object to an instance of BaseMessage.
-
.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.
Instance Method Summary collapse
- #initialize(data: nil, brand_id: nil, channels: nil, context: nil, metadata: nil, providers: nil, routing: nil, timeout: nil, delay: nil, expiry: nil, additional_properties: nil) ⇒ Send::BaseMessage constructor
-
#to_json(*_args) ⇒ JSON
Serialize an instance of BaseMessage to a JSON object.
Constructor Details
#initialize(data: nil, brand_id: nil, channels: nil, context: nil, metadata: nil, providers: nil, routing: nil, timeout: nil, delay: nil, expiry: nil, additional_properties: nil) ⇒ Send::BaseMessage
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/trycourier/send/types/base_message.rb', line 34 def initialize(data: nil, brand_id: nil, channels: nil, context: nil, metadata: nil, providers: nil, routing: nil, timeout: nil, delay: nil, expiry: nil, additional_properties: nil) # @type [Send::MESSAGE_DATA] An arbitrary object that includes any data you want to pass to the message. # The data will populate the corresponding template or elements variables. @data = data # @type [String] @brand_id = brand_id # @type [Send::MESSAGE_CHANNELS] "Define run-time configuration for one or more channels. If you don't specify channels, the default configuration for each channel will be used. Valid ChannelId's are: email, sms, push, inbox, direct_message, banner, and webhook." @channels = channels # @type [Send::MessageContext] Context to load with this recipient. Will override any context set on message.context. @context = context # @type [Send::MessageMetadata] Metadata such as utm tracking attached with the notification through this channel. @metadata = # @type [Send::MESSAGE_PROVIDERS] An object whose keys are valid provider identifiers which map to an object. @providers = providers # @type [Send::Routing] @routing = routing # @type [Send::Timeout] Time in ms to attempt the channel before failing over to the next available channel. @timeout = timeout # @type [Send::Delay] Defines the time to wait before delivering the message. @delay = delay # @type [Send::Expiry] "Expiry allows you to set an absolute or relative time in which a message expires. # Note: This is only valid for the Courier Inbox channel as of 12-08-2022." @expiry = expiry # @type [OpenStruct] Additional properties unmapped to the current class definition @additional_properties = additional_properties end |
Instance Attribute Details
#additional_properties ⇒ Object (readonly)
Returns the value of attribute additional_properties.
17 18 19 |
# File 'lib/trycourier/send/types/base_message.rb', line 17 def additional_properties @additional_properties end |
#brand_id ⇒ Object (readonly)
Returns the value of attribute brand_id.
17 18 19 |
# File 'lib/trycourier/send/types/base_message.rb', line 17 def brand_id @brand_id end |
#channels ⇒ Object (readonly)
Returns the value of attribute channels.
17 18 19 |
# File 'lib/trycourier/send/types/base_message.rb', line 17 def channels @channels end |
#context ⇒ Object (readonly)
Returns the value of attribute context.
17 18 19 |
# File 'lib/trycourier/send/types/base_message.rb', line 17 def context @context end |
#data ⇒ Object (readonly)
Returns the value of attribute data.
17 18 19 |
# File 'lib/trycourier/send/types/base_message.rb', line 17 def data @data end |
#delay ⇒ Object (readonly)
Returns the value of attribute delay.
17 18 19 |
# File 'lib/trycourier/send/types/base_message.rb', line 17 def delay @delay end |
#expiry ⇒ Object (readonly)
Returns the value of attribute expiry.
17 18 19 |
# File 'lib/trycourier/send/types/base_message.rb', line 17 def expiry @expiry end |
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
17 18 19 |
# File 'lib/trycourier/send/types/base_message.rb', line 17 def @metadata end |
#providers ⇒ Object (readonly)
Returns the value of attribute providers.
17 18 19 |
# File 'lib/trycourier/send/types/base_message.rb', line 17 def providers @providers end |
#routing ⇒ Object (readonly)
Returns the value of attribute routing.
17 18 19 |
# File 'lib/trycourier/send/types/base_message.rb', line 17 def routing @routing end |
#timeout ⇒ Object (readonly)
Returns the value of attribute timeout.
17 18 19 |
# File 'lib/trycourier/send/types/base_message.rb', line 17 def timeout @timeout end |
Class Method Details
.from_json(json_object:) ⇒ Send::BaseMessage
Deserialize a JSON object to an instance of BaseMessage
66 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 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/trycourier/send/types/base_message.rb', line 66 def self.from_json(json_object:) struct = JSON.parse(json_object, object_class: OpenStruct) parsed_json = JSON.parse(json_object) data = struct.data brand_id = struct.brand_id channels = struct.channels if parsed_json["context"].nil? context = nil else context = parsed_json["context"].to_json context = Send::MessageContext.from_json(json_object: context) end if parsed_json["metadata"].nil? = nil else = parsed_json["metadata"].to_json = Send::MessageMetadata.from_json(json_object: ) end providers = struct.providers if parsed_json["routing"].nil? routing = nil else routing = parsed_json["routing"].to_json routing = Send::Routing.from_json(json_object: routing) end if parsed_json["timeout"].nil? timeout = nil else timeout = parsed_json["timeout"].to_json timeout = Send::Timeout.from_json(json_object: timeout) end if parsed_json["delay"].nil? delay = nil else delay = parsed_json["delay"].to_json delay = Send::Delay.from_json(json_object: delay) end if parsed_json["expiry"].nil? expiry = nil else expiry = parsed_json["expiry"].to_json expiry = Send::Expiry.from_json(json_object: expiry) end new(data: data, brand_id: brand_id, channels: channels, context: context, metadata: , providers: providers, routing: routing, timeout: timeout, delay: delay, expiry: expiry, 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.
135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/trycourier/send/types/base_message.rb', line 135 def self.validate_raw(obj:) obj.data&.is_a?(Hash) != false || raise("Passed value for field obj.data is not the expected type, validation failed.") obj.brand_id&.is_a?(String) != false || raise("Passed value for field obj.brand_id is not the expected type, validation failed.") obj.channels&.is_a?(Hash) != false || raise("Passed value for field obj.channels is not the expected type, validation failed.") obj.context.nil? || Send::MessageContext.validate_raw(obj: obj.context) obj..nil? || Send::MessageMetadata.validate_raw(obj: obj.) obj.providers&.is_a?(Hash) != false || raise("Passed value for field obj.providers is not the expected type, validation failed.") obj.routing.nil? || Send::Routing.validate_raw(obj: obj.routing) obj.timeout.nil? || Send::Timeout.validate_raw(obj: obj.timeout) obj.delay.nil? || Send::Delay.validate_raw(obj: obj.delay) obj.expiry.nil? || Send::Expiry.validate_raw(obj: obj.expiry) end |
Instance Method Details
#to_json(*_args) ⇒ JSON
Serialize an instance of BaseMessage to a JSON object
116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/trycourier/send/types/base_message.rb', line 116 def to_json(*_args) { "data": @data, "brand_id": @brand_id, "channels": @channels, "context": @context, "metadata": @metadata, "providers": @providers, "routing": @routing, "timeout": @timeout, "delay": @delay, "expiry": @expiry }.to_json end |