Class: Courier::Send::RoutingStrategyProvider

Inherits:
Object
  • Object
show all
Defined in:
lib/trycourier/send/types/routing_strategy_provider.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, metadata:, config: nil, if_: nil, additional_properties: nil) ⇒ Send::RoutingStrategyProvider

Parameters:

  • name (String)
  • config (Hash{String => String}) (defaults to: nil)
  • if_ (String) (defaults to: nil)
  • metadata (Send::Metadata)
  • additional_properties (OpenStruct) (defaults to: nil)

    Additional properties unmapped to the current class definition



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/trycourier/send/types/routing_strategy_provider.rb', line 17

def initialize(name:, metadata:, config: nil, if_: nil, additional_properties: nil)
  # @type [String]
  @name = name
  # @type [Hash{String => String}]
  @config = config
  # @type [String]
  @if_ = if_
  # @type [Send::Metadata]
  @metadata = 
  # @type [OpenStruct] Additional properties unmapped to the current class definition
  @additional_properties = additional_properties
end

Instance Attribute Details

#additional_propertiesObject (readonly)

Returns the value of attribute additional_properties.



9
10
11
# File 'lib/trycourier/send/types/routing_strategy_provider.rb', line 9

def additional_properties
  @additional_properties
end

#configObject (readonly)

Returns the value of attribute config.



9
10
11
# File 'lib/trycourier/send/types/routing_strategy_provider.rb', line 9

def config
  @config
end

#if_Object (readonly)

Returns the value of attribute if_.



9
10
11
# File 'lib/trycourier/send/types/routing_strategy_provider.rb', line 9

def if_
  @if_
end

#metadataObject (readonly)

Returns the value of attribute metadata.



9
10
11
# File 'lib/trycourier/send/types/routing_strategy_provider.rb', line 9

def 
  @metadata
end

#nameObject (readonly)

Returns the value of attribute name.



9
10
11
# File 'lib/trycourier/send/types/routing_strategy_provider.rb', line 9

def name
  @name
end

Class Method Details

.from_json(json_object:) ⇒ Send::RoutingStrategyProvider

Deserialize a JSON object to an instance of RoutingStrategyProvider

Parameters:

  • json_object (JSON)

Returns:



34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/trycourier/send/types/routing_strategy_provider.rb', line 34

def self.from_json(json_object:)
  struct = JSON.parse(json_object, object_class: OpenStruct)
  parsed_json = JSON.parse(json_object)
  name = struct.name
  config = struct.config
  if_ = struct.if
  if parsed_json["metadata"].nil?
     = nil
  else
     = parsed_json["metadata"].to_json
     = Send::Metadata.from_json(json_object: )
  end
  new(name: name, config: config, if_: if_, metadata: , 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)


60
61
62
63
64
65
# File 'lib/trycourier/send/types/routing_strategy_provider.rb', line 60

def self.validate_raw(obj:)
  obj.name.is_a?(String) != false || raise("Passed value for field obj.name is not the expected type, validation failed.")
  obj.config&.is_a?(Hash) != false || raise("Passed value for field obj.config is not the expected type, validation failed.")
  obj.if_&.is_a?(String) != false || raise("Passed value for field obj.if_ is not the expected type, validation failed.")
  Send::Metadata.validate_raw(obj: obj.)
end

Instance Method Details

#to_json(*_args) ⇒ JSON

Serialize an instance of RoutingStrategyProvider to a JSON object

Returns:

  • (JSON)


52
53
54
# File 'lib/trycourier/send/types/routing_strategy_provider.rb', line 52

def to_json(*_args)
  { "name": @name, "config": @config, "if": @if_, "metadata": @metadata }.to_json
end