square_connect 2.20180712.2.237 → 2.20180918.0.244

Sign up to get free protection for your applications and to get access to all the features.
Files changed (105) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGES.md +20 -1
  3. data/README.md +33 -1
  4. data/docs/BatchChangeInventoryRequest.md +14 -0
  5. data/docs/BatchChangeInventoryResponse.md +13 -0
  6. data/docs/BatchRetrieveInventoryChangesRequest.md +18 -0
  7. data/docs/BatchRetrieveInventoryChangesResponse.md +14 -0
  8. data/docs/BatchRetrieveInventoryCountsRequest.md +15 -0
  9. data/docs/BatchRetrieveInventoryCountsResponse.md +14 -0
  10. data/docs/Card.md +1 -1
  11. data/docs/CreateCustomerRequest.md +1 -0
  12. data/docs/Customer.md +1 -0
  13. data/docs/CustomersApi.md +2 -2
  14. data/docs/ErrorCode.md +2 -0
  15. data/docs/InventoryAdjustment.md +28 -0
  16. data/docs/InventoryApi.md +391 -0
  17. data/docs/InventoryChange.md +15 -0
  18. data/docs/InventoryChangeType.md +14 -0
  19. data/docs/InventoryCount.md +17 -0
  20. data/docs/InventoryPhysicalCount.md +22 -0
  21. data/docs/InventoryState.md +23 -0
  22. data/docs/InventoryTransfer.md +23 -0
  23. data/docs/Product.md +19 -0
  24. data/docs/RetrieveInventoryAdjustmentRequest.md +11 -0
  25. data/docs/RetrieveInventoryAdjustmentResponse.md +13 -0
  26. data/docs/RetrieveInventoryChangesRequest.md +13 -0
  27. data/docs/RetrieveInventoryChangesResponse.md +14 -0
  28. data/docs/RetrieveInventoryCountRequest.md +13 -0
  29. data/docs/RetrieveInventoryCountResponse.md +14 -0
  30. data/docs/RetrieveInventoryPhysicalCountRequest.md +11 -0
  31. data/docs/RetrieveInventoryPhysicalCountResponse.md +13 -0
  32. data/docs/SourceApplication.md +14 -0
  33. data/docs/TransactionsApi.md +1 -1
  34. data/docs/UpdateCustomerRequest.md +1 -0
  35. data/docs/V1Timecard.md +4 -1
  36. data/lib/square_connect.rb +24 -0
  37. data/lib/square_connect/api/apple_pay_api.rb +1 -1
  38. data/lib/square_connect/api/catalog_api.rb +11 -11
  39. data/lib/square_connect/api/checkout_api.rb +1 -1
  40. data/lib/square_connect/api/customers_api.rb +12 -12
  41. data/lib/square_connect/api/inventory_api.rb +417 -0
  42. data/lib/square_connect/api/locations_api.rb +1 -1
  43. data/lib/square_connect/api/mobile_authorization_api.rb +1 -1
  44. data/lib/square_connect/api/o_auth_api.rb +3 -3
  45. data/lib/square_connect/api/orders_api.rb +2 -2
  46. data/lib/square_connect/api/reporting_api.rb +2 -2
  47. data/lib/square_connect/api/transactions_api.rb +9 -9
  48. data/lib/square_connect/api_client.rb +1 -1
  49. data/lib/square_connect/models/batch_change_inventory_request.rb +208 -0
  50. data/lib/square_connect/models/batch_change_inventory_response.rb +200 -0
  51. data/lib/square_connect/models/batch_retrieve_inventory_changes_request.rb +275 -0
  52. data/lib/square_connect/models/batch_retrieve_inventory_changes_response.rb +210 -0
  53. data/lib/square_connect/models/batch_retrieve_inventory_counts_request.rb +220 -0
  54. data/lib/square_connect/models/batch_retrieve_inventory_counts_response.rb +210 -0
  55. data/lib/square_connect/models/card.rb +1 -1
  56. data/lib/square_connect/models/create_customer_request.rb +14 -4
  57. data/lib/square_connect/models/customer.rb +11 -1
  58. data/lib/square_connect/models/error.rb +2 -2
  59. data/lib/square_connect/models/error_code.rb +2 -0
  60. data/lib/square_connect/models/inventory_adjustment.rb +391 -0
  61. data/lib/square_connect/models/inventory_change.rb +249 -0
  62. data/lib/square_connect/models/inventory_change_type.rb +20 -0
  63. data/lib/square_connect/models/inventory_count.rb +269 -0
  64. data/lib/square_connect/models/inventory_physical_count.rb +319 -0
  65. data/lib/square_connect/models/inventory_state.rb +29 -0
  66. data/lib/square_connect/models/inventory_transfer.rb +329 -0
  67. data/lib/square_connect/models/money.rb +0 -9
  68. data/lib/square_connect/models/product.rb +25 -0
  69. data/lib/square_connect/models/retrieve_inventory_adjustment_request.rb +176 -0
  70. data/lib/square_connect/models/retrieve_inventory_adjustment_response.rb +198 -0
  71. data/lib/square_connect/models/retrieve_inventory_changes_request.rb +196 -0
  72. data/lib/square_connect/models/retrieve_inventory_changes_response.rb +210 -0
  73. data/lib/square_connect/models/retrieve_inventory_count_request.rb +196 -0
  74. data/lib/square_connect/models/retrieve_inventory_count_response.rb +210 -0
  75. data/lib/square_connect/models/retrieve_inventory_physical_count_request.rb +176 -0
  76. data/lib/square_connect/models/retrieve_inventory_physical_count_response.rb +198 -0
  77. data/lib/square_connect/models/source_application.rb +239 -0
  78. data/lib/square_connect/models/update_customer_request.rb +14 -4
  79. data/lib/square_connect/models/v1_timecard.rb +35 -5
  80. data/lib/square_connect/version.rb +1 -1
  81. data/spec/api/inventory_api_spec.rb +120 -0
  82. data/spec/models/batch_change_inventory_request_spec.rb +51 -0
  83. data/spec/models/batch_change_inventory_response_spec.rb +45 -0
  84. data/spec/models/batch_retrieve_inventory_changes_request_spec.rb +83 -0
  85. data/spec/models/batch_retrieve_inventory_changes_response_spec.rb +51 -0
  86. data/spec/models/batch_retrieve_inventory_counts_request_spec.rb +57 -0
  87. data/spec/models/batch_retrieve_inventory_counts_response_spec.rb +51 -0
  88. data/spec/models/inventory_adjustment_spec.rb +143 -0
  89. data/spec/models/inventory_change_spec.rb +61 -0
  90. data/spec/models/inventory_change_type_spec.rb +33 -0
  91. data/spec/models/inventory_count_spec.rb +73 -0
  92. data/spec/models/inventory_physical_count_spec.rb +103 -0
  93. data/spec/models/inventory_state_spec.rb +33 -0
  94. data/spec/models/inventory_transfer_spec.rb +109 -0
  95. data/spec/models/product_spec.rb +33 -0
  96. data/spec/models/retrieve_inventory_adjustment_request_spec.rb +33 -0
  97. data/spec/models/retrieve_inventory_adjustment_response_spec.rb +45 -0
  98. data/spec/models/retrieve_inventory_changes_request_spec.rb +45 -0
  99. data/spec/models/retrieve_inventory_changes_response_spec.rb +51 -0
  100. data/spec/models/retrieve_inventory_count_request_spec.rb +45 -0
  101. data/spec/models/retrieve_inventory_count_response_spec.rb +51 -0
  102. data/spec/models/retrieve_inventory_physical_count_request_spec.rb +33 -0
  103. data/spec/models/retrieve_inventory_physical_count_response_spec.rb +45 -0
  104. data/spec/models/source_application_spec.rb +55 -0
  105. metadata +99 -3
@@ -0,0 +1,176 @@
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 RetrieveInventoryPhysicalCountRequest
15
+
16
+ # Attribute mapping from ruby-style variable name to JSON key.
17
+ def self.attribute_map
18
+ {
19
+ }
20
+ end
21
+
22
+ # Attribute type mapping.
23
+ def self.swagger_types
24
+ {
25
+ }
26
+ end
27
+
28
+ # Initializes the object
29
+ # @param [Hash] attributes Model attributes in the form of hash
30
+ def initialize(attributes = {})
31
+ return unless attributes.is_a?(Hash)
32
+
33
+ # convert string to symbol for hash key
34
+ attributes = attributes.each_with_object({}){|(k,v), h| h[k.to_sym] = v}
35
+
36
+ end
37
+
38
+ # Show invalid properties with the reasons. Usually used together with valid?
39
+ # @return Array for valid properies with the reasons
40
+ def list_invalid_properties
41
+ invalid_properties = Array.new
42
+ return invalid_properties
43
+ end
44
+
45
+ # Check to see if the all the properties in the model are valid
46
+ # @return true if the model is valid
47
+ def valid?
48
+ return true
49
+ end
50
+
51
+ # Checks equality by comparing each attribute.
52
+ # @param [Object] Object to be compared
53
+ def ==(o)
54
+ return true if self.equal?(o)
55
+ self.class == o.class
56
+ end
57
+
58
+ # @see the `==` method
59
+ # @param [Object] Object to be compared
60
+ def eql?(o)
61
+ self == o
62
+ end
63
+
64
+ # Calculates hash code according to all attributes.
65
+ # @return [Fixnum] Hash code
66
+ def hash
67
+ [].hash
68
+ end
69
+
70
+ # Builds the object from hash
71
+ # @param [Hash] attributes Model attributes in the form of hash
72
+ # @return [Object] Returns the model itself
73
+ def build_from_hash(attributes)
74
+ return nil unless attributes.is_a?(Hash)
75
+ self.class.swagger_types.each_pair do |key, type|
76
+ if type =~ /\AArray<(.*)>/i
77
+ # check to ensure the input is an array given that the the attribute
78
+ # is documented as an array but the input is not
79
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
80
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map{ |v| _deserialize($1, v) } )
81
+ end
82
+ elsif !attributes[self.class.attribute_map[key]].nil?
83
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
84
+ end # or else data not found in attributes(hash), not an issue as the data can be optional
85
+ end
86
+
87
+ self
88
+ end
89
+
90
+ # Deserializes the data based on type
91
+ # @param string type Data type
92
+ # @param string value Value to be deserialized
93
+ # @return [Object] Deserialized data
94
+ def _deserialize(type, value)
95
+ case type.to_sym
96
+ when :DateTime
97
+ DateTime.parse(value)
98
+ when :Date
99
+ Date.parse(value)
100
+ when :String
101
+ value.to_s
102
+ when :Integer
103
+ value.to_i
104
+ when :Float
105
+ value.to_f
106
+ when :BOOLEAN
107
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
108
+ true
109
+ else
110
+ false
111
+ end
112
+ when :Object
113
+ # generic object (usually a Hash), return directly
114
+ value
115
+ when /\AArray<(?<inner_type>.+)>\z/
116
+ inner_type = Regexp.last_match[:inner_type]
117
+ value.map { |v| _deserialize(inner_type, v) }
118
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
119
+ k_type = Regexp.last_match[:k_type]
120
+ v_type = Regexp.last_match[:v_type]
121
+ {}.tap do |hash|
122
+ value.each do |k, v|
123
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
124
+ end
125
+ end
126
+ else # model
127
+ temp_model = SquareConnect.const_get(type).new
128
+ temp_model.build_from_hash(value)
129
+ end
130
+ end
131
+
132
+ # Returns the string representation of the object
133
+ # @return [String] String presentation of the object
134
+ def to_s
135
+ to_hash.to_s
136
+ end
137
+
138
+ # to_body is an alias to to_hash (backward compatibility)
139
+ # @return [Hash] Returns the object in the form of hash
140
+ def to_body
141
+ to_hash
142
+ end
143
+
144
+ # Returns the object in the form of hash
145
+ # @return [Hash] Returns the object in the form of hash
146
+ def to_hash
147
+ hash = {}
148
+ self.class.attribute_map.each_pair do |attr, param|
149
+ value = self.send(attr)
150
+ next if value.nil?
151
+ hash[param] = _to_hash(value)
152
+ end
153
+ hash
154
+ end
155
+
156
+ # Outputs non-array value in the form of hash
157
+ # For object, use to_hash. Otherwise, just return the value
158
+ # @param [Object] value Any valid value
159
+ # @return [Hash] Returns the value in the form of hash
160
+ def _to_hash(value)
161
+ if value.is_a?(Array)
162
+ value.compact.map{ |v| _to_hash(v) }
163
+ elsif value.is_a?(Hash)
164
+ {}.tap do |hash|
165
+ value.each { |k, v| hash[k] = _to_hash(v) }
166
+ end
167
+ elsif value.respond_to? :to_hash
168
+ value.to_hash
169
+ else
170
+ value
171
+ end
172
+ end
173
+
174
+ end
175
+
176
+ end
@@ -0,0 +1,198 @@
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 RetrieveInventoryPhysicalCountResponse
15
+ # Any errors that occurred during the request.
16
+ attr_accessor :errors
17
+
18
+ # The requested [InventoryPhysicalCount](#type-inventoryphysicalcount).
19
+ attr_accessor :count
20
+
21
+
22
+ # Attribute mapping from ruby-style variable name to JSON key.
23
+ def self.attribute_map
24
+ {
25
+ :'errors' => :'errors',
26
+ :'count' => :'count'
27
+ }
28
+ end
29
+
30
+ # Attribute type mapping.
31
+ def self.swagger_types
32
+ {
33
+ :'errors' => :'Array<Error>',
34
+ :'count' => :'InventoryPhysicalCount'
35
+ }
36
+ end
37
+
38
+ # Initializes the object
39
+ # @param [Hash] attributes Model attributes in the form of hash
40
+ def initialize(attributes = {})
41
+ return unless attributes.is_a?(Hash)
42
+
43
+ # convert string to symbol for hash key
44
+ attributes = attributes.each_with_object({}){|(k,v), h| h[k.to_sym] = v}
45
+
46
+ if attributes.has_key?(:'errors')
47
+ if (value = attributes[:'errors']).is_a?(Array)
48
+ self.errors = value
49
+ end
50
+ end
51
+
52
+ if attributes.has_key?(:'count')
53
+ self.count = attributes[:'count']
54
+ end
55
+
56
+ end
57
+
58
+ # Show invalid properties with the reasons. Usually used together with valid?
59
+ # @return Array for valid properies with the reasons
60
+ def list_invalid_properties
61
+ invalid_properties = Array.new
62
+ return invalid_properties
63
+ end
64
+
65
+ # Check to see if the all the properties in the model are valid
66
+ # @return true if the model is valid
67
+ def valid?
68
+ return true
69
+ end
70
+
71
+ # Checks equality by comparing each attribute.
72
+ # @param [Object] Object to be compared
73
+ def ==(o)
74
+ return true if self.equal?(o)
75
+ self.class == o.class &&
76
+ errors == o.errors &&
77
+ count == o.count
78
+ end
79
+
80
+ # @see the `==` method
81
+ # @param [Object] Object to be compared
82
+ def eql?(o)
83
+ self == o
84
+ end
85
+
86
+ # Calculates hash code according to all attributes.
87
+ # @return [Fixnum] Hash code
88
+ def hash
89
+ [errors, count].hash
90
+ end
91
+
92
+ # Builds the object from hash
93
+ # @param [Hash] attributes Model attributes in the form of hash
94
+ # @return [Object] Returns the model itself
95
+ def build_from_hash(attributes)
96
+ return nil unless attributes.is_a?(Hash)
97
+ self.class.swagger_types.each_pair do |key, type|
98
+ if type =~ /\AArray<(.*)>/i
99
+ # check to ensure the input is an array given that the the attribute
100
+ # is documented as an array but the input is not
101
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
102
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map{ |v| _deserialize($1, v) } )
103
+ end
104
+ elsif !attributes[self.class.attribute_map[key]].nil?
105
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
106
+ end # or else data not found in attributes(hash), not an issue as the data can be optional
107
+ end
108
+
109
+ self
110
+ end
111
+
112
+ # Deserializes the data based on type
113
+ # @param string type Data type
114
+ # @param string value Value to be deserialized
115
+ # @return [Object] Deserialized data
116
+ def _deserialize(type, value)
117
+ case type.to_sym
118
+ when :DateTime
119
+ DateTime.parse(value)
120
+ when :Date
121
+ Date.parse(value)
122
+ when :String
123
+ value.to_s
124
+ when :Integer
125
+ value.to_i
126
+ when :Float
127
+ value.to_f
128
+ when :BOOLEAN
129
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
130
+ true
131
+ else
132
+ false
133
+ end
134
+ when :Object
135
+ # generic object (usually a Hash), return directly
136
+ value
137
+ when /\AArray<(?<inner_type>.+)>\z/
138
+ inner_type = Regexp.last_match[:inner_type]
139
+ value.map { |v| _deserialize(inner_type, v) }
140
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
141
+ k_type = Regexp.last_match[:k_type]
142
+ v_type = Regexp.last_match[:v_type]
143
+ {}.tap do |hash|
144
+ value.each do |k, v|
145
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
146
+ end
147
+ end
148
+ else # model
149
+ temp_model = SquareConnect.const_get(type).new
150
+ temp_model.build_from_hash(value)
151
+ end
152
+ end
153
+
154
+ # Returns the string representation of the object
155
+ # @return [String] String presentation of the object
156
+ def to_s
157
+ to_hash.to_s
158
+ end
159
+
160
+ # to_body is an alias to to_hash (backward compatibility)
161
+ # @return [Hash] Returns the object in the form of hash
162
+ def to_body
163
+ to_hash
164
+ end
165
+
166
+ # Returns the object in the form of hash
167
+ # @return [Hash] Returns the object in the form of hash
168
+ def to_hash
169
+ hash = {}
170
+ self.class.attribute_map.each_pair do |attr, param|
171
+ value = self.send(attr)
172
+ next if value.nil?
173
+ hash[param] = _to_hash(value)
174
+ end
175
+ hash
176
+ end
177
+
178
+ # Outputs non-array value in the form of hash
179
+ # For object, use to_hash. Otherwise, just return the value
180
+ # @param [Object] value Any valid value
181
+ # @return [Hash] Returns the value in the form of hash
182
+ def _to_hash(value)
183
+ if value.is_a?(Array)
184
+ value.compact.map{ |v| _to_hash(v) }
185
+ elsif value.is_a?(Hash)
186
+ {}.tap do |hash|
187
+ value.each { |k, v| hash[k] = _to_hash(v) }
188
+ end
189
+ elsif value.respond_to? :to_hash
190
+ value.to_hash
191
+ else
192
+ value
193
+ end
194
+ end
195
+
196
+ end
197
+
198
+ end
@@ -0,0 +1,239 @@
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
+ # Provides information about the application used to generate an inventory change.
14
+ class SourceApplication
15
+ # Read-only [Product](#type-product) type for the application.
16
+ attr_accessor :product
17
+
18
+ # Read-only Square ID assigned to the application. Only used for [Product](#type-product) type `EXTERNAL_API`.
19
+ attr_accessor :application_id
20
+
21
+ # Read-only display name assigned to the application (e.g. `\"Custom Application\"`, `\"Square POS 4.74 for Android\"`).
22
+ attr_accessor :name
23
+
24
+ class EnumAttributeValidator
25
+ attr_reader :datatype
26
+ attr_reader :allowable_values
27
+
28
+ def initialize(datatype, allowable_values)
29
+ @allowable_values = allowable_values.map do |value|
30
+ case datatype.to_s
31
+ when /Integer/i
32
+ value.to_i
33
+ when /Float/i
34
+ value.to_f
35
+ else
36
+ value
37
+ end
38
+ end
39
+ end
40
+
41
+ def valid?(value)
42
+ !value || allowable_values.include?(value)
43
+ end
44
+ end
45
+
46
+ # Attribute mapping from ruby-style variable name to JSON key.
47
+ def self.attribute_map
48
+ {
49
+ :'product' => :'product',
50
+ :'application_id' => :'application_id',
51
+ :'name' => :'name'
52
+ }
53
+ end
54
+
55
+ # Attribute type mapping.
56
+ def self.swagger_types
57
+ {
58
+ :'product' => :'String',
59
+ :'application_id' => :'String',
60
+ :'name' => :'String'
61
+ }
62
+ end
63
+
64
+ # Initializes the object
65
+ # @param [Hash] attributes Model attributes in the form of hash
66
+ def initialize(attributes = {})
67
+ return unless attributes.is_a?(Hash)
68
+
69
+ # convert string to symbol for hash key
70
+ attributes = attributes.each_with_object({}){|(k,v), h| h[k.to_sym] = v}
71
+
72
+ if attributes.has_key?(:'product')
73
+ self.product = attributes[:'product']
74
+ end
75
+
76
+ if attributes.has_key?(:'application_id')
77
+ self.application_id = attributes[:'application_id']
78
+ end
79
+
80
+ if attributes.has_key?(:'name')
81
+ self.name = attributes[:'name']
82
+ end
83
+
84
+ end
85
+
86
+ # Show invalid properties with the reasons. Usually used together with valid?
87
+ # @return Array for valid properies with the reasons
88
+ def list_invalid_properties
89
+ invalid_properties = Array.new
90
+ return invalid_properties
91
+ end
92
+
93
+ # Check to see if the all the properties in the model are valid
94
+ # @return true if the model is valid
95
+ def valid?
96
+ product_validator = EnumAttributeValidator.new('String', ["SQUARE_POS", "EXTERNAL_API", "BILLING", "APPOINTMENTS", "INVOICES", "ONLINE_STORE", "PAYROLL", "OTHER"])
97
+ return false unless product_validator.valid?(@product)
98
+ return true
99
+ end
100
+
101
+ # Custom attribute writer method checking allowed values (enum).
102
+ # @param [Object] product Object to be assigned
103
+ def product=(product)
104
+ validator = EnumAttributeValidator.new('String', ["SQUARE_POS", "EXTERNAL_API", "BILLING", "APPOINTMENTS", "INVOICES", "ONLINE_STORE", "PAYROLL", "OTHER"])
105
+ unless validator.valid?(product)
106
+ fail ArgumentError, "invalid value for 'product', must be one of #{validator.allowable_values}."
107
+ end
108
+ @product = product
109
+ end
110
+
111
+ # Checks equality by comparing each attribute.
112
+ # @param [Object] Object to be compared
113
+ def ==(o)
114
+ return true if self.equal?(o)
115
+ self.class == o.class &&
116
+ product == o.product &&
117
+ application_id == o.application_id &&
118
+ name == o.name
119
+ end
120
+
121
+ # @see the `==` method
122
+ # @param [Object] Object to be compared
123
+ def eql?(o)
124
+ self == o
125
+ end
126
+
127
+ # Calculates hash code according to all attributes.
128
+ # @return [Fixnum] Hash code
129
+ def hash
130
+ [product, application_id, name].hash
131
+ end
132
+
133
+ # Builds the object from hash
134
+ # @param [Hash] attributes Model attributes in the form of hash
135
+ # @return [Object] Returns the model itself
136
+ def build_from_hash(attributes)
137
+ return nil unless attributes.is_a?(Hash)
138
+ self.class.swagger_types.each_pair do |key, type|
139
+ if type =~ /\AArray<(.*)>/i
140
+ # check to ensure the input is an array given that the the attribute
141
+ # is documented as an array but the input is not
142
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
143
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map{ |v| _deserialize($1, v) } )
144
+ end
145
+ elsif !attributes[self.class.attribute_map[key]].nil?
146
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
147
+ end # or else data not found in attributes(hash), not an issue as the data can be optional
148
+ end
149
+
150
+ self
151
+ end
152
+
153
+ # Deserializes the data based on type
154
+ # @param string type Data type
155
+ # @param string value Value to be deserialized
156
+ # @return [Object] Deserialized data
157
+ def _deserialize(type, value)
158
+ case type.to_sym
159
+ when :DateTime
160
+ DateTime.parse(value)
161
+ when :Date
162
+ Date.parse(value)
163
+ when :String
164
+ value.to_s
165
+ when :Integer
166
+ value.to_i
167
+ when :Float
168
+ value.to_f
169
+ when :BOOLEAN
170
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
171
+ true
172
+ else
173
+ false
174
+ end
175
+ when :Object
176
+ # generic object (usually a Hash), return directly
177
+ value
178
+ when /\AArray<(?<inner_type>.+)>\z/
179
+ inner_type = Regexp.last_match[:inner_type]
180
+ value.map { |v| _deserialize(inner_type, v) }
181
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
182
+ k_type = Regexp.last_match[:k_type]
183
+ v_type = Regexp.last_match[:v_type]
184
+ {}.tap do |hash|
185
+ value.each do |k, v|
186
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
187
+ end
188
+ end
189
+ else # model
190
+ temp_model = SquareConnect.const_get(type).new
191
+ temp_model.build_from_hash(value)
192
+ end
193
+ end
194
+
195
+ # Returns the string representation of the object
196
+ # @return [String] String presentation of the object
197
+ def to_s
198
+ to_hash.to_s
199
+ end
200
+
201
+ # to_body is an alias to to_hash (backward compatibility)
202
+ # @return [Hash] Returns the object in the form of hash
203
+ def to_body
204
+ to_hash
205
+ end
206
+
207
+ # Returns the object in the form of hash
208
+ # @return [Hash] Returns the object in the form of hash
209
+ def to_hash
210
+ hash = {}
211
+ self.class.attribute_map.each_pair do |attr, param|
212
+ value = self.send(attr)
213
+ next if value.nil?
214
+ hash[param] = _to_hash(value)
215
+ end
216
+ hash
217
+ end
218
+
219
+ # Outputs non-array value in the form of hash
220
+ # For object, use to_hash. Otherwise, just return the value
221
+ # @param [Object] value Any valid value
222
+ # @return [Hash] Returns the value in the form of hash
223
+ def _to_hash(value)
224
+ if value.is_a?(Array)
225
+ value.compact.map{ |v| _to_hash(v) }
226
+ elsif value.is_a?(Hash)
227
+ {}.tap do |hash|
228
+ value.each { |k, v| hash[k] = _to_hash(v) }
229
+ end
230
+ elsif value.respond_to? :to_hash
231
+ value.to_hash
232
+ else
233
+ value
234
+ end
235
+ end
236
+
237
+ end
238
+
239
+ end