quake_timesheets_client 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. checksums.yaml +7 -0
  2. data/GENERATING_README.md +17 -0
  3. data/Gemfile +9 -0
  4. data/README.md +161 -0
  5. data/Rakefile +10 -0
  6. data/build.sh +10 -0
  7. data/commands +13 -0
  8. data/docs/Approval.md +34 -0
  9. data/docs/ApprovalType.md +24 -0
  10. data/docs/ApprovalTypesApi.md +153 -0
  11. data/docs/ApprovalsApi.md +153 -0
  12. data/docs/Dataset.md +24 -0
  13. data/docs/DatasetsApi.md +214 -0
  14. data/docs/EntriesApi.md +251 -0
  15. data/docs/Entry.md +36 -0
  16. data/docs/PeopleApi.md +151 -0
  17. data/docs/Person.md +22 -0
  18. data/git_push.sh +58 -0
  19. data/lib/quake_timesheets_client.rb +58 -0
  20. data/lib/quake_timesheets_client/api/approval_types_api.rb +158 -0
  21. data/lib/quake_timesheets_client/api/approvals_api.rb +174 -0
  22. data/lib/quake_timesheets_client/api/datasets_api.rb +202 -0
  23. data/lib/quake_timesheets_client/api/entries_api.rb +253 -0
  24. data/lib/quake_timesheets_client/api/people_api.rb +151 -0
  25. data/lib/quake_timesheets_client/api_client.rb +396 -0
  26. data/lib/quake_timesheets_client/api_error.rb +57 -0
  27. data/lib/quake_timesheets_client/configuration.rb +302 -0
  28. data/lib/quake_timesheets_client/models/approval.rb +378 -0
  29. data/lib/quake_timesheets_client/models/approval_type.rb +269 -0
  30. data/lib/quake_timesheets_client/models/dataset.rb +268 -0
  31. data/lib/quake_timesheets_client/models/entry.rb +361 -0
  32. data/lib/quake_timesheets_client/models/person.rb +254 -0
  33. data/lib/quake_timesheets_client/version.rb +24 -0
  34. data/quake_timesheets_client.gemspec +38 -0
  35. data/ruby-templates/README.mustache +187 -0
  36. data/ruby-templates/api_client.mustache +263 -0
  37. data/ruby-templates/api_client_faraday_partial.mustache +140 -0
  38. data/ruby-templates/configuration.mustache +379 -0
  39. data/ruby-templates/gem.mustache +59 -0
  40. data/ruby-templates/version.mustache +16 -0
  41. data/ruby.config.yaml +10 -0
  42. data/spec/api/approval_types_api_spec.rb +59 -0
  43. data/spec/api/approvals_api_spec.rb +60 -0
  44. data/spec/api/datasets_api_spec.rb +67 -0
  45. data/spec/api/entries_api_spec.rb +82 -0
  46. data/spec/api/people_api_spec.rb +58 -0
  47. data/spec/api_client_spec.rb +188 -0
  48. data/spec/configuration_spec.rb +42 -0
  49. data/spec/models/approval_spec.rb +86 -0
  50. data/spec/models/approval_type_spec.rb +52 -0
  51. data/spec/models/dataset_spec.rb +52 -0
  52. data/spec/models/entry_spec.rb +92 -0
  53. data/spec/models/person_spec.rb +46 -0
  54. data/spec/spec_helper.rb +111 -0
  55. metadata +149 -0
@@ -0,0 +1,57 @@
1
+ =begin
2
+ #TimesheetsApi (params in:formData)
3
+
4
+ # <p>Another API description</p>
5
+
6
+ The version of the OpenAPI document: 1.0
7
+
8
+ Generated by: https://openapi-generator.tech
9
+ OpenAPI Generator version: 5.1.0
10
+
11
+ =end
12
+
13
+ module Quake::Timesheets
14
+ class ApiError < StandardError
15
+ attr_reader :code, :response_headers, :response_body
16
+
17
+ # Usage examples:
18
+ # ApiError.new
19
+ # ApiError.new("message")
20
+ # ApiError.new(:code => 500, :response_headers => {}, :response_body => "")
21
+ # ApiError.new(:code => 404, :message => "Not Found")
22
+ def initialize(arg = nil)
23
+ if arg.is_a? Hash
24
+ if arg.key?(:message) || arg.key?('message')
25
+ super(arg[:message] || arg['message'])
26
+ else
27
+ super arg
28
+ end
29
+
30
+ arg.each do |k, v|
31
+ instance_variable_set "@#{k}", v
32
+ end
33
+ else
34
+ super arg
35
+ end
36
+ end
37
+
38
+ # Override to_s to display a friendly error message
39
+ def to_s
40
+ message
41
+ end
42
+
43
+ def message
44
+ if @message.nil?
45
+ msg = "Error message: the server returns an error"
46
+ else
47
+ msg = @message
48
+ end
49
+
50
+ msg += "\nHTTP status code: #{code}" if code
51
+ msg += "\nResponse headers: #{response_headers}" if response_headers
52
+ msg += "\nResponse body: #{response_body}" if response_body
53
+
54
+ msg
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,302 @@
1
+ =begin
2
+ #TimesheetsApi (params in:formData)
3
+
4
+ # <p>Another API description</p>
5
+
6
+ The version of the OpenAPI document: 1.0
7
+
8
+ Generated by: https://openapi-generator.tech
9
+ OpenAPI Generator version: 5.1.0
10
+
11
+ =end
12
+
13
+ module Quake::Timesheets
14
+ class Configuration
15
+ # Defines url scheme
16
+ attr_accessor :scheme
17
+
18
+ # Defines url host
19
+ attr_accessor :host
20
+
21
+ # Defines url base path
22
+ attr_accessor :base_path
23
+
24
+ # Define server configuration index
25
+ attr_accessor :server_index
26
+
27
+ # Define server operation configuration index
28
+ attr_accessor :server_operation_index
29
+
30
+ # Default server variables
31
+ attr_accessor :server_variables
32
+
33
+ # Default server operation variables
34
+ attr_accessor :server_operation_variables
35
+
36
+ # Defines API keys used with API Key authentications.
37
+ #
38
+ # @return [Hash] key: parameter name, value: parameter value (API key)
39
+ #
40
+ # @example parameter name is "api_key", API key is "xxx" (e.g. "api_key=xxx" in query string)
41
+ # config.api_key['api_key'] = 'xxx'
42
+ attr_accessor :api_key
43
+
44
+ # Defines API key prefixes used with API Key authentications.
45
+ #
46
+ # @return [Hash] key: parameter name, value: API key prefix
47
+ #
48
+ # @example parameter name is "Authorization", API key prefix is "Token" (e.g. "Authorization: Token xxx" in headers)
49
+ # config.api_key_prefix['api_key'] = 'Token'
50
+ attr_accessor :api_key_prefix
51
+
52
+ # Defines the username used with HTTP basic authentication.
53
+ #
54
+ # @return [String]
55
+ attr_accessor :username
56
+
57
+ # Defines the password used with HTTP basic authentication.
58
+ #
59
+ # @return [String]
60
+ attr_accessor :password
61
+
62
+ # Defines the access token (Bearer) used with OAuth2.
63
+ attr_accessor :access_token
64
+
65
+ # Set this to enable/disable debugging. When enabled (set to true), HTTP request/response
66
+ # details will be logged with `logger.debug` (see the `logger` attribute).
67
+ # Default to false.
68
+ #
69
+ # @return [true, false]
70
+ attr_accessor :debugging
71
+
72
+ # Defines the logger used for debugging.
73
+ # Default to `Rails.logger` (when in Rails) or logging to STDOUT.
74
+ #
75
+ # @return [#debug]
76
+ attr_accessor :logger
77
+
78
+ # Defines the temporary folder to store downloaded files
79
+ # (for API endpoints that have file response).
80
+ # Default to use `Tempfile`.
81
+ #
82
+ # @return [String]
83
+ attr_accessor :temp_folder_path
84
+
85
+ # The time limit for HTTP request in seconds.
86
+ # Default to 0 (never times out).
87
+ attr_accessor :timeout
88
+
89
+ # Set this to false to skip client side validation in the operation.
90
+ # Default to true.
91
+ # @return [true, false]
92
+ attr_accessor :client_side_validation
93
+
94
+ attr_accessor :faraday_middlewares
95
+ ### TLS/SSL setting
96
+ # Set this to false to skip verifying SSL certificate when calling API from https server.
97
+ # Default to true.
98
+ #
99
+ # @note Do NOT set it to false in production code, otherwise you would face multiple types of cryptographic attacks.
100
+ #
101
+ # @return [true, false]
102
+ attr_accessor :ssl_verify
103
+
104
+ ### TLS/SSL setting
105
+ # Any `OpenSSL::SSL::` constant (see https://ruby-doc.org/stdlib-2.5.1/libdoc/openssl/rdoc/OpenSSL/SSL.html)
106
+ #
107
+ # @note Do NOT set it to false in production code, otherwise you would face multiple types of cryptographic attacks.
108
+ #
109
+ attr_accessor :ssl_verify_mode
110
+
111
+ ### TLS/SSL setting
112
+ # Set this to customize the certificate file to verify the peer.
113
+ #
114
+ # @return [String] the path to the certificate file
115
+ attr_accessor :ssl_ca_file
116
+
117
+ ### TLS/SSL setting
118
+ # Client certificate file (for client certificate)
119
+ attr_accessor :ssl_client_cert
120
+
121
+ ### TLS/SSL setting
122
+ # Client private key file (for client certificate)
123
+ attr_accessor :ssl_client_key
124
+
125
+ # Set this to customize parameters encoding of array parameter with multi collectionFormat.
126
+ # Default to nil.
127
+ #
128
+ # @see The params_encoding option of Ethon. Related source code:
129
+ # https://github.com/typhoeus/ethon/blob/master/lib/ethon/easy/queryable.rb#L96
130
+ attr_accessor :params_encoding
131
+
132
+ attr_accessor :inject_format
133
+
134
+ attr_accessor :force_ending_format
135
+
136
+ attr_accessor :server_settings
137
+
138
+ attr_accessor :user_agent
139
+
140
+ def initialize
141
+ @scheme = 'https'
142
+ @host = 'timesheetsapi.svc.lumbry.co.uk'
143
+ @base_path = ''
144
+ @server_index = 0
145
+ @server_operation_index = {}
146
+ @server_variables = {}
147
+ @server_operation_variables = {}
148
+ @api_key = {}
149
+ @api_key_prefix = {}
150
+ @timeout = 0
151
+ @client_side_validation = true
152
+ @ssl_verify = true
153
+ @ssl_verify_mode = nil
154
+ @ssl_ca_file = nil
155
+ @ssl_client_cert = nil
156
+ @ssl_client_key = nil
157
+ @faraday_middlewares = []
158
+ @debugging = false
159
+ @inject_format = false
160
+ @force_ending_format = false
161
+ @logger = defined?(Rails) ? Rails.logger : Logger.new(STDOUT)
162
+ @server_settings = default_server_settings
163
+ @user_agent = "OpenAPI-Generator/#{VERSION}/ruby"
164
+
165
+ timesheets_initialize
166
+
167
+ yield(self) if block_given?
168
+ end
169
+
170
+ ###################################
171
+ # This is newly added / overrides #
172
+ # to support specific for our app #
173
+ # #
174
+ # This will need to be handled #
175
+ # differently when we change auth #
176
+ # schemes #
177
+ ###################################
178
+ def timesheets_initialize
179
+ @api_key_prefix['authToken'] = 'Bearer'
180
+ @user_agent = "quake/timesheets-client/ruby/#{VERSION}"
181
+ end
182
+
183
+ def endpoint=(value)
184
+ @server_settings = [{ url: value }]
185
+ end
186
+ ###################################
187
+ # end of overrides #
188
+ ###################################
189
+
190
+ # The default Configuration object.
191
+ def self.default
192
+ @@default ||= Configuration.new
193
+ end
194
+
195
+ def configure
196
+ yield(self) if block_given?
197
+ end
198
+
199
+ def scheme=(scheme)
200
+ # remove :// from scheme
201
+ @scheme = scheme.sub(/:\/\//, '')
202
+ end
203
+
204
+ def host=(host)
205
+ # remove http(s):// and anything after a slash
206
+ @host = host.sub(/https?:\/\//, '').split('/').first
207
+ end
208
+
209
+ def base_path=(base_path)
210
+ # Add leading and trailing slashes to base_path
211
+ @base_path = "/#{base_path}".gsub(/\/+/, '/')
212
+ @base_path = '' if @base_path == '/'
213
+ end
214
+
215
+ # Returns base URL for specified operation based on server settings
216
+ def base_url(operation = nil)
217
+ index = server_operation_index.fetch(operation, server_index)
218
+ return "#{scheme}://#{[host, base_path].join('/').gsub(/\/+/, '/')}".sub(/\/+\z/, '') if index == nil
219
+
220
+ server_url(index, server_operation_variables.fetch(operation, server_variables), operation_server_settings[operation])
221
+ end
222
+
223
+ # Gets API key (with prefix if set).
224
+ # @param [String] param_name the parameter name of API key auth
225
+ def api_key_with_prefix(param_name, param_alias = nil)
226
+ key = @api_key[param_name]
227
+ key = @api_key.fetch(param_alias, key) unless param_alias.nil?
228
+ if @api_key_prefix[param_name]
229
+ "#{@api_key_prefix[param_name]} #{key}"
230
+ else
231
+ key
232
+ end
233
+ end
234
+
235
+ # Gets Basic Auth token string
236
+ def basic_auth_token
237
+ 'Basic ' + ["#{username}:#{password}"].pack('m').delete("\r\n")
238
+ end
239
+
240
+ # Returns Auth Settings hash for api client.
241
+ def auth_settings
242
+ {
243
+ 'authToken' =>
244
+ {
245
+ type: 'api_key',
246
+ in: 'header',
247
+ key: 'authorization',
248
+ value: api_key_with_prefix('authToken')
249
+ },
250
+ }
251
+ end
252
+
253
+ # Returns an array of Server setting
254
+ def default_server_settings
255
+ [
256
+ {
257
+ url: "https://timesheetsapi.svc.lumbry.co.uk:443",
258
+ description: "No description provided",
259
+ }
260
+ ]
261
+ end
262
+
263
+ def operation_server_settings
264
+ {
265
+ }
266
+ end
267
+
268
+ # Returns URL based on server settings
269
+ #
270
+ # @param index array index of the server settings
271
+ # @param variables hash of variable and the corresponding value
272
+ def server_url(index, variables = {}, servers = nil)
273
+ servers = server_settings if servers == nil
274
+
275
+ # check array index out of bound
276
+ if (index < 0 || index >= servers.size)
277
+ fail ArgumentError, "Invalid index #{index} when selecting the server. Must be less than #{servers.size}"
278
+ end
279
+
280
+ server = servers[index]
281
+ url = server[:url]
282
+
283
+ return url unless server.key? :variables
284
+
285
+ # go through variable and assign a value
286
+ server[:variables].each do |name, variable|
287
+ if variables.key?(name)
288
+ if (!server[:variables][name].key?(:enum_values) || server[:variables][name][:enum_values].include?(variables[name]))
289
+ url.gsub! "{" + name.to_s + "}", variables[name]
290
+ else
291
+ fail ArgumentError, "The variable `#{name}` in the server URL has invalid value #{variables[name]}. Must be #{server[:variables][name][:enum_values]}."
292
+ end
293
+ else
294
+ # use default value
295
+ url.gsub! "{" + name.to_s + "}", server[:variables][name][:default_value]
296
+ end
297
+ end
298
+
299
+ url
300
+ end
301
+ end
302
+ end
@@ -0,0 +1,378 @@
1
+ =begin
2
+ #TimesheetsApi (params in:formData)
3
+
4
+ # <p>Another API description</p>
5
+
6
+ The version of the OpenAPI document: 1.0
7
+
8
+ Generated by: https://openapi-generator.tech
9
+ OpenAPI Generator version: 5.1.0
10
+
11
+ =end
12
+
13
+ require 'date'
14
+ require 'time'
15
+
16
+ module Quake::Timesheets
17
+ class Approval
18
+ # The ID of the approval type
19
+ attr_accessor :id
20
+
21
+ # ID of the dataset this approval type is linked to
22
+ attr_accessor :dataset_id
23
+
24
+ # The ID of the Entry this Approval is linked to
25
+ attr_accessor :entry_ids
26
+
27
+ # The ID of the Person who created this Approval
28
+ attr_accessor :approver_id
29
+
30
+ # The ID of the Approval Type of this Approval
31
+ attr_accessor :approval_type_id
32
+
33
+ attr_accessor :state
34
+
35
+ attr_accessor :notes
36
+
37
+ # Time at which the record was created
38
+ attr_accessor :created_at
39
+
40
+ # Time at which the record was updated
41
+ attr_accessor :updated_at
42
+
43
+ class EnumAttributeValidator
44
+ attr_reader :datatype
45
+ attr_reader :allowable_values
46
+
47
+ def initialize(datatype, allowable_values)
48
+ @allowable_values = allowable_values.map do |value|
49
+ case datatype.to_s
50
+ when /Integer/i
51
+ value.to_i
52
+ when /Float/i
53
+ value.to_f
54
+ else
55
+ value
56
+ end
57
+ end
58
+ end
59
+
60
+ def valid?(value)
61
+ !value || allowable_values.include?(value)
62
+ end
63
+ end
64
+
65
+ # Attribute mapping from ruby-style variable name to JSON key.
66
+ def self.attribute_map
67
+ {
68
+ :'id' => :'id',
69
+ :'dataset_id' => :'dataset_id',
70
+ :'entry_ids' => :'entry_ids',
71
+ :'approver_id' => :'approver_id',
72
+ :'approval_type_id' => :'approval_type_id',
73
+ :'state' => :'state',
74
+ :'notes' => :'notes',
75
+ :'created_at' => :'created_at',
76
+ :'updated_at' => :'updated_at'
77
+ }
78
+ end
79
+
80
+ # Returns all the JSON keys this model knows about
81
+ def self.acceptable_attributes
82
+ attribute_map.values
83
+ end
84
+
85
+ # Attribute type mapping.
86
+ def self.openapi_types
87
+ {
88
+ :'id' => :'String',
89
+ :'dataset_id' => :'String',
90
+ :'entry_ids' => :'Array<String>',
91
+ :'approver_id' => :'String',
92
+ :'approval_type_id' => :'String',
93
+ :'state' => :'String',
94
+ :'notes' => :'String',
95
+ :'created_at' => :'String',
96
+ :'updated_at' => :'String'
97
+ }
98
+ end
99
+
100
+ # List of attributes with nullable: true
101
+ def self.openapi_nullable
102
+ Set.new([
103
+ ])
104
+ end
105
+
106
+ # Initializes the object
107
+ # @param [Hash] attributes Model attributes in the form of hash
108
+ def initialize(attributes = {})
109
+ if (!attributes.is_a?(Hash))
110
+ fail ArgumentError, "The input argument (attributes) must be a hash in `Quake::Timesheets::Approval` initialize method"
111
+ end
112
+
113
+ # check to see if the attribute exists and convert string to symbol for hash key
114
+ attributes = attributes.each_with_object({}) { |(k, v), h|
115
+ if (!self.class.attribute_map.key?(k.to_sym))
116
+ fail ArgumentError, "`#{k}` is not a valid attribute in `Quake::Timesheets::Approval`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
117
+ end
118
+ h[k.to_sym] = v
119
+ }
120
+
121
+ if attributes.key?(:'id')
122
+ self.id = attributes[:'id']
123
+ end
124
+
125
+ if attributes.key?(:'dataset_id')
126
+ self.dataset_id = attributes[:'dataset_id']
127
+ end
128
+
129
+ if attributes.key?(:'entry_ids')
130
+ if (value = attributes[:'entry_ids']).is_a?(Array)
131
+ self.entry_ids = value
132
+ end
133
+ end
134
+
135
+ if attributes.key?(:'approver_id')
136
+ self.approver_id = attributes[:'approver_id']
137
+ end
138
+
139
+ if attributes.key?(:'approval_type_id')
140
+ self.approval_type_id = attributes[:'approval_type_id']
141
+ end
142
+
143
+ if attributes.key?(:'state')
144
+ self.state = attributes[:'state']
145
+ end
146
+
147
+ if attributes.key?(:'notes')
148
+ self.notes = attributes[:'notes']
149
+ end
150
+
151
+ if attributes.key?(:'created_at')
152
+ self.created_at = attributes[:'created_at']
153
+ end
154
+
155
+ if attributes.key?(:'updated_at')
156
+ self.updated_at = attributes[:'updated_at']
157
+ end
158
+ end
159
+
160
+ # Show invalid properties with the reasons. Usually used together with valid?
161
+ # @return Array for valid properties with the reasons
162
+ def list_invalid_properties
163
+ invalid_properties = Array.new
164
+ if @id.nil?
165
+ invalid_properties.push('invalid value for "id", id cannot be nil.')
166
+ end
167
+
168
+ if @dataset_id.nil?
169
+ invalid_properties.push('invalid value for "dataset_id", dataset_id cannot be nil.')
170
+ end
171
+
172
+ if @entry_ids.nil?
173
+ invalid_properties.push('invalid value for "entry_ids", entry_ids cannot be nil.')
174
+ end
175
+
176
+ if @approver_id.nil?
177
+ invalid_properties.push('invalid value for "approver_id", approver_id cannot be nil.')
178
+ end
179
+
180
+ if @approval_type_id.nil?
181
+ invalid_properties.push('invalid value for "approval_type_id", approval_type_id cannot be nil.')
182
+ end
183
+
184
+ if @state.nil?
185
+ invalid_properties.push('invalid value for "state", state cannot be nil.')
186
+ end
187
+
188
+ if @notes.nil?
189
+ invalid_properties.push('invalid value for "notes", notes cannot be nil.')
190
+ end
191
+
192
+ if @created_at.nil?
193
+ invalid_properties.push('invalid value for "created_at", created_at cannot be nil.')
194
+ end
195
+
196
+ if @updated_at.nil?
197
+ invalid_properties.push('invalid value for "updated_at", updated_at cannot be nil.')
198
+ end
199
+
200
+ invalid_properties
201
+ end
202
+
203
+ # Check to see if the all the properties in the model are valid
204
+ # @return true if the model is valid
205
+ def valid?
206
+ return false if @id.nil?
207
+ return false if @dataset_id.nil?
208
+ return false if @entry_ids.nil?
209
+ return false if @approver_id.nil?
210
+ return false if @approval_type_id.nil?
211
+ return false if @state.nil?
212
+ state_validator = EnumAttributeValidator.new('String', ["requested", "approved", "withdrawn"])
213
+ return false unless state_validator.valid?(@state)
214
+ return false if @notes.nil?
215
+ return false if @created_at.nil?
216
+ return false if @updated_at.nil?
217
+ true
218
+ end
219
+
220
+ # Custom attribute writer method checking allowed values (enum).
221
+ # @param [Object] state Object to be assigned
222
+ def state=(state)
223
+ validator = EnumAttributeValidator.new('String', ["requested", "approved", "withdrawn"])
224
+ unless validator.valid?(state)
225
+ fail ArgumentError, "invalid value for \"state\", must be one of #{validator.allowable_values}."
226
+ end
227
+ @state = state
228
+ end
229
+
230
+ # Checks equality by comparing each attribute.
231
+ # @param [Object] Object to be compared
232
+ def ==(o)
233
+ return true if self.equal?(o)
234
+ self.class == o.class &&
235
+ id == o.id &&
236
+ dataset_id == o.dataset_id &&
237
+ entry_ids == o.entry_ids &&
238
+ approver_id == o.approver_id &&
239
+ approval_type_id == o.approval_type_id &&
240
+ state == o.state &&
241
+ notes == o.notes &&
242
+ created_at == o.created_at &&
243
+ updated_at == o.updated_at
244
+ end
245
+
246
+ # @see the `==` method
247
+ # @param [Object] Object to be compared
248
+ def eql?(o)
249
+ self == o
250
+ end
251
+
252
+ # Calculates hash code according to all attributes.
253
+ # @return [Integer] Hash code
254
+ def hash
255
+ [id, dataset_id, entry_ids, approver_id, approval_type_id, state, notes, created_at, updated_at].hash
256
+ end
257
+
258
+ # Builds the object from hash
259
+ # @param [Hash] attributes Model attributes in the form of hash
260
+ # @return [Object] Returns the model itself
261
+ def self.build_from_hash(attributes)
262
+ new.build_from_hash(attributes)
263
+ end
264
+
265
+ # Builds the object from hash
266
+ # @param [Hash] attributes Model attributes in the form of hash
267
+ # @return [Object] Returns the model itself
268
+ def build_from_hash(attributes)
269
+ return nil unless attributes.is_a?(Hash)
270
+ self.class.openapi_types.each_pair do |key, type|
271
+ if attributes[self.class.attribute_map[key]].nil? && self.class.openapi_nullable.include?(key)
272
+ self.send("#{key}=", nil)
273
+ elsif type =~ /\AArray<(.*)>/i
274
+ # check to ensure the input is an array given that the attribute
275
+ # is documented as an array but the input is not
276
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
277
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
278
+ end
279
+ elsif !attributes[self.class.attribute_map[key]].nil?
280
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
281
+ end
282
+ end
283
+
284
+ self
285
+ end
286
+
287
+ # Deserializes the data based on type
288
+ # @param string type Data type
289
+ # @param string value Value to be deserialized
290
+ # @return [Object] Deserialized data
291
+ def _deserialize(type, value)
292
+ case type.to_sym
293
+ when :Time
294
+ Time.parse(value)
295
+ when :Date
296
+ Date.parse(value)
297
+ when :String
298
+ value.to_s
299
+ when :Integer
300
+ value.to_i
301
+ when :Float
302
+ value.to_f
303
+ when :Boolean
304
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
305
+ true
306
+ else
307
+ false
308
+ end
309
+ when :Object
310
+ # generic object (usually a Hash), return directly
311
+ value
312
+ when /\AArray<(?<inner_type>.+)>\z/
313
+ inner_type = Regexp.last_match[:inner_type]
314
+ value.map { |v| _deserialize(inner_type, v) }
315
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
316
+ k_type = Regexp.last_match[:k_type]
317
+ v_type = Regexp.last_match[:v_type]
318
+ {}.tap do |hash|
319
+ value.each do |k, v|
320
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
321
+ end
322
+ end
323
+ else # model
324
+ # models (e.g. Pet) or oneOf
325
+ klass = Quake::Timesheets.const_get(type)
326
+ klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
327
+ end
328
+ end
329
+
330
+ # Returns the string representation of the object
331
+ # @return [String] String presentation of the object
332
+ def to_s
333
+ to_hash.to_s
334
+ end
335
+
336
+ # to_body is an alias to to_hash (backward compatibility)
337
+ # @return [Hash] Returns the object in the form of hash
338
+ def to_body
339
+ to_hash
340
+ end
341
+
342
+ # Returns the object in the form of hash
343
+ # @return [Hash] Returns the object in the form of hash
344
+ def to_hash
345
+ hash = {}
346
+ self.class.attribute_map.each_pair do |attr, param|
347
+ value = self.send(attr)
348
+ if value.nil?
349
+ is_nullable = self.class.openapi_nullable.include?(attr)
350
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
351
+ end
352
+
353
+ hash[param] = _to_hash(value)
354
+ end
355
+ hash
356
+ end
357
+
358
+ # Outputs non-array value in the form of hash
359
+ # For object, use to_hash. Otherwise, just return the value
360
+ # @param [Object] value Any valid value
361
+ # @return [Hash] Returns the value in the form of hash
362
+ def _to_hash(value)
363
+ if value.is_a?(Array)
364
+ value.compact.map { |v| _to_hash(v) }
365
+ elsif value.is_a?(Hash)
366
+ {}.tap do |hash|
367
+ value.each { |k, v| hash[k] = _to_hash(v) }
368
+ end
369
+ elsif value.respond_to? :to_hash
370
+ value.to_hash
371
+ else
372
+ value
373
+ end
374
+ end
375
+
376
+ end
377
+
378
+ end