wolf_core 0.1.4 → 0.1.5

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: b630da917ad473715336622e1089d9f5fe560a31b21a8618e21e1f6ca79dcbb2
4
- data.tar.gz: d51967508c290fcd7f7631405a1fdfc2abc7406b9fa52a35b48eef8c33d0316e
3
+ metadata.gz: a4485e1d17306d577f5bc91c91bf5b6842c0ca185daddbb929a00e0da0132143
4
+ data.tar.gz: a8a16ac488d4d4456af04581b3eae6b468df954212d0c656d8928ed01cd32c6c
5
5
  SHA512:
6
- metadata.gz: f6eaf5bde62cca9d34f082bceedbfef952d35465b451c3e4f963b161ea1cd43cd1c8415a83a9f7484600601dc29dd31192f7d1d980301caa59cf33e102059f70
7
- data.tar.gz: 44be0309aa988db4784fb10fe9c7632e94bcdb4a03e5148a847ae090d18c52adaf5f492f92a3a19ae14e2c5b758a7bf12f56083448e714d4aacbf0ced544f5d3
6
+ metadata.gz: ef91f05f88b518b7ae08edf65c9864ed8c040f2c0bd6edd2ca79617f8ff7b85fc056a520da93421b806cfb044c8b9ecc131d1f077276cd9abcd08590666c706b
7
+ data.tar.gz: 9571885831d0c0b76fed39f9f771acc8c4dde62b3b8afd6490d169f844123371da062b158ef3c9e768d7df40f6a7b3d96c81b1b4a9b6fe61acd41a851dfa652f
@@ -1,5 +1,8 @@
1
1
  module WolfCore
2
2
  class ApplicationService
3
+ include WolfCore::ExceptionOperations
4
+ include WolfCore::HttpOperations
5
+
3
6
  def call
4
7
  process
5
8
  rescue => e
@@ -29,10 +32,6 @@ module WolfCore
29
32
  raise_service_error({ message: message })
30
33
  end
31
34
 
32
- def raise_service_error(error_data)
33
- raise WolfCore::ServiceException, error_data
34
- end
35
-
36
35
  def remove_non_permitted_parameters(params, allowed_params)
37
36
  permitted = params.slice(*allowed_params)
38
37
  if permitted.blank?
@@ -41,14 +40,6 @@ module WolfCore
41
40
  return permitted
42
41
  end
43
42
 
44
- def http_get(url:, headers: {}, query: nil)
45
- WolfCore::HttpDataSource.http_get(url: url, headers: headers, query: query)
46
- end
47
-
48
- def http_post(url:, headers: {}, body: nil, query: nil)
49
- WolfCore::HttpDataSource.http_post(url: url, headers: headers, query: query, body: body)
50
- end
51
-
52
43
  def barton_integration_http_post(path:, body:, error_message:)
53
44
  domain_url = ENV['CURRENT_SAM_URL']
54
45
  response = http_post(url: "#{domain_url}/#{path}", body: body)
@@ -58,25 +49,6 @@ module WolfCore
58
49
  response
59
50
  end
60
51
 
61
- def validate_http_response(response:, message:, error_data: nil)
62
- unless response.code == 200
63
- error_data = {
64
- message: message,
65
- response: parse_http_response(response)
66
- }.merge(error_data || {})
67
- raise_service_error(error_data)
68
- end
69
- end
70
-
71
- def parse_http_response(response)
72
- body = JSON.parse(response.body) rescue response.body
73
- {
74
- code: response.code,
75
- body: body,
76
- message: response.message,
77
- }
78
- end
79
-
80
52
  def get_salesforce_access_token
81
53
  result = WolfCore::SalesforceOauthService.new.call
82
54
  raise_failed_result(result)
@@ -84,7 +56,7 @@ module WolfCore
84
56
  end
85
57
 
86
58
  def get_salesforce_foreign_object(record_id:)
87
- foreign_object = saleforce_http_get(
59
+ foreign_object = salesforce_http_get(
88
60
  query: { calltype: 'getRecord', RecordId: record_id }
89
61
  )
90
62
  puts "foreign object is"
@@ -92,7 +64,7 @@ module WolfCore
92
64
  foreign_object
93
65
  end
94
66
 
95
- def saleforce_http_get(query: nil)
67
+ def salesforce_http_get(query: nil)
96
68
  response = http_get(
97
69
  url: ENV['SALESFORCE_URL'],
98
70
  headers: { 'Authorization' => "Bearer #{@salesforce_access_token}" },
@@ -0,0 +1,7 @@
1
+ module WolfCore
2
+ module ExceptionOperations
3
+ def raise_service_error(error_data)
4
+ raise WolfCore::ServiceException, error_data
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,19 @@
1
+ module WolfCore
2
+ module FkmOperations
3
+ include WolfCore::HttpOperations
4
+
5
+ def get_foreign_key_destination_id(tenant:, source:, source_id:, destination:)
6
+ response_body = get_foreign_keys(tenant: tenant, source: source, source_id: source_id)
7
+ foreign_keys = response_body
8
+ foreign_keys.find { |fk| fk['destination'] == destination }&.dig('destination_id')
9
+ end
10
+
11
+ def get_foreign_keys(tenant:, source:, source_id:)
12
+ response = http_get(
13
+ url: "#{ENV['FKM_URL']}/Prod/lookup?tenant=#{tenant}&source=#{source}&source_id=#{source_id}"
14
+ )
15
+ validate_http_response(response: response, message: 'Error getting foreign keys')
16
+ parse_http_response(response).body
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,32 @@
1
+ module WolfCore
2
+ module HttpOperations
3
+ include WolfCore::ExceptionOperations
4
+
5
+ def http_get(url:, headers: {}, query: nil)
6
+ WolfCore::HttpDataSource.http_get(url: url, headers: headers, query: query)
7
+ end
8
+
9
+ def http_post(url:, headers: {}, body: nil, query: nil)
10
+ WolfCore::HttpDataSource.http_post(url: url, headers: headers, query: query, body: body)
11
+ end
12
+
13
+ def validate_http_response(response:, message:, error_data: nil)
14
+ unless response.code == 200
15
+ error_data = {
16
+ message: message,
17
+ response: parse_http_response(response)
18
+ }.merge(error_data || {})
19
+ raise_service_error(error_data)
20
+ end
21
+ end
22
+
23
+ def parse_http_response(response)
24
+ body = JSON.parse(response.body) rescue response.body
25
+ OpenStruct.new({
26
+ code: response.code,
27
+ body: body,
28
+ message: response.message,
29
+ })
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,36 @@
1
+ module WolfCore
2
+ module FileUtils
3
+ module_function
4
+
5
+ def require_relative_folder(*folders)
6
+ folder_files = File.join(*folders, '**', '*.rb')
7
+ files_to_require = Dir[folder_files].sort
8
+ safe_require(files_to_require)
9
+ end
10
+
11
+ def safe_require(missing_files)
12
+ while missing_files.any?
13
+ files_to_require = missing_files
14
+ missing_files = []
15
+ files_to_require.each do |file|
16
+ begin
17
+ require_relative file
18
+ rescue NameError
19
+ missing_files << file
20
+ end
21
+ end
22
+ end
23
+ end
24
+
25
+ def delete_files(*args)
26
+ pattern = File.join(*args)
27
+ files_to_delete = Dir.glob(pattern)
28
+ files_to_delete.each do |file|
29
+ File.delete(file)
30
+ puts "File deleted: #{file}"
31
+ end
32
+
33
+ puts "File Deleting Process Finished! (#{files_to_delete.size} files deleted)"
34
+ end
35
+ end
36
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module WolfCore
4
- VERSION = "0.1.4"
4
+ VERSION = "0.1.5"
5
5
  end
data/lib/wolf_core.rb CHANGED
@@ -7,6 +7,6 @@ require 'active_support/core_ext'
7
7
 
8
8
  module WolfCore; end
9
9
 
10
- require 'wolf_core/utils/require_utils'
10
+ require 'wolf_core/utils/file_utils'
11
11
 
12
- WolfCore::RequireUtils.require_relative_folder(__dir__, 'wolf_core')
12
+ WolfCore::FileUtils.require_relative_folder(__dir__, 'wolf_core')
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: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Javier Roncallo
@@ -47,10 +47,13 @@ extra_rdoc_files: []
47
47
  files:
48
48
  - lib/wolf_core.rb
49
49
  - lib/wolf_core/application/application_service.rb
50
+ - lib/wolf_core/application/exception_operations.rb
51
+ - lib/wolf_core/application/fkm_operations.rb
52
+ - lib/wolf_core/application/http_operations.rb
50
53
  - lib/wolf_core/application/salesforce_oauth_service.rb
51
54
  - lib/wolf_core/application/service_exception.rb
52
55
  - lib/wolf_core/infrastructure/http_data_source.rb
53
- - lib/wolf_core/utils/require_utils.rb
56
+ - lib/wolf_core/utils/file_utils.rb
54
57
  - lib/wolf_core/utils/result.rb
55
58
  - lib/wolf_core/version.rb
56
59
  homepage: https://github.com/onewolfxyz/wolf_core
@@ -1,10 +0,0 @@
1
- module WolfCore
2
- module RequireUtils
3
- module_function
4
-
5
- def require_relative_folder(*folders)
6
- folder_files = File.join(*folders, '**', '*.rb')
7
- Dir[folder_files].sort.each { |file| require_relative file }
8
- end
9
- end
10
- end