squake 0.3.0 → 0.4.1

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: f7838d5d10515e9d94811494249d36e789e441a04ab31f7e94c83c306a9fb2bf
4
- data.tar.gz: 61d6f7415ec816567ebf260493d43f1a3515090b9062e1740b339f4eb40de405
3
+ metadata.gz: 2f9d466b184e2ac142e79b4e11765c58b1dee90c05a4290a0ff456bcbce419f3
4
+ data.tar.gz: 7c6ff3a5a9c0784a9a2afa8b160669cdabe4c373b55acc7364685ac9791092ac
5
5
  SHA512:
6
- metadata.gz: 314d29865f690a9d4f7faf867269686dc5b184e9e36aa988d5ea19c60b75d608e09d9e90ccd086f733cfb01dd753c8c8b036a406cb48f1d3444d61f57b049fdc
7
- data.tar.gz: 1234e584e92277e455c8d3094b3624e54e37b972af10c27c1f6836ce5bb4ca54f92f2b548fe95be5dca2531b6c9d7f0a87072aae1fb0afd4e5f06be163287394
6
+ metadata.gz: 5e69d259a78944b62660b2229455678b1d62cad6a1a5435f37c42e3dea9e43f5eee31787263e4a4e8353e1bc3f072083e40a66fdc1cce021fb832175c8832371
7
+ data.tar.gz: c5b377cbe1ddcacb5842da69d167025cd3ea4cc1d3485df99a614dee2cc40820f8df766c88fe334a283dac08325d9ed9c7795448aad9d61af9261889854938df
@@ -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
+ headers = 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.1'
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.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-06-23 00:00:00.000000000 Z
11
+ date: 2023-07-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: net-http