wolf_core 1.0.57 → 1.0.59

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: b975d4a8f428560a91186b0148a2d9e897c8eeb453faa1f6fb7424e4ce85d992
4
- data.tar.gz: 2c3190104347045083c078384102e6b4bbf4931b1b62f733c38b0752df00270b
3
+ metadata.gz: f8a49d9f69bf0479d8e1bb729b4860cb39bf2653754533814b5f570fd33a56dc
4
+ data.tar.gz: bf7e77f83cbd435fffb27b72c8ed1c6c19dafc982641e8d20f0b7ff514d66e33
5
5
  SHA512:
6
- metadata.gz: 1966aabafe2690a73b7ced6b882cb0c39596e9bc61d246ab13f88146ba5fdbc9f1220c8df4ec146ab551a48d8e5940e5dfbbada09096f0dab4733c5284952962
7
- data.tar.gz: 6b2a27082d1bbf77d29cc7c9018bfd7d5f0d7aeedc9ed9cee6baf28dd72a8435c42a83552d15307ec95343523eca6661fbcda2b1b1d31a3569869df0993e784a
6
+ metadata.gz: 85f4405412747716e4f10e675ff553d53d8da5508390264130a6c2d8a6e1eb5f25448ab67d857c749896e28517ce2e0540a5cae1779373d13519c1107e7f1bb9
7
+ data.tar.gz: bde2251dc5a5be9a038d71001a6b0564696386cf0aad941e075b9934fb8a55d75fb0f5260fb70b8a7991be0d6bf54f3fb57e186818fdea55aa5363b461ec00d0
@@ -0,0 +1,14 @@
1
+ module WolfCore
2
+ module Integrations
3
+ module EnvironmentOperations
4
+ def load_environment_variables(json_file)
5
+ file_content = File.read(json_file)
6
+ data = JSON.parse(file_content)
7
+ data.each do |key, value|
8
+ parsed_key = key.gsub(/([a-z])([A-Z])/, '\1_\2').upcase
9
+ ENV[parsed_key] = value
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,80 @@
1
+ module WolfCore
2
+ module Integrations
3
+ class IterateOrdersService < WolfCore::ApplicationService
4
+ include WolfCore::Integrations::OrdersApiOperations
5
+
6
+ def initialize(params: nil)
7
+ params ||= {}
8
+ @page = params[:page] || 1
9
+ @per_page = params[:per_page] || 100
10
+ @max_page = params[:max_page]
11
+ end
12
+
13
+ def process
14
+ @wolf_token = get_wolf_token
15
+ iterate_all_orders
16
+ build_success_result
17
+ end
18
+
19
+ private
20
+ def iterate_all_orders
21
+ begin
22
+ @orders = get_page_orders
23
+ @orders.each do |order|
24
+ log_object '===== Processing order ====='
25
+ log_object order, title: 'order is'
26
+ process_order(order)
27
+ end
28
+ end while page_is_less_or_equal_to_last
29
+ @page -= 1
30
+ end
31
+
32
+ def build_success_result
33
+ Result.success(
34
+ data: {
35
+ page: @page,
36
+ per_page: @per_page,
37
+ max_page: @max_page,
38
+ }.merge(build_success_result_data)
39
+ )
40
+ end
41
+
42
+ def get_page_orders
43
+ 3.times { log_object '===== Starting get_page_orders =====' }
44
+ query = { per_page: @per_page, page: @page, client_id: 1 }
45
+ log_object query, title: 'fetching orders query params are'
46
+ response = fetch_orders!(
47
+ wolf_token: @wolf_token, tenant: ENV['TENANT'], query: query,
48
+ wolf_platform_url: ENV['WOLF_PLATFORM_URL'], error_message: 'Failed to fetch orders',
49
+ )
50
+ @total_pages = response.dig('total_pages')
51
+ log_object "total_pages are #{@total_pages}"
52
+ @page += 1
53
+ 3.times { log_object '===== Ending get_page_orders =====' }
54
+ response.dig('orders')
55
+ end
56
+
57
+ def process_order(order)
58
+ raise_service_error({ message: 'process_order must be implemented in a subclass' })
59
+ end
60
+
61
+ def page_is_less_or_equal_to_last
62
+ 3.times { log_object '===== Starting evaluating page_is_less_or_equal_to_last =====' }
63
+ log_object "page is #{@page}"
64
+ log_object "max_page is #{@max_page}"
65
+ if @max_page.present?
66
+ log_object "@page < @max_page is #{@page < @max_page}"
67
+ return @page < @max_page
68
+ end
69
+ log_object "total_pages is #{@total_pages}"
70
+ log_object "@page <= @total_pages is #{@page <= @total_pages}"
71
+ 3.times { log_object '===== Ending evaluating page_is_less_or_equal_to_last =====' }
72
+ @page <= @total_pages
73
+ end
74
+
75
+ def build_success_result_data
76
+ {}
77
+ end
78
+ end
79
+ end
80
+ end
@@ -3,6 +3,26 @@ module WolfCore
3
3
  module OrdersApiOperations
4
4
  include WolfCore::HttpOperations
5
5
 
6
+ def fetch_orders!(wolf_token:, tenant:, query:, wolf_platform_url:, error_message:, error_data: nil)
7
+ response = fetch_orders(
8
+ wolf_token: wolf_token, tenant: tenant, query: query,
9
+ wolf_platform_url: wolf_platform_url,
10
+ )
11
+ validate_http_response(response: response, message: error_message, error_data: error_data)
12
+ response_body = response.body
13
+ response_body.dig("data", "table")
14
+ end
15
+
16
+ def fetch_orders(wolf_token:, tenant:, query:, wolf_platform_url:)
17
+ query ||= {}
18
+ query = query.merge({ tenant: tenant })
19
+ parsed_http_get(
20
+ headers: { 'Authorization' => "Bearer #{wolf_token}" },
21
+ url: "#{wolf_platform_url}/api/v2/orders",
22
+ query: query,
23
+ )
24
+ end
25
+
6
26
  def fetch_order!(wolf_token:, order_id:, tenant:, wolf_platform_url:, error_message:)
7
27
  response = safe_http_get(
8
28
  headers: { "Authorization" => "Bearer #{wolf_token}" },
@@ -15,7 +35,7 @@ module WolfCore
15
35
  end
16
36
 
17
37
  def fetch_order(wolf_token:, order_id:, tenant:, wolf_platform_url:)
18
- http_get(
38
+ parsed_http_get(
19
39
  headers: { "Authorization" => "Bearer #{wolf_token}" },
20
40
  url: "#{wolf_platform_url}/api/v2/orders/#{order_id}",
21
41
  query: { tenant: tenant }
@@ -33,7 +53,7 @@ module WolfCore
33
53
  end
34
54
 
35
55
  def create_order(wolf_token:, order:, tenant:, wolf_platform_url:)
36
- http_post(
56
+ parsed_http_post(
37
57
  headers: { "Authorization" => "Bearer #{wolf_token}" },
38
58
  url: "#{wolf_platform_url}/api/v2/orders",
39
59
  query: { tenant: tenant },
@@ -2,26 +2,28 @@ module WolfCore
2
2
  module HttpDataSource
3
3
  module_function
4
4
 
5
- def http_get(url:, headers: {}, query: nil)
6
- HTTParty.get(url, headers: headers, query: query)
5
+ TIMEOUT = 900
6
+
7
+ def http_get(url:, headers: {}, query: nil, timeout: TIMEOUT)
8
+ HTTParty.get(url, headers: headers, query: query, timeout: timeout)
7
9
  end
8
10
 
9
- def http_post(url:, headers: {}, query: nil, body: nil)
11
+ def http_post(url:, headers: {}, query: nil, body: nil, timeout: TIMEOUT)
10
12
  headers['Content-Type'] ||= 'application/json'
11
13
  body = body&.to_json if headers['Content-Type'] == 'application/json'
12
- HTTParty.post(url, headers: headers, query: query, body: body)
14
+ HTTParty.post(url, headers: headers, query: query, body: body, timeout: timeout)
13
15
  end
14
16
 
15
- def http_put(url:, headers: {}, query: nil, body: nil)
17
+ def http_put(url:, headers: {}, query: nil, body: nil, timeout: TIMEOUT)
16
18
  headers['Content-Type'] ||= 'application/json'
17
19
  body = body&.to_json if headers['Content-Type'] == 'application/json'
18
- HTTParty.put(url, headers: headers, query: query, body: body)
20
+ HTTParty.put(url, headers: headers, query: query, body: body, timeout: timeout)
19
21
  end
20
22
 
21
- def http_patch(url:, headers: {}, query: nil, body: nil)
23
+ def http_patch(url:, headers: {}, query: nil, body: nil, timeout: TIMEOUT)
22
24
  headers['Content-Type'] ||= 'application/json'
23
25
  body = body&.to_json if headers['Content-Type'] == 'application/json'
24
- HTTParty.patch(url, headers: headers, query: query, body: body)
26
+ HTTParty.patch(url, headers: headers, query: query, body: body, timeout: timeout)
25
27
  end
26
28
  end
27
29
  end
@@ -4,8 +4,8 @@ module WolfCore
4
4
  include WolfCore::AsyncUtils
5
5
  include WolfCore::LoggingUtils
6
6
 
7
- def parsed_http_get(url:, headers: {}, query: nil)
8
- response = http_get(url: url, headers: headers, query: query)
7
+ def parsed_http_get(url:, headers: {}, query: nil, timeout: nil)
8
+ response = http_get(url: url, headers: headers, query: query, timeout: timeout)
9
9
  parse_http_response(response)
10
10
  end
11
11
 
@@ -18,8 +18,8 @@ module WolfCore
18
18
  end
19
19
  end
20
20
 
21
- def safe_http_get(url:, headers: {}, query: nil, error_message: nil, title: nil)
22
- response = http_get(url: url, headers: headers, query: query)
21
+ def safe_http_get(url:, headers: {}, query: nil, error_message: nil, title: nil, timeout: nil)
22
+ response = http_get(url: url, headers: headers, query: query, timeout: timeout)
23
23
  response = parse_http_response(response)
24
24
 
25
25
  log_object response, title: title if title.present?
@@ -30,12 +30,12 @@ module WolfCore
30
30
  response
31
31
  end
32
32
 
33
- def http_get(url:, headers: {}, query: nil)
34
- WolfCore::HttpDataSource.http_get(url: url, headers: headers, query: query)
33
+ def http_get(url:, headers: {}, query: nil, timeout: nil)
34
+ WolfCore::HttpDataSource.http_get(url: url, headers: headers, query: query, timeout: timeout)
35
35
  end
36
36
 
37
- def parsed_http_post(url:, body: nil, headers: {}, query: nil)
38
- response = http_post(url: url, headers: headers, query: query, body: body)
37
+ def parsed_http_post(url:, body: nil, headers: {}, query: nil, timeout: nil)
38
+ response = http_post(url: url, headers: headers, query: query, body: body, timeout: timeout)
39
39
  parse_http_response(response)
40
40
  end
41
41
 
@@ -48,8 +48,8 @@ module WolfCore
48
48
  end
49
49
  end
50
50
 
51
- def safe_http_post(url:, headers: {}, body: nil, query: nil, error_message: nil, title: nil, error_data: nil)
52
- response = http_post(url: url, headers: headers, body: body, query: query)
51
+ def safe_http_post(url:, headers: {}, body: nil, query: nil, error_message: nil, title: nil, error_data: nil, timeout: nil)
52
+ response = http_post(url: url, headers: headers, body: body, query: query, timeout: timeout)
53
53
  response = parse_http_response(response)
54
54
 
55
55
  title ||= "safe_http_post response is"
@@ -61,12 +61,12 @@ module WolfCore
61
61
  response
62
62
  end
63
63
 
64
- def http_post(url:, headers: {}, body: nil, query: nil)
65
- WolfCore::HttpDataSource.http_post(url: url, headers: headers, query: query, body: body)
64
+ def http_post(url:, headers: {}, body: nil, query: nil, timeout: nil)
65
+ WolfCore::HttpDataSource.http_post(url: url, headers: headers, query: query, body: body, timeout: timeout)
66
66
  end
67
67
 
68
- def parsed_http_put(url:, body: nil, headers: {}, query: nil)
69
- response = http_put(url: url, headers: headers, query: query, body: body)
68
+ def parsed_http_put(url:, body: nil, headers: {}, query: nil, timeout: nil)
69
+ response = http_put(url: url, headers: headers, query: query, body: body, timeout: timeout)
70
70
  parse_http_response(response)
71
71
  end
72
72
 
@@ -79,8 +79,8 @@ module WolfCore
79
79
  end
80
80
  end
81
81
 
82
- def safe_http_put(url:, headers: {}, body: nil, query: nil, error_message: nil, title: nil, error_data: nil)
83
- response = http_put(url: url, headers: headers, body: body, query: query)
82
+ def safe_http_put(url:, headers: {}, body: nil, query: nil, error_message: nil, title: nil, error_data: nil, timeout: nil)
83
+ response = http_put(url: url, headers: headers, body: body, query: query, timeout: timeout)
84
84
  response = parse_http_response(response)
85
85
 
86
86
  title ||= "safe_http_put response is"
@@ -92,12 +92,12 @@ module WolfCore
92
92
  response
93
93
  end
94
94
 
95
- def http_put(url:, headers: {}, body: nil, query: nil)
96
- WolfCore::HttpDataSource.http_put(url: url, headers: headers, query: query, body: body)
95
+ def http_put(url:, headers: {}, body: nil, query: nil, timeout: nil)
96
+ WolfCore::HttpDataSource.http_put(url: url, headers: headers, query: query, body: body, timeout: timeout)
97
97
  end
98
98
 
99
- def parsed_http_patch(url:, headers: {}, query: nil)
100
- response = http_patch(url: url, headers: headers, query: query)
99
+ def parsed_http_patch(url:, headers: {}, query: nil, body: nil, timeout: nil)
100
+ response = http_patch(url: url, headers: headers, query: query, body: body, timeout: timeout)
101
101
  parse_http_response(response)
102
102
  end
103
103
 
@@ -110,8 +110,8 @@ module WolfCore
110
110
  end
111
111
  end
112
112
 
113
- def safe_http_patch(url:, headers: {}, body: nil, query: nil, error_message: nil, title: nil, error_data: nil)
114
- response = http_patch(url: url, headers: headers, body: body, query: query)
113
+ def safe_http_patch(url:, headers: {}, body: nil, query: nil, error_message: nil, title: nil, error_data: nil, timeout: nil)
114
+ response = http_patch(url: url, headers: headers, body: body, query: query, timeout: timeout)
115
115
  response = parse_http_response(response)
116
116
 
117
117
  title ||= "safe_http_patch response is"
@@ -123,8 +123,8 @@ module WolfCore
123
123
  response
124
124
  end
125
125
 
126
- def http_patch(url:, headers: {}, body: nil, query: nil)
127
- WolfCore::HttpDataSource.http_patch(url: url, headers: headers, query: query, body: body)
126
+ def http_patch(url:, headers: {}, body: nil, query: nil, timeout: nil)
127
+ WolfCore::HttpDataSource.http_patch(url: url, headers: headers, query: query, body: body, timeout: timeout)
128
128
  end
129
129
 
130
130
  def validate_http_response(response:, message:, error_data: nil)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module WolfCore
4
- VERSION = "1.0.57"
4
+ VERSION = "1.0.59"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wolf_core
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.57
4
+ version: 1.0.59
5
5
  platform: ruby
6
6
  authors:
7
7
  - Javier Roncallo
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-01-07 00:00:00.000000000 Z
11
+ date: 2025-01-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -110,6 +110,8 @@ files:
110
110
  - lib/wolf_core/application/exception_operations.rb
111
111
  - lib/wolf_core/application/integrations/change_detection.rb
112
112
  - lib/wolf_core/application/integrations/client_api_operations.rb
113
+ - lib/wolf_core/application/integrations/environment_operations.rb
114
+ - lib/wolf_core/application/integrations/iterate_orders_service.rb
113
115
  - lib/wolf_core/application/integrations/jobseeker_api_operations.rb
114
116
  - lib/wolf_core/application/integrations/orders_api_operations.rb
115
117
  - lib/wolf_core/application/integrations/routing_operations.rb