patch_ruby 1.0.0.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +10 -0
  3. data/Gemfile.lock +72 -0
  4. data/README.md +54 -0
  5. data/Rakefile +10 -0
  6. data/lib/patch_ruby.rb +61 -0
  7. data/lib/patch_ruby/api/estimates_api.rb +213 -0
  8. data/lib/patch_ruby/api/orders_api.rb +339 -0
  9. data/lib/patch_ruby/api/preferences_api.rb +276 -0
  10. data/lib/patch_ruby/api/projects_api.rb +148 -0
  11. data/lib/patch_ruby/api_client.rb +388 -0
  12. data/lib/patch_ruby/api_error.rb +57 -0
  13. data/lib/patch_ruby/configuration.rb +254 -0
  14. data/lib/patch_ruby/models/allocation.rb +229 -0
  15. data/lib/patch_ruby/models/create_mass_estimate_request.rb +216 -0
  16. data/lib/patch_ruby/models/create_order_request.rb +216 -0
  17. data/lib/patch_ruby/models/create_preference_request.rb +216 -0
  18. data/lib/patch_ruby/models/error_response.rb +239 -0
  19. data/lib/patch_ruby/models/estimate.rb +238 -0
  20. data/lib/patch_ruby/models/estimate_list_response.rb +255 -0
  21. data/lib/patch_ruby/models/estimate_response.rb +239 -0
  22. data/lib/patch_ruby/models/meta_index_object.rb +220 -0
  23. data/lib/patch_ruby/models/order.rb +313 -0
  24. data/lib/patch_ruby/models/order_list_response.rb +255 -0
  25. data/lib/patch_ruby/models/order_response.rb +239 -0
  26. data/lib/patch_ruby/models/preference.rb +229 -0
  27. data/lib/patch_ruby/models/preference_list_response.rb +255 -0
  28. data/lib/patch_ruby/models/preference_response.rb +239 -0
  29. data/lib/patch_ruby/models/project.rb +283 -0
  30. data/lib/patch_ruby/models/project_list_response.rb +255 -0
  31. data/lib/patch_ruby/models/project_response.rb +239 -0
  32. data/lib/patch_ruby/version.rb +15 -0
  33. data/patch_ruby.gemspec +39 -0
  34. data/spec/api/estimates_api_spec.rb +71 -0
  35. data/spec/api/orders_api_spec.rb +95 -0
  36. data/spec/api/preferences_api_spec.rb +83 -0
  37. data/spec/api/projects_api_spec.rb +59 -0
  38. data/spec/api_client_spec.rb +226 -0
  39. data/spec/configuration_spec.rb +42 -0
  40. data/spec/fixtures/vcr_cassettes/estimate_orders.yml +276 -0
  41. data/spec/fixtures/vcr_cassettes/estimates.yml +211 -0
  42. data/spec/fixtures/vcr_cassettes/orders.yml +229 -0
  43. data/spec/fixtures/vcr_cassettes/preferences.yml +352 -0
  44. data/spec/fixtures/vcr_cassettes/projects.yml +143 -0
  45. data/spec/integration/estimates_spec.rb +31 -0
  46. data/spec/integration/orders_spec.rb +53 -0
  47. data/spec/integration/preferences_spec.rb +40 -0
  48. data/spec/integration/projects_spec.rb +31 -0
  49. data/spec/models/allocation_spec.rb +53 -0
  50. data/spec/models/create_mass_estimate_request_spec.rb +41 -0
  51. data/spec/models/create_order_request_spec.rb +41 -0
  52. data/spec/models/create_preference_request_spec.rb +41 -0
  53. data/spec/models/error_response_spec.rb +53 -0
  54. data/spec/models/estimate_list_response_spec.rb +59 -0
  55. data/spec/models/estimate_response_spec.rb +53 -0
  56. data/spec/models/estimate_spec.rb +59 -0
  57. data/spec/models/meta_index_object_spec.rb +47 -0
  58. data/spec/models/order_list_response_spec.rb +59 -0
  59. data/spec/models/order_response_spec.rb +53 -0
  60. data/spec/models/order_spec.rb +85 -0
  61. data/spec/models/preference_list_response_spec.rb +59 -0
  62. data/spec/models/preference_response_spec.rb +53 -0
  63. data/spec/models/preference_spec.rb +53 -0
  64. data/spec/models/project_list_response_spec.rb +59 -0
  65. data/spec/models/project_response_spec.rb +53 -0
  66. data/spec/models/project_spec.rb +89 -0
  67. data/spec/spec_helper.rb +122 -0
  68. metadata +203 -0
@@ -0,0 +1,57 @@
1
+ =begin
2
+ #Patch API V1
3
+
4
+ #The core API used to integrate with Patch's service
5
+
6
+ The version of the OpenAPI document: v1
7
+ Contact: developers@usepatch.com
8
+ Generated by: https://openapi-generator.tech
9
+ OpenAPI Generator version: 4.3.1
10
+
11
+ =end
12
+
13
+ module Patch
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,254 @@
1
+ =begin
2
+ #Patch API V1
3
+
4
+ #The core API used to integrate with Patch's service
5
+
6
+ The version of the OpenAPI document: v1
7
+ Contact: developers@usepatch.com
8
+ Generated by: https://openapi-generator.tech
9
+ OpenAPI Generator version: 4.3.1
10
+
11
+ =end
12
+
13
+ module Patch
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 :verify_ssl
90
+
91
+ ### TLS/SSL setting
92
+ # Set this to false to skip verifying SSL host name
93
+ # Default to true.
94
+ #
95
+ # @note Do NOT set it to false in production code, otherwise you would face multiple types of cryptographic attacks.
96
+ #
97
+ # @return [true, false]
98
+ attr_accessor :verify_ssl_host
99
+
100
+ ### TLS/SSL setting
101
+ # Set this to customize the certificate file to verify the peer.
102
+ #
103
+ # @return [String] the path to the certificate file
104
+ #
105
+ # @see The `cainfo` option of Typhoeus, `--cert` option of libcurl. Related source code:
106
+ # https://github.com/typhoeus/typhoeus/blob/master/lib/typhoeus/easy_factory.rb#L145
107
+ attr_accessor :ssl_ca_cert
108
+
109
+ ### TLS/SSL setting
110
+ # Client certificate file (for client certificate)
111
+ attr_accessor :cert_file
112
+
113
+ ### TLS/SSL setting
114
+ # Client private key file (for client certificate)
115
+ attr_accessor :key_file
116
+
117
+ # Set this to customize parameters encoding of array parameter with multi collectionFormat.
118
+ # Default to nil.
119
+ #
120
+ # @see The params_encoding option of Ethon. Related source code:
121
+ # https://github.com/typhoeus/ethon/blob/master/lib/ethon/easy/queryable.rb#L96
122
+ attr_accessor :params_encoding
123
+
124
+ attr_accessor :inject_format
125
+
126
+ attr_accessor :force_ending_format
127
+
128
+ def initialize
129
+ @scheme = 'https'
130
+ @host = 'api.usepatch.com'
131
+ @base_path = ''
132
+ @api_key = {}
133
+ @api_key_prefix = {}
134
+ @timeout = 0
135
+ @client_side_validation = true
136
+ @verify_ssl = true
137
+ @verify_ssl_host = true
138
+ @params_encoding = nil
139
+ @cert_file = nil
140
+ @key_file = nil
141
+ @debugging = false
142
+ @inject_format = false
143
+ @force_ending_format = false
144
+ @logger = defined?(Rails) ? Rails.logger : Logger.new(STDOUT)
145
+
146
+ yield(self) if block_given?
147
+ end
148
+
149
+ # The default Configuration object.
150
+ def self.default
151
+ @@default ||= Configuration.new
152
+ end
153
+
154
+ def configure
155
+ yield(self) if block_given?
156
+ end
157
+
158
+ def scheme=(scheme)
159
+ # remove :// from scheme
160
+ @scheme = scheme.sub(/:\/\//, '')
161
+ end
162
+
163
+ def host=(host)
164
+ # remove http(s):// and anything after a slash
165
+ @host = host.sub(/https?:\/\//, '').split('/').first
166
+ end
167
+
168
+ def base_path=(base_path)
169
+ # Add leading and trailing slashes to base_path
170
+ @base_path = "/#{base_path}".gsub(/\/+/, '/')
171
+ @base_path = '' if @base_path == '/'
172
+ end
173
+
174
+ def base_url
175
+ "#{scheme}://#{[host, base_path].join('/').gsub(/\/+/, '/')}".sub(/\/+\z/, '')
176
+ end
177
+
178
+ # Gets API key (with prefix if set).
179
+ # @param [String] param_name the parameter name of API key auth
180
+ def api_key_with_prefix(param_name)
181
+ if @api_key_prefix[param_name]
182
+ "#{@api_key_prefix[param_name]} #{@api_key[param_name]}"
183
+ else
184
+ @api_key[param_name]
185
+ end
186
+ end
187
+
188
+ # Gets Basic Auth token string
189
+ def basic_auth_token
190
+ 'Basic ' + ["#{username}:#{password}"].pack('m').delete("\r\n")
191
+ end
192
+
193
+ # Returns Auth Settings hash for api client.
194
+ def auth_settings
195
+ {
196
+ 'bearer_auth' =>
197
+ {
198
+ type: 'bearer',
199
+ in: 'header',
200
+ key: 'Authorization',
201
+ value: "Bearer #{access_token}"
202
+ },
203
+ }
204
+ end
205
+
206
+ # Returns an array of Server setting
207
+ def server_settings
208
+ [
209
+ {
210
+ url: "https://{defaultHost}",
211
+ description: "No description provided",
212
+ variables: {
213
+ defaultHost: {
214
+ description: "No description provided",
215
+ default_value: "api.usepatch.com",
216
+ }
217
+ }
218
+ }
219
+ ]
220
+ end
221
+
222
+ # Returns URL based on server settings
223
+ #
224
+ # @param index array index of the server settings
225
+ # @param variables hash of variable and the corresponding value
226
+ def server_url(index, variables = {})
227
+ servers = server_settings
228
+
229
+ # check array index out of bound
230
+ if (index < 0 || index >= servers.size)
231
+ fail ArgumentError, "Invalid index #{index} when selecting the server. Must be less than #{servers.size}"
232
+ end
233
+
234
+ server = servers[index]
235
+ url = server[:url]
236
+
237
+ # go through variable and assign a value
238
+ server[:variables].each do |name, variable|
239
+ if variables.key?(name)
240
+ if (server[:variables][name][:enum_values].include? variables[name])
241
+ url.gsub! "{" + name.to_s + "}", variables[name]
242
+ else
243
+ fail ArgumentError, "The variable `#{name}` in the server URL has invalid value #{variables[name]}. Must be #{server[:variables][name][:enum_values]}."
244
+ end
245
+ else
246
+ # use default value
247
+ url.gsub! "{" + name.to_s + "}", server[:variables][name][:default_value]
248
+ end
249
+ end
250
+
251
+ url
252
+ end
253
+ end
254
+ end
@@ -0,0 +1,229 @@
1
+ =begin
2
+ #Patch API V1
3
+
4
+ #The core API used to integrate with Patch's service
5
+
6
+ The version of the OpenAPI document: v1
7
+ Contact: developers@usepatch.com
8
+ Generated by: https://openapi-generator.tech
9
+ OpenAPI Generator version: 4.3.1
10
+
11
+ =end
12
+
13
+ require 'date'
14
+
15
+ module Patch
16
+ class Allocation
17
+ attr_accessor :id
18
+
19
+ attr_accessor :production
20
+
21
+ attr_accessor :mass_g
22
+
23
+ # Attribute mapping from ruby-style variable name to JSON key.
24
+ def self.attribute_map
25
+ {
26
+ :'id' => :'id',
27
+ :'production' => :'production',
28
+ :'mass_g' => :'mass_g'
29
+ }
30
+ end
31
+
32
+ # Attribute type mapping.
33
+ def self.openapi_types
34
+ {
35
+ :'id' => :'String',
36
+ :'production' => :'Boolean',
37
+ :'mass_g' => :'Integer'
38
+ }
39
+ end
40
+
41
+ # Allows models with corresponding API classes to delegate API operations to those API classes
42
+ # Exposes Model.operation_id which delegates to ModelsApi.new.operation_id
43
+ # Eg. Order.create_order delegates to OrdersApi.new.create_order
44
+ def self.method_missing(message, *args, &block)
45
+ if Object.const_defined?('Patch::AllocationsApi::OPERATIONS') && Patch::AllocationsApi::OPERATIONS.include?(message)
46
+ Patch::AllocationsApi.new.send(message, *args)
47
+ else
48
+ super
49
+ end
50
+ end
51
+
52
+ # Initializes the object
53
+ # @param [Hash] attributes Model attributes in the form of hash
54
+ def initialize(attributes = {})
55
+ if (!attributes.is_a?(Hash))
56
+ fail ArgumentError, "The input argument (attributes) must be a hash in `Patch::Allocation` initialize method"
57
+ end
58
+
59
+ # check to see if the attribute exists and convert string to symbol for hash key
60
+ attributes = attributes.each_with_object({}) { |(k, v), h|
61
+ if (!self.class.attribute_map.key?(k.to_sym))
62
+ fail ArgumentError, "`#{k}` is not a valid attribute in `Patch::Allocation`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
63
+ end
64
+ h[k.to_sym] = v
65
+ }
66
+
67
+ if attributes.key?(:'id')
68
+ self.id = attributes[:'id']
69
+ end
70
+
71
+ if attributes.key?(:'production')
72
+ self.production = attributes[:'production']
73
+ end
74
+
75
+ if attributes.key?(:'mass_g')
76
+ self.mass_g = attributes[:'mass_g']
77
+ end
78
+ end
79
+
80
+ # Show invalid properties with the reasons. Usually used together with valid?
81
+ # @return Array for valid properties with the reasons
82
+ def list_invalid_properties
83
+ invalid_properties = Array.new
84
+ invalid_properties
85
+ end
86
+
87
+ # Check to see if the all the properties in the model are valid
88
+ # @return true if the model is valid
89
+ def valid?
90
+ true
91
+ end
92
+
93
+ # Checks equality by comparing each attribute.
94
+ # @param [Object] Object to be compared
95
+ def ==(o)
96
+ return true if self.equal?(o)
97
+ self.class == o.class &&
98
+ id == o.id &&
99
+ production == o.production &&
100
+ mass_g == o.mass_g
101
+ end
102
+
103
+ # @see the `==` method
104
+ # @param [Object] Object to be compared
105
+ def eql?(o)
106
+ self == o
107
+ end
108
+
109
+ # Calculates hash code according to all attributes.
110
+ # @return [Integer] Hash code
111
+ def hash
112
+ [id, production, mass_g].hash
113
+ end
114
+
115
+ # Builds the object from hash
116
+ # @param [Hash] attributes Model attributes in the form of hash
117
+ # @return [Object] Returns the model itself
118
+ def self.build_from_hash(attributes)
119
+ new.build_from_hash(attributes)
120
+ end
121
+
122
+ # Builds the object from hash
123
+ # @param [Hash] attributes Model attributes in the form of hash
124
+ # @return [Object] Returns the model itself
125
+ def build_from_hash(attributes)
126
+ return nil unless attributes.is_a?(Hash)
127
+ self.class.openapi_types.each_pair do |key, type|
128
+ if type =~ /\AArray<(.*)>/i
129
+ # check to ensure the input is an array given that the attribute
130
+ # is documented as an array but the input is not
131
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
132
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
133
+ end
134
+ elsif !attributes[self.class.attribute_map[key]].nil?
135
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
136
+ end # or else data not found in attributes(hash), not an issue as the data can be optional
137
+ end
138
+
139
+ self
140
+ end
141
+
142
+ # Deserializes the data based on type
143
+ # @param string type Data type
144
+ # @param string value Value to be deserialized
145
+ # @return [Object] Deserialized data
146
+ def _deserialize(type, value)
147
+ case type.to_sym
148
+ when :DateTime
149
+ DateTime.parse(value)
150
+ when :Date
151
+ Date.parse(value)
152
+ when :String
153
+ value.to_s
154
+ when :Integer
155
+ value.to_i
156
+ when :Float
157
+ value.to_f
158
+ when :Boolean
159
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
160
+ true
161
+ else
162
+ false
163
+ end
164
+ when :Object
165
+ # generic object (usually a Hash), return directly
166
+ value
167
+ when /\AArray<(?<inner_type>.+)>\z/
168
+ inner_type = Regexp.last_match[:inner_type]
169
+ value.map { |v| _deserialize(inner_type, v) }
170
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
171
+ k_type = Regexp.last_match[:k_type]
172
+ v_type = Regexp.last_match[:v_type]
173
+ {}.tap do |hash|
174
+ value.each do |k, v|
175
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
176
+ end
177
+ end
178
+ else # model
179
+ Patch.const_get(type).build_from_hash(value)
180
+ end
181
+ end
182
+
183
+ # Returns the string representation of the object
184
+ # @return [String] String presentation of the object
185
+ def to_s
186
+ to_hash.to_s
187
+ end
188
+
189
+ # to_body is an alias to to_hash (backward compatibility)
190
+ # @return [Hash] Returns the object in the form of hash
191
+ def to_body
192
+ to_hash
193
+ end
194
+
195
+ # Returns the object in the form of hash
196
+ # @return [Hash] Returns the object in the form of hash
197
+ def to_hash
198
+ hash = {}
199
+ self.class.attribute_map.each_pair do |attr, param|
200
+ value = self.send(attr)
201
+ if value.nil?
202
+ is_nullable = self.class.openapi_nullable.include?(attr)
203
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
204
+ end
205
+
206
+ hash[param] = _to_hash(value)
207
+ end
208
+ hash
209
+ end
210
+
211
+ # Outputs non-array value in the form of hash
212
+ # For object, use to_hash. Otherwise, just return the value
213
+ # @param [Object] value Any valid value
214
+ # @return [Hash] Returns the value in the form of hash
215
+ def _to_hash(value)
216
+ if value.is_a?(Array)
217
+ value.compact.map { |v| _to_hash(v) }
218
+ elsif value.is_a?(Hash)
219
+ {}.tap do |hash|
220
+ value.each { |k, v| hash[k] = _to_hash(v) }
221
+ end
222
+ elsif value.respond_to? :to_hash
223
+ value.to_hash
224
+ else
225
+ value
226
+ end
227
+ end
228
+ end
229
+ end