tng-gtk-utils 0.4.0 → 0.4.1
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/tng/gtk/utils/fetch.rb +13 -12
- data/lib/tng/gtk/utils/services.rb +3 -3
- data/lib/tng/gtk/utils/version.rb +1 -1
- data/lib/tng/gtk/utils.rb +4 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 49c965e9e3a31a115b50d4e553c9b287e9289e9cc0de312882ef5fa762254ede
|
4
|
+
data.tar.gz: 290a0a066ee706e752791a5c748c6338b6f14a7889dec2398a17168c11a7c546
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1677767e5d19e1ff4990a7c98a8e8ed96c1b37dfd72eab55a3c322cccc52edc1424af9456ead6fd4e839af6f81acc9c34d14fdba7bdc3951c379296774c1a2a7
|
7
|
+
data.tar.gz: 82eb5dc8ff9b5f67f0232854f90e429f95af431ec48df5222a28263ac7f7e51cd2362191b251571ccbfe02fc48fc73845285a5203bccf702305fb20eb1d0449c
|
data/lib/tng/gtk/utils/fetch.rb
CHANGED
@@ -43,12 +43,13 @@ module Tng
|
|
43
43
|
|
44
44
|
class Fetch
|
45
45
|
|
46
|
+
LOGGER= Tng::Gtk::Utils::Logger
|
46
47
|
class << self; attr_accessor :site; end
|
47
48
|
|
48
49
|
def self.call(params)
|
49
50
|
msg=self.name+'#'+__method__.to_s
|
50
51
|
began_at=Time.now.utc
|
51
|
-
|
52
|
+
LOGGER.info(start_stop: 'START', component:self.name, operation:__method__.to_s, message:"params=#{params} site=#{self.site}")
|
52
53
|
original_params = params.dup
|
53
54
|
begin
|
54
55
|
if params.key?(:uuid)
|
@@ -65,29 +66,29 @@ module Tng
|
|
65
66
|
uri = URI.parse(self.site)
|
66
67
|
uri.query = URI.encode_www_form(sanitize(params))
|
67
68
|
end
|
68
|
-
|
69
|
+
LOGGER.debug(component:self.name, operation:__method__.to_s, message:"uri=#{uri}")
|
69
70
|
request = Net::HTTP::Get.new(uri)
|
70
71
|
request['content-type'] = 'application/json'
|
71
72
|
response = Net::HTTP.start(uri.hostname, uri.port) {|http| http.request(request)}
|
72
|
-
|
73
|
+
LOGGER.debug(component:self.name, operation:__method__.to_s, message:"response=#{response.inspect}")
|
73
74
|
case response
|
74
75
|
when Net::HTTPSuccess
|
75
76
|
body = response.read_body
|
76
|
-
|
77
|
+
LOGGER.debug(component:self.name, operation:__method__.to_s, message:"body=#{body}", status: '200')
|
77
78
|
result = JSON.parse(body, quirks_mode: true, symbolize_names: true)
|
78
79
|
cache_result(result)
|
79
|
-
|
80
|
+
LOGGER.info(start_stop: 'STOP', component:self.name, operation:__method__.to_s, message:"result=#{result} site=#{self.site}", time_elapsed: Time.now.utc - began_at)
|
80
81
|
return result
|
81
82
|
when Net::HTTPNotFound
|
82
|
-
|
83
|
+
LOGGER.info(start_stop: 'STOP', component:self.name, operation:__method__.to_s, message:"body=#{body}", status:'404', time_elapsed: Time.now.utc - began_at)
|
83
84
|
return {} unless uuid.nil?
|
84
85
|
return []
|
85
86
|
else
|
86
|
-
|
87
|
+
LOGGER.error(start_stop: 'STOP', component:self.name, operation:__method__.to_s, message:"#{response.message}", status:'404', time_elapsed: Time.now.utc - began_at)
|
87
88
|
return nil
|
88
89
|
end
|
89
90
|
rescue Exception => e
|
90
|
-
|
91
|
+
LOGGER.error(start_stop: 'STOP', component:self.name, operation:__method__.to_s, message:"#{e.message}", time_elapsed: Time.now.utc - began_at)
|
91
92
|
end
|
92
93
|
nil
|
93
94
|
end
|
@@ -100,15 +101,15 @@ module Tng
|
|
100
101
|
end
|
101
102
|
|
102
103
|
def self.cache_result(result)
|
103
|
-
|
104
|
+
LOGGER.debug(component:self.name, operation:__method__.to_s, message:"result=#{result}")
|
104
105
|
if result.is_a?(Hash)
|
105
|
-
|
106
|
+
LOGGER.info(component:self.name, operation:__method__.to_s, message:"Caching #{result}")
|
106
107
|
Tng::Gtk::Utils::Cache.cache(result)
|
107
108
|
return
|
108
109
|
end
|
109
|
-
|
110
|
+
LOGGER.info(component:self.name, operation:__method__.to_s, message:"#{result} is not an Hash")
|
110
111
|
result.each do |record|
|
111
|
-
|
112
|
+
LOGGER.info(component:self.name, operation:__method__.to_s, message:"Caching #{record}")
|
112
113
|
Tng::Gtk::Utils::Cache.cache(record)
|
113
114
|
end
|
114
115
|
end
|
@@ -80,17 +80,17 @@ class ServicesController < Tng::Gtk::Utils::ApplicationController
|
|
80
80
|
halt 200, {}, result.to_json
|
81
81
|
end
|
82
82
|
|
83
|
-
get '/:
|
83
|
+
get '/:uuid/?' do
|
84
84
|
msg='#get (single)'
|
85
85
|
began_at = Time.now.utc
|
86
86
|
LOGGER.info(component:LOGGED_COMPONENT, operation:msg, start_stop: 'START', message:"Started at #{began_at}")
|
87
87
|
captures=params.delete('captures') if params.key? 'captures'
|
88
|
-
LOGGER.debug(component:LOGGED_COMPONENT, operation:msg, message:"params['
|
88
|
+
LOGGER.debug(component:LOGGED_COMPONENT, operation:msg, message:"params['uuid']='#{params['uuid']}'")
|
89
89
|
result = FetchNSDService.call(symbolized_hash(params))
|
90
90
|
LOGGER.debug(component:LOGGED_COMPONENT, operation:msg, message:"result=#{result}")
|
91
91
|
if result.to_s.empty? # covers nil
|
92
92
|
LOGGER.info(component:LOGGED_COMPONENT, operation:msg, start_stop: 'STOP', message:"Ended at #{Time.now.utc}", status: '404', time_elapsed:"#{Time.now.utc-began_at}")
|
93
|
-
halt 404, {}, {error: ERROR_SERVICE_NOT_FOUND % params[:
|
93
|
+
halt 404, {}, {error: ERROR_SERVICE_NOT_FOUND % params[:uuid]}.to_json
|
94
94
|
end
|
95
95
|
LOGGER.info(component:LOGGED_COMPONENT, operation:msg, start_stop: 'STOP', message:"Ended at #{Time.now.utc}", status: '200', time_elapsed:"#{Time.now.utc-began_at}")
|
96
96
|
halt 200, {}, result.to_json
|
data/lib/tng/gtk/utils.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tng-gtk-utils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- José Bonnet
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-11-
|
11
|
+
date: 2018-11-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|