Class: ApiReference::Item
- Defined in:
- lib/api_reference/models/item.rb
Overview
The Item resource represents a sellable product or good. Items are associated with all line items, billable metrics, and prices and are used for defining external sync behavior for invoices and tax calculation purposes.
Instance Attribute Summary collapse
-
#archived_at ⇒ DateTime
The time at which the item was archived.
-
#created_at ⇒ DateTime
The time at which the item was created.
-
#external_connections ⇒ Array[ItemExternalConnection]
A list of external connections for this item, used to sync with external invoicing and tax systems.
-
#id ⇒ String
The Orb-assigned unique identifier for the item.
-
#metadata ⇒ Hash[String, String]
User specified key-value pairs for the resource.
-
#name ⇒ String
The name of the item.
Class Method Summary collapse
-
.from_hash(hash) ⇒ Object
Creates an instance of the object from a hash.
-
.names ⇒ Object
A mapping from model property names to API property names.
-
.nullables ⇒ Object
An array for nullable fields.
-
.optionals ⇒ Object
An array for optional fields.
Instance Method Summary collapse
-
#initialize(metadata:, id:, name:, created_at:, external_connections:, archived_at: SKIP, additional_properties: nil) ⇒ Item
constructor
A new instance of Item.
-
#inspect ⇒ Object
Provides a debugging-friendly string with detailed object information.
- #to_custom_archived_at ⇒ Object
- #to_custom_created_at ⇒ Object
-
#to_s ⇒ Object
Provides a human-readable string representation of the object.
Methods inherited from BaseModel
#check_for_conflict, #process_additional_properties, #process_array, #process_basic_value, #process_hash, #to_hash, #to_json
Constructor Details
#initialize(metadata:, id:, name:, created_at:, external_connections:, archived_at: SKIP, additional_properties: nil) ⇒ Item
Returns a new instance of Item.
71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/api_reference/models/item.rb', line 71 def initialize(metadata:, id:, name:, created_at:, external_connections:, archived_at: SKIP, additional_properties: nil) # Add additional model properties to the instance additional_properties = {} if additional_properties.nil? @metadata = @id = id @name = name @created_at = created_at @external_connections = external_connections @archived_at = archived_at unless archived_at == SKIP @additional_properties = additional_properties end |
Instance Attribute Details
#archived_at ⇒ DateTime
The time at which the item was archived. If null, the item is not archived.
43 44 45 |
# File 'lib/api_reference/models/item.rb', line 43 def archived_at @archived_at end |
#created_at ⇒ DateTime
The time at which the item was created.
33 34 35 |
# File 'lib/api_reference/models/item.rb', line 33 def created_at @created_at end |
#external_connections ⇒ Array[ItemExternalConnection]
A list of external connections for this item, used to sync with external invoicing and tax systems.
38 39 40 |
# File 'lib/api_reference/models/item.rb', line 38 def external_connections @external_connections end |
#id ⇒ String
The Orb-assigned unique identifier for the item.
25 26 27 |
# File 'lib/api_reference/models/item.rb', line 25 def id @id end |
#metadata ⇒ Hash[String, String]
User specified key-value pairs for the resource. If not present, this
defaults to an empty dictionary. Individual keys can be removed by setting
the value to null, and the entire metadata mapping can be cleared by
setting metadata to null.
21 22 23 |
# File 'lib/api_reference/models/item.rb', line 21 def @metadata end |
#name ⇒ String
The name of the item.
29 30 31 |
# File 'lib/api_reference/models/item.rb', line 29 def name @name end |
Class Method Details
.from_hash(hash) ⇒ Object
Creates an instance of the object from a hash.
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 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/api_reference/models/item.rb', line 86 def self.from_hash(hash) return nil unless hash # Extract variables from the hash. = hash.key?('metadata') ? hash['metadata'] : nil id = hash.key?('id') ? hash['id'] : nil name = hash.key?('name') ? hash['name'] : nil created_at = if hash.key?('created_at') (DateTimeHelper.from_rfc3339(hash['created_at']) if hash['created_at']) end # Parameter is an array, so we need to iterate through it external_connections = nil unless hash['external_connections'].nil? external_connections = [] hash['external_connections'].each do |structure| external_connections << (ItemExternalConnection.from_hash(structure) if structure) end end external_connections = nil unless hash.key?('external_connections') archived_at = if hash.key?('archived_at') (DateTimeHelper.from_rfc3339(hash['archived_at']) if hash['archived_at']) else SKIP end # Create a new hash for additional properties, removing known properties. new_hash = hash.reject { |k, _| names.value?(k) } additional_properties = APIHelper.get_additional_properties( new_hash, proc { |value| value } ) # Create object from extracted values. Item.new(metadata: , id: id, name: name, created_at: created_at, external_connections: external_connections, archived_at: archived_at, additional_properties: additional_properties) end |
.names ⇒ Object
A mapping from model property names to API property names.
46 47 48 49 50 51 52 53 54 55 |
# File 'lib/api_reference/models/item.rb', line 46 def self.names @_hash = {} if @_hash.nil? @_hash['metadata'] = 'metadata' @_hash['id'] = 'id' @_hash['name'] = 'name' @_hash['created_at'] = 'created_at' @_hash['external_connections'] = 'external_connections' @_hash['archived_at'] = 'archived_at' @_hash end |
.nullables ⇒ Object
An array for nullable fields
65 66 67 68 69 |
# File 'lib/api_reference/models/item.rb', line 65 def self.nullables %w[ archived_at ] end |
.optionals ⇒ Object
An array for optional fields
58 59 60 61 62 |
# File 'lib/api_reference/models/item.rb', line 58 def self.optionals %w[ archived_at ] end |
Instance Method Details
#inspect ⇒ Object
Provides a debugging-friendly string with detailed object information.
146 147 148 149 150 151 152 |
# File 'lib/api_reference/models/item.rb', line 146 def inspect class_name = self.class.name.split('::').last "<#{class_name} metadata: #{@metadata.inspect}, id: #{@id.inspect}, name: #{@name.inspect},"\ " created_at: #{@created_at.inspect}, external_connections:"\ " #{@external_connections.inspect}, archived_at: #{@archived_at.inspect},"\ " additional_properties: #{@additional_properties}>" end |
#to_custom_archived_at ⇒ Object
133 134 135 |
# File 'lib/api_reference/models/item.rb', line 133 def to_custom_archived_at DateTimeHelper.to_rfc3339(archived_at) end |
#to_custom_created_at ⇒ Object
129 130 131 |
# File 'lib/api_reference/models/item.rb', line 129 def to_custom_created_at DateTimeHelper.to_rfc3339(created_at) end |
#to_s ⇒ Object
Provides a human-readable string representation of the object.
138 139 140 141 142 143 |
# File 'lib/api_reference/models/item.rb', line 138 def to_s class_name = self.class.name.split('::').last "<#{class_name} metadata: #{@metadata}, id: #{@id}, name: #{@name}, created_at:"\ " #{@created_at}, external_connections: #{@external_connections}, archived_at:"\ " #{@archived_at}, additional_properties: #{@additional_properties}>" end |