Class: Courier::Brands::Brand

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(created:, name:, published:, settings:, updated:, version:, id: nil, snippets: nil, additional_properties: nil) ⇒ Brands::Brand

Parameters:

  • created (Integer)

    The date/time of when the brand was created. Represented in milliseconds since Unix epoch.

  • id (String) (defaults to: nil)

    Brand Identifier

  • name (String)

    Brand name

  • published (Integer)

    The date/time of when the brand was published. Represented in milliseconds since Unix epoch.

  • settings (Brands::BrandSettings)
  • updated (Integer)

    The date/time of when the brand was updated. Represented in milliseconds since Unix epoch.

  • snippets (Brands::BrandSnippets) (defaults to: nil)
  • version (String)

    The version identifier for the brand

  • additional_properties (OpenStruct) (defaults to: nil)

    Additional properties unmapped to the current class definition



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/trycourier/brands/types/brand.rb', line 22

def initialize(created:, name:, published:, settings:, updated:, version:, id: nil, snippets: nil,
               additional_properties: nil)
  # @type [Integer] The date/time of when the brand was created. Represented in milliseconds since Unix epoch.
  @created = created
  # @type [String] Brand Identifier
  @id = id
  # @type [String] Brand name
  @name = name
  # @type [Integer] The date/time of when the brand was published. Represented in milliseconds since Unix epoch.
  @published = published
  # @type [Brands::BrandSettings]
  @settings = settings
  # @type [Integer] The date/time of when the brand was updated. Represented in milliseconds since Unix epoch.
  @updated = updated
  # @type [Brands::BrandSnippets]
  @snippets = snippets
  # @type [String] The version identifier for the brand
  @version = version
  # @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.rb', line 10

def additional_properties
  @additional_properties
end

#createdObject (readonly)

Returns the value of attribute created.



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

def created
  @created
end

#idObject (readonly)

Returns the value of attribute id.



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

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#publishedObject (readonly)

Returns the value of attribute published.



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

def published
  @published
end

#settingsObject (readonly)

Returns the value of attribute settings.



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

def settings
  @settings
end

#snippetsObject (readonly)

Returns the value of attribute snippets.



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

def snippets
  @snippets
end

#updatedObject (readonly)

Returns the value of attribute updated.



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

def updated
  @updated
end

#versionObject (readonly)

Returns the value of attribute version.



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

def version
  @version
end

Class Method Details

.from_json(json_object:) ⇒ Brands::Brand

Deserialize a JSON object to an instance of Brand

Parameters:

  • json_object (JSON)

Returns:



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/trycourier/brands/types/brand.rb', line 48

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


93
94
95
96
97
98
99
100
101
102
# File 'lib/trycourier/brands/types/brand.rb', line 93

def self.validate_raw(obj:)
  obj.created.is_a?(Integer) != false || raise("Passed value for field obj.created is not the expected type, validation failed.")
  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.")
  obj.published.is_a?(Integer) != false || raise("Passed value for field obj.published is not the expected type, validation failed.")
  Brands::BrandSettings.validate_raw(obj: obj.settings)
  obj.updated.is_a?(Integer) != false || raise("Passed value for field obj.updated is not the expected type, validation failed.")
  obj.snippets.nil? || Brands::BrandSnippets.validate_raw(obj: obj.snippets)
  obj.version.is_a?(String) != false || raise("Passed value for field obj.version is not the expected type, validation failed.")
end

Instance Method Details

#to_json(*_args) ⇒ JSON

Serialize an instance of Brand to a JSON object

Returns:

  • (JSON)


76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/trycourier/brands/types/brand.rb', line 76

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