squake 0.5.1 → 0.6.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8777e0847a6851455fbf62736f46f685c18a393e33a1586f1f879ceee4fdc4ba
4
- data.tar.gz: b6c5bb698721fdce1b2d51e552ac3d1c82fac4f8330098667b4f6a17f20b0bd2
3
+ metadata.gz: 8d74376a8394904dde68ee22c591d59a26de63cc3f7273077cec9d1c755a8e01
4
+ data.tar.gz: ebf2977af63c7874817ee0251a3f3ce117f2da242597c31c07a43326eec984a8
5
5
  SHA512:
6
- metadata.gz: 5c701fef3eb69146d564477e923f551328f6e5898161e58fc65ed659ed7e2c5796d02f432359fb19b1a7ea611524de3ff0daa7dbe891f963b6c1c70f62feffd7
7
- data.tar.gz: 55f77258422c2f3fc525a63d2815fd3e68edf5480145e2629d4738489e42df9eafb43bb4f4de81c0ad8c9593482992eca2afbf039488ef225c2be2ee414a676d
6
+ metadata.gz: 5a93a636570247e9a16cf6d81b2ee94c37271d00d75516e104a7813b508173cf80f6b301422e9b5c037751a857b9a490afa2d077522aa09d50d88b96780d4be8
7
+ data.tar.gz: a0742ff2711d8c0e461ae6594135a532908afe498a2cca43036d7e34c981f33d928157dfe36ceb6e0af92ec1d8f3c17dc3f0e4d41e4b423a4a264b0f855e8bd7
data/README.md CHANGED
@@ -123,11 +123,12 @@ end
123
123
 
124
124
  ```ruby
125
125
  Squake::Pricing.quote(
126
- client: squake_client, # optional
127
- carbon_quantity: 1000, # required
128
- carbon_unit: 'kilogram', # optional, default: 'gram', other options: 'kilogram', 'tonne'
129
- product_id: 'some_product_id', # required
130
- expand: [], # optional, default: [], allowed values: 'product', 'price' to enrich the response
126
+ client: squake_client, # optional
127
+ carbon_quantity: 1000, # required
128
+ carbon_unit: 'kilogram', # optional, default: 'gram', other options: 'kilogram', 'tonne'
129
+ product_id: 'some_product_id', # required
130
+ expand: [], # optional, default: [], allowed values: 'product', 'price' to enrich the response
131
+ payment_link_return_url: 'https://squake.earth', # optional, default: nil
131
132
  )
132
133
 
133
134
  if context.success?
@@ -159,12 +160,13 @@ end
159
160
 
160
161
  ```ruby
161
162
  context = Squake::CalculationWithPricing.quote(
162
- items: items, # required
163
- product: 'product-id', # required
164
- currency: 'EUR', # optional, default: 'EUR'
165
- carbon_unit: 'gram', # optional, default: 'gram', other options: 'kilogram', 'tonne'
166
- expand: [], # optional, default: [], allowed values: 'items', 'product', 'price' to enrich the response
167
- client: client, # optional
163
+ items: items, # required
164
+ product: 'product-id', # required
165
+ currency: 'EUR', # optional, default: 'EUR'
166
+ carbon_unit: 'gram', # optional, default: 'gram', other options: 'kilogram', 'tonne'
167
+ expand: [], # optional, default: [], allowed values: 'items', 'product', 'price' to enrich the response
168
+ payment_link_return_url: 'https://squake.earth', # optional, default: nil
169
+ client: client, # optional
168
170
  )
169
171
 
170
172
  if context.success?
@@ -15,12 +15,14 @@ module Squake
15
15
  currency: String,
16
16
  carbon_unit: String,
17
17
  expand: T::Array[String],
18
+ payment_link_return_url: T.nilable(String),
18
19
  client: Squake::Client,
19
20
  request_id: T.nilable(String),
20
21
  ).returns(Squake::Return[Squake::Model::Pricing])
21
22
  end
22
23
  def self.quote(
23
- items:, product:, currency: 'EUR', carbon_unit: 'gram', expand: [], client: Squake::Client.new, request_id: nil
24
+ items:, product:, currency: 'EUR', carbon_unit: 'gram',
25
+ expand: [], payment_link_return_url: nil, client: Squake::Client.new, request_id: nil
24
26
  )
25
27
  # @TODO: add typed objects for all possible items. Until then, we allow either a Hash or a T::Struct
26
28
  items = items.map do |item|
@@ -37,6 +39,7 @@ module Squake
37
39
  currency: currency,
38
40
  carbon_unit: carbon_unit,
39
41
  expand: expand,
42
+ payment_link_return_url: payment_link_return_url,
40
43
  },
41
44
  )
42
45
 
data/lib/squake/client.rb CHANGED
@@ -68,7 +68,7 @@ module Squake
68
68
 
69
69
  headers = request_headers(api_key).merge!(headers)
70
70
  query = query_params ? Util.encode_parameters(query_params) : nil
71
- body = body_params ? ::Oj.dump(body_params) : nil
71
+ body = body_params ? ::Oj.dump(body_params, Squake::OJ_CONFIG) : nil
72
72
  sanitized_path = path[0] == '/' ? path : "/#{path}"
73
73
  uri = URI.parse(api_base + sanitized_path)
74
74
 
@@ -93,6 +93,7 @@ module Squake
93
93
  'http.route': request.path,
94
94
  'http.headers': request.to_hash,
95
95
  },
96
+ Squake::OJ_CONFIG,
96
97
  )
97
98
  canonical_request_line.gsub!(api_key, 'API_KEY_REDACTED')
98
99
  @config.logger.info(canonical_request_line)
@@ -118,7 +119,7 @@ module Squake
118
119
 
119
120
  sig { params(result_body: T.untyped).returns(JsonResponseBody) }
120
121
  private def try_parse_json(result_body)
121
- ::Oj.load(result_body, symbol_keys: true)
122
+ ::Oj.load(result_body, Squake::OJ_CONFIG)
122
123
  rescue ::Oj::ParseError, TypeError, JSON::ParserError, EncodingError => e
123
124
  # in case of an error, Squake's response body is HTML not JSON
124
125
  { error: { 'message' => e.message, 'body' => result_body } }
@@ -16,13 +16,14 @@ module Squake
16
16
  carbon_quantity: T.nilable(Numeric),
17
17
  carbon_unit: T.nilable(String),
18
18
  expand: T::Array[String],
19
+ payment_link_return_url: T.nilable(String),
19
20
  client: Squake::Client,
20
21
  request_id: T.nilable(String),
21
22
  ).returns(Squake::Return[Squake::Model::Pricing])
22
23
  end
23
- def self.quote(
24
+ def self.quote( # rubocop:disable Metrics/ParameterLists
24
25
  product_id:, fixed_total: nil, currency: 'EUR', carbon_quantity: nil, carbon_unit: 'gram',
25
- expand: [], client: Squake::Client.new, request_id: nil
26
+ expand: [], payment_link_return_url: nil, client: Squake::Client.new, request_id: nil
26
27
  )
27
28
 
28
29
  result = client.call(
@@ -36,6 +37,7 @@ module Squake
36
37
  carbon_quantity: carbon_quantity,
37
38
  carbon_unit: carbon_unit,
38
39
  expand: expand,
40
+ payment_link_return_url: payment_link_return_url,
39
41
  },
40
42
  )
41
43
 
@@ -36,7 +36,7 @@ module Squake
36
36
  <<~TXT
37
37
  Failed Request
38
38
  http_code=#{code}
39
- body=#{::Oj.dump(body)}
39
+ body=#{::Oj.dump(body, Squake::OJ_CONFIG)}
40
40
  original_request_http_method=#{original_request.method}
41
41
  original_request_http_path=#{original_request.path}
42
42
  TXT
@@ -2,5 +2,5 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module Squake
5
- VERSION = '0.5.1'
5
+ VERSION = '0.6.1'
6
6
  end
data/lib/squake.rb CHANGED
@@ -5,14 +5,21 @@ require 'sorbet-runtime'
5
5
  require 'oj'
6
6
  require 'net/http'
7
7
 
8
- Oj.default_options = {
9
- mode: :compat, # required to dump hashes with symbol-keys
10
- symbol_keys: true,
11
- }
12
-
13
8
  Dir[File.join(__dir__, './**/*', '*.rb')].each { require(_1) }
14
9
 
15
10
  module Squake
11
+ # Don't freeze this constant, since we don't know what Oj is doing with the object under the hood
12
+ # Don't set this as global Oj settings to avoid bleeding into other apps that build on this gem
13
+ # rubocop:disable Style/MutableConstant
14
+ OJ_CONFIG = T.let(
15
+ {
16
+ mode: :compat, # required to dump hashes with symbol-keys
17
+ symbol_keys: true,
18
+ },
19
+ T::Hash[Symbol, T.untyped],
20
+ )
21
+ # rubocop:enable Style/MutableConstant
22
+
16
23
  class << self
17
24
  extend T::Sig
18
25
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: squake
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - SQUAKE
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-10-21 00:00:00.000000000 Z
11
+ date: 2024-01-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: net-http
@@ -218,7 +218,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
218
218
  - !ruby/object:Gem::Version
219
219
  version: '0'
220
220
  requirements: []
221
- rubygems_version: 3.4.19
221
+ rubygems_version: 3.5.3
222
222
  signing_key:
223
223
  specification_version: 4
224
224
  summary: The industry solution for sustainable travel and logistics.