domoscio_viz 0.1.1.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: d47506288c283595f9537fd540bf754239d0c95366e582dfe04f17c17a9fba42
4
+ data.tar.gz: 16c73ed3d9f6ae52dc0cc920920aa196e42104a6d339eb7a5e8127428b1b06e5
5
+ SHA512:
6
+ metadata.gz: c3854e49ac043dcc41571d90e84a6b9dd9fe9cee853fae9a3b5aab8cf3f9c3a2d57baf338cdf0ae82adf5f944e2b97bb8041373221486ff8b01adde069e6098a
7
+ data.tar.gz: 5e38902b0677b7d5ee5224fb32ededaebd6243cafb9cf2d710932ceb1fee8fc1e7b8e5e3ed84a228ef5b67200f00b04064e987afbe76bd52aa52befaaeacfcbd
@@ -0,0 +1,20 @@
1
+ Copyright 2014 YOURNAME
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,32 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'DomoscioViz'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+
18
+
19
+
20
+ Bundler::GemHelper.install_tasks
21
+
22
+ require 'rake/testtask'
23
+
24
+ Rake::TestTask.new(:test) do |t|
25
+ t.libs << 'lib'
26
+ t.libs << 'test'
27
+ t.pattern = 'test/**/*_test.rb'
28
+ t.verbose = false
29
+ end
30
+
31
+
32
+ task default: :test
@@ -0,0 +1,128 @@
1
+
2
+ require 'net/https'
3
+ require 'cgi/util'
4
+ require 'multi_json'
5
+
6
+ # helpers
7
+ require 'domoscio_viz/version'
8
+ require 'domoscio_viz/json'
9
+ require 'domoscio_viz/errors'
10
+ require 'domoscio_viz/authorization_token'
11
+
12
+ # generators
13
+ require 'domoscio_viz/generators/install_generator'
14
+
15
+ # resources
16
+ require 'domoscio_viz/http_calls'
17
+ require 'domoscio_viz/resource'
18
+ require 'domoscio_viz/chart/chart'
19
+
20
+ module DomoscioViz
21
+
22
+ class Configuration
23
+ attr_accessor :preproduction, :test, :root_url,
24
+ :client_id, :client_passphrase,
25
+ :temp_dir
26
+
27
+ def preproduction
28
+ @preproduction || false
29
+ end
30
+
31
+ def test
32
+ @test || false
33
+ end
34
+
35
+ def root_url
36
+ if @preproduction == true
37
+ if @test == true
38
+ @root_url || "https://domoscio-viz-engine-preprod.azurewebsites.net"
39
+ else
40
+ @root_url || "https://domoscio-viz-engine-v2.azurewebsites.net"
41
+ end
42
+ else
43
+ @root_url || "http://localhost:3002"
44
+ end
45
+ end
46
+ end
47
+
48
+ class << self
49
+ attr_accessor :configuration
50
+ end
51
+
52
+ def self.configure
53
+ self.configuration ||= Configuration.new
54
+ yield configuration
55
+ end
56
+
57
+ def self.api_uri(url='')
58
+ URI(configuration.root_url + url)
59
+ end
60
+
61
+ #
62
+ def self.request(method, url, params={}, filters={}, headers = request_headers, before_request_proc = nil)
63
+ return false if @disabled
64
+ uri = api_uri(url)
65
+ uri.query = URI.encode_www_form(filters) unless filters.empty?
66
+
67
+ res = DomoscioViz.send_request(uri, method, params, headers, before_request_proc)
68
+
69
+ # decode json data
70
+ begin
71
+ 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 = {}
75
+ end
76
+
77
+ data
78
+ end
79
+
80
+
81
+ 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
87
+ end
88
+ end
89
+
90
+ private
91
+
92
+ def self.user_agent
93
+ @uname ||= get_uname
94
+
95
+ {
96
+ bindings_version: DomoscioViz::VERSION,
97
+ lang: 'ruby',
98
+ lang_version: "#{RUBY_VERSION} p#{RUBY_PATCHLEVEL} (#{RUBY_RELEASE_DATE})",
99
+ platform: RUBY_PLATFORM,
100
+ uname: @uname
101
+ }
102
+ end
103
+
104
+ def self.get_uname
105
+ `uname -a 2>/dev/null`.strip if RUBY_PLATFORM =~ /linux|darwin/i
106
+ rescue Errno::ENOMEM
107
+ 'uname lookup failed'
108
+ end
109
+
110
+ 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
+ }
117
+ headers
118
+ end
119
+
120
+ DomoscioViz.configure do |c|
121
+ c.preproduction = false
122
+ c.client_id = nil
123
+ c.client_passphrase = nil
124
+ c.temp_dir = File.expand_path('../tmp', __FILE__)
125
+ FileUtils.mkdir_p(c.temp_dir) unless File.directory?(c.temp_dir)
126
+ end
127
+
128
+ end
Binary file
@@ -0,0 +1,70 @@
1
+ module DomoscioViz
2
+ module AuthorizationToken
3
+
4
+ class Manager
5
+
6
+ class << self
7
+ def storage
8
+ @@storage ||= FileStorage.new
9
+ end
10
+
11
+ def storage= (storage)
12
+ @@storage = storage
13
+ end
14
+
15
+ def get_token
16
+ token = storage.get
17
+ token = DomoscioViz.configuration.client_passphrase if token.nil?
18
+ token
19
+ end
20
+ end
21
+ end
22
+
23
+ class StaticStorage
24
+ def get
25
+ @@token ||= nil
26
+ end
27
+
28
+ def store(token)
29
+ @@token = token
30
+ end
31
+ end
32
+
33
+ class FileStorage
34
+ require 'yaml'
35
+ @temp_dir
36
+
37
+ def initialize(temp_dir = nil)
38
+ @temp_dir = temp_dir || DomoscioViz.configuration.temp_dir
39
+ if !@temp_dir
40
+ raise "Path to temporary folder is not defined"
41
+ end
42
+ end
43
+
44
+ def get
45
+ begin
46
+ f = File.open(file_path, File::RDONLY)
47
+ f.flock(File::LOCK_SH)
48
+ txt = f.read
49
+ f.close
50
+ YAML.load(txt) || nil
51
+ rescue Errno::ENOENT
52
+ nil
53
+ end
54
+ end
55
+
56
+ def store(token)
57
+ File.open(file_path, File::RDWR|File::CREAT, 0644) do |f|
58
+ f.flock(File::LOCK_EX)
59
+ f.truncate(0)
60
+ f.rewind
61
+ f.puts(YAML.dump(token))
62
+ end
63
+ end
64
+
65
+ def file_path
66
+ File.join(@temp_dir, "DomoscioViz.AuthorizationToken.FileStore.tmp")
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,6 @@
1
+ module DomoscioViz
2
+ # A Recommandation.
3
+ class Chart < Resource
4
+ include DomoscioViz::HTTPCalls::GetUrl
5
+ end
6
+ end
@@ -0,0 +1,24 @@
1
+ module DomoscioViz
2
+
3
+ # Generic error superclass for MangoPay specific errors.
4
+ # Currently never instantiated directly.
5
+ # Currently only single subclass used.
6
+ class Error < StandardError
7
+ end
8
+
9
+ # Thrown from any MangoPay API call whenever
10
+ # it returns response with HTTP code != 200.
11
+ 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
17
+ super(message) if message
18
+ end
19
+
20
+ def message; @details['Message']; end
21
+ def type; @details['Type']; end
22
+ def errors; @details['errors']; end
23
+ end
24
+ end
@@ -0,0 +1,12 @@
1
+ require 'rails/generators'
2
+
3
+ module DomoscioViz
4
+ class InstallGenerator < ::Rails::Generators::Base
5
+ source_root File.expand_path('../templates', __FILE__)
6
+ desc "Generate config file for DomoscioViz configuration"
7
+
8
+ def install
9
+ copy_file "install.rb", "config/initializers/domoscio_viz.rb"
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,13 @@
1
+ DomoscioViz.configure do |c|
2
+ if Rails.env == "production"
3
+ c.preproduction = true
4
+ else
5
+ c.preproduction = false
6
+ end
7
+ c.client_id = ENV['DOMOSCIO_ID']
8
+ c.client_passphrase = ENV['DOMOSCIO_PASSWORD']
9
+
10
+ c.temp_dir = File.expand_path('../tmp', __FILE__)
11
+
12
+ FileUtils.mkdir_p(c.temp_dir) unless File.directory?(c.temp_dir)
13
+ end
@@ -0,0 +1,17 @@
1
+ module DomoscioViz
2
+ module HTTPCalls
3
+
4
+ module GetUrl
5
+ module ClassMethods
6
+ def get_url(util_name = nil, params = {})
7
+ DomoscioViz.request(:post, url(util_name), params)
8
+ end
9
+ end
10
+
11
+ def self.included(base)
12
+ base.extend(ClassMethods)
13
+ end
14
+ end
15
+
16
+ end
17
+ end
@@ -0,0 +1,23 @@
1
+ module DomoscioViz
2
+ module JSON
3
+ class << self
4
+ if MultiJson.respond_to?(:dump)
5
+ def dump(*args)
6
+ MultiJson.dump(*args)
7
+ end
8
+
9
+ def load(*args)
10
+ MultiJson.load(*args)
11
+ end
12
+ else
13
+ def dump(*args)
14
+ MultiJson.encode(*args)
15
+ end
16
+
17
+ def load(*args)
18
+ MultiJson.decode(*args)
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,24 @@
1
+ module DomoscioViz
2
+ # @abstract
3
+ class Resource
4
+ class << self
5
+ def class_name
6
+ name.split('::')[-1]
7
+ end
8
+
9
+ def url(util_name = nil, on_self = nil )
10
+ if self == Resource
11
+ raise NotImplementedError.new('Resource is an abstract class. Do not use it directly.')
12
+ end
13
+
14
+ build_url = ""
15
+ if !on_self
16
+ if util_name
17
+ build_url << "/#{util_name}"
18
+ end
19
+ end
20
+ return build_url
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,3 @@
1
+ module DomoscioViz
2
+ VERSION = "0.1.1.3"
3
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :domoscio_viz do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,72 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: domoscio_viz
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1.3
5
+ platform: ruby
6
+ authors:
7
+ - Benoit Praly
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-08-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '3.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '3.2'
27
+ description: Ruby client to interact with Domoscio Viz Engine.
28
+ email:
29
+ - benoit.praly@domoscio.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - MIT-LICENSE
35
+ - Rakefile
36
+ - lib/domoscio_viz.rb
37
+ - lib/domoscio_viz.tbz
38
+ - lib/domoscio_viz/authorization_token.rb
39
+ - lib/domoscio_viz/chart/chart.rb
40
+ - lib/domoscio_viz/errors.rb
41
+ - lib/domoscio_viz/generators/install_generator.rb
42
+ - lib/domoscio_viz/generators/templates/install.rb
43
+ - lib/domoscio_viz/http_calls.rb
44
+ - lib/domoscio_viz/json.rb
45
+ - lib/domoscio_viz/resource.rb
46
+ - lib/domoscio_viz/version.rb
47
+ - lib/tasks/domoscio_rails_tasks.rake
48
+ homepage: http://www.domoscio.com
49
+ licenses:
50
+ - MIT
51
+ metadata: {}
52
+ post_install_message:
53
+ rdoc_options: []
54
+ require_paths:
55
+ - lib
56
+ required_ruby_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ requirements: []
67
+ rubyforge_project:
68
+ rubygems_version: 2.7.6
69
+ signing_key:
70
+ specification_version: 4
71
+ summary: Summary of DomoscioViz.
72
+ test_files: []