dear-inventory-ruby 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,57 @@
1
+ =begin
2
+ #DEAR Inventory API
3
+
4
+ #This specifing endpoints for DEAR Inventory API
5
+
6
+ The version of the OpenAPI document: 2.0.0
7
+ Contact: nnhansg@gmail.com
8
+ Generated by: https://openapi-generator.tech
9
+ OpenAPI Generator version: 4.2.3
10
+
11
+ =end
12
+
13
+ module DearInventoryRuby
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,250 @@
1
+ =begin
2
+ #DEAR Inventory API
3
+
4
+ #This specifing endpoints for DEAR Inventory API
5
+
6
+ The version of the OpenAPI document: 2.0.0
7
+ Contact: nnhansg@gmail.com
8
+ Generated by: https://openapi-generator.tech
9
+ OpenAPI Generator version: 4.2.3
10
+
11
+ =end
12
+
13
+ module DearInventoryRuby
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
+ # Defines API keys used with API Key authentications.
25
+ #
26
+ # @return [Hash] key: parameter name, value: parameter value (API key)
27
+ #
28
+ # @example parameter name is "api_key", API key is "xxx" (e.g. "api_key=xxx" in query string)
29
+ # config.api_key['api_key'] = 'xxx'
30
+ attr_accessor :api_key
31
+
32
+ # Defines API key prefixes used with API Key authentications.
33
+ #
34
+ # @return [Hash] key: parameter name, value: API key prefix
35
+ #
36
+ # @example parameter name is "Authorization", API key prefix is "Token" (e.g. "Authorization: Token xxx" in headers)
37
+ # config.api_key_prefix['api_key'] = 'Token'
38
+ attr_accessor :api_key_prefix
39
+
40
+ # Defines the username used with HTTP basic authentication.
41
+ #
42
+ # @return [String]
43
+ attr_accessor :username
44
+
45
+ # Defines the password used with HTTP basic authentication.
46
+ #
47
+ # @return [String]
48
+ attr_accessor :password
49
+
50
+ # Defines the access token (Bearer) used with OAuth2.
51
+ attr_accessor :access_token
52
+
53
+ # Set this to enable/disable debugging. When enabled (set to true), HTTP request/response
54
+ # details will be logged with `logger.debug` (see the `logger` attribute).
55
+ # Default to false.
56
+ #
57
+ # @return [true, false]
58
+ attr_accessor :debugging
59
+
60
+ # Defines the logger used for debugging.
61
+ # Default to `Rails.logger` (when in Rails) or logging to STDOUT.
62
+ #
63
+ # @return [#debug]
64
+ attr_accessor :logger
65
+
66
+ # Defines the temporary folder to store downloaded files
67
+ # (for API endpoints that have file response).
68
+ # Default to use `Tempfile`.
69
+ #
70
+ # @return [String]
71
+ attr_accessor :temp_folder_path
72
+
73
+ # The time limit for HTTP request in seconds.
74
+ # Default to 0 (never times out).
75
+ attr_accessor :timeout
76
+
77
+ # Set this to false to skip client side validation in the operation.
78
+ # Default to true.
79
+ # @return [true, false]
80
+ attr_accessor :client_side_validation
81
+
82
+ ### TLS/SSL setting
83
+ # Set this to false to skip verifying SSL certificate when calling API from https server.
84
+ # Default to true.
85
+ #
86
+ # @note Do NOT set it to false in production code, otherwise you would face multiple types of cryptographic attacks.
87
+ #
88
+ # @return [true, false]
89
+ attr_accessor :ssl_verify
90
+
91
+ ### TLS/SSL setting
92
+ # Any `OpenSSL::SSL::` constant (see https://ruby-doc.org/stdlib-2.5.1/libdoc/openssl/rdoc/OpenSSL/SSL.html)
93
+ #
94
+ # @note Do NOT set it to false in production code, otherwise you would face multiple types of cryptographic attacks.
95
+ #
96
+ attr_accessor :ssl_verify_mode
97
+
98
+ ### TLS/SSL setting
99
+ # Set this to customize the certificate file to verify the peer.
100
+ #
101
+ # @return [String] the path to the certificate file
102
+ attr_accessor :ssl_ca_file
103
+
104
+ ### TLS/SSL setting
105
+ # Client certificate file (for client certificate)
106
+ attr_accessor :ssl_client_cert
107
+
108
+ ### TLS/SSL setting
109
+ # Client private key file (for client certificate)
110
+ attr_accessor :ssl_client_key
111
+
112
+ # Set this to customize parameters encoding of array parameter with multi collectionFormat.
113
+ # Default to nil.
114
+ #
115
+ # @see The params_encoding option of Ethon. Related source code:
116
+ # https://github.com/typhoeus/ethon/blob/master/lib/ethon/easy/queryable.rb#L96
117
+ attr_accessor :params_encoding
118
+
119
+ attr_accessor :inject_format
120
+
121
+ attr_accessor :force_ending_format
122
+
123
+ def initialize
124
+ @scheme = 'https'
125
+ @host = 'inventory.dearsystems.com'
126
+ @base_path = '/ExternalApi/v2'
127
+ @api_key = {}
128
+ @api_key_prefix = {}
129
+ @timeout = 0
130
+ @client_side_validation = true
131
+ @ssl_verify = true
132
+ @ssl_verify_mode = nil
133
+ @ssl_ca_file = nil
134
+ @ssl_client_cert = nil
135
+ @ssl_client_key = nil
136
+ @debugging = false
137
+ @inject_format = false
138
+ @force_ending_format = false
139
+ @logger = defined?(Rails) ? Rails.logger : Logger.new(STDOUT)
140
+
141
+ yield(self) if block_given?
142
+ end
143
+
144
+ # The default Configuration object.
145
+ def self.default
146
+ @@default ||= Configuration.new
147
+ end
148
+
149
+ def configure
150
+ yield(self) if block_given?
151
+ end
152
+
153
+ def scheme=(scheme)
154
+ # remove :// from scheme
155
+ @scheme = scheme.sub(/:\/\//, '')
156
+ end
157
+
158
+ def host=(host)
159
+ # remove http(s):// and anything after a slash
160
+ @host = host.sub(/https?:\/\//, '').split('/').first
161
+ end
162
+
163
+ def base_path=(base_path)
164
+ # Add leading and trailing slashes to base_path
165
+ @base_path = "/#{base_path}".gsub(/\/+/, '/')
166
+ @base_path = '' if @base_path == '/'
167
+ end
168
+
169
+ def base_url
170
+ "#{scheme}://#{[host, base_path].join('/').gsub(/\/+/, '/')}".sub(/\/+\z/, '')
171
+ end
172
+
173
+ # Gets API key (with prefix if set).
174
+ # @param [String] param_name the parameter name of API key auth
175
+ def api_key_with_prefix(param_name)
176
+ if @api_key_prefix[param_name]
177
+ "#{@api_key_prefix[param_name]} #{@api_key[param_name]}"
178
+ else
179
+ @api_key[param_name]
180
+ end
181
+ end
182
+
183
+ # Gets Basic Auth token string
184
+ def basic_auth_token
185
+ 'Basic ' + ["#{username}:#{password}"].pack('m').delete("\r\n")
186
+ end
187
+
188
+ # Returns Auth Settings hash for api client.
189
+ def auth_settings
190
+ {
191
+ 'accountID' =>
192
+ {
193
+ type: 'api_key',
194
+ in: 'header',
195
+ key: 'api_auth_accountid',
196
+ value: api_key_with_prefix('api_auth_accountid')
197
+ },
198
+ 'appKey' =>
199
+ {
200
+ type: 'api_key',
201
+ in: 'header',
202
+ key: 'api_auth_applicationkey',
203
+ value: api_key_with_prefix('api_auth_applicationkey')
204
+ },
205
+ }
206
+ end
207
+
208
+ # Returns an array of Server setting
209
+ def server_settings
210
+ [
211
+ {
212
+ url: "https://inventory.dearsystems.com/ExternalApi/v2",
213
+ description: "No description provided",
214
+ }
215
+ ]
216
+ end
217
+
218
+ # Returns URL based on server settings
219
+ #
220
+ # @param index array index of the server settings
221
+ # @param variables hash of variable and the corresponding value
222
+ def server_url(index, variables = {})
223
+ servers = server_settings
224
+
225
+ # check array index out of bound
226
+ if (index < 0 || index >= servers.size)
227
+ fail ArgumentError, "Invalid index #{index} when selecting the server. Must be less than #{servers.size}"
228
+ end
229
+
230
+ server = servers[index]
231
+ url = server[:url]
232
+
233
+ # go through variable and assign a value
234
+ server[:variables].each do |name, variable|
235
+ if variables.key?(name)
236
+ if (server[:variables][name][:enum_values].include? variables[name])
237
+ url.gsub! "{" + name.to_s + "}", variables[name]
238
+ else
239
+ fail ArgumentError, "The variable `#{name}` in the server URL has invalid value #{variables[name]}. Must be #{server[:variables][name][:enum_values]}."
240
+ end
241
+ else
242
+ # use default value
243
+ url.gsub! "{" + name.to_s + "}", server[:variables][name][:default_value]
244
+ end
245
+ end
246
+
247
+ url
248
+ end
249
+ end
250
+ end
@@ -0,0 +1,398 @@
1
+ =begin
2
+ #DEAR Inventory API
3
+
4
+ #This specifing endpoints for DEAR Inventory API
5
+
6
+ The version of the OpenAPI document: 2.0.0
7
+ Contact: nnhansg@gmail.com
8
+ Generated by: https://openapi-generator.tech
9
+ OpenAPI Generator version: 4.2.3
10
+
11
+ =end
12
+
13
+ require 'date'
14
+
15
+ module DearInventoryRuby
16
+ class Address
17
+ # If passed in PUT method, entry will be searched by id, found entry will be updated, otherwise created
18
+ attr_accessor :id
19
+
20
+ # Address Line 1
21
+ attr_accessor :line1
22
+
23
+ # Address Line 2
24
+ attr_accessor :line2
25
+
26
+ # City / Suburb
27
+ attr_accessor :city
28
+
29
+ # State / Province
30
+ attr_accessor :state
31
+
32
+ # Zip / PostCode
33
+ attr_accessor :post_code
34
+
35
+ # Country name
36
+ attr_accessor :country
37
+
38
+ # Address Type. Should be one of the following values: `Billing`, `Business` or `Shipping`.
39
+ attr_accessor :type
40
+
41
+ # Points that Address is used as default for chosen Type. `false` as default.
42
+ attr_accessor :default_for_type
43
+
44
+ class EnumAttributeValidator
45
+ attr_reader :datatype
46
+ attr_reader :allowable_values
47
+
48
+ def initialize(datatype, allowable_values)
49
+ @allowable_values = allowable_values.map do |value|
50
+ case datatype.to_s
51
+ when /Integer/i
52
+ value.to_i
53
+ when /Float/i
54
+ value.to_f
55
+ else
56
+ value
57
+ end
58
+ end
59
+ end
60
+
61
+ def valid?(value)
62
+ !value || allowable_values.include?(value)
63
+ end
64
+ end
65
+
66
+ # Attribute mapping from ruby-style variable name to JSON key.
67
+ def self.attribute_map
68
+ {
69
+ :'id' => :'ID',
70
+ :'line1' => :'Line1',
71
+ :'line2' => :'Line2',
72
+ :'city' => :'City',
73
+ :'state' => :'State',
74
+ :'post_code' => :'PostCode',
75
+ :'country' => :'Country',
76
+ :'type' => :'Type',
77
+ :'default_for_type' => :'DefaultForType'
78
+ }
79
+ end
80
+
81
+ # Attribute type mapping.
82
+ def self.openapi_types
83
+ {
84
+ :'id' => :'String',
85
+ :'line1' => :'String',
86
+ :'line2' => :'String',
87
+ :'city' => :'String',
88
+ :'state' => :'String',
89
+ :'post_code' => :'String',
90
+ :'country' => :'String',
91
+ :'type' => :'String',
92
+ :'default_for_type' => :'Boolean'
93
+ }
94
+ end
95
+
96
+ # List of attributes with nullable: true
97
+ def self.openapi_nullable
98
+ Set.new([
99
+ ])
100
+ end
101
+
102
+ # Initializes the object
103
+ # @param [Hash] attributes Model attributes in the form of hash
104
+ def initialize(attributes = {})
105
+ if (!attributes.is_a?(Hash))
106
+ fail ArgumentError, "The input argument (attributes) must be a hash in `DearInventoryRuby::Address` initialize method"
107
+ end
108
+
109
+ # check to see if the attribute exists and convert string to symbol for hash key
110
+ attributes = attributes.each_with_object({}) { |(k, v), h|
111
+ if (!self.class.attribute_map.key?(k.to_sym))
112
+ fail ArgumentError, "`#{k}` is not a valid attribute in `DearInventoryRuby::Address`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
113
+ end
114
+ h[k.to_sym] = v
115
+ }
116
+
117
+ if attributes.key?(:'id')
118
+ self.id = attributes[:'id']
119
+ end
120
+
121
+ if attributes.key?(:'line1')
122
+ self.line1 = attributes[:'line1']
123
+ end
124
+
125
+ if attributes.key?(:'line2')
126
+ self.line2 = attributes[:'line2']
127
+ end
128
+
129
+ if attributes.key?(:'city')
130
+ self.city = attributes[:'city']
131
+ end
132
+
133
+ if attributes.key?(:'state')
134
+ self.state = attributes[:'state']
135
+ end
136
+
137
+ if attributes.key?(:'post_code')
138
+ self.post_code = attributes[:'post_code']
139
+ end
140
+
141
+ if attributes.key?(:'country')
142
+ self.country = attributes[:'country']
143
+ end
144
+
145
+ if attributes.key?(:'type')
146
+ self.type = attributes[:'type']
147
+ end
148
+
149
+ if attributes.key?(:'default_for_type')
150
+ self.default_for_type = attributes[:'default_for_type']
151
+ else
152
+ self.default_for_type = false
153
+ end
154
+ end
155
+
156
+ # Show invalid properties with the reasons. Usually used together with valid?
157
+ # @return Array for valid properties with the reasons
158
+ def list_invalid_properties
159
+ invalid_properties = Array.new
160
+ if !@line1.nil? && @line1.to_s.length > 256
161
+ invalid_properties.push('invalid value for "line1", the character length must be smaller than or equal to 256.')
162
+ end
163
+
164
+ if !@line2.nil? && @line2.to_s.length > 256
165
+ invalid_properties.push('invalid value for "line2", the character length must be smaller than or equal to 256.')
166
+ end
167
+
168
+ if !@city.nil? && @city.to_s.length > 256
169
+ invalid_properties.push('invalid value for "city", the character length must be smaller than or equal to 256.')
170
+ end
171
+
172
+ if !@state.nil? && @state.to_s.length > 256
173
+ invalid_properties.push('invalid value for "state", the character length must be smaller than or equal to 256.')
174
+ end
175
+
176
+ if !@post_code.nil? && @post_code.to_s.length > 20
177
+ invalid_properties.push('invalid value for "post_code", the character length must be smaller than or equal to 20.')
178
+ end
179
+
180
+ invalid_properties
181
+ end
182
+
183
+ # Check to see if the all the properties in the model are valid
184
+ # @return true if the model is valid
185
+ def valid?
186
+ return false if !@line1.nil? && @line1.to_s.length > 256
187
+ return false if !@line2.nil? && @line2.to_s.length > 256
188
+ return false if !@city.nil? && @city.to_s.length > 256
189
+ return false if !@state.nil? && @state.to_s.length > 256
190
+ return false if !@post_code.nil? && @post_code.to_s.length > 20
191
+ type_validator = EnumAttributeValidator.new('String', ["Billing", "Business", "Shipping"])
192
+ return false unless type_validator.valid?(@type)
193
+ true
194
+ end
195
+
196
+ # Custom attribute writer method with validation
197
+ # @param [Object] line1 Value to be assigned
198
+ def line1=(line1)
199
+ if !line1.nil? && line1.to_s.length > 256
200
+ fail ArgumentError, 'invalid value for "line1", the character length must be smaller than or equal to 256.'
201
+ end
202
+
203
+ @line1 = line1
204
+ end
205
+
206
+ # Custom attribute writer method with validation
207
+ # @param [Object] line2 Value to be assigned
208
+ def line2=(line2)
209
+ if !line2.nil? && line2.to_s.length > 256
210
+ fail ArgumentError, 'invalid value for "line2", the character length must be smaller than or equal to 256.'
211
+ end
212
+
213
+ @line2 = line2
214
+ end
215
+
216
+ # Custom attribute writer method with validation
217
+ # @param [Object] city Value to be assigned
218
+ def city=(city)
219
+ if !city.nil? && city.to_s.length > 256
220
+ fail ArgumentError, 'invalid value for "city", the character length must be smaller than or equal to 256.'
221
+ end
222
+
223
+ @city = city
224
+ end
225
+
226
+ # Custom attribute writer method with validation
227
+ # @param [Object] state Value to be assigned
228
+ def state=(state)
229
+ if !state.nil? && state.to_s.length > 256
230
+ fail ArgumentError, 'invalid value for "state", the character length must be smaller than or equal to 256.'
231
+ end
232
+
233
+ @state = state
234
+ end
235
+
236
+ # Custom attribute writer method with validation
237
+ # @param [Object] post_code Value to be assigned
238
+ def post_code=(post_code)
239
+ if !post_code.nil? && post_code.to_s.length > 20
240
+ fail ArgumentError, 'invalid value for "post_code", the character length must be smaller than or equal to 20.'
241
+ end
242
+
243
+ @post_code = post_code
244
+ end
245
+
246
+ # Custom attribute writer method checking allowed values (enum).
247
+ # @param [Object] type Object to be assigned
248
+ def type=(type)
249
+ validator = EnumAttributeValidator.new('String', ["Billing", "Business", "Shipping"])
250
+ unless validator.valid?(type)
251
+ fail ArgumentError, "invalid value for \"type\", must be one of #{validator.allowable_values}."
252
+ end
253
+ @type = type
254
+ end
255
+
256
+ # Checks equality by comparing each attribute.
257
+ # @param [Object] Object to be compared
258
+ def ==(o)
259
+ return true if self.equal?(o)
260
+ self.class == o.class &&
261
+ id == o.id &&
262
+ line1 == o.line1 &&
263
+ line2 == o.line2 &&
264
+ city == o.city &&
265
+ state == o.state &&
266
+ post_code == o.post_code &&
267
+ country == o.country &&
268
+ type == o.type &&
269
+ default_for_type == o.default_for_type
270
+ end
271
+
272
+ # @see the `==` method
273
+ # @param [Object] Object to be compared
274
+ def eql?(o)
275
+ self == o
276
+ end
277
+
278
+ # Calculates hash code according to all attributes.
279
+ # @return [Integer] Hash code
280
+ def hash
281
+ [id, line1, line2, city, state, post_code, country, type, default_for_type].hash
282
+ end
283
+
284
+ # Builds the object from hash
285
+ # @param [Hash] attributes Model attributes in the form of hash
286
+ # @return [Object] Returns the model itself
287
+ def self.build_from_hash(attributes)
288
+ new.build_from_hash(attributes)
289
+ end
290
+
291
+ # Builds the object from hash
292
+ # @param [Hash] attributes Model attributes in the form of hash
293
+ # @return [Object] Returns the model itself
294
+ def build_from_hash(attributes)
295
+ return nil unless attributes.is_a?(Hash)
296
+ self.class.openapi_types.each_pair do |key, type|
297
+ if type =~ /\AArray<(.*)>/i
298
+ # check to ensure the input is an array given that the attribute
299
+ # is documented as an array but the input is not
300
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
301
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
302
+ end
303
+ elsif !attributes[self.class.attribute_map[key]].nil?
304
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
305
+ end # or else data not found in attributes(hash), not an issue as the data can be optional
306
+ end
307
+
308
+ self
309
+ end
310
+
311
+ # Deserializes the data based on type
312
+ # @param string type Data type
313
+ # @param string value Value to be deserialized
314
+ # @return [Object] Deserialized data
315
+ def _deserialize(type, value)
316
+ case type.to_sym
317
+ when :DateTime
318
+ DateTime.parse(value)
319
+ when :Date
320
+ Date.parse(value)
321
+ when :String
322
+ value.to_s
323
+ when :Integer
324
+ value.to_i
325
+ when :Float
326
+ value.to_f
327
+ when :Boolean
328
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
329
+ true
330
+ else
331
+ false
332
+ end
333
+ when :Object
334
+ # generic object (usually a Hash), return directly
335
+ value
336
+ when /\AArray<(?<inner_type>.+)>\z/
337
+ inner_type = Regexp.last_match[:inner_type]
338
+ value.map { |v| _deserialize(inner_type, v) }
339
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
340
+ k_type = Regexp.last_match[:k_type]
341
+ v_type = Regexp.last_match[:v_type]
342
+ {}.tap do |hash|
343
+ value.each do |k, v|
344
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
345
+ end
346
+ end
347
+ else # model
348
+ DearInventoryRuby.const_get(type).build_from_hash(value)
349
+ end
350
+ end
351
+
352
+ # Returns the string representation of the object
353
+ # @return [String] String presentation of the object
354
+ def to_s
355
+ to_hash.to_s
356
+ end
357
+
358
+ # to_body is an alias to to_hash (backward compatibility)
359
+ # @return [Hash] Returns the object in the form of hash
360
+ def to_body
361
+ to_hash
362
+ end
363
+
364
+ # Returns the object in the form of hash
365
+ # @return [Hash] Returns the object in the form of hash
366
+ def to_hash
367
+ hash = {}
368
+ self.class.attribute_map.each_pair do |attr, param|
369
+ value = self.send(attr)
370
+ if value.nil?
371
+ is_nullable = self.class.openapi_nullable.include?(attr)
372
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
373
+ end
374
+
375
+ hash[param] = _to_hash(value)
376
+ end
377
+ hash
378
+ end
379
+
380
+ # Outputs non-array value in the form of hash
381
+ # For object, use to_hash. Otherwise, just return the value
382
+ # @param [Object] value Any valid value
383
+ # @return [Hash] Returns the value in the form of hash
384
+ def _to_hash(value)
385
+ if value.is_a?(Array)
386
+ value.compact.map { |v| _to_hash(v) }
387
+ elsif value.is_a?(Hash)
388
+ {}.tap do |hash|
389
+ value.each { |k, v| hash[k] = _to_hash(v) }
390
+ end
391
+ elsif value.respond_to? :to_hash
392
+ value.to_hash
393
+ else
394
+ value
395
+ end
396
+ end
397
+ end
398
+ end