squake 0.3.0 → 0.4.0

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: f7838d5d10515e9d94811494249d36e789e441a04ab31f7e94c83c306a9fb2bf
4
- data.tar.gz: 61d6f7415ec816567ebf260493d43f1a3515090b9062e1740b339f4eb40de405
3
+ metadata.gz: 484c86583e41e8eab5c20322ab33a706071eab0016a07adb14cf0e8f9a660391
4
+ data.tar.gz: b2806206e6e720e06f6802a3c5083d9cf4f0678c60848bf18146604b11f79b6a
5
5
  SHA512:
6
- metadata.gz: 314d29865f690a9d4f7faf867269686dc5b184e9e36aa988d5ea19c60b75d608e09d9e90ccd086f733cfb01dd753c8c8b036a406cb48f1d3444d61f57b049fdc
7
- data.tar.gz: 1234e584e92277e455c8d3094b3624e54e37b972af10c27c1f6836ce5bb4ca54f92f2b548fe95be5dca2531b6c9d7f0a87072aae1fb0afd4e5f06be163287394
6
+ metadata.gz: 1e8d99981b4b792c1dbd97c48dc643b06f1ff9eb6e4f70765d4d4549e556243935c73252430c724c5121c9df110fe05fbaca05987776f3ce5ee889a6f4bd6d62
7
+ data.tar.gz: eb93bc6ec43d386d6e5b019a0ac8b58859f09a1c50ec6b7e047d86636b884a31c231d0589b37147fac957e95875d7f9e1f2c3bb8cefe5863f81b8a84a8814029
@@ -14,9 +14,10 @@ module Squake
14
14
  carbon_unit: String,
15
15
  expand: T::Array[String],
16
16
  client: Squake::Client,
17
+ request_id: T.nilable(String),
17
18
  ).returns(Squake::Return[Squake::Model::Carbon])
18
19
  end
19
- def self.create(items:, carbon_unit: 'gram', expand: [], client: Squake::Client.new)
20
+ def self.create(items:, carbon_unit: 'gram', expand: [], client: Squake::Client.new, request_id: nil)
20
21
  # @TODO: add typed objects for all possible items. Until then, we allow either a Hash or a T::Struct
21
22
  items = items.map do |item|
22
23
  item.is_a?(T::Struct) ? item.serialize : item
@@ -25,6 +26,7 @@ module Squake
25
26
  result = client.call(
26
27
  path: ENDPOINT,
27
28
  method: :post,
29
+ headers: { 'X-Request-Id' => request_id }.compact,
28
30
  params: {
29
31
  items: items,
30
32
  carbon_unit: carbon_unit,
@@ -16,9 +16,12 @@ module Squake
16
16
  carbon_unit: String,
17
17
  expand: T::Array[String],
18
18
  client: Squake::Client,
19
+ request_id: T.nilable(String),
19
20
  ).returns(Squake::Return[Squake::Model::Pricing])
20
21
  end
21
- def self.quote(items:, product:, currency: 'EUR', carbon_unit: 'gram', expand: [], client: Squake::Client.new)
22
+ def self.quote(
23
+ items:, product:, currency: 'EUR', carbon_unit: 'gram', expand: [], client: Squake::Client.new, request_id: nil
24
+ )
22
25
  # @TODO: add typed objects for all possible items. Until then, we allow either a Hash or a T::Struct
23
26
  items = items.map do |item|
24
27
  item.is_a?(T::Struct) ? item.serialize : item
@@ -27,6 +30,7 @@ module Squake
27
30
  result = client.call(
28
31
  path: ENDPOINT,
29
32
  method: :post,
33
+ headers: { 'X-Request-Id' => request_id }.compact,
30
34
  params: {
31
35
  items: items,
32
36
  product: product,
data/lib/squake/client.rb CHANGED
@@ -66,7 +66,7 @@ module Squake
66
66
  raise "Unrecognized HTTP method: #{method}. Expected one of: get, head, delete, post"
67
67
  end
68
68
 
69
- headers = request_headers(api_key).update(headers)
69
+ request_headers(api_key).merge!(headers)
70
70
  query = query_params ? Util.encode_parameters(query_params) : nil
71
71
  body = body_params ? ::Oj.dump(body_params) : nil
72
72
  sanitized_path = path[0] == '/' ? path : "/#{path}"
@@ -14,14 +14,16 @@ module Squake
14
14
  product_id: T.nilable(String),
15
15
  locale: String,
16
16
  client: Squake::Client,
17
+ request_id: T.nilable(String),
17
18
  ).returns(Squake::Return[T::Array[Squake::Model::Product]])
18
19
  end
19
- def self.get(product_id: nil, locale: DEFAULT_LOCALE, client: Squake::Client.new)
20
+ def self.get(product_id: nil, locale: DEFAULT_LOCALE, client: Squake::Client.new, request_id: nil)
20
21
  path = product_id.nil? ? ENDPOINT : "#{ENDPOINT}/#{product_id}"
21
22
 
22
23
  result = client.call(
23
24
  path: path,
24
25
  method: :get,
26
+ headers: { 'X-Request-Id' => request_id }.compact,
25
27
  params: {
26
28
  locale: locale,
27
29
  },
@@ -8,7 +8,6 @@ module Squake
8
8
 
9
9
  ENDPOINT = T.let('/v2/purchases', String)
10
10
 
11
- # rubocop:disable Metrics/ParameterLists, Layout/LineLength
12
11
  sig do
13
12
  params(
14
13
  pricing: String,
@@ -18,12 +17,17 @@ module Squake
18
17
  external_reference: String, # used for idempotency, if given, MUST be unique
19
18
  expand: T::Array[String],
20
19
  client: Squake::Client,
20
+ request_id: T.nilable(String),
21
21
  ).returns(Squake::Return[Squake::Model::Purchase])
22
22
  end
23
- def self.create(pricing:, confirmation_document: nil, certificate_document: nil, metadata: nil, external_reference: SecureRandom.uuid, expand: [], client: Squake::Client.new)
23
+ def self.create(
24
+ pricing:, confirmation_document: nil, certificate_document: nil, metadata: nil,
25
+ external_reference: SecureRandom.uuid, expand: [], client: Squake::Client.new, request_id: nil
26
+ )
24
27
  result = client.call(
25
28
  path: ENDPOINT,
26
29
  method: :post,
30
+ headers: { 'X-Request-Id' => request_id }.compact,
27
31
  params: {
28
32
  pricing: pricing,
29
33
  confirmation_document: confirmation_document,
@@ -47,7 +51,6 @@ module Squake
47
51
  Return.new(errors: [error])
48
52
  end
49
53
  end
50
- # rubocop:enable Metrics/ParameterLists, Layout/LineLength
51
54
 
52
55
  sig do
53
56
  params(
@@ -2,5 +2,5 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module Squake
5
- VERSION = '0.3.0'
5
+ VERSION = '0.4.0'
6
6
  end
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.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - SQUAKE
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-06-23 00:00:00.000000000 Z
11
+ date: 2023-07-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: net-http