wolf_core 1.1.17 → 1.1.19

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: 45745f516e8eb69746381a70a65e22f580f3dda4b3600b6eda99eda75bf0f057
4
- data.tar.gz: 1448150fb318029c96b9406852ac0326fd4f433af9226308441583a3511083d5
3
+ metadata.gz: b0fe4cb5e85ecc712aa3a2625fbbbf5b7ded94f0fabef91d7ea4ca5bcd0d0307
4
+ data.tar.gz: fda66823c4d880b772e7da73862134c34111edae03cb4d492be573016ac62ef8
5
5
  SHA512:
6
- metadata.gz: bd293374a86ee9166d0b820a0392493efa6828597c3e3a7d74e8337141782142e8303cb82d525e17cefe7d1e6dc15f479e15b17af295920339bb5995e4e78037
7
- data.tar.gz: 32c9a77c6ba34ba5ffc8e5ea81a1294d65f7a13314489d6d8ee26125105dcd9a78a02117fe53cf5363bff0d1f6359c742f66eabd4d6d5aab1aeb4ba9ce123a07
6
+ metadata.gz: e168ba53069007c54145bf43440b09fd918b86ebedb1c9c6b541eada9ae7cdc7db511ab3e493e4a26d21d6e47e58812dcfa454376daaabc28b8f86fb0300c1f7
7
+ data.tar.gz: 4159d44682c64b8e1291bad9cd6c3fc1ca5c1f44f7591af116fd999f954b5f225abeed64ba6ca0268a703266a639d7eaa2172d3aa80e2bac3151ededfb8cfd87
@@ -0,0 +1,75 @@
1
+ module WolfCore
2
+ module Integrations
3
+ module ContractApiOperations
4
+ include WolfCore::HttpOperations
5
+
6
+ CONTRACT_ID_REGEX = /.*-(\d+)-(\d+)/
7
+
8
+ def fetch_contract!(wolf_token:, tenant:, wolf_platform_url:, contract_id:, error_message:, error_data: nil, query: nil)
9
+ response = fetch_contract(
10
+ wolf_token: wolf_token,
11
+ tenant: tenant,
12
+ wolf_platform_url: wolf_platform_url,
13
+ contract_id: contract_id,
14
+ query: query
15
+ )
16
+ order_id, jobseeker_id = extract_ids_from_contract_id(contract_id)
17
+ error_data ||= {}
18
+ validate_http_response(
19
+ response: response,
20
+ message: error_message,
21
+ error_data: error_data.merge(contract_id: contract_id, order_id: order_id, jobseeker_id: jobseeker_id, query: query)
22
+ )
23
+ response.body.dig("data", "table", "contract")
24
+ end
25
+
26
+ def fetch_contract(wolf_token:, tenant:, wolf_platform_url:, contract_id:, query: nil)
27
+ order_id, jobseeker_id = extract_ids_from_contract_id(contract_id)
28
+ query ||= {}
29
+ parsed_http_get(
30
+ headers: { "Authorization" => "Bearer #{wolf_token}" },
31
+ url: "#{wolf_platform_url}/api/v2/contracts/#{order_id}/#{jobseeker_id}",
32
+ query: query.merge(tenant: tenant)
33
+ )
34
+ end
35
+
36
+ def update_contract!(wolf_token:, tenant:, wolf_platform_url:, contract_id:, contract:, error_message:, error_data: nil)
37
+ response = update_contract(
38
+ wolf_token: wolf_token,
39
+ tenant: tenant,
40
+ wolf_platform_url: wolf_platform_url,
41
+ contract_id: contract_id,
42
+ contract: contract
43
+ )
44
+ order_id, jobseeker_id = extract_ids_from_contract_id(contract_id)
45
+ error_data ||= {}
46
+ validate_http_response(
47
+ response: response,
48
+ message: error_message,
49
+ error_data: error_data.merge(contract_id: contract_id, order_id: order_id, jobseeker_id: jobseeker_id, contract: contract)
50
+ )
51
+ response
52
+ end
53
+
54
+ def update_contract(wolf_token:, tenant:, wolf_platform_url:, contract_id:, contract:)
55
+ order_id, jobseeker_id = extract_ids_from_contract_id(contract_id)
56
+ parsed_http_put(
57
+ headers: { "Authorization" => "Bearer #{wolf_token}" },
58
+ url: "#{wolf_platform_url}/api/v2/contracts/#{order_id}/#{jobseeker_id}",
59
+ query: { tenant: tenant },
60
+ body: contract
61
+ )
62
+ end
63
+
64
+ private
65
+
66
+ def extract_ids_from_contract_id(contract_id)
67
+ match = contract_id.match(CONTRACT_ID_REGEX)
68
+ raise_service_error(message: "Invalid contract_id format", data: { contract_id: contract_id }) unless match
69
+ order_id = match[1]
70
+ jobseeker_id = match[2]
71
+ [order_id, jobseeker_id]
72
+ end
73
+ end
74
+ end
75
+ end
@@ -22,15 +22,15 @@ module WolfCore
22
22
  end
23
23
  end
24
24
 
25
- def schedule_recurring(job_id:, schedule:, target:, config: {})
26
- Result.try do
27
- expr = expression_from_schedule!(schedule)
28
- normalized_target = normalize_target(target)
29
- response = schedule_with_expression(job_id: job_id, expr: expr, target: normalized_target,
30
- config: config)
31
- Result.success(data: { response: response })
32
- end
25
+ def schedule_recurring(job_id:, schedule:, target:, config: {})
26
+ Result.try do
27
+ expr = expression_from_schedule!(schedule)
28
+ normalized_target = normalize_target(target)
29
+ response = schedule_with_expression(job_id: job_id, expr: expr, target: normalized_target,
30
+ config: config)
31
+ Result.success(data: { response: response })
33
32
  end
33
+ end
34
34
 
35
35
  def cancel_schedule(job_id:, options: {})
36
36
  Result.try do
@@ -76,14 +76,16 @@ class Result
76
76
  fold_result
77
77
  end
78
78
 
79
+ def data_or_raise_error
80
+ raise_error.data
81
+ end
82
+
79
83
  def raise_error
80
- if failure?
81
- err_class = error.error_class || StandardError
82
- e = err_class.new(error.message)
83
- if error.backtrace
84
- e.set_backtrace(error.backtrace)
85
- end
86
- raise e
87
- end
84
+ return self if success?
85
+
86
+ err_class = error.error_class || StandardError
87
+ e = err_class.new(error.message)
88
+ e.set_backtrace(error.backtrace) if error.backtrace
89
+ raise e
88
90
  end
89
- end
91
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module WolfCore
4
- VERSION = "1.1.17"
4
+ VERSION = "1.1.19"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wolf_core
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.17
4
+ version: 1.1.19
5
5
  platform: ruby
6
6
  authors:
7
7
  - Javier Roncallo
@@ -123,6 +123,7 @@ files:
123
123
  - lib/wolf_core/application/exception_operations.rb
124
124
  - lib/wolf_core/application/integrations/change_detection.rb
125
125
  - lib/wolf_core/application/integrations/client_api_operations.rb
126
+ - lib/wolf_core/application/integrations/contract_api_operations.rb
126
127
  - lib/wolf_core/application/integrations/custom_value_api_operations.rb
127
128
  - lib/wolf_core/application/integrations/environment_operations.rb
128
129
  - lib/wolf_core/application/integrations/iterate_orders_service.rb