wolf_core 0.1.3 → 0.1.5
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/application_service.rb +5 -33
- data/lib/wolf_core/application/exception_operations.rb +7 -0
- data/lib/wolf_core/application/fkm_operations.rb +19 -0
- data/lib/wolf_core/application/http_operations.rb +32 -0
- data/lib/wolf_core/utils/file_utils.rb +36 -0
- data/lib/wolf_core/version.rb +1 -1
- data/lib/wolf_core.rb +4 -2
- metadata +19 -4
- data/lib/wolf_core/utils/hash_extension.rb +0 -26
- data/lib/wolf_core/utils/object_extension.rb +0 -9
- data/lib/wolf_core/utils/require_utils.rb +0 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a4485e1d17306d577f5bc91c91bf5b6842c0ca185daddbb929a00e0da0132143
|
4
|
+
data.tar.gz: a8a16ac488d4d4456af04581b3eae6b468df954212d0c656d8928ed01cd32c6c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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 =
|
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
|
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,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
|
data/lib/wolf_core/version.rb
CHANGED
data/lib/wolf_core.rb
CHANGED
@@ -2,9 +2,11 @@
|
|
2
2
|
|
3
3
|
require 'ostruct'
|
4
4
|
require 'httparty'
|
5
|
+
require 'active_support'
|
6
|
+
require 'active_support/core_ext'
|
5
7
|
|
6
8
|
module WolfCore; end
|
7
9
|
|
8
|
-
require 'wolf_core/utils/
|
10
|
+
require 'wolf_core/utils/file_utils'
|
9
11
|
|
10
|
-
WolfCore::
|
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
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Javier Roncallo
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: activesupport
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
27
41
|
description: Repository to store shared code among Ruby projects.
|
28
42
|
email:
|
29
43
|
- jroncallo96@gmail.com
|
@@ -33,12 +47,13 @@ extra_rdoc_files: []
|
|
33
47
|
files:
|
34
48
|
- lib/wolf_core.rb
|
35
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
|
36
53
|
- lib/wolf_core/application/salesforce_oauth_service.rb
|
37
54
|
- lib/wolf_core/application/service_exception.rb
|
38
55
|
- lib/wolf_core/infrastructure/http_data_source.rb
|
39
|
-
- lib/wolf_core/utils/
|
40
|
-
- lib/wolf_core/utils/object_extension.rb
|
41
|
-
- lib/wolf_core/utils/require_utils.rb
|
56
|
+
- lib/wolf_core/utils/file_utils.rb
|
42
57
|
- lib/wolf_core/utils/result.rb
|
43
58
|
- lib/wolf_core/version.rb
|
44
59
|
homepage: https://github.com/onewolfxyz/wolf_core
|
@@ -1,26 +0,0 @@
|
|
1
|
-
class Hash
|
2
|
-
def with_indifferent_access
|
3
|
-
hash = self.dup
|
4
|
-
hash.extend IndifferentAccess
|
5
|
-
hash
|
6
|
-
end
|
7
|
-
|
8
|
-
module IndifferentAccess
|
9
|
-
def [](key)
|
10
|
-
fetch(key.to_s) { fetch(key.to_sym) { nil } }
|
11
|
-
end
|
12
|
-
|
13
|
-
def fetch(key, *extras)
|
14
|
-
super(key.to_s, *extras)
|
15
|
-
rescue KeyError
|
16
|
-
super(key.to_sym, *extras)
|
17
|
-
end
|
18
|
-
|
19
|
-
def has_key?(key)
|
20
|
-
key?(key.to_s) || key?(key.to_sym)
|
21
|
-
end
|
22
|
-
alias_method :include?, :has_key?
|
23
|
-
alias_method :key?, :has_key?
|
24
|
-
alias_method :member?, :has_key?
|
25
|
-
end
|
26
|
-
end
|