trophonius 1.2.7 → 1.2.7.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/trophonius_single.rb +184 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7b4fa3606dce996196ab6530704a27b93fbbf3e2134add785319b7b7921696cb
|
4
|
+
data.tar.gz: 16042983fe5510c9a29986aab3b77018033063980f1191d5fbf4234aa6bd229c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 36fa65b8130dfe29303627c0727fb8504e832ac50e7b5d74f574f810efeaf9842a55898f68595ba7e2931afefabc4db0f98ec12e0d7aa8d790cde86672b1a614
|
7
|
+
data.tar.gz: ebdd54e6f7486fedb7cb03cdf87cf6d1df28ce7c06ab6bc3afaa8320bb9a6f94244cb68a59a158bf4059a578795c1cc932092b7e6c40f5dabc1ca7d71bbffbea
|
@@ -0,0 +1,184 @@
|
|
1
|
+
require 'trophonius_date'
|
2
|
+
require 'trophonius_time'
|
3
|
+
require 'trophonius_error'
|
4
|
+
require 'trophonius_record'
|
5
|
+
require 'trophonius_recordset'
|
6
|
+
|
7
|
+
module Trophonius
|
8
|
+
class Trophonius::Single
|
9
|
+
attr_reader :query
|
10
|
+
def initialize(config:)
|
11
|
+
@config = config
|
12
|
+
@query = {}
|
13
|
+
@translations = {}
|
14
|
+
@all_fields = {}
|
15
|
+
end
|
16
|
+
|
17
|
+
def where(fieldData)
|
18
|
+
url =
|
19
|
+
URI(
|
20
|
+
URI.escape(
|
21
|
+
"http#{@config[:ssl] == true ? 's' : ''}://#{@config[:host]}/fmi/data/v1/databases/#{@config[:database]}/layouts/#{
|
22
|
+
@config[:layout_name]
|
23
|
+
}/_find"
|
24
|
+
)
|
25
|
+
)
|
26
|
+
@query.merge!(query: [fieldData])
|
27
|
+
@query.merge!(limit: '10000000')
|
28
|
+
token = setup_connection
|
29
|
+
response = make_request(url, token, 'post', @query.to_json)
|
30
|
+
|
31
|
+
r_results = response['response']['data']
|
32
|
+
if response['messages'][0]['code'] != '0' && response['messages'][0]['code'] != '401'
|
33
|
+
Error.throw_error(response['messages'][0]['code'])
|
34
|
+
elsif response['messages'][0]['code'] == '401'
|
35
|
+
return RecordSet.new(@config[:layout_name], @config[:non_modifiable_fields])
|
36
|
+
else
|
37
|
+
ret_val = RecordSet.new(@config[:layout_name], @config[:non_modifiable_fields])
|
38
|
+
r_results.each do |r|
|
39
|
+
hash = build_result(r)
|
40
|
+
ret_val << hash
|
41
|
+
end
|
42
|
+
end
|
43
|
+
@query = {}
|
44
|
+
close_connection(token)
|
45
|
+
|
46
|
+
return ret_val
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
def build_result(result)
|
52
|
+
hash = Trophonius::Record.new
|
53
|
+
hash.record_id = result['recordId']
|
54
|
+
hash.layout_name = @config[:layout_name]
|
55
|
+
hash.model_name = 'Single'
|
56
|
+
|
57
|
+
result['fieldData'].keys.each do |key|
|
58
|
+
# unless key[/\s/] || key[/\W/]
|
59
|
+
@translations.merge!(
|
60
|
+
{ "#{ActiveSupport::Inflector.parameterize(ActiveSupport::Inflector.underscore(key.to_s), separator: '_').downcase}" => "#{key}" }
|
61
|
+
)
|
62
|
+
hash.send(:define_singleton_method, ActiveSupport::Inflector.parameterize(ActiveSupport::Inflector.underscore(key.to_s), separator: '_')) do
|
63
|
+
hash[key]
|
64
|
+
end
|
65
|
+
unless @config[:non_modifiable_fields]&.include?(key)
|
66
|
+
@all_fields.merge!(
|
67
|
+
ActiveSupport::Inflector.parameterize(ActiveSupport::Inflector.underscore(key.to_s), separator: '_').downcase =>
|
68
|
+
ActiveSupport::Inflector.parameterize(ActiveSupport::Inflector.underscore(key.to_s), separator: '_')
|
69
|
+
)
|
70
|
+
hash.send(
|
71
|
+
:define_singleton_method,
|
72
|
+
"#{ActiveSupport::Inflector.parameterize(ActiveSupport::Inflector.underscore(key.to_s), separator: '_')}="
|
73
|
+
) do |new_val|
|
74
|
+
hash[key] = new_val
|
75
|
+
hash.modifiable_fields[key] = new_val
|
76
|
+
hash.modified_fields[key] = new_val
|
77
|
+
end
|
78
|
+
end
|
79
|
+
# end
|
80
|
+
hash.merge!({ key => result['fieldData'][key] })
|
81
|
+
hash.modifiable_fields.merge!({ key => result['fieldData'][key] }) unless @config[:non_modifiable_fields]&.include?(key)
|
82
|
+
end
|
83
|
+
result['portalData'].keys.each do |key|
|
84
|
+
unless key[/\s/] || key[/\W/]
|
85
|
+
hash.send(:define_singleton_method, ActiveSupport::Inflector.parameterize(ActiveSupport::Inflector.underscore(key.to_s), separator: '_')) do
|
86
|
+
hash[key]
|
87
|
+
end
|
88
|
+
end
|
89
|
+
result['portalData'][key].each_with_index do |inner_hash|
|
90
|
+
inner_hash.keys.each do |inner_key|
|
91
|
+
inner_method =
|
92
|
+
ActiveSupport::Inflector.parameterize(ActiveSupport::Inflector.underscore(inner_key.gsub(/\w+::/, '').to_s), separator: '_')
|
93
|
+
unless inner_method[/\s/] || inner_method[/\W/]
|
94
|
+
inner_hash.send(:define_singleton_method, inner_method.to_s) { inner_hash[inner_key] }
|
95
|
+
inner_hash.send(:define_singleton_method, 'record_id') { inner_hash['recordId'] }
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
hash.merge!({ key => result['portalData'][key] })
|
100
|
+
end
|
101
|
+
return hash
|
102
|
+
end
|
103
|
+
|
104
|
+
def make_request(url_param, token, method, body, params = '')
|
105
|
+
ssl_verifyhost = @config[:local_network] ? 0 : 2
|
106
|
+
ssl_verifypeer = !@config[:local_network]
|
107
|
+
request =
|
108
|
+
Typhoeus::Request.new(
|
109
|
+
url_param,
|
110
|
+
method: method.to_sym,
|
111
|
+
body: body,
|
112
|
+
params: params,
|
113
|
+
ssl_verifyhost: ssl_verifyhost,
|
114
|
+
ssl_verifypeer: ssl_verifypeer,
|
115
|
+
headers: { 'Content-Type' => 'application/json', Authorization: "Bearer #{token}" }
|
116
|
+
)
|
117
|
+
temp = request.run
|
118
|
+
begin
|
119
|
+
JSON.parse(temp.response_body)
|
120
|
+
rescue Exception => e
|
121
|
+
Error.throw_error('1631')
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
def setup_connection
|
126
|
+
ssl_verifyhost = @config[:local_network] ? 0 : 2
|
127
|
+
ssl_verifypeer = !@config[:local_network]
|
128
|
+
url = URI(URI.escape("http#{@config[:ssl] == true ? 's' : ''}://#{@config[:host]}/fmi/data/v1/databases/#{@config[:database]}/sessions"))
|
129
|
+
request =
|
130
|
+
Typhoeus::Request.new(
|
131
|
+
url,
|
132
|
+
method: :post,
|
133
|
+
body:
|
134
|
+
if @config[:external_name].nil? || @config[:external_name].empty?
|
135
|
+
{}
|
136
|
+
else
|
137
|
+
{
|
138
|
+
fmDataSource: [{ database: @config[:external_name], username: @config[:external_username], password: @config[:external_password] }]
|
139
|
+
}.to_json
|
140
|
+
end,
|
141
|
+
params: {},
|
142
|
+
ssl_verifyhost: ssl_verifyhost,
|
143
|
+
ssl_verifypeer: ssl_verifypeer,
|
144
|
+
headers: {
|
145
|
+
'Content-Type' => 'application/json', Authorization: "Basic #{Base64.strict_encode64("#{@config[:username]}:#{@config[:password]}")}"
|
146
|
+
}
|
147
|
+
)
|
148
|
+
temp = request.run
|
149
|
+
begin
|
150
|
+
parsed = JSON.parse(temp.response_body)
|
151
|
+
rescue Exception => e
|
152
|
+
Error.throw_error('1631')
|
153
|
+
end
|
154
|
+
Error.throw_error(parsed['messages'][0]['code']) if parsed['messages'][0]['code'] != '0'
|
155
|
+
return parsed['response']['token']
|
156
|
+
end
|
157
|
+
|
158
|
+
def close_connection(token)
|
159
|
+
url =
|
160
|
+
URI(URI.escape("http#{@config[:ssl] == true ? 's' : ''}://#{@config[:host]}/fmi/data/v1/databases/#{@config[:database]}/sessions/#{token}"))
|
161
|
+
ssl_verifyhost = @config[:local_network] ? 0 : 2
|
162
|
+
ssl_verifypeer = !@config[:local_network]
|
163
|
+
|
164
|
+
request =
|
165
|
+
Typhoeus::Request.new(
|
166
|
+
url,
|
167
|
+
method: :delete,
|
168
|
+
params: {},
|
169
|
+
ssl_verifyhost: ssl_verifyhost,
|
170
|
+
ssl_verifypeer: ssl_verifypeer,
|
171
|
+
headers: { 'Content-Type' => 'application/json' }
|
172
|
+
)
|
173
|
+
temp = request.run
|
174
|
+
|
175
|
+
begin
|
176
|
+
parsed = JSON.parse(temp.response_body)
|
177
|
+
rescue Exception => e
|
178
|
+
Error.throw_error('1631')
|
179
|
+
end
|
180
|
+
Error.throw_error(parsed['messages'][0]['code']) if parsed['messages'][0]['code'] != '0'
|
181
|
+
return true
|
182
|
+
end
|
183
|
+
end
|
184
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: trophonius
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.7
|
4
|
+
version: 1.2.7.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kempen Automatisering
|
@@ -71,6 +71,7 @@ files:
|
|
71
71
|
- lib/trophonius_recordset.rb
|
72
72
|
- lib/trophonius_redis_manager.rb
|
73
73
|
- lib/trophonius_request.rb
|
74
|
+
- lib/trophonius_single.rb
|
74
75
|
- lib/trophonius_time.rb
|
75
76
|
homepage: https://github.com/Willem-Jan/Trophonius
|
76
77
|
licenses:
|