Class: Courier::Brands::BrandParameters

Inherits:
Object
  • Object
show all
Defined in:
lib/trycourier/brands/types/brand_parameters.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, settings:, id: nil, snippets: nil, additional_properties: nil) ⇒ Brands::BrandParameters

Parameters:

  • id (String) (defaults to: nil)
  • name (String)

    The name of the brand.

  • settings (Brands::BrandSettings)
  • snippets (Brands::BrandSnippets) (defaults to: nil)
  • additional_properties (OpenStruct) (defaults to: nil)

    Additional properties unmapped to the current class definition



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/trycourier/brands/types/brand_parameters.rb', line 18

def initialize(name:, settings:, id: nil, snippets: nil, additional_properties: nil)
  # @type [String]
  @id = id
  # @type [String] The name of the brand.
  @name = name
  # @type [Brands::BrandSettings]
  @settings = settings
  # @type [Brands::BrandSnippets]
  @snippets = snippets
  # @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.



10
11
12
# File 'lib/trycourier/brands/types/brand_parameters.rb', line 10

def additional_properties
  @additional_properties
end

#idObject (readonly)

Returns the value of attribute id.



10
11
12
# File 'lib/trycourier/brands/types/brand_parameters.rb', line 10

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name.



10
11
12
# File 'lib/trycourier/brands/types/brand_parameters.rb', line 10

def name
  @name
end

#settingsObject (readonly)

Returns the value of attribute settings.



10
11
12
# File 'lib/trycourier/brands/types/brand_parameters.rb', line 10

def settings
  @settings
end

#snippetsObject (readonly)

Returns the value of attribute snippets.



10
11
12
# File 'lib/trycourier/brands/types/brand_parameters.rb', line 10

def snippets
  @snippets
end

Class Method Details

.from_json(json_object:) ⇒ Brands::BrandParameters

Deserialize a JSON object to an instance of BrandParameters

Parameters:

  • json_object (JSON)

Returns:



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/trycourier/brands/types/brand_parameters.rb', line 35

def self.from_json(json_object:)
  struct = JSON.parse(json_object, object_class: OpenStruct)
  parsed_json = JSON.parse(json_object)
  id = struct.id
  name = struct.name
  if parsed_json["settings"].nil?
    settings = nil
  else
    settings = parsed_json["settings"].to_json
    settings = Brands::BrandSettings.from_json(json_object: settings)
  end
  if parsed_json["snippets"].nil?
    snippets = nil
  else
    snippets = parsed_json["snippets"].to_json
    snippets = Brands::BrandSnippets.from_json(json_object: snippets)
  end
  new(id: id, name: name, settings: settings, snippets: snippets, 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)


66
67
68
69
70
71
# File 'lib/trycourier/brands/types/brand_parameters.rb', line 66

def self.validate_raw(obj:)
  obj.id&.is_a?(String) != false || raise("Passed value for field obj.id is not the expected type, validation failed.")
  obj.name.is_a?(String) != false || raise("Passed value for field obj.name is not the expected type, validation failed.")
  Brands::BrandSettings.validate_raw(obj: obj.settings)
  obj.snippets.nil? || Brands::BrandSnippets.validate_raw(obj: obj.snippets)
end

Instance Method Details

#to_json(*_args) ⇒ JSON

Serialize an instance of BrandParameters to a JSON object

Returns:

  • (JSON)


58
59
60
# File 'lib/trycourier/brands/types/brand_parameters.rb', line 58

def to_json(*_args)
  { "id": @id, "name": @name, "settings": @settings, "snippets": @snippets }.to_json
end