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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 99e606a92c3081912e1ac1595a7b1a554e43996afb971a8ed1266ef02500e271
4
- data.tar.gz: 73182e07bf66045124103c73f7461ed1c02c2b3246a85aaa6d376b4020b5d01a
3
+ metadata.gz: 49c965e9e3a31a115b50d4e553c9b287e9289e9cc0de312882ef5fa762254ede
4
+ data.tar.gz: 290a0a066ee706e752791a5c748c6338b6f14a7889dec2398a17168c11a7c546
5
5
  SHA512:
6
- metadata.gz: 1f18e089baed8541b880ca87393f911fe5c4bdd673438f6706dd5f70ee856f206f0f7a7d4e9630f7910f41e93765917afe6ae5064b26888d969c250bf6cfd1bf
7
- data.tar.gz: e1825f73b98f88e6b811ff405bfb13302c4d7a5f818ad595464f836835574f9d412c9107e70051c82f7dc801ba017b50655ddf5260d66ea7e160bc48b402de75
6
+ metadata.gz: 1677767e5d19e1ff4990a7c98a8e8ed96c1b37dfd72eab55a3c322cccc52edc1424af9456ead6fd4e839af6f81acc9c34d14fdba7bdc3951c379296774c1a2a7
7
+ data.tar.gz: 82eb5dc8ff9b5f67f0232854f90e429f95af431ec48df5222a28263ac7f7e51cd2362191b251571ccbfe02fc48fc73845285a5203bccf702305fb20eb1d0449c
@@ -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
- Tng::Gtk::Utils::Logger.info(start_stop: 'START', component:self.name, operation:__method__.to_s, message:"params=#{params} site=#{self.site}")
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
- Tng::Gtk::Utils::Logger.debug(component:self.name, operation:__method__.to_s, message:"uri=#{uri}")
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
- Tng::Gtk::Utils::Logger.debug(component:self.name, operation:__method__.to_s, message:"response=#{response.inspect}")
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
- Tng::Gtk::Utils::Logger.debug(component:self.name, operation:__method__.to_s, message:"body=#{body}", status: '200')
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
- Tng::Gtk::Utils::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
+ 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
- Tng::Gtk::Utils::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
+ 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
- Tng::Gtk::Utils::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
+ 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
- Tng::Gtk::Utils::Logger.error(start_stop: 'STOP', component:self.name, operation:__method__.to_s, message:"#{e.message}", time_elapsed: Time.now.utc - began_at)
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
- Tng::Gtk::Utils::Logger.debug(component:self.name, operation:__method__.to_s, message:"result=#{result}")
104
+ LOGGER.debug(component:self.name, operation:__method__.to_s, message:"result=#{result}")
104
105
  if result.is_a?(Hash)
105
- STDERR.puts "Caching #{result}"
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
- STDERR.puts "#{result} is not an Hash"
110
+ LOGGER.info(component:self.name, operation:__method__.to_s, message:"#{result} is not an Hash")
110
111
  result.each do |record|
111
- STDERR.puts "Caching #{record}"
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 '/:service_uuid/?' do
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['service_uuid']='#{params['service_uuid']}'")
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[:service_uuid]}.to_json
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
@@ -1,7 +1,7 @@
1
1
  module Tng
2
2
  module Gtk
3
3
  module Utils
4
- VERSION = "0.4.0"
4
+ VERSION = "0.4.1"
5
5
  end
6
6
  end
7
7
  end
data/lib/tng/gtk/utils.rb CHANGED
@@ -3,7 +3,10 @@ require "tng/gtk/utils/version"
3
3
  module Tng
4
4
  module Gtk
5
5
  module Utils
6
- # Your code goes here...
6
+ def uuid_valid?(uuid)
7
+ return true if (uuid =~ /[a-f0-9]{8}-([a-f0-9]{4}-){3}[a-f0-9]{12}/) == 0
8
+ false
9
+ end
7
10
  end
8
11
  end
9
12
  end
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.0
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-16 00:00:00.000000000 Z
11
+ date: 2018-11-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler