Class: Courier::Lists::List

Inherits:
Object
  • Object
show all
Defined in:
lib/trycourier/lists/types/list.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id:, name:, created: nil, updated: nil, additional_properties: nil) ⇒ Lists::List

Parameters:

  • id (String)
  • name (String)
  • created (Integer) (defaults to: nil)
  • updated (Integer) (defaults to: nil)
  • additional_properties (OpenStruct) (defaults to: nil)

    Additional properties unmapped to the current class definition



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/trycourier/lists/types/list.rb', line 16

def initialize(id:, name:, created: nil, updated: nil, additional_properties: nil)
  # @type [String]
  @id = id
  # @type [String]
  @name = name
  # @type [Integer]
  @created = created
  # @type [Integer]
  @updated = updated
  # @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.



8
9
10
# File 'lib/trycourier/lists/types/list.rb', line 8

def additional_properties
  @additional_properties
end

#createdObject (readonly)

Returns the value of attribute created.



8
9
10
# File 'lib/trycourier/lists/types/list.rb', line 8

def created
  @created
end

#idObject (readonly)

Returns the value of attribute id.



8
9
10
# File 'lib/trycourier/lists/types/list.rb', line 8

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name.



8
9
10
# File 'lib/trycourier/lists/types/list.rb', line 8

def name
  @name
end

#updatedObject (readonly)

Returns the value of attribute updated.



8
9
10
# File 'lib/trycourier/lists/types/list.rb', line 8

def updated
  @updated
end

Class Method Details

.from_json(json_object:) ⇒ Lists::List

Deserialize a JSON object to an instance of List

Parameters:

  • json_object (JSON)

Returns:



33
34
35
36
37
38
39
40
41
# File 'lib/trycourier/lists/types/list.rb', line 33

def self.from_json(json_object:)
  struct = JSON.parse(json_object, object_class: OpenStruct)
  JSON.parse(json_object)
  id = struct.id
  name = struct.name
  created = struct.created
  updated = struct.updated
  new(id: id, name: name, created: created, updated: updated, 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)


54
55
56
57
58
59
# File 'lib/trycourier/lists/types/list.rb', line 54

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.")
  obj.created&.is_a?(Integer) != false || raise("Passed value for field obj.created is not the expected type, validation failed.")
  obj.updated&.is_a?(Integer) != false || raise("Passed value for field obj.updated is not the expected type, validation failed.")
end

Instance Method Details

#to_json(*_args) ⇒ JSON

Serialize an instance of List to a JSON object

Returns:

  • (JSON)


46
47
48
# File 'lib/trycourier/lists/types/list.rb', line 46

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