domoscio_viz 0.1.1.4 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/domoscio_viz.rb +47 -28
- data/lib/domoscio_viz/authorization_token.rb +0 -1
- data/lib/domoscio_viz/errors.rb +14 -12
- data/lib/domoscio_viz/generators/install_generator.rb +1 -3
- data/lib/domoscio_viz/generators/templates/install.rb +0 -2
- data/lib/domoscio_viz/http_calls.rb +1 -6
- data/lib/domoscio_viz/resource.rb +1 -1
- data/lib/domoscio_viz/version.rb +2 -2
- metadata +3 -4
- data/lib/tasks/domoscio_rails_tasks.rake +0 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 887c55dd8caa52f79ff7cdb18b53f7ed134b538f0d3783d5f4826bbe99efe0db
|
4
|
+
data.tar.gz: 6229db276d697d67b482d5c6bedf8bf0cd5a236ce3336f73f5187ab4d995af85
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 665710baedb373e38e2cfb5a821f95ce52d5ba80d16de6d56127a8cc90ad1b80cbd9391ae45a377f679f6316bff32623f99e5c1598c1bd4122207d6dae616c4e
|
7
|
+
data.tar.gz: e02a53ce48feffc03b70377f129339dd3e4c7ad43f0b776be02baa67d9d8741ec9fc2544ba19e762d36576f8d2bdd1f2a7eb2a433bb9d69cbfce5fb704ffae79
|
data/lib/domoscio_viz.rb
CHANGED
@@ -2,16 +2,13 @@
|
|
2
2
|
require 'net/https'
|
3
3
|
require 'cgi/util'
|
4
4
|
require 'multi_json'
|
5
|
-
|
6
5
|
# helpers
|
7
6
|
require 'domoscio_viz/version'
|
8
7
|
require 'domoscio_viz/json'
|
9
8
|
require 'domoscio_viz/errors'
|
10
9
|
require 'domoscio_viz/authorization_token'
|
11
|
-
|
12
10
|
# generators
|
13
11
|
require 'domoscio_viz/generators/install_generator'
|
14
|
-
|
15
12
|
# resources
|
16
13
|
require 'domoscio_viz/http_calls'
|
17
14
|
require 'domoscio_viz/resource'
|
@@ -35,9 +32,9 @@ module DomoscioViz
|
|
35
32
|
def root_url
|
36
33
|
if @preproduction == true
|
37
34
|
if @test == true
|
38
|
-
@root_url || "https://domoscio-viz-engine-preprod.azurewebsites.net"
|
35
|
+
@root_url || "https://domoscio-viz-engine-v2-preprod.azurewebsites.net"
|
39
36
|
else
|
40
|
-
@root_url || "https://
|
37
|
+
@root_url || "https://visualization-engine.domoscio.com"
|
41
38
|
end
|
42
39
|
else
|
43
40
|
@root_url || "http://localhost:3002"
|
@@ -58,40 +55,52 @@ module DomoscioViz
|
|
58
55
|
URI(configuration.root_url + url)
|
59
56
|
end
|
60
57
|
|
61
|
-
#
|
62
58
|
def self.request(method, url, params={}, filters={}, headers = request_headers, before_request_proc = nil)
|
63
59
|
return false if @disabled
|
64
60
|
uri = api_uri(url)
|
65
61
|
uri.query = URI.encode_www_form(filters) unless filters.empty?
|
66
|
-
|
67
62
|
res = DomoscioViz.send_request(uri, method, params, headers, before_request_proc)
|
68
|
-
|
69
|
-
# decode json data
|
63
|
+
return res if res.kind_of? DomoscioViz::ProcessingError
|
70
64
|
begin
|
65
|
+
raise_http_failure(uri, res, params)
|
71
66
|
data = DomoscioViz::JSON.load(res.body.nil? ? '' : res.body)
|
72
|
-
DomoscioViz::AuthorizationToken::Manager.storage.store({
|
73
|
-
rescue MultiJson::LoadError
|
74
|
-
|
67
|
+
DomoscioViz::AuthorizationToken::Manager.storage.store({access_token: res['Accesstoken'], refresh_token: res['Refreshtoken']})
|
68
|
+
rescue MultiJson::LoadError => exception
|
69
|
+
return ProcessingError.new(uri, 500, exception, res.body, params)
|
70
|
+
rescue ResponseError => exception
|
71
|
+
return exception
|
75
72
|
end
|
76
|
-
|
77
73
|
data
|
78
74
|
end
|
79
75
|
|
80
|
-
|
81
76
|
def self.send_request(uri, method, params, headers, before_request_proc)
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
77
|
+
begin
|
78
|
+
res = Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == 'https') do |http|
|
79
|
+
req = Net::HTTP::const_get(method.capitalize).new(uri.request_uri, headers)
|
80
|
+
req.body = DomoscioRails::JSON.dump(params)
|
81
|
+
before_request_proc.call(req) if before_request_proc
|
82
|
+
http.request req
|
83
|
+
end
|
84
|
+
rescue Timeout::Error, Errno::EINVAL, HTTP::ConnectionError, Errno::ECONNREFUSED, Errno::ECONNRESET, EOFError, Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError => exception
|
85
|
+
ProcessingError.new(uri, 500, exception, res, params)
|
87
86
|
end
|
88
87
|
end
|
89
88
|
|
90
89
|
private
|
91
90
|
|
91
|
+
def self.raise_http_failure(uri, res, params)
|
92
|
+
unless res.kind_of? Net::HTTPSuccess
|
93
|
+
if res.blank?
|
94
|
+
raise ResponseError.new(uri, 500, {error: {status: 500, message: 'VisualizationEngine not available'}}, {}, params)
|
95
|
+
else
|
96
|
+
body = DomoscioRails::JSON.load((res.body.nil? ? '' : res.body), :symbolize_keys => true)
|
97
|
+
raise ResponseError.new(uri, res.code.to_i, body, res.body, params)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
92
102
|
def self.user_agent
|
93
103
|
@uname ||= get_uname
|
94
|
-
|
95
104
|
{
|
96
105
|
bindings_version: DomoscioViz::VERSION,
|
97
106
|
lang: 'ruby',
|
@@ -108,12 +117,23 @@ module DomoscioViz
|
|
108
117
|
end
|
109
118
|
|
110
119
|
def self.request_headers
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
120
|
+
auth_token = DomoscioViz::AuthorizationToken::Manager.get_token
|
121
|
+
if !auth_token.is_a? String
|
122
|
+
headers = {
|
123
|
+
'user_agent' => "#{DomoscioViz.user_agent}",
|
124
|
+
'ClientId' => "#{DomoscioViz.configuration.client_id}",
|
125
|
+
'AccessToken' => "#{auth_token[:access_token]}",
|
126
|
+
'RefreshToken' => "#{auth_token[:refresh_token]}",
|
127
|
+
'Content-Type' => 'application/json'
|
128
|
+
}
|
129
|
+
else
|
130
|
+
headers = {
|
131
|
+
'user_agent' => "#{DomoscioViz.user_agent}",
|
132
|
+
'ClientId' => "#{DomoscioViz.configuration.client_id}",
|
133
|
+
'Authorization' => "Token token=#{DomoscioViz.configuration.client_passphrase}",
|
134
|
+
'Content-Type' => 'application/json'
|
135
|
+
}
|
136
|
+
end
|
117
137
|
headers
|
118
138
|
end
|
119
139
|
|
@@ -124,5 +144,4 @@ module DomoscioViz
|
|
124
144
|
c.temp_dir = File.expand_path('../tmp', __FILE__)
|
125
145
|
FileUtils.mkdir_p(c.temp_dir) unless File.directory?(c.temp_dir)
|
126
146
|
end
|
127
|
-
|
128
|
-
end
|
147
|
+
end
|
data/lib/domoscio_viz/errors.rb
CHANGED
@@ -1,24 +1,26 @@
|
|
1
1
|
module DomoscioViz
|
2
|
-
|
3
2
|
# Generic error superclass for MangoPay specific errors.
|
4
3
|
# Currently never instantiated directly.
|
5
4
|
# Currently only single subclass used.
|
6
5
|
class Error < StandardError
|
7
6
|
end
|
8
|
-
|
9
|
-
# Thrown from any MangoPay API call whenever
|
10
|
-
# it returns response with HTTP code != 200.
|
7
|
+
# ResponseError from VizEngine
|
11
8
|
class ResponseError < Error
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
def initialize(request_url, code, details)
|
16
|
-
@request_url, @code, @details = request_url, code, details
|
9
|
+
attr_reader :request_url, :code, :details, :body, :request_params
|
10
|
+
def initialize(request_url, code, details = {}, body = nil, request_params = {})
|
11
|
+
@request_url, @code, @details, @body, @request_params = request_url, code, details, body, request_params
|
17
12
|
super(message) if message
|
18
13
|
end
|
14
|
+
def message; @details.is_a?(Hash) ? @details.dig(:error, :message) : @details; end
|
15
|
+
end
|
19
16
|
|
20
|
-
|
21
|
-
|
22
|
-
|
17
|
+
# ProcessingError from Domoscio_viz
|
18
|
+
class ProcessingError < Error
|
19
|
+
attr_reader :request_url, :code, :details, :body, :request_params
|
20
|
+
def initialize(request_url, code, details = {}, body = nil, request_params = {})
|
21
|
+
@request_url, @code, @details, @body, @request_params = request_url, code, details, body, request_params
|
22
|
+
super(message) if message
|
23
|
+
end
|
24
|
+
def message; @details.message; end
|
23
25
|
end
|
24
26
|
end
|
@@ -1,12 +1,10 @@
|
|
1
1
|
require 'rails/generators'
|
2
|
-
|
3
2
|
module DomoscioViz
|
4
3
|
class InstallGenerator < ::Rails::Generators::Base
|
5
4
|
source_root File.expand_path('../templates', __FILE__)
|
6
5
|
desc "Generate config file for DomoscioViz configuration"
|
7
|
-
|
8
6
|
def install
|
9
|
-
|
7
|
+
copy_file "install.rb", "config/initializers/domoscio_viz.rb"
|
10
8
|
end
|
11
9
|
end
|
12
10
|
end
|
@@ -2,15 +2,10 @@ module DomoscioViz
|
|
2
2
|
module HTTPCalls
|
3
3
|
module GetUrl
|
4
4
|
module ClassMethods
|
5
|
-
# In order to catch current SocketsTimeoutError that seem to appear when the VizEngine stays Idle for too long
|
6
|
-
# Perform the request a second time if it fails the fisrt time
|
7
5
|
def get_url(util_name = nil, params = {})
|
8
|
-
|
9
|
-
response = DomoscioViz.request(:post, url(util_name), params) unless response && response.is_a?(Hash) && response['url'] && response['success'] == true
|
10
|
-
response
|
6
|
+
DomoscioViz.request(:post, url(util_name), params)
|
11
7
|
end
|
12
8
|
end
|
13
|
-
|
14
9
|
def self.included(base)
|
15
10
|
base.extend(ClassMethods)
|
16
11
|
end
|
data/lib/domoscio_viz/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
1
|
module DomoscioViz
|
2
|
-
VERSION = "0.
|
3
|
-
end
|
2
|
+
VERSION = "0.2.4"
|
3
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: domoscio_viz
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Benoit Praly
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-01-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -44,7 +44,6 @@ files:
|
|
44
44
|
- lib/domoscio_viz/json.rb
|
45
45
|
- lib/domoscio_viz/resource.rb
|
46
46
|
- lib/domoscio_viz/version.rb
|
47
|
-
- lib/tasks/domoscio_rails_tasks.rake
|
48
47
|
homepage: http://www.domoscio.com
|
49
48
|
licenses:
|
50
49
|
- MIT
|
@@ -64,7 +63,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
64
63
|
- !ruby/object:Gem::Version
|
65
64
|
version: '0'
|
66
65
|
requirements: []
|
67
|
-
rubygems_version: 3.
|
66
|
+
rubygems_version: 3.1.2
|
68
67
|
signing_key:
|
69
68
|
specification_version: 4
|
70
69
|
summary: Summary of DomoscioViz.
|