domoscio_viz 0.1.1.3 → 0.2.3

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: d47506288c283595f9537fd540bf754239d0c95366e582dfe04f17c17a9fba42
4
- data.tar.gz: 16c73ed3d9f6ae52dc0cc920920aa196e42104a6d339eb7a5e8127428b1b06e5
3
+ metadata.gz: 050c44f613da493c3ca25fd68c8ba142362bf42f461cb20e39934a88688bc53f
4
+ data.tar.gz: 83f2f4df4edcb932d70fd9a52b993369a3e758c2ec4f9d1d43c0da9ee458bcbd
5
5
  SHA512:
6
- metadata.gz: c3854e49ac043dcc41571d90e84a6b9dd9fe9cee853fae9a3b5aab8cf3f9c3a2d57baf338cdf0ae82adf5f944e2b97bb8041373221486ff8b01adde069e6098a
7
- data.tar.gz: 5e38902b0677b7d5ee5224fb32ededaebd6243cafb9cf2d710932ceb1fee8fc1e7b8e5e3ed84a228ef5b67200f00b04064e987afbe76bd52aa52befaaeacfcbd
6
+ metadata.gz: 7ad6e1ebc52711ef09bcaf1fbe20da7ae480750829b967702094963f63db1c7679206db7333533d02157235c5056bd8876a5cff76618bac08e584209893d5912
7
+ data.tar.gz: e9d0ad596fe0f9c4f8e5411d7a41e962ece08f5c19a7c6ee9b568f24008b76a4d1484914a745aa6d39fad62c4d3e270367c5b62a5da15d64e1f3d042f7c48d14
@@ -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'
@@ -63,27 +60,33 @@ module DomoscioViz
63
60
  return false if @disabled
64
61
  uri = api_uri(url)
65
62
  uri.query = URI.encode_www_form(filters) unless filters.empty?
66
-
67
63
  res = DomoscioViz.send_request(uri, method, params, headers, before_request_proc)
68
-
69
- # decode json data
70
- begin
64
+ return res if res.kind_of? DomoscioViz::ProcessingError
65
+ # decode json data
66
+ begin
71
67
  data = DomoscioViz::JSON.load(res.body.nil? ? '' : res.body)
72
- DomoscioViz::AuthorizationToken::Manager.storage.store({client_id: res['ClientID'], client_passphrase: res['ClientPassphrase']})
73
- rescue MultiJson::LoadError
74
- data = {}
68
+ raise ResponseError.new(uri, res.code.to_i, data, res.body, params) unless res.kind_of? Net::HTTPSuccess
69
+ unless (res.kind_of? Net::HTTPClientError) || (res.kind_of? Net::HTTPServerError)
70
+ DomoscioViz::AuthorizationToken::Manager.storage.store({access_token: res['Accesstoken'], refresh_token: res['Refreshtoken']})
71
+ end
72
+ rescue MultiJson::LoadError => exception
73
+ return ProcessingError.new(uri, 500, exception, res.body, params)
74
+ rescue ResponseError => exception
75
+ return exception
75
76
  end
76
-
77
77
  data
78
78
  end
79
79
 
80
-
81
80
  def self.send_request(uri, method, params, headers, before_request_proc)
82
- res = Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == 'https') do |http| # , use_ssl: uri.scheme == 'https') do |http|
83
- req = Net::HTTP::const_get(method.capitalize).new(uri.request_uri, headers)
84
- req.body = DomoscioViz::JSON.dump(params)
85
- before_request_proc.call(req) if before_request_proc
86
- http.request req
81
+ begin
82
+ res = Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == 'https') do |http|
83
+ req = Net::HTTP::const_get(method.capitalize).new(uri.request_uri, headers)
84
+ req.body = DomoscioRails::JSON.dump(params)
85
+ before_request_proc.call(req) if before_request_proc
86
+ http.request req
87
+ end
88
+ rescue Timeout::Error, Errno::EINVAL, HTTP::ConnectionError, Errno::ECONNREFUSED, Errno::ECONNRESET, EOFError, Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError => exception
89
+ ProcessingError.new(uri, 500, exception, res.body, params)
87
90
  end
88
91
  end
89
92
 
@@ -91,7 +94,6 @@ module DomoscioViz
91
94
 
92
95
  def self.user_agent
93
96
  @uname ||= get_uname
94
-
95
97
  {
96
98
  bindings_version: DomoscioViz::VERSION,
97
99
  lang: 'ruby',
@@ -108,12 +110,23 @@ module DomoscioViz
108
110
  end
109
111
 
110
112
  def self.request_headers
111
- headers = {
112
- 'user_agent' => "DomoscioViz RubyBindings/#{DomoscioViz::VERSION}",
113
- 'ClientID' => "#{DomoscioViz.configuration.client_id}",
114
- 'ClientPassphrase' => "#{DomoscioViz.configuration.client_passphrase}",
115
- 'Content-Type' => 'application/json'
116
- }
113
+ auth_token = DomoscioViz::AuthorizationToken::Manager.get_token
114
+ if !auth_token.is_a? String
115
+ headers = {
116
+ 'user_agent' => "#{DomoscioViz.user_agent}",
117
+ 'ClientId' => "#{DomoscioViz.configuration.client_id}",
118
+ 'AccessToken' => "#{auth_token[:access_token]}",
119
+ 'RefreshToken' => "#{auth_token[:refresh_token]}",
120
+ 'Content-Type' => 'application/json'
121
+ }
122
+ else
123
+ headers = {
124
+ 'user_agent' => "#{DomoscioViz.user_agent}",
125
+ 'ClientId' => "#{DomoscioViz.configuration.client_id}",
126
+ 'Authorization' => "Token token=#{DomoscioViz.configuration.client_passphrase}",
127
+ 'Content-Type' => 'application/json'
128
+ }
129
+ end
117
130
  headers
118
131
  end
119
132
 
@@ -124,5 +137,4 @@ module DomoscioViz
124
137
  c.temp_dir = File.expand_path('../tmp', __FILE__)
125
138
  FileUtils.mkdir_p(c.temp_dir) unless File.directory?(c.temp_dir)
126
139
  end
127
-
128
- end
140
+ end
@@ -1,6 +1,5 @@
1
1
  module DomoscioViz
2
2
  module AuthorizationToken
3
-
4
3
  class Manager
5
4
 
6
5
  class << self
@@ -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
+ # ErrorMessage from VizEngine
11
8
  class ResponseError < Error
12
-
13
- attr_reader :request_url, :code, :details
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, 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.dig(:error, :message) || @details; end
15
+ end
19
16
 
20
- def message; @details['Message']; end
21
- def type; @details['Type']; end
22
- def errors; @details['errors']; end
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, 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,10 +1,8 @@
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
@@ -6,8 +6,6 @@ DomoscioViz.configure do |c|
6
6
  end
7
7
  c.client_id = ENV['DOMOSCIO_ID']
8
8
  c.client_passphrase = ENV['DOMOSCIO_PASSWORD']
9
-
10
9
  c.temp_dir = File.expand_path('../tmp', __FILE__)
11
-
12
10
  FileUtils.mkdir_p(c.temp_dir) unless File.directory?(c.temp_dir)
13
11
  end
@@ -1,10 +1,13 @@
1
1
  module DomoscioViz
2
2
  module HTTPCalls
3
-
4
3
  module GetUrl
5
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
6
7
  def get_url(util_name = nil, params = {})
7
- DomoscioViz.request(:post, url(util_name), params)
8
+ response = DomoscioViz.request(:post, url(util_name), params)
9
+ response = DomoscioViz.request(:post, url(util_name), params) unless response && response.is_a?(Hash) && response['url'] && response['success'] == true
10
+ response
8
11
  end
9
12
  end
10
13
 
@@ -12,6 +15,5 @@ module DomoscioViz
12
15
  base.extend(ClassMethods)
13
16
  end
14
17
  end
15
-
16
18
  end
17
19
  end
@@ -21,4 +21,4 @@ module DomoscioViz
21
21
  end
22
22
  end
23
23
  end
24
- end
24
+ end
@@ -1,3 +1,3 @@
1
1
  module DomoscioViz
2
- VERSION = "0.1.1.3"
3
- end
2
+ VERSION = "0.2.3"
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.1.1.3
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Benoit Praly
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-08-07 00:00:00.000000000 Z
11
+ date: 2020-12-03 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,8 +63,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
64
63
  - !ruby/object:Gem::Version
65
64
  version: '0'
66
65
  requirements: []
67
- rubyforge_project:
68
- rubygems_version: 2.7.6
66
+ rubygems_version: 3.0.3
69
67
  signing_key:
70
68
  specification_version: 4
71
69
  summary: Summary of DomoscioViz.
@@ -1,4 +0,0 @@
1
- # desc "Explaining what the task does"
2
- # task :domoscio_viz do
3
- # # Task goes here
4
- # end