wolf_core 1.0.84 → 1.0.86

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: 4d7fa6a31a50c43cce5941f2892e68193eea7903d585332783ac0c88277b30fa
4
- data.tar.gz: 24c484564b6779998fd59ef8a8d87884a83b90a05737952e20d17a597fd61387
3
+ metadata.gz: c81a077657054ee1653188910f9843979df9e9b8fef277427b2ef6191b53825c
4
+ data.tar.gz: 23de16a0ee4e5c14823ba600beecd21343b93c0d09c16a5bd2fd22a9d4b19bc0
5
5
  SHA512:
6
- metadata.gz: 390850d53daea04127dc5c9786960ffeab9c8dbcd56196d1fcc97f2ec051187dc46ef583df56f8e47ba309347b5c1152bf90874fd4d61cd13e38d8f409b7b626
7
- data.tar.gz: bddd441d1c619c082096e31f0521019a9801086dc193e25bc17092a0f27681f81d1e1bb9170de132e814f06fe0ec5d46ca79bd61dc8760b03db4076c189dfe16
6
+ metadata.gz: fac822154372b8d46780147384d36d92e93d90809989236578c534895330c03f9a99087e730483de6d45f4a3fa7bd09860515f1a7de87de4489427f9c5f1a0aa
7
+ data.tar.gz: 0d3cf005b0d0579ba5366e05b2fc60556a889d7aacb28fd5f16cb3846111656f5aa290c81dadc6afe4675b807e519d0fe5f8151b26680dd4f03974c4b836cf2d
@@ -12,7 +12,8 @@ module WolfCore
12
12
  wolf_platform_url: wolf_platform_url,
13
13
  query: query
14
14
  )
15
- validate_http_response(response: response, message: error_message, error_data: error_data)
15
+ error_data ||= {}
16
+ validate_http_response(response: response, message: error_message, error_data: error_data.merge(query: query))
16
17
  response.body.dig("data", "table", "custom_responses")
17
18
  end
18
19
 
@@ -34,7 +35,8 @@ module WolfCore
34
35
  wolf_platform_url: wolf_platform_url,
35
36
  query: query
36
37
  )
37
- validate_http_response(response: response, message: error_message, error_data: error_data)
38
+ error_data ||= {}
39
+ validate_http_response(response: response, message: error_message, error_data: error_data.merge(custom_value_id: custom_value_id))
38
40
  response.body.dig("data", "table", "custom_responses")
39
41
  end
40
42
 
@@ -57,7 +59,8 @@ module WolfCore
57
59
  custom_requirement_id: custom_requirement_id,
58
60
  query: query
59
61
  )
60
- validate_http_response(response: response, message: error_message, error_data: error_data)
62
+ error_data ||= {}
63
+ validate_http_response(response: response, message: error_message, error_data: error_data.merge(custom_value: custom_value))
61
64
  response
62
65
  end
63
66
 
@@ -82,7 +85,8 @@ module WolfCore
82
85
  custom_value_id: custom_value_id,
83
86
  query: query
84
87
  )
85
- validate_http_response(response: response, message: error_message, error_data: error_data)
88
+ error_data ||= {}
89
+ validate_http_response(response: response, message: error_message, error_data: error_data.merge(custom_value_id: custom_value_id, custom_value: custom_value))
86
90
  response
87
91
  end
88
92
 
@@ -104,7 +108,8 @@ module WolfCore
104
108
  wolf_platform_url: wolf_platform_url,
105
109
  query: query
106
110
  )
107
- validate_http_response(response: response, message: error_message, error_data: error_data)
111
+ error_data ||= {}
112
+ validate_http_response(response: response, message: error_message, error_data: error_data.merge(query: query))
108
113
  custom_values = response.body.dig("data", "table", "custom_responses")
109
114
 
110
115
  response = if custom_values&.any?
@@ -3,33 +3,69 @@ module WolfCore
3
3
  module JobseekerApiOperations
4
4
  include WolfCore::HttpOperations
5
5
 
6
- def fetch_jobseeker!(wolf_token:, jobseeker_id:, tenant:, wolf_platform_url:, error_message:)
7
- response = safe_http_get(
6
+ def fetch_jobseeker_by_user_id!(wolf_token:, tenant:, wolf_platform_url:, user_id:)
7
+ jobseekers = fetch_jobseekers!(
8
+ wolf_token: wolf_token,
9
+ tenant: tenant,
10
+ wolf_platform_url: wolf_platform_url,
11
+ query: { user_id: user_id }
12
+ )
13
+ jobseekers.first
14
+ end
15
+
16
+ def fetch_jobseekers!(wolf_token:, tenant:, wolf_platform_url:, error_message:, query: nil, error_data: nil)
17
+ response = fetch_jobseekers(
18
+ wolf_token: wolf_token,
19
+ tenant: tenant,
20
+ wolf_platform_url: wolf_platform_url,
21
+ query: query
22
+ )
23
+ error_data ||= {}
24
+ validate_http_response(response: response, message: error_message, error_data: error_data.merge(query: query))
25
+ response.body.dig("data", "table", "jobseeker")
26
+ end
27
+
28
+ def fetch_jobseekers(wolf_token:, tenant:, wolf_platform_url:, query: nil)
29
+ query ||= {}
30
+ parsed_http_get(
8
31
  headers: { "Authorization" => "Bearer #{wolf_token}" },
9
- url: "#{wolf_platform_url}/api/v2/jobseekers/#{jobseeker_id}",
10
- query: { tenant: tenant },
11
- error_message: error_message
32
+ url: "#{wolf_platform_url}/api/v2/jobseekers",
33
+ query: query.merge(tenant: tenant)
12
34
  )
13
- response_body = response.body
14
- response_body.dig("data", "table", "jobseeker")
15
35
  end
16
36
 
17
- def fetch_jobseeker(wolf_token:, jobseeker_id:, tenant:, wolf_platform_url:)
37
+ def fetch_jobseeker!(wolf_token:, jobseeker_id:, tenant:, wolf_platform_url:, error_message:, query: nil, error_data: nil)
38
+ response = fetch_jobseeker(
39
+ wolf_token: wolf_token,
40
+ jobseeker_id: jobseeker_id,
41
+ tenant: tenant,
42
+ wolf_platform_url: wolf_platform_url,
43
+ query: query
44
+ )
45
+ error_data ||= {}
46
+ validate_http_response(response: response, message: error_message, error_data: error_data.merge(jobseeker_id: jobseeker_id, query: query))
47
+ response.body.dig("data", "table", "jobseeker")
48
+ end
49
+
50
+ def fetch_jobseeker(wolf_token:, jobseeker_id:, tenant:, wolf_platform_url:, query: nil)
51
+ query ||= {}
18
52
  parsed_http_get(
19
53
  headers: { "Authorization" => "Bearer #{wolf_token}" },
20
54
  url: "#{wolf_platform_url}/api/v2/jobseekers/#{jobseeker_id}",
21
- query: { tenant: tenant }
55
+ query: query.merge(tenant: tenant)
22
56
  )
23
57
  end
24
58
 
25
- def create_jobseeker!(wolf_token:, jobseeker:, tenant:, wolf_platform_url:, error_message:)
26
- safe_http_post(
27
- headers: { "Authorization" => "Bearer #{wolf_token}" },
28
- query: { tenant: tenant },
29
- url: "#{wolf_platform_url}/api/v2/jobseekers",
30
- body: jobseeker,
31
- error_message: error_message
59
+ def create_jobseeker!(wolf_token:, jobseeker:, tenant:, wolf_platform_url:, error_message:, error_data: nil)
60
+ response = create_jobseeker(
61
+ wolf_token: wolf_token,
62
+ jobseeker: jobseeker,
63
+ tenant: tenant,
64
+ wolf_platform_url: wolf_platform_url
32
65
  )
66
+ error_data ||= {}
67
+ validate_http_response(response: response, message: error_message, error_data: error_data.merge(jobseeker: jobseeker))
68
+ response
33
69
  end
34
70
 
35
71
  def create_jobseeker(wolf_token:, jobseeker:, tenant:, wolf_platform_url:)
@@ -41,14 +77,17 @@ module WolfCore
41
77
  )
42
78
  end
43
79
 
44
- def update_jobseeker!(wolf_token:, jobseeker:, tenant:, wolf_platform_url:, error_message:, jobseeker_id:)
45
- safe_http_put(
46
- headers: { "Authorization" => "Bearer #{wolf_token}" },
47
- query: { tenant: tenant },
48
- url: "#{wolf_platform_url}/api/v2/jobseekers/#{jobseeker_id}",
49
- body: jobseeker,
50
- error_message: error_message
80
+ def update_jobseeker!(wolf_token:, jobseeker:, tenant:, wolf_platform_url:, error_message:, jobseeker_id:, error_data: nil)
81
+ response = update_jobseeker(
82
+ wolf_token: wolf_token,
83
+ jobseeker: jobseeker,
84
+ tenant: tenant,
85
+ wolf_platform_url: wolf_platform_url,
86
+ jobseeker_id: jobseeker_id
51
87
  )
88
+ error_data ||= {}
89
+ validate_http_response(response: response, message: error_message, error_data: error_data.merge(jobseeker_id: jobseeker_id, jobseeker: jobseeker))
90
+ response
52
91
  end
53
92
 
54
93
  def update_jobseeker(wolf_token:, jobseeker:, tenant:, wolf_platform_url:, jobseeker_id:)
@@ -0,0 +1,83 @@
1
+ # frozen_string_literal: true
2
+
3
+ module WolfCore
4
+ class DomainObject
5
+ include ActiveModel::Model
6
+ include ActiveModel::Serializers::JSON
7
+ include ActiveModel::Dirty
8
+ include ActiveModel::Callbacks
9
+
10
+ define_model_callbacks :initialize, only: [:after, :before]
11
+ delegate :[], to: :attributes
12
+
13
+ class_attribute :fields, default: []
14
+
15
+ def self.define_attributes(*attributes)
16
+ self.fields += attributes
17
+
18
+ attr_accessor(*attributes)
19
+
20
+ define_attribute_methods(*attributes)
21
+
22
+ attributes.each do |attribute|
23
+ define_method(:"#{attribute}=") do |value|
24
+ send(:"#{attribute}_will_change!") unless value == send(attribute)
25
+ instance_variable_set(:"@#{attribute}", value)
26
+ valid?
27
+ value
28
+ end
29
+ end
30
+ end
31
+
32
+ def self.create_all(objects)
33
+ success_key = extract_success_key(objects.first)
34
+ final_array = []
35
+ objects.each do |object|
36
+ result = create(object)
37
+ if result.failure?
38
+ return result
39
+ else
40
+ final_array << result.data[success_key.to_sym]
41
+ end
42
+ end
43
+ Result.success(data: { success_key.pluralize.to_s => final_array })
44
+ end
45
+
46
+ def self.create(params = {}, **kwargs)
47
+ params = {} unless params.is_a?(Hash)
48
+ params = params.merge(kwargs)
49
+ object = self.new(parse_params(params))
50
+ object.reset_changes
51
+ if object.valid?
52
+ success_key = extract_success_key(object)
53
+ Result.success(data: { success_key => object })
54
+ else
55
+ Result.failure(error: { message: object.errors.full_messages.to_sentence })
56
+ end
57
+ rescue ActiveModel::UnknownAttributeError => e
58
+ Result.failure(error: { message: e.message, error_type: e.class.to_s })
59
+ end
60
+
61
+ def self.extract_success_key(object)
62
+ object.class.to_s.split('::').last.underscore
63
+ end
64
+
65
+ def self.parse_params(params)
66
+ (params.to_h).with_indifferent_access
67
+ end
68
+
69
+ def initialize(attributes = {})
70
+ run_callbacks :initialize do
71
+ super
72
+ end
73
+ end
74
+
75
+ def attributes
76
+ instance_values.slice(*self.class.fields.map(&:to_s)).with_indifferent_access
77
+ end
78
+
79
+ def reset_changes
80
+ self.changes_applied
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'domain_object'
4
+
5
+ module WolfCore
6
+ class Entity < DomainObject
7
+ define_attributes :id
8
+ validates :id, presence: true
9
+
10
+ define_model_callbacks :validation, only: [:after, :before]
11
+
12
+ after_initialize do
13
+ @id ||= generate_id
14
+ end
15
+
16
+ def valid?(*args)
17
+ run_callbacks(:validation) do
18
+ super
19
+ end
20
+ end
21
+
22
+ def ==(other)
23
+ id == other.id
24
+ end
25
+
26
+ def created_at
27
+ return if id.blank?
28
+
29
+ timestamp = id.split('-')[1].to_i
30
+ @created_at ||= Time.at(timestamp).utc
31
+ end
32
+
33
+ private
34
+
35
+ def generate_id
36
+ prefix = self.class.to_s.underscore.split('/').last.downcase[0..4]
37
+ timestamp = Time.now.utc.to_i
38
+ uuid = SecureRandom.uuid.delete('-')[0..9]
39
+ "#{prefix}-#{timestamp}-#{uuid}"
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'domain_object'
4
+
5
+ module WolfCore
6
+ class ValueObject < DomainObject
7
+ def ==(other)
8
+ return false unless other.is_a?(self.class)
9
+ self.class.fields.each do |key|
10
+ return false unless attributes[key] == other.attributes[key]
11
+ end
12
+ true
13
+ end
14
+ end
15
+ end
@@ -15,7 +15,7 @@ module WolfCore
15
15
  safe_require(files_to_require)
16
16
  end
17
17
 
18
- def safe_require(missing_files) # rubocop:disable Metrics/MethodLength
18
+ def safe_require(missing_files)
19
19
  error_counter = {}
20
20
  while missing_files.any?
21
21
  files_to_require = missing_files
@@ -28,6 +28,7 @@ module WolfCore
28
28
  if error_counter[file] >= 10
29
29
  log_object "Error requiring file: #{file}"
30
30
  log_object e, title: "Error is"
31
+ log_object e.backtrace, title: "Error backtrace is"
31
32
  end
32
33
  missing_files << file if error_counter[file] < 15
33
34
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module WolfCore
4
- VERSION = "1.0.84"
4
+ VERSION = "1.0.86"
5
5
  end
data/lib/wolf_core.rb CHANGED
@@ -4,6 +4,7 @@ require 'json'
4
4
  require 'ostruct'
5
5
  require 'httparty'
6
6
  require 'active_support'
7
+ require 'active_model'
7
8
  require 'active_support/core_ext'
8
9
  require 'aws-sdk-lambda'
9
10
  require 'redis'
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.84
4
+ version: 1.0.86
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-02-06 00:00:00.000000000 Z
11
+ date: 2025-02-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -94,6 +94,20 @@ dependencies:
94
94
  - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: activemodel
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
97
111
  description: Repository to store shared code among Ruby projects.
98
112
  email:
99
113
  - jroncallo96@gmail.com
@@ -119,6 +133,9 @@ files:
119
133
  - lib/wolf_core/application/integrations/webhooks_operations.rb
120
134
  - lib/wolf_core/application/salesforce_oauth_service.rb
121
135
  - lib/wolf_core/application/service_exception.rb
136
+ - lib/wolf_core/domain/domain_object.rb
137
+ - lib/wolf_core/domain/entity.rb
138
+ - lib/wolf_core/domain/value_object.rb
122
139
  - lib/wolf_core/infrastructure/fkm_operations.rb
123
140
  - lib/wolf_core/infrastructure/http_data_source.rb
124
141
  - lib/wolf_core/infrastructure/http_operations.rb