wolf_core 1.0.56 → 1.0.58
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 +4 -4
- data/lib/wolf_core/application/integrations/environment_operations.rb +14 -0
- data/lib/wolf_core/application/integrations/iterate_orders_service.rb +80 -0
- data/lib/wolf_core/application/integrations/orders_api_operations.rb +22 -2
- data/lib/wolf_core/version.rb +1 -1
- data/lib/wolf_core.rb +1 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bbc5d0c5991964b51bc263ff1a69a94ee25bda148781d99a1bc59aa52d4e5165
|
4
|
+
data.tar.gz: 314f170de28d271ee53d55390d2c31f52cdd52c25806de46a2207dec4136027a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e8b4973cd4bd497e57f793d1d9d744e5342d7d357d6d1fb1b24c6f0e67256bfba1694bd7f8ddfcae2d9bc1f716461f4b6118b5f5c438d90de1bf950a834adb18
|
7
|
+
data.tar.gz: bbf40707450f690727498cdf5d7b832cb6732bc12af82a526791a2169ac54b34345ccacb0ee92bf537614d5edc2c32e9ffaf27d38d7beffafe012b20de8a8f98
|
@@ -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
|
-
|
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
|
-
|
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 },
|
data/lib/wolf_core/version.rb
CHANGED
data/lib/wolf_core.rb
CHANGED
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.
|
4
|
+
version: 1.0.58
|
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-
|
11
|
+
date: 2025-01-14 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
|