patch_ruby 1.2.3 → 1.2.4
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +12 -1
- data/Gemfile.lock +1 -1
- data/README.md +14 -1
- data/lib/patch_ruby/models/create_order_request.rb +31 -16
- data/lib/patch_ruby/version.rb +1 -1
- data/spec/integration/orders_spec.rb +26 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2cc157169de2e66eca8ad5c41897f0345f9bd9286bf8ee62ab6c1040a327d3ff
|
4
|
+
data.tar.gz: 5960f6ea41e96264a1293c6b40531817afcd810dd9e5a36988750d94a042c34b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7053e90b8e96ab75c3c3563146adb3cafa62c370e8c6bf429c7c0ff5e8d90f5020603d4ffb90b63847fd8821e47f5c47ccff1eace9f02734aa40e9053421597f
|
7
|
+
data.tar.gz: 589fd1ec70c6ac629bc77d4249d82b0b17205d465909990f8c86992792a661ca972cfa32e666e0a1807c1dff94807d13b9e7c2c293e2becf15bf006a54a2f5af
|
data/CHANGELOG.md
CHANGED
@@ -7,7 +7,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
7
7
|
|
8
8
|
## [Unreleased]
|
9
9
|
|
10
|
-
## [1.2.
|
10
|
+
## [1.2.4] - 2020-10-14
|
11
|
+
|
12
|
+
### Added
|
13
|
+
|
14
|
+
- `total_price_cents_usd` field to `orders`
|
15
|
+
- allows users to create an order by total price
|
16
|
+
|
17
|
+
### Changed
|
18
|
+
|
19
|
+
- order creation requires either `mass_g` or `total_price_cents_usd`, but not both
|
20
|
+
|
21
|
+
## [1.2.3] - 2020-10-05
|
11
22
|
|
12
23
|
### Added
|
13
24
|
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -45,14 +45,27 @@ 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
|
+
In Patch, orders represent a purchase of carbon offsets or negative emissions by mass.
|
49
|
+
Place orders directly if you know the amount of carbon dioxide you would like to sequester.
|
50
|
+
If you do not know how much to purchase, use an estimate.
|
51
|
+
You can also create an order with a maximum desired price, and we'll allocate enough mass to
|
52
|
+
fulfill the order for you.
|
53
|
+
|
48
54
|
[API Reference](https://docs.usepatch.com/#/?id=orders)
|
49
55
|
|
50
56
|
#### Examples
|
51
57
|
```ruby
|
52
|
-
# Create an order
|
58
|
+
# Create an order - you can create an order
|
59
|
+
# providing either mass_g or total_price_cents_usd, but not both
|
60
|
+
|
61
|
+
# Create order with mass
|
53
62
|
mass = 1_000_000 # Pass in the mass in grams (i.e. 1 metric tonne)
|
54
63
|
Patch::Order.create_order(mass_g: mass)
|
55
64
|
|
65
|
+
# Create an order with maximum total price
|
66
|
+
total_price_cents_usd = 5_00 # Pass in the total price in cents (i.e. 5 dollars)
|
67
|
+
Patch::Order.create_order(total_price_cents_usd: total_price_cents_usd)
|
68
|
+
|
56
69
|
## You can also specify a project-id field (optional) to be used instead of the preferred one
|
57
70
|
project_id = 'pro_test_1234' # Pass in the project's ID
|
58
71
|
Patch::Order.create_order(mass_g: mass, project_id: project_id)
|
@@ -16,6 +16,8 @@ module Patch
|
|
16
16
|
class CreateOrderRequest
|
17
17
|
attr_accessor :mass_g
|
18
18
|
|
19
|
+
attr_accessor :total_price_cents_usd
|
20
|
+
|
19
21
|
attr_accessor :project_id
|
20
22
|
|
21
23
|
attr_accessor :metadata
|
@@ -24,6 +26,7 @@ module Patch
|
|
24
26
|
def self.attribute_map
|
25
27
|
{
|
26
28
|
:'mass_g' => :'mass_g',
|
29
|
+
:'total_price_cents_usd' => :'total_price_cents_usd',
|
27
30
|
:'project_id' => :'project_id',
|
28
31
|
:'metadata' => :'metadata'
|
29
32
|
}
|
@@ -33,6 +36,7 @@ module Patch
|
|
33
36
|
def self.openapi_types
|
34
37
|
{
|
35
38
|
:'mass_g' => :'Integer',
|
39
|
+
:'total_price_cents_usd' => :'Integer',
|
36
40
|
:'project_id' => :'String',
|
37
41
|
:'metadata' => :'Object'
|
38
42
|
}
|
@@ -68,6 +72,10 @@ module Patch
|
|
68
72
|
self.mass_g = attributes[:'mass_g']
|
69
73
|
end
|
70
74
|
|
75
|
+
if attributes.key?(:'total_price_cents_usd')
|
76
|
+
self.total_price_cents_usd = attributes[:'total_price_cents_usd']
|
77
|
+
end
|
78
|
+
|
71
79
|
if attributes.key?(:'project_id')
|
72
80
|
self.project_id = attributes[:'project_id']
|
73
81
|
end
|
@@ -81,54 +89,61 @@ module Patch
|
|
81
89
|
# @return Array for valid properties with the reasons
|
82
90
|
def list_invalid_properties
|
83
91
|
invalid_properties = Array.new
|
84
|
-
if
|
85
|
-
invalid_properties.push('invalid value for "mass_g", mass_g cannot be nil.')
|
86
|
-
end
|
87
|
-
|
88
|
-
if @mass_g > 2000000000
|
92
|
+
if !@mass_g.nil? && @mass_g > 2000000000
|
89
93
|
invalid_properties.push('invalid value for "mass_g", must be smaller than or equal to 2000000000.')
|
90
94
|
end
|
91
95
|
|
92
|
-
if @mass_g < 1
|
96
|
+
if !@mass_g.nil? && @mass_g < 1
|
93
97
|
invalid_properties.push('invalid value for "mass_g", must be greater than or equal to 1.')
|
94
98
|
end
|
95
99
|
|
100
|
+
if !@total_price_cents_usd.nil? && @total_price_cents_usd < 1
|
101
|
+
invalid_properties.push('invalid value for "total_price_cents_usd", must be greater than or equal to 1.')
|
102
|
+
end
|
103
|
+
|
96
104
|
invalid_properties
|
97
105
|
end
|
98
106
|
|
99
107
|
# Check to see if the all the properties in the model are valid
|
100
108
|
# @return true if the model is valid
|
101
109
|
def valid?
|
102
|
-
return false if
|
103
|
-
return false if @mass_g
|
104
|
-
return false if @
|
110
|
+
return false if !@mass_g.nil? && @mass_g > 2000000000
|
111
|
+
return false if !@mass_g.nil? && @mass_g < 1
|
112
|
+
return false if !@total_price_cents_usd.nil? && @total_price_cents_usd < 1
|
105
113
|
true
|
106
114
|
end
|
107
115
|
|
108
116
|
# Custom attribute writer method with validation
|
109
117
|
# @param [Object] mass_g Value to be assigned
|
110
118
|
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
|
119
|
+
if !mass_g.nil? && mass_g > 2000000000
|
116
120
|
fail ArgumentError, 'invalid value for "mass_g", must be smaller than or equal to 2000000000.'
|
117
121
|
end
|
118
122
|
|
119
|
-
if mass_g < 1
|
123
|
+
if !mass_g.nil? && mass_g < 1
|
120
124
|
fail ArgumentError, 'invalid value for "mass_g", must be greater than or equal to 1.'
|
121
125
|
end
|
122
126
|
|
123
127
|
@mass_g = mass_g
|
124
128
|
end
|
125
129
|
|
130
|
+
# Custom attribute writer method with validation
|
131
|
+
# @param [Object] total_price_cents_usd Value to be assigned
|
132
|
+
def total_price_cents_usd=(total_price_cents_usd)
|
133
|
+
if !total_price_cents_usd.nil? && total_price_cents_usd < 1
|
134
|
+
fail ArgumentError, 'invalid value for "total_price_cents_usd", must be greater than or equal to 1.'
|
135
|
+
end
|
136
|
+
|
137
|
+
@total_price_cents_usd = total_price_cents_usd
|
138
|
+
end
|
139
|
+
|
126
140
|
# Checks equality by comparing each attribute.
|
127
141
|
# @param [Object] Object to be compared
|
128
142
|
def ==(o)
|
129
143
|
return true if self.equal?(o)
|
130
144
|
self.class == o.class &&
|
131
145
|
mass_g == o.mass_g &&
|
146
|
+
total_price_cents_usd == o.total_price_cents_usd &&
|
132
147
|
project_id == o.project_id &&
|
133
148
|
metadata == o.metadata
|
134
149
|
end
|
@@ -142,7 +157,7 @@ module Patch
|
|
142
157
|
# Calculates hash code according to all attributes.
|
143
158
|
# @return [Integer] Hash code
|
144
159
|
def hash
|
145
|
-
[mass_g, project_id, metadata].hash
|
160
|
+
[mass_g, total_price_cents_usd, project_id, metadata].hash
|
146
161
|
end
|
147
162
|
|
148
163
|
# Builds the object from hash
|
data/lib/patch_ruby/version.rb
CHANGED
@@ -47,6 +47,32 @@ RSpec.describe 'Orders Integration' do
|
|
47
47
|
expect(create_order_response.data.patch_fee_cents_usd).not_to be_empty
|
48
48
|
end
|
49
49
|
|
50
|
+
it 'supports create with a total price' do
|
51
|
+
retrieve_project_response = Patch::Project.retrieve_project(
|
52
|
+
Constants::BIOMASS_TEST_PROJECT_ID
|
53
|
+
)
|
54
|
+
|
55
|
+
project_id = retrieve_project_response.data.id
|
56
|
+
total_price_cents_usd = 5_00
|
57
|
+
|
58
|
+
create_order_response = Patch::Order.create_order(
|
59
|
+
total_price_cents_usd: total_price_cents_usd,
|
60
|
+
project_id: project_id
|
61
|
+
)
|
62
|
+
|
63
|
+
expect(create_order_response.success).to eq true
|
64
|
+
|
65
|
+
order = create_order_response.data
|
66
|
+
|
67
|
+
expect(order.id).not_to be_nil
|
68
|
+
expect(order.mass_g).to eq(5_000_000)
|
69
|
+
expect(order.price_cents_usd.to_i).to eq(500)
|
70
|
+
expect(order.patch_fee_cents_usd).not_to be_empty
|
71
|
+
expect(
|
72
|
+
order.price_cents_usd.to_i + order.patch_fee_cents_usd.to_i
|
73
|
+
).to eq(total_price_cents_usd)
|
74
|
+
end
|
75
|
+
|
50
76
|
it 'supports create with metadata' do
|
51
77
|
metadata = { user: 'john doe' }
|
52
78
|
|
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.2.
|
4
|
+
version: 1.2.4
|
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-10-
|
11
|
+
date: 2020-10-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: typhoeus
|