patch_ruby 1.1.0 → 1.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7d57ecb3d4eed4573df5b34a2fe8b15abff918db6d50343d483a94daeb832ef0
4
- data.tar.gz: 01ef9aced2b39b3fc83e4139682bf2ef4671cd5a1cf22c04486bb5005a8fae50
3
+ metadata.gz: 7c6fea9c586a5bafe867ad4910ca99e8d794eceb17965adbca02f5767f986b69
4
+ data.tar.gz: f4afe79ee1e0afdede909be37c1f0aa6b56e4fc018e35a9f2cad3c6d886e6f12
5
5
  SHA512:
6
- metadata.gz: 915adff1e3f63bd96b7cf1c360914faa8f2bb4d901e8960c459c0f74134385c72906f5eb9f06d4d51cccdc023b01a618c1a438a049b8fa1f39e4373682ec711a
7
- data.tar.gz: 3f16c440a5d2e67c4dc864605d6201b9fb10f0c6c28fd10b821b76758b36b8a319a990f124218515265621550f3db273bd75359b6a4579af3bb132b85d4b994f
6
+ metadata.gz: 9e8f1dadfd649f383d4961ff69bf00392972c5c6eac5cf78d51203965771245c5b8e44e8a4be76a3a3779fb41f020403f8d86596e62ddc6baf17e279d521a96b
7
+ data.tar.gz: a46785a949700cfa7268424959162baabae59a959254a3a057ae0cddda972e5ad7d71a4b1bbe46abfa1943767752b612c01900c1229260105bc459cc4f07fe46
@@ -7,6 +7,27 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [1.2.2] - 2020-09-18
11
+
12
+ ### Added
13
+
14
+ - `photos` field to `projects`
15
+
16
+ ## [1.2.1] - 2020-09-18
17
+
18
+ ### Fixed
19
+
20
+ - Fixing an issue related to the OpenApi code generator.
21
+
22
+ ## [1.2.0] - 2020-09-17
23
+
24
+ ### Added
25
+
26
+ - `average_price_per_tonne_cents_usd` field to `projects`
27
+ - `remaining_mass_g` field to `projects`
28
+ - `standard` field to `projects`
29
+ - validations on `mass_g` field (has to be greater than 1 and less than 2,000,000,000).
30
+
10
31
  ## [1.1.0] - 2020-08-19
11
32
 
12
33
  ### Added
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- patch_ruby (1.1.0)
4
+ patch_ruby (1.2.2)
5
5
  json (~> 2.1, >= 2.1.0)
6
6
  typhoeus (~> 1.0, >= 1.0.1)
7
7
 
data/README.md CHANGED
@@ -6,7 +6,7 @@
6
6
  The official Ruby gem for the [Patch API](https://www.usepatch.com)
7
7
 
8
8
  ## Documentation
9
- For a complete API reference, check out [Patch's API Reference.](https://docs.usepatch.com/docs/patch/openapi/v1/swagger.yaml)
9
+ For a complete API reference, check out [Patch's API Reference.](https://docs.usepatch.com/)
10
10
 
11
11
  ## Installation
12
12
 
@@ -45,7 +45,7 @@ end
45
45
  ### Orders
46
46
  In Patch, orders represent a purchase of carbon offsets or negative emissions by mass. Place orders directly if you know the amount of carbon dioxide you would like to sequester. If you do not know how much to purchase, use an estimate.
47
47
 
48
- [API Reference](https://docs.usepatch.com/docs/patch/openapi/v1/swagger.yaml/paths/~1v1~1orders/get)
48
+ [API Reference](https://docs.usepatch.com/#/?id=orders)
49
49
 
50
50
  #### Examples
51
51
  ```ruby
@@ -81,7 +81,7 @@ Patch::Order.retrieve_orders(page: page)
81
81
  ### Estimates
82
82
  Estimates allow API users to get a quote for the cost of compensating a certain amount of CO2. When creating an estimate, an order in the `draft` state will also be created, reserving the allocation of a project for 5 minutes. If you don't place your draft order within those 5 minutes, the order will automatically be cancelled.
83
83
 
84
- [API Reference](https://docs.usepatch.com/docs/patch/openapi/v1/swagger.yaml/paths/~1v1~1estimates/get)
84
+ [API Reference](https://docs.usepatch.com/#/?id=estimates)
85
85
 
86
86
  #### Examples
87
87
  ```ruby
@@ -105,7 +105,7 @@ Patch::Estimate.retrieve_estimates(page: page)
105
105
  ### Projects
106
106
  Projects are the ways Patch takes CO2 out of the air. They can represent reforestation, enhanced weathering, direct air carbon capture, etc. When you place an order via Patch, it is allocated to a project.
107
107
 
108
- [API Reference](https://docs.usepatch.com/docs/patch/openapi/v1/swagger.yaml/paths/~1v1~1projects/get)
108
+ [API Reference](https://docs.usepatch.com/#/?id=projects)
109
109
 
110
110
  #### Examples
111
111
  ```ruby
@@ -121,7 +121,7 @@ Patch::Project.retrieve_projects(page: page)
121
121
  ### Preferences
122
122
  Preferences are how you route your orders in Patch. If you don't have a preference, Patch will allocate your order to the least expensive option. If you do have a preference, all of your orders will be sent to that project. You can set your preferences via API, or through the [Patch Dashboard](https://dashboard.usepatch.com/projects).
123
123
 
124
- [API Reference](https://docs.usepatch.com/docs/patch/openapi/v1/swagger.yaml/paths/~1v1~1preferences/post)
124
+ [API Reference](https://docs.usepatch.com/#/?id=preferences)
125
125
 
126
126
  #### Examples
127
127
  ```ruby
@@ -29,12 +29,14 @@ require 'patch_ruby/models/meta_index_object'
29
29
  require 'patch_ruby/models/order'
30
30
  require 'patch_ruby/models/order_list_response'
31
31
  require 'patch_ruby/models/order_response'
32
+ require 'patch_ruby/models/photo'
32
33
  require 'patch_ruby/models/preference'
33
34
  require 'patch_ruby/models/preference_list_response'
34
35
  require 'patch_ruby/models/preference_response'
35
36
  require 'patch_ruby/models/project'
36
37
  require 'patch_ruby/models/project_list_response'
37
38
  require 'patch_ruby/models/project_response'
39
+ require 'patch_ruby/models/standard'
38
40
 
39
41
  # APIs
40
42
  require 'patch_ruby/api/estimates_api'
@@ -77,6 +77,14 @@ module Patch
77
77
  invalid_properties.push('invalid value for "mass_g", mass_g cannot be nil.')
78
78
  end
79
79
 
80
+ if @mass_g > 2000000000
81
+ invalid_properties.push('invalid value for "mass_g", must be smaller than or equal to 2000000000.')
82
+ end
83
+
84
+ if @mass_g < 1
85
+ invalid_properties.push('invalid value for "mass_g", must be greater than or equal to 1.')
86
+ end
87
+
80
88
  invalid_properties
81
89
  end
82
90
 
@@ -84,9 +92,29 @@ module Patch
84
92
  # @return true if the model is valid
85
93
  def valid?
86
94
  return false if @mass_g.nil?
95
+ return false if @mass_g > 2000000000
96
+ return false if @mass_g < 1
87
97
  true
88
98
  end
89
99
 
100
+ # Custom attribute writer method with validation
101
+ # @param [Object] mass_g Value to be assigned
102
+ def mass_g=(mass_g)
103
+ if mass_g.nil?
104
+ fail ArgumentError, 'mass_g cannot be nil'
105
+ end
106
+
107
+ if mass_g > 2000000000
108
+ fail ArgumentError, 'invalid value for "mass_g", must be smaller than or equal to 2000000000.'
109
+ end
110
+
111
+ if mass_g < 1
112
+ fail ArgumentError, 'invalid value for "mass_g", must be greater than or equal to 1.'
113
+ end
114
+
115
+ @mass_g = mass_g
116
+ end
117
+
90
118
  # Checks equality by comparing each attribute.
91
119
  # @param [Object] Object to be compared
92
120
  def ==(o)
@@ -85,6 +85,14 @@ module Patch
85
85
  invalid_properties.push('invalid value for "mass_g", mass_g cannot be nil.')
86
86
  end
87
87
 
88
+ if @mass_g > 2000000000
89
+ invalid_properties.push('invalid value for "mass_g", must be smaller than or equal to 2000000000.')
90
+ end
91
+
92
+ if @mass_g < 1
93
+ invalid_properties.push('invalid value for "mass_g", must be greater than or equal to 1.')
94
+ end
95
+
88
96
  invalid_properties
89
97
  end
90
98
 
@@ -92,9 +100,29 @@ module Patch
92
100
  # @return true if the model is valid
93
101
  def valid?
94
102
  return false if @mass_g.nil?
103
+ return false if @mass_g > 2000000000
104
+ return false if @mass_g < 1
95
105
  true
96
106
  end
97
107
 
108
+ # Custom attribute writer method with validation
109
+ # @param [Object] mass_g Value to be assigned
110
+ def mass_g=(mass_g)
111
+ if mass_g.nil?
112
+ fail ArgumentError, 'mass_g cannot be nil'
113
+ end
114
+
115
+ if mass_g > 2000000000
116
+ fail ArgumentError, 'invalid value for "mass_g", must be smaller than or equal to 2000000000.'
117
+ end
118
+
119
+ if mass_g < 1
120
+ fail ArgumentError, 'invalid value for "mass_g", must be greater than or equal to 1.'
121
+ end
122
+
123
+ @mass_g = mass_g
124
+ end
125
+
98
126
  # Checks equality by comparing each attribute.
99
127
  # @param [Object] Object to be compared
100
128
  def ==(o)
@@ -153,6 +153,14 @@ module Patch
153
153
  invalid_properties.push('invalid value for "mass_g", mass_g cannot be nil.')
154
154
  end
155
155
 
156
+ if @mass_g > 2000000000
157
+ invalid_properties.push('invalid value for "mass_g", must be smaller than or equal to 2000000000.')
158
+ end
159
+
160
+ if @mass_g < 1
161
+ invalid_properties.push('invalid value for "mass_g", must be greater than or equal to 1.')
162
+ end
163
+
156
164
  if @production.nil?
157
165
  invalid_properties.push('invalid value for "production", production cannot be nil.')
158
166
  end
@@ -181,6 +189,8 @@ module Patch
181
189
  def valid?
182
190
  return false if @id.nil?
183
191
  return false if @mass_g.nil?
192
+ return false if @mass_g > 2000000000
193
+ return false if @mass_g < 1
184
194
  return false if @production.nil?
185
195
  return false if @state.nil?
186
196
  state_validator = EnumAttributeValidator.new('String', ["draft", "placed", "complete", "cancelled"])
@@ -193,6 +203,24 @@ module Patch
193
203
  true
194
204
  end
195
205
 
206
+ # Custom attribute writer method with validation
207
+ # @param [Object] mass_g Value to be assigned
208
+ def mass_g=(mass_g)
209
+ if mass_g.nil?
210
+ fail ArgumentError, 'mass_g cannot be nil'
211
+ end
212
+
213
+ if mass_g > 2000000000
214
+ fail ArgumentError, 'invalid value for "mass_g", must be smaller than or equal to 2000000000.'
215
+ end
216
+
217
+ if mass_g < 1
218
+ fail ArgumentError, 'invalid value for "mass_g", must be greater than or equal to 1.'
219
+ end
220
+
221
+ @mass_g = mass_g
222
+ end
223
+
196
224
  # Custom attribute writer method checking allowed values (enum).
197
225
  # @param [Object] state Object to be assigned
198
226
  def state=(state)
@@ -0,0 +1,211 @@
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 Photo
17
+ attr_accessor :url
18
+
19
+ # Attribute mapping from ruby-style variable name to JSON key.
20
+ def self.attribute_map
21
+ {
22
+ :'url' => :'url'
23
+ }
24
+ end
25
+
26
+ # Attribute type mapping.
27
+ def self.openapi_types
28
+ {
29
+ :'url' => :'String'
30
+ }
31
+ end
32
+
33
+ # Allows models with corresponding API classes to delegate API operations to those API classes
34
+ # Exposes Model.operation_id which delegates to ModelsApi.new.operation_id
35
+ # Eg. Order.create_order delegates to OrdersApi.new.create_order
36
+ def self.method_missing(message, *args, &block)
37
+ if Object.const_defined?('Patch::PhotosApi::OPERATIONS') && Patch::PhotosApi::OPERATIONS.include?(message)
38
+ Patch::PhotosApi.new.send(message, *args)
39
+ else
40
+ super
41
+ end
42
+ end
43
+
44
+ # Initializes the object
45
+ # @param [Hash] attributes Model attributes in the form of hash
46
+ def initialize(attributes = {})
47
+ if (!attributes.is_a?(Hash))
48
+ fail ArgumentError, "The input argument (attributes) must be a hash in `Patch::Photo` initialize method"
49
+ end
50
+
51
+ # check to see if the attribute exists and convert string to symbol for hash key
52
+ attributes = attributes.each_with_object({}) { |(k, v), h|
53
+ if (!self.class.attribute_map.key?(k.to_sym))
54
+ fail ArgumentError, "`#{k}` is not a valid attribute in `Patch::Photo`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
55
+ end
56
+ h[k.to_sym] = v
57
+ }
58
+
59
+ if attributes.key?(:'url')
60
+ self.url = attributes[:'url']
61
+ end
62
+ end
63
+
64
+ # Show invalid properties with the reasons. Usually used together with valid?
65
+ # @return Array for valid properties with the reasons
66
+ def list_invalid_properties
67
+ invalid_properties = Array.new
68
+ invalid_properties
69
+ end
70
+
71
+ # Check to see if the all the properties in the model are valid
72
+ # @return true if the model is valid
73
+ def valid?
74
+ true
75
+ end
76
+
77
+ # Checks equality by comparing each attribute.
78
+ # @param [Object] Object to be compared
79
+ def ==(o)
80
+ return true if self.equal?(o)
81
+ self.class == o.class &&
82
+ url == o.url
83
+ end
84
+
85
+ # @see the `==` method
86
+ # @param [Object] Object to be compared
87
+ def eql?(o)
88
+ self == o
89
+ end
90
+
91
+ # Calculates hash code according to all attributes.
92
+ # @return [Integer] Hash code
93
+ def hash
94
+ [url].hash
95
+ end
96
+
97
+ # Builds the object from hash
98
+ # @param [Hash] attributes Model attributes in the form of hash
99
+ # @return [Object] Returns the model itself
100
+ def self.build_from_hash(attributes)
101
+ new.build_from_hash(attributes)
102
+ end
103
+
104
+ # Builds the object from hash
105
+ # @param [Hash] attributes Model attributes in the form of hash
106
+ # @return [Object] Returns the model itself
107
+ def build_from_hash(attributes)
108
+ return nil unless attributes.is_a?(Hash)
109
+ self.class.openapi_types.each_pair do |key, type|
110
+ if type =~ /\AArray<(.*)>/i
111
+ # check to ensure the input is an array given that the attribute
112
+ # is documented as an array but the input is not
113
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
114
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
115
+ end
116
+ elsif !attributes[self.class.attribute_map[key]].nil?
117
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
118
+ end # or else data not found in attributes(hash), not an issue as the data can be optional
119
+ end
120
+
121
+ self
122
+ end
123
+
124
+ # Deserializes the data based on type
125
+ # @param string type Data type
126
+ # @param string value Value to be deserialized
127
+ # @return [Object] Deserialized data
128
+ def _deserialize(type, value)
129
+ case type.to_sym
130
+ when :DateTime
131
+ DateTime.parse(value)
132
+ when :Date
133
+ Date.parse(value)
134
+ when :String
135
+ value.to_s
136
+ when :Integer
137
+ value.to_i
138
+ when :Float
139
+ value.to_f
140
+ when :Boolean
141
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
142
+ true
143
+ else
144
+ false
145
+ end
146
+ when :Object
147
+ # generic object (usually a Hash), return directly
148
+ value
149
+ when /\AArray<(?<inner_type>.+)>\z/
150
+ inner_type = Regexp.last_match[:inner_type]
151
+ value.map { |v| _deserialize(inner_type, v) }
152
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
153
+ k_type = Regexp.last_match[:k_type]
154
+ v_type = Regexp.last_match[:v_type]
155
+ {}.tap do |hash|
156
+ value.each do |k, v|
157
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
158
+ end
159
+ end
160
+ else # model
161
+ Patch.const_get(type).build_from_hash(value)
162
+ end
163
+ end
164
+
165
+ # Returns the string representation of the object
166
+ # @return [String] String presentation of the object
167
+ def to_s
168
+ to_hash.to_s
169
+ end
170
+
171
+ # to_body is an alias to to_hash (backward compatibility)
172
+ # @return [Hash] Returns the object in the form of hash
173
+ def to_body
174
+ to_hash
175
+ end
176
+
177
+ # Returns the object in the form of hash
178
+ # @return [Hash] Returns the object in the form of hash
179
+ def to_hash
180
+ hash = {}
181
+ self.class.attribute_map.each_pair do |attr, param|
182
+ value = self.send(attr)
183
+ if value.nil?
184
+ is_nullable = self.class.openapi_nullable.include?(attr)
185
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
186
+ end
187
+
188
+ hash[param] = _to_hash(value)
189
+ end
190
+ hash
191
+ end
192
+
193
+ # Outputs non-array value in the form of hash
194
+ # For object, use to_hash. Otherwise, just return the value
195
+ # @param [Object] value Any valid value
196
+ # @return [Hash] Returns the value in the form of hash
197
+ def _to_hash(value)
198
+ if value.is_a?(Array)
199
+ value.compact.map { |v| _to_hash(v) }
200
+ elsif value.is_a?(Hash)
201
+ {}.tap do |hash|
202
+ value.each { |k, v| hash[k] = _to_hash(v) }
203
+ end
204
+ elsif value.respond_to? :to_hash
205
+ value.to_hash
206
+ else
207
+ value
208
+ end
209
+ end
210
+ end
211
+ end
@@ -28,6 +28,14 @@ module Patch
28
28
 
29
29
  attr_accessor :developer
30
30
 
31
+ attr_accessor :photos
32
+
33
+ attr_accessor :average_price_per_tonne_cents_usd
34
+
35
+ attr_accessor :remaining_mass_g
36
+
37
+ attr_accessor :standard
38
+
31
39
  class EnumAttributeValidator
32
40
  attr_reader :datatype
33
41
  attr_reader :allowable_values
@@ -59,7 +67,11 @@ module Patch
59
67
  :'description' => :'description',
60
68
  :'type' => :'type',
61
69
  :'country' => :'country',
62
- :'developer' => :'developer'
70
+ :'developer' => :'developer',
71
+ :'photos' => :'photos',
72
+ :'average_price_per_tonne_cents_usd' => :'average_price_per_tonne_cents_usd',
73
+ :'remaining_mass_g' => :'remaining_mass_g',
74
+ :'standard' => :'standard'
63
75
  }
64
76
  end
65
77
 
@@ -72,7 +84,11 @@ module Patch
72
84
  :'description' => :'String',
73
85
  :'type' => :'String',
74
86
  :'country' => :'String',
75
- :'developer' => :'String'
87
+ :'developer' => :'String',
88
+ :'photos' => :'Array<Photo>',
89
+ :'average_price_per_tonne_cents_usd' => :'Integer',
90
+ :'remaining_mass_g' => :'Integer',
91
+ :'standard' => :'Standard'
76
92
  }
77
93
  end
78
94
 
@@ -129,6 +145,24 @@ module Patch
129
145
  if attributes.key?(:'developer')
130
146
  self.developer = attributes[:'developer']
131
147
  end
148
+
149
+ if attributes.key?(:'photos')
150
+ if (value = attributes[:'photos']).is_a?(Array)
151
+ self.photos = value
152
+ end
153
+ end
154
+
155
+ if attributes.key?(:'average_price_per_tonne_cents_usd')
156
+ self.average_price_per_tonne_cents_usd = attributes[:'average_price_per_tonne_cents_usd']
157
+ end
158
+
159
+ if attributes.key?(:'remaining_mass_g')
160
+ self.remaining_mass_g = attributes[:'remaining_mass_g']
161
+ end
162
+
163
+ if attributes.key?(:'standard')
164
+ self.standard = attributes[:'standard']
165
+ end
132
166
  end
133
167
 
134
168
  # Show invalid properties with the reasons. Usually used together with valid?
@@ -159,6 +193,14 @@ module Patch
159
193
  invalid_properties.push('invalid value for "developer", developer cannot be nil.')
160
194
  end
161
195
 
196
+ if @average_price_per_tonne_cents_usd.nil?
197
+ invalid_properties.push('invalid value for "average_price_per_tonne_cents_usd", average_price_per_tonne_cents_usd cannot be nil.')
198
+ end
199
+
200
+ if @remaining_mass_g.nil?
201
+ invalid_properties.push('invalid value for "remaining_mass_g", remaining_mass_g cannot be nil.')
202
+ end
203
+
162
204
  invalid_properties
163
205
  end
164
206
 
@@ -173,6 +215,8 @@ module Patch
173
215
  return false unless type_validator.valid?(@type)
174
216
  return false if @country.nil?
175
217
  return false if @developer.nil?
218
+ return false if @average_price_per_tonne_cents_usd.nil?
219
+ return false if @remaining_mass_g.nil?
176
220
  true
177
221
  end
178
222
 
@@ -197,7 +241,11 @@ module Patch
197
241
  description == o.description &&
198
242
  type == o.type &&
199
243
  country == o.country &&
200
- developer == o.developer
244
+ developer == o.developer &&
245
+ photos == o.photos &&
246
+ average_price_per_tonne_cents_usd == o.average_price_per_tonne_cents_usd &&
247
+ remaining_mass_g == o.remaining_mass_g &&
248
+ standard == o.standard
201
249
  end
202
250
 
203
251
  # @see the `==` method
@@ -209,7 +257,7 @@ module Patch
209
257
  # Calculates hash code according to all attributes.
210
258
  # @return [Integer] Hash code
211
259
  def hash
212
- [id, production, name, description, type, country, developer].hash
260
+ [id, production, name, description, type, country, developer, photos, average_price_per_tonne_cents_usd, remaining_mass_g, standard].hash
213
261
  end
214
262
 
215
263
  # Builds the object from hash
@@ -0,0 +1,244 @@
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 Standard
17
+ attr_accessor :type
18
+
19
+ attr_accessor :acronym
20
+
21
+ attr_accessor :description
22
+
23
+ # Attribute mapping from ruby-style variable name to JSON key.
24
+ def self.attribute_map
25
+ {
26
+ :'type' => :'type',
27
+ :'acronym' => :'acronym',
28
+ :'description' => :'description'
29
+ }
30
+ end
31
+
32
+ # Attribute type mapping.
33
+ def self.openapi_types
34
+ {
35
+ :'type' => :'String',
36
+ :'acronym' => :'String',
37
+ :'description' => :'String'
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::StandardsApi::OPERATIONS') && Patch::StandardsApi::OPERATIONS.include?(message)
46
+ Patch::StandardsApi.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::Standard` 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::Standard`. 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?(:'type')
68
+ self.type = attributes[:'type']
69
+ end
70
+
71
+ if attributes.key?(:'acronym')
72
+ self.acronym = attributes[:'acronym']
73
+ end
74
+
75
+ if attributes.key?(:'description')
76
+ self.description = attributes[:'description']
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
+ if @type.nil?
85
+ invalid_properties.push('invalid value for "type", type cannot be nil.')
86
+ end
87
+
88
+ if @acronym.nil?
89
+ invalid_properties.push('invalid value for "acronym", acronym cannot be nil.')
90
+ end
91
+
92
+ if @description.nil?
93
+ invalid_properties.push('invalid value for "description", description cannot be nil.')
94
+ end
95
+
96
+ invalid_properties
97
+ end
98
+
99
+ # Check to see if the all the properties in the model are valid
100
+ # @return true if the model is valid
101
+ def valid?
102
+ return false if @type.nil?
103
+ return false if @acronym.nil?
104
+ return false if @description.nil?
105
+ true
106
+ end
107
+
108
+ # Checks equality by comparing each attribute.
109
+ # @param [Object] Object to be compared
110
+ def ==(o)
111
+ return true if self.equal?(o)
112
+ self.class == o.class &&
113
+ type == o.type &&
114
+ acronym == o.acronym &&
115
+ description == o.description
116
+ end
117
+
118
+ # @see the `==` method
119
+ # @param [Object] Object to be compared
120
+ def eql?(o)
121
+ self == o
122
+ end
123
+
124
+ # Calculates hash code according to all attributes.
125
+ # @return [Integer] Hash code
126
+ def hash
127
+ [type, acronym, description].hash
128
+ end
129
+
130
+ # Builds the object from hash
131
+ # @param [Hash] attributes Model attributes in the form of hash
132
+ # @return [Object] Returns the model itself
133
+ def self.build_from_hash(attributes)
134
+ new.build_from_hash(attributes)
135
+ end
136
+
137
+ # Builds the object from hash
138
+ # @param [Hash] attributes Model attributes in the form of hash
139
+ # @return [Object] Returns the model itself
140
+ def build_from_hash(attributes)
141
+ return nil unless attributes.is_a?(Hash)
142
+ self.class.openapi_types.each_pair do |key, type|
143
+ if type =~ /\AArray<(.*)>/i
144
+ # check to ensure the input is an array given that the attribute
145
+ # is documented as an array but the input is not
146
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
147
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
148
+ end
149
+ elsif !attributes[self.class.attribute_map[key]].nil?
150
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
151
+ end # or else data not found in attributes(hash), not an issue as the data can be optional
152
+ end
153
+
154
+ self
155
+ end
156
+
157
+ # Deserializes the data based on type
158
+ # @param string type Data type
159
+ # @param string value Value to be deserialized
160
+ # @return [Object] Deserialized data
161
+ def _deserialize(type, value)
162
+ case type.to_sym
163
+ when :DateTime
164
+ DateTime.parse(value)
165
+ when :Date
166
+ Date.parse(value)
167
+ when :String
168
+ value.to_s
169
+ when :Integer
170
+ value.to_i
171
+ when :Float
172
+ value.to_f
173
+ when :Boolean
174
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
175
+ true
176
+ else
177
+ false
178
+ end
179
+ when :Object
180
+ # generic object (usually a Hash), return directly
181
+ value
182
+ when /\AArray<(?<inner_type>.+)>\z/
183
+ inner_type = Regexp.last_match[:inner_type]
184
+ value.map { |v| _deserialize(inner_type, v) }
185
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
186
+ k_type = Regexp.last_match[:k_type]
187
+ v_type = Regexp.last_match[:v_type]
188
+ {}.tap do |hash|
189
+ value.each do |k, v|
190
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
191
+ end
192
+ end
193
+ else # model
194
+ Patch.const_get(type).build_from_hash(value)
195
+ end
196
+ end
197
+
198
+ # Returns the string representation of the object
199
+ # @return [String] String presentation of the object
200
+ def to_s
201
+ to_hash.to_s
202
+ end
203
+
204
+ # to_body is an alias to to_hash (backward compatibility)
205
+ # @return [Hash] Returns the object in the form of hash
206
+ def to_body
207
+ to_hash
208
+ end
209
+
210
+ # Returns the object in the form of hash
211
+ # @return [Hash] Returns the object in the form of hash
212
+ def to_hash
213
+ hash = {}
214
+ self.class.attribute_map.each_pair do |attr, param|
215
+ value = self.send(attr)
216
+ if value.nil?
217
+ is_nullable = self.class.openapi_nullable.include?(attr)
218
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
219
+ end
220
+
221
+ hash[param] = _to_hash(value)
222
+ end
223
+ hash
224
+ end
225
+
226
+ # Outputs non-array value in the form of hash
227
+ # For object, use to_hash. Otherwise, just return the value
228
+ # @param [Object] value Any valid value
229
+ # @return [Hash] Returns the value in the form of hash
230
+ def _to_hash(value)
231
+ if value.is_a?(Array)
232
+ value.compact.map { |v| _to_hash(v) }
233
+ elsif value.is_a?(Hash)
234
+ {}.tap do |hash|
235
+ value.each { |k, v| hash[k] = _to_hash(v) }
236
+ end
237
+ elsif value.respond_to? :to_hash
238
+ value.to_hash
239
+ else
240
+ value
241
+ end
242
+ end
243
+ end
244
+ end
@@ -11,5 +11,5 @@ OpenAPI Generator version: 4.3.1
11
11
  =end
12
12
 
13
13
  module Patch
14
- VERSION = '1.1.0'
14
+ VERSION = '1.2.2'
15
15
  end
@@ -21,4 +21,22 @@ RSpec.describe 'Projects Integration' do
21
21
  retrieve_project_response = Patch::Project.retrieve_project(project_id)
22
22
  expect(retrieve_project_response.data.id).to eq project_id
23
23
  end
24
+
25
+ describe 'returned fields' do
26
+ before do
27
+ @project = Patch::Project.retrieve_projects(page: 1).data.first
28
+ end
29
+
30
+ it 'returns photos' do
31
+ expect(@project.photos).to be_an_instance_of(Array)
32
+ end
33
+
34
+ it 'returns average_price_per_tonne_cents_usd' do
35
+ expect(@project.average_price_per_tonne_cents_usd).to be_an_instance_of(Integer)
36
+ end
37
+
38
+ it 'returns remaining_mass_g' do
39
+ expect(@project.remaining_mass_g).to be_an_instance_of(Integer)
40
+ end
41
+ end
24
42
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: patch_ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Patch Technology
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-08-20 00:00:00.000000000 Z
11
+ date: 2020-09-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: typhoeus
@@ -102,12 +102,14 @@ files:
102
102
  - lib/patch_ruby/models/order.rb
103
103
  - lib/patch_ruby/models/order_list_response.rb
104
104
  - lib/patch_ruby/models/order_response.rb
105
+ - lib/patch_ruby/models/photo.rb
105
106
  - lib/patch_ruby/models/preference.rb
106
107
  - lib/patch_ruby/models/preference_list_response.rb
107
108
  - lib/patch_ruby/models/preference_response.rb
108
109
  - lib/patch_ruby/models/project.rb
109
110
  - lib/patch_ruby/models/project_list_response.rb
110
111
  - lib/patch_ruby/models/project_response.rb
112
+ - lib/patch_ruby/models/standard.rb
111
113
  - lib/patch_ruby/version.rb
112
114
  - patch_ruby.gemspec
113
115
  - spec/api/estimates_api_spec.rb
@@ -163,32 +165,32 @@ signing_key:
163
165
  specification_version: 4
164
166
  summary: Ruby wrapper for the Patch API
165
167
  test_files:
166
- - spec/api/preferences_api_spec.rb
167
- - spec/api/orders_api_spec.rb
168
168
  - spec/api/projects_api_spec.rb
169
169
  - spec/api/estimates_api_spec.rb
170
+ - spec/api/preferences_api_spec.rb
171
+ - spec/api/orders_api_spec.rb
170
172
  - spec/api_client_spec.rb
171
173
  - spec/configuration_spec.rb
174
+ - spec/integration/estimates_spec.rb
172
175
  - spec/integration/preferences_spec.rb
173
176
  - spec/integration/projects_spec.rb
174
- - spec/integration/estimates_spec.rb
175
177
  - spec/integration/orders_spec.rb
176
- - spec/models/estimate_response_spec.rb
177
- - spec/models/project_list_response_spec.rb
178
+ - spec/models/order_spec.rb
179
+ - spec/models/order_response_spec.rb
178
180
  - spec/models/create_preference_request_spec.rb
179
- - spec/models/project_response_spec.rb
180
181
  - spec/models/allocation_spec.rb
181
- - spec/models/estimate_spec.rb
182
- - spec/models/meta_index_object_spec.rb
183
- - spec/models/estimate_list_response_spec.rb
184
- - spec/models/project_spec.rb
182
+ - spec/models/project_list_response_spec.rb
183
+ - spec/models/project_response_spec.rb
185
184
  - spec/models/order_list_response_spec.rb
186
- - spec/models/create_mass_estimate_request_spec.rb
187
185
  - spec/models/preference_spec.rb
188
- - spec/models/error_response_spec.rb
189
- - spec/models/order_response_spec.rb
186
+ - spec/models/estimate_spec.rb
187
+ - spec/models/estimate_list_response_spec.rb
190
188
  - spec/models/preference_response_spec.rb
191
- - spec/models/order_spec.rb
192
189
  - spec/models/create_order_request_spec.rb
190
+ - spec/models/estimate_response_spec.rb
191
+ - spec/models/create_mass_estimate_request_spec.rb
193
192
  - spec/models/preference_list_response_spec.rb
193
+ - spec/models/error_response_spec.rb
194
+ - spec/models/project_spec.rb
195
+ - spec/models/meta_index_object_spec.rb
194
196
  - spec/spec_helper.rb