square_connect 2.20190710.0.321 → 2.20190724.0.325

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGES.md +5 -0
  3. data/README.md +8 -2
  4. data/docs/CatalogItem.md +2 -1
  5. data/docs/CatalogItemOption.md +17 -0
  6. data/docs/CatalogItemOptionForItem.md +12 -0
  7. data/docs/CatalogItemOptionValue.md +17 -0
  8. data/docs/CatalogItemOptionValueForItemVariation.md +13 -0
  9. data/docs/CatalogItemProductType.md +1 -1
  10. data/docs/CatalogItemVariation.md +1 -0
  11. data/docs/CatalogObject.md +2 -0
  12. data/docs/CatalogObjectType.md +3 -0
  13. data/docs/CatalogQuery.md +2 -0
  14. data/docs/CatalogQueryItemVariationsForItemOptionValues.md +12 -0
  15. data/docs/CatalogQueryItemsForItemOptions.md +12 -0
  16. data/lib/square_connect.rb +6 -0
  17. data/lib/square_connect/api_client.rb +1 -1
  18. data/lib/square_connect/models/catalog_item.rb +17 -5
  19. data/lib/square_connect/models/catalog_item_option.rb +238 -0
  20. data/lib/square_connect/models/catalog_item_option_for_item.rb +186 -0
  21. data/lib/square_connect/models/catalog_item_option_value.rb +236 -0
  22. data/lib/square_connect/models/catalog_item_option_value_for_item_variation.rb +196 -0
  23. data/lib/square_connect/models/catalog_item_variation.rb +13 -1
  24. data/lib/square_connect/models/catalog_object.rb +24 -4
  25. data/lib/square_connect/models/catalog_object_type.rb +3 -0
  26. data/lib/square_connect/models/catalog_query.rb +24 -4
  27. data/lib/square_connect/models/catalog_query_item_variations_for_item_option_values.rb +188 -0
  28. data/lib/square_connect/models/catalog_query_items_for_item_options.rb +188 -0
  29. data/lib/square_connect/version.rb +1 -1
  30. data/spec/models/catalog_item_option_for_item_spec.rb +39 -0
  31. data/spec/models/catalog_item_option_spec.rb +69 -0
  32. data/spec/models/catalog_item_option_value_for_item_variation_spec.rb +45 -0
  33. data/spec/models/catalog_item_option_value_spec.rb +69 -0
  34. data/spec/models/catalog_query_item_variations_for_item_option_values_spec.rb +39 -0
  35. data/spec/models/catalog_query_items_for_item_options_spec.rb +39 -0
  36. metadata +26 -2
@@ -51,6 +51,9 @@ module SquareConnect
51
51
  # If the [CatalogItem](#type-catalogitem) that owns this item variation is of type `APPOINTMENTS_SERVICE`, then this is the duration of the service in milliseconds. For example, a 30 minute appointment would have the value `1800000`, which is equal to 30 (minutes) * 60 (seconds per minute) * 1000 (milliseconds per second).
52
52
  attr_accessor :service_duration
53
53
 
54
+ # List of item option values associated with this item variation. Listed in the same order as the item options of the parent item.
55
+ attr_accessor :item_option_values
56
+
54
57
  # ID of the ‘CatalogMeasurementUnit’ that is used to measure the quantity sold of this item variation. If left unset, the item will be sold in whole quantities.
55
58
  attr_accessor :measurement_unit_id
56
59
 
@@ -71,6 +74,7 @@ module SquareConnect
71
74
  :'inventory_alert_threshold' => :'inventory_alert_threshold',
72
75
  :'user_data' => :'user_data',
73
76
  :'service_duration' => :'service_duration',
77
+ :'item_option_values' => :'item_option_values',
74
78
  :'measurement_unit_id' => :'measurement_unit_id'
75
79
  }
76
80
  end
@@ -91,6 +95,7 @@ module SquareConnect
91
95
  :'inventory_alert_threshold' => :'Integer',
92
96
  :'user_data' => :'String',
93
97
  :'service_duration' => :'Integer',
98
+ :'item_option_values' => :'Array<CatalogItemOptionValueForItemVariation>',
94
99
  :'measurement_unit_id' => :'String'
95
100
  }
96
101
  end
@@ -157,6 +162,12 @@ module SquareConnect
157
162
  self.service_duration = attributes[:'service_duration']
158
163
  end
159
164
 
165
+ if attributes.has_key?(:'item_option_values')
166
+ if (value = attributes[:'item_option_values']).is_a?(Array)
167
+ self.item_option_values = value
168
+ end
169
+ end
170
+
160
171
  if attributes.has_key?(:'measurement_unit_id')
161
172
  self.measurement_unit_id = attributes[:'measurement_unit_id']
162
173
  end
@@ -194,6 +205,7 @@ module SquareConnect
194
205
  inventory_alert_threshold == o.inventory_alert_threshold &&
195
206
  user_data == o.user_data &&
196
207
  service_duration == o.service_duration &&
208
+ item_option_values == o.item_option_values &&
197
209
  measurement_unit_id == o.measurement_unit_id
198
210
  end
199
211
 
@@ -206,7 +218,7 @@ module SquareConnect
206
218
  # Calculates hash code according to all attributes.
207
219
  # @return [Fixnum] Hash code
208
220
  def hash
209
- [item_id, name, sku, upc, ordinal, pricing_type, price_money, location_overrides, track_inventory, inventory_alert_type, inventory_alert_threshold, user_data, service_duration, measurement_unit_id].hash
221
+ [item_id, name, sku, upc, ordinal, pricing_type, price_money, location_overrides, track_inventory, inventory_alert_type, inventory_alert_threshold, user_data, service_duration, item_option_values, measurement_unit_id].hash
210
222
  end
211
223
 
212
224
  # Builds the object from hash
@@ -78,6 +78,12 @@ module SquareConnect
78
78
  # Structured data for a [CatalogMeasurementUnit](#type-catalogmeasurementunit), set for CatalogObjects of type `MEASUREMENT_UNIT`.
79
79
  attr_accessor :measurement_unit_data
80
80
 
81
+ # Structured data for a [CatalogItemOption](#type-catalogitemoption), set for CatalogObjects of type `ITEM_OPTION`.
82
+ attr_accessor :item_option_data
83
+
84
+ # Structured data for a [CatalogItemOptionValue](#type-catalogitemoptionvalue), set for CatalogObjects of type `ITEM_OPTION_VAL`.
85
+ attr_accessor :item_option_value_data
86
+
81
87
 
82
88
  # Attribute mapping from ruby-style variable name to JSON key.
83
89
  def self.attribute_map
@@ -103,7 +109,9 @@ module SquareConnect
103
109
  :'product_set_data' => :'product_set_data',
104
110
  :'pricing_rule_data' => :'pricing_rule_data',
105
111
  :'image_data' => :'image_data',
106
- :'measurement_unit_data' => :'measurement_unit_data'
112
+ :'measurement_unit_data' => :'measurement_unit_data',
113
+ :'item_option_data' => :'item_option_data',
114
+ :'item_option_value_data' => :'item_option_value_data'
107
115
  }
108
116
  end
109
117
 
@@ -131,7 +139,9 @@ module SquareConnect
131
139
  :'product_set_data' => :'CatalogProductSet',
132
140
  :'pricing_rule_data' => :'CatalogPricingRule',
133
141
  :'image_data' => :'CatalogImage',
134
- :'measurement_unit_data' => :'CatalogMeasurementUnit'
142
+ :'measurement_unit_data' => :'CatalogMeasurementUnit',
143
+ :'item_option_data' => :'CatalogItemOption',
144
+ :'item_option_value_data' => :'CatalogItemOptionValue'
135
145
  }
136
146
  end
137
147
 
@@ -237,6 +247,14 @@ module SquareConnect
237
247
  self.measurement_unit_data = attributes[:'measurement_unit_data']
238
248
  end
239
249
 
250
+ if attributes.has_key?(:'item_option_data')
251
+ self.item_option_data = attributes[:'item_option_data']
252
+ end
253
+
254
+ if attributes.has_key?(:'item_option_value_data')
255
+ self.item_option_value_data = attributes[:'item_option_value_data']
256
+ end
257
+
240
258
  end
241
259
 
242
260
  # Show invalid properties with the reasons. Usually used together with valid?
@@ -307,7 +325,9 @@ module SquareConnect
307
325
  product_set_data == o.product_set_data &&
308
326
  pricing_rule_data == o.pricing_rule_data &&
309
327
  image_data == o.image_data &&
310
- measurement_unit_data == o.measurement_unit_data
328
+ measurement_unit_data == o.measurement_unit_data &&
329
+ item_option_data == o.item_option_data &&
330
+ item_option_value_data == o.item_option_value_data
311
331
  end
312
332
 
313
333
  # @see the `==` method
@@ -319,7 +339,7 @@ module SquareConnect
319
339
  # Calculates hash code according to all attributes.
320
340
  # @return [Fixnum] Hash code
321
341
  def hash
322
- [type, id, updated_at, version, is_deleted, catalog_v1_ids, present_at_all_locations, present_at_location_ids, absent_at_location_ids, image_id, item_data, category_data, item_variation_data, tax_data, discount_data, modifier_list_data, modifier_data, time_period_data, product_set_data, pricing_rule_data, image_data, measurement_unit_data].hash
342
+ [type, id, updated_at, version, is_deleted, catalog_v1_ids, present_at_all_locations, present_at_location_ids, absent_at_location_ids, image_id, item_data, category_data, item_variation_data, tax_data, discount_data, modifier_list_data, modifier_data, time_period_data, product_set_data, pricing_rule_data, image_data, measurement_unit_data, item_option_data, item_option_value_data].hash
323
343
  end
324
344
 
325
345
  # Builds the object from hash
@@ -23,6 +23,9 @@ module SquareConnect
23
23
  PRICING_RULE = "PRICING_RULE".freeze
24
24
  PRODUCT_SET = "PRODUCT_SET".freeze
25
25
  TIME_PERIOD = "TIME_PERIOD".freeze
26
+ MEASUREMENT_UNIT = "MEASUREMENT_UNIT".freeze
27
+ ITEM_OPTION = "ITEM_OPTION".freeze
28
+ ITEM_OPTION_VAL = "ITEM_OPTION_VAL".freeze
26
29
  end
27
30
 
28
31
  end
@@ -33,6 +33,12 @@ module SquareConnect
33
33
  # A query that returns all [CatalogItem](#type-catalogitem)s that have any of the given [CatalogModifierList](#type-catalogmodifierlist)s enabled.
34
34
  attr_accessor :items_for_modifier_list_query
35
35
 
36
+ # A query that returns all [CatalogItem](#type-catalogitem)s that have all of the given [CatalogItemOption](#type-catalogitemoption)s.
37
+ attr_accessor :items_for_item_options_query
38
+
39
+ # A query that returns all [CatalogItemVariation](#type-catalogitemvariations)s that have all of the given [CatalogItemOption](#type-catalogitemoption) values.
40
+ attr_accessor :item_variations_for_item_option_values_query
41
+
36
42
 
37
43
  # Attribute mapping from ruby-style variable name to JSON key.
38
44
  def self.attribute_map
@@ -43,7 +49,9 @@ module SquareConnect
43
49
  :'range_query' => :'range_query',
44
50
  :'text_query' => :'text_query',
45
51
  :'items_for_tax_query' => :'items_for_tax_query',
46
- :'items_for_modifier_list_query' => :'items_for_modifier_list_query'
52
+ :'items_for_modifier_list_query' => :'items_for_modifier_list_query',
53
+ :'items_for_item_options_query' => :'items_for_item_options_query',
54
+ :'item_variations_for_item_option_values_query' => :'item_variations_for_item_option_values_query'
47
55
  }
48
56
  end
49
57
 
@@ -56,7 +64,9 @@ module SquareConnect
56
64
  :'range_query' => :'CatalogQueryRange',
57
65
  :'text_query' => :'CatalogQueryText',
58
66
  :'items_for_tax_query' => :'CatalogQueryItemsForTax',
59
- :'items_for_modifier_list_query' => :'CatalogQueryItemsForModifierList'
67
+ :'items_for_modifier_list_query' => :'CatalogQueryItemsForModifierList',
68
+ :'items_for_item_options_query' => :'CatalogQueryItemsForItemOptions',
69
+ :'item_variations_for_item_option_values_query' => :'CatalogQueryItemVariationsForItemOptionValues'
60
70
  }
61
71
  end
62
72
 
@@ -96,6 +106,14 @@ module SquareConnect
96
106
  self.items_for_modifier_list_query = attributes[:'items_for_modifier_list_query']
97
107
  end
98
108
 
109
+ if attributes.has_key?(:'items_for_item_options_query')
110
+ self.items_for_item_options_query = attributes[:'items_for_item_options_query']
111
+ end
112
+
113
+ if attributes.has_key?(:'item_variations_for_item_option_values_query')
114
+ self.item_variations_for_item_option_values_query = attributes[:'item_variations_for_item_option_values_query']
115
+ end
116
+
99
117
  end
100
118
 
101
119
  # Show invalid properties with the reasons. Usually used together with valid?
@@ -122,7 +140,9 @@ module SquareConnect
122
140
  range_query == o.range_query &&
123
141
  text_query == o.text_query &&
124
142
  items_for_tax_query == o.items_for_tax_query &&
125
- items_for_modifier_list_query == o.items_for_modifier_list_query
143
+ items_for_modifier_list_query == o.items_for_modifier_list_query &&
144
+ items_for_item_options_query == o.items_for_item_options_query &&
145
+ item_variations_for_item_option_values_query == o.item_variations_for_item_option_values_query
126
146
  end
127
147
 
128
148
  # @see the `==` method
@@ -134,7 +154,7 @@ module SquareConnect
134
154
  # Calculates hash code according to all attributes.
135
155
  # @return [Fixnum] Hash code
136
156
  def hash
137
- [sorted_attribute_query, exact_query, prefix_query, range_query, text_query, items_for_tax_query, items_for_modifier_list_query].hash
157
+ [sorted_attribute_query, exact_query, prefix_query, range_query, text_query, items_for_tax_query, items_for_modifier_list_query, items_for_item_options_query, item_variations_for_item_option_values_query].hash
138
158
  end
139
159
 
140
160
  # Builds the object from hash
@@ -0,0 +1,188 @@
1
+ =begin
2
+ #Square Connect API
3
+
4
+ OpenAPI spec version: 2.0
5
+ Contact: developers@squareup.com
6
+ Generated by: https://github.com/swagger-api/swagger-codegen.git
7
+
8
+ =end
9
+
10
+ require 'date'
11
+
12
+ module SquareConnect
13
+ #
14
+ class CatalogQueryItemVariationsForItemOptionValues
15
+ # A set of [CatalogItemOptionValue](#type-catalogitemoptionvalue) IDs to be used to find associated [CatalogItemVariation](#type-catalogitemvariation)s. All ItemVariations that contain all of the given Item Option Values (in any order) will be returned.
16
+ attr_accessor :item_option_value_ids
17
+
18
+
19
+ # Attribute mapping from ruby-style variable name to JSON key.
20
+ def self.attribute_map
21
+ {
22
+ :'item_option_value_ids' => :'item_option_value_ids'
23
+ }
24
+ end
25
+
26
+ # Attribute type mapping.
27
+ def self.swagger_types
28
+ {
29
+ :'item_option_value_ids' => :'Array<String>'
30
+ }
31
+ end
32
+
33
+ # Initializes the object
34
+ # @param [Hash] attributes Model attributes in the form of hash
35
+ def initialize(attributes = {})
36
+ return unless attributes.is_a?(Hash)
37
+
38
+ # convert string to symbol for hash key
39
+ attributes = attributes.each_with_object({}){|(k,v), h| h[k.to_sym] = v}
40
+
41
+ if attributes.has_key?(:'item_option_value_ids')
42
+ if (value = attributes[:'item_option_value_ids']).is_a?(Array)
43
+ self.item_option_value_ids = value
44
+ end
45
+ end
46
+
47
+ end
48
+
49
+ # Show invalid properties with the reasons. Usually used together with valid?
50
+ # @return Array for valid properies with the reasons
51
+ def list_invalid_properties
52
+ invalid_properties = Array.new
53
+ return invalid_properties
54
+ end
55
+
56
+ # Check to see if the all the properties in the model are valid
57
+ # @return true if the model is valid
58
+ def valid?
59
+ return true
60
+ end
61
+
62
+ # Checks equality by comparing each attribute.
63
+ # @param [Object] Object to be compared
64
+ def ==(o)
65
+ return true if self.equal?(o)
66
+ self.class == o.class &&
67
+ item_option_value_ids == o.item_option_value_ids
68
+ end
69
+
70
+ # @see the `==` method
71
+ # @param [Object] Object to be compared
72
+ def eql?(o)
73
+ self == o
74
+ end
75
+
76
+ # Calculates hash code according to all attributes.
77
+ # @return [Fixnum] Hash code
78
+ def hash
79
+ [item_option_value_ids].hash
80
+ end
81
+
82
+ # Builds the object from hash
83
+ # @param [Hash] attributes Model attributes in the form of hash
84
+ # @return [Object] Returns the model itself
85
+ def build_from_hash(attributes)
86
+ return nil unless attributes.is_a?(Hash)
87
+ self.class.swagger_types.each_pair do |key, type|
88
+ if type =~ /\AArray<(.*)>/i
89
+ # check to ensure the input is an array given that the the attribute
90
+ # is documented as an array but the input is not
91
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
92
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map{ |v| _deserialize($1, v) } )
93
+ end
94
+ elsif !attributes[self.class.attribute_map[key]].nil?
95
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
96
+ end # or else data not found in attributes(hash), not an issue as the data can be optional
97
+ end
98
+
99
+ self
100
+ end
101
+
102
+ # Deserializes the data based on type
103
+ # @param string type Data type
104
+ # @param string value Value to be deserialized
105
+ # @return [Object] Deserialized data
106
+ def _deserialize(type, value)
107
+ case type.to_sym
108
+ when :DateTime
109
+ DateTime.parse(value)
110
+ when :Date
111
+ Date.parse(value)
112
+ when :String
113
+ value.to_s
114
+ when :Integer
115
+ value.to_i
116
+ when :Float
117
+ value.to_f
118
+ when :BOOLEAN
119
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
120
+ true
121
+ else
122
+ false
123
+ end
124
+ when :Object
125
+ # generic object (usually a Hash), return directly
126
+ value
127
+ when /\AArray<(?<inner_type>.+)>\z/
128
+ inner_type = Regexp.last_match[:inner_type]
129
+ value.map { |v| _deserialize(inner_type, v) }
130
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
131
+ k_type = Regexp.last_match[:k_type]
132
+ v_type = Regexp.last_match[:v_type]
133
+ {}.tap do |hash|
134
+ value.each do |k, v|
135
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
136
+ end
137
+ end
138
+ else # model
139
+ temp_model = SquareConnect.const_get(type).new
140
+ temp_model.build_from_hash(value)
141
+ end
142
+ end
143
+
144
+ # Returns the string representation of the object
145
+ # @return [String] String presentation of the object
146
+ def to_s
147
+ to_hash.to_s
148
+ end
149
+
150
+ # to_body is an alias to to_hash (backward compatibility)
151
+ # @return [Hash] Returns the object in the form of hash
152
+ def to_body
153
+ to_hash
154
+ end
155
+
156
+ # Returns the object in the form of hash
157
+ # @return [Hash] Returns the object in the form of hash
158
+ def to_hash
159
+ hash = {}
160
+ self.class.attribute_map.each_pair do |attr, param|
161
+ value = self.send(attr)
162
+ next if value.nil?
163
+ hash[param] = _to_hash(value)
164
+ end
165
+ hash
166
+ end
167
+
168
+ # Outputs non-array value in the form of hash
169
+ # For object, use to_hash. Otherwise, just return the value
170
+ # @param [Object] value Any valid value
171
+ # @return [Hash] Returns the value in the form of hash
172
+ def _to_hash(value)
173
+ if value.is_a?(Array)
174
+ value.compact.map{ |v| _to_hash(v) }
175
+ elsif value.is_a?(Hash)
176
+ {}.tap do |hash|
177
+ value.each { |k, v| hash[k] = _to_hash(v) }
178
+ end
179
+ elsif value.respond_to? :to_hash
180
+ value.to_hash
181
+ else
182
+ value
183
+ end
184
+ end
185
+
186
+ end
187
+
188
+ end
@@ -0,0 +1,188 @@
1
+ =begin
2
+ #Square Connect API
3
+
4
+ OpenAPI spec version: 2.0
5
+ Contact: developers@squareup.com
6
+ Generated by: https://github.com/swagger-api/swagger-codegen.git
7
+
8
+ =end
9
+
10
+ require 'date'
11
+
12
+ module SquareConnect
13
+ #
14
+ class CatalogQueryItemsForItemOptions
15
+ # A set of [CatalogItemOption](#type-catalogitemoption) IDs to be used to find associated [CatalogItem](#type-catalogitem)s. All Items that contain all of the given Item Options (in any order) will be returned.
16
+ attr_accessor :item_option_ids
17
+
18
+
19
+ # Attribute mapping from ruby-style variable name to JSON key.
20
+ def self.attribute_map
21
+ {
22
+ :'item_option_ids' => :'item_option_ids'
23
+ }
24
+ end
25
+
26
+ # Attribute type mapping.
27
+ def self.swagger_types
28
+ {
29
+ :'item_option_ids' => :'Array<String>'
30
+ }
31
+ end
32
+
33
+ # Initializes the object
34
+ # @param [Hash] attributes Model attributes in the form of hash
35
+ def initialize(attributes = {})
36
+ return unless attributes.is_a?(Hash)
37
+
38
+ # convert string to symbol for hash key
39
+ attributes = attributes.each_with_object({}){|(k,v), h| h[k.to_sym] = v}
40
+
41
+ if attributes.has_key?(:'item_option_ids')
42
+ if (value = attributes[:'item_option_ids']).is_a?(Array)
43
+ self.item_option_ids = value
44
+ end
45
+ end
46
+
47
+ end
48
+
49
+ # Show invalid properties with the reasons. Usually used together with valid?
50
+ # @return Array for valid properies with the reasons
51
+ def list_invalid_properties
52
+ invalid_properties = Array.new
53
+ return invalid_properties
54
+ end
55
+
56
+ # Check to see if the all the properties in the model are valid
57
+ # @return true if the model is valid
58
+ def valid?
59
+ return true
60
+ end
61
+
62
+ # Checks equality by comparing each attribute.
63
+ # @param [Object] Object to be compared
64
+ def ==(o)
65
+ return true if self.equal?(o)
66
+ self.class == o.class &&
67
+ item_option_ids == o.item_option_ids
68
+ end
69
+
70
+ # @see the `==` method
71
+ # @param [Object] Object to be compared
72
+ def eql?(o)
73
+ self == o
74
+ end
75
+
76
+ # Calculates hash code according to all attributes.
77
+ # @return [Fixnum] Hash code
78
+ def hash
79
+ [item_option_ids].hash
80
+ end
81
+
82
+ # Builds the object from hash
83
+ # @param [Hash] attributes Model attributes in the form of hash
84
+ # @return [Object] Returns the model itself
85
+ def build_from_hash(attributes)
86
+ return nil unless attributes.is_a?(Hash)
87
+ self.class.swagger_types.each_pair do |key, type|
88
+ if type =~ /\AArray<(.*)>/i
89
+ # check to ensure the input is an array given that the the attribute
90
+ # is documented as an array but the input is not
91
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
92
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map{ |v| _deserialize($1, v) } )
93
+ end
94
+ elsif !attributes[self.class.attribute_map[key]].nil?
95
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
96
+ end # or else data not found in attributes(hash), not an issue as the data can be optional
97
+ end
98
+
99
+ self
100
+ end
101
+
102
+ # Deserializes the data based on type
103
+ # @param string type Data type
104
+ # @param string value Value to be deserialized
105
+ # @return [Object] Deserialized data
106
+ def _deserialize(type, value)
107
+ case type.to_sym
108
+ when :DateTime
109
+ DateTime.parse(value)
110
+ when :Date
111
+ Date.parse(value)
112
+ when :String
113
+ value.to_s
114
+ when :Integer
115
+ value.to_i
116
+ when :Float
117
+ value.to_f
118
+ when :BOOLEAN
119
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
120
+ true
121
+ else
122
+ false
123
+ end
124
+ when :Object
125
+ # generic object (usually a Hash), return directly
126
+ value
127
+ when /\AArray<(?<inner_type>.+)>\z/
128
+ inner_type = Regexp.last_match[:inner_type]
129
+ value.map { |v| _deserialize(inner_type, v) }
130
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
131
+ k_type = Regexp.last_match[:k_type]
132
+ v_type = Regexp.last_match[:v_type]
133
+ {}.tap do |hash|
134
+ value.each do |k, v|
135
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
136
+ end
137
+ end
138
+ else # model
139
+ temp_model = SquareConnect.const_get(type).new
140
+ temp_model.build_from_hash(value)
141
+ end
142
+ end
143
+
144
+ # Returns the string representation of the object
145
+ # @return [String] String presentation of the object
146
+ def to_s
147
+ to_hash.to_s
148
+ end
149
+
150
+ # to_body is an alias to to_hash (backward compatibility)
151
+ # @return [Hash] Returns the object in the form of hash
152
+ def to_body
153
+ to_hash
154
+ end
155
+
156
+ # Returns the object in the form of hash
157
+ # @return [Hash] Returns the object in the form of hash
158
+ def to_hash
159
+ hash = {}
160
+ self.class.attribute_map.each_pair do |attr, param|
161
+ value = self.send(attr)
162
+ next if value.nil?
163
+ hash[param] = _to_hash(value)
164
+ end
165
+ hash
166
+ end
167
+
168
+ # Outputs non-array value in the form of hash
169
+ # For object, use to_hash. Otherwise, just return the value
170
+ # @param [Object] value Any valid value
171
+ # @return [Hash] Returns the value in the form of hash
172
+ def _to_hash(value)
173
+ if value.is_a?(Array)
174
+ value.compact.map{ |v| _to_hash(v) }
175
+ elsif value.is_a?(Hash)
176
+ {}.tap do |hash|
177
+ value.each { |k, v| hash[k] = _to_hash(v) }
178
+ end
179
+ elsif value.respond_to? :to_hash
180
+ value.to_hash
181
+ else
182
+ value
183
+ end
184
+ end
185
+
186
+ end
187
+
188
+ end