domoscio_rails 0.2.14 → 0.3.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 +5 -5
- data/lib/domoscio_rails.rb +91 -58
- data/lib/domoscio_rails/adaptative/predictive/objective_knowledge_node.rb +4 -4
- data/lib/domoscio_rails/adaptative/predictive/objective_knowledge_node_student.rb +5 -5
- data/lib/domoscio_rails/adaptative/predictive/objective_student.rb +2 -1
- data/lib/domoscio_rails/authorization_token.rb +4 -15
- data/lib/domoscio_rails/data/learning_session.rb +10 -0
- data/lib/domoscio_rails/errors.rb +14 -13
- data/lib/domoscio_rails/http_calls.rb +12 -9
- data/lib/domoscio_rails/metadata/delta_object.rb +6 -0
- data/lib/domoscio_rails/resource.rb +1 -4
- data/lib/domoscio_rails/utils/alerts_util.rb +6 -0
- data/lib/domoscio_rails/utils/recommendation_util.rb +6 -0
- data/lib/domoscio_rails/version.rb +2 -2
- metadata +8 -7
- data/lib/domoscio_rails/admin/user.rb +0 -10
- data/lib/tasks/domoscio_rails_tasks.rake +0 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 4b1afdf503120aeb74bb9d38237a533f7becd888b329098199446db697b9fe26
|
4
|
+
data.tar.gz: bda6a20da9b44d4ef8a32910688ec633606168f012b7d6af4047854d7e443a0e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d350f60cbbb55a8e5a8222edac01778216c3e3db07c645b3212c849ab41dc670eb1d79f9d31ff8256a0f5d702934af3043cf368fb9635bc206d44e2023ba50bb
|
7
|
+
data.tar.gz: 388c1db2de8db63dfccea4335a0c8542615725408501283293aa537282a8d5ed4e285231f4d3ed45dae603cde678ebef80fb6ad356cc4bf1857dff1c3a4e67a8
|
data/lib/domoscio_rails.rb
CHANGED
@@ -1,14 +1,12 @@
|
|
1
|
-
|
2
|
-
require 'net/
|
1
|
+
|
2
|
+
require 'net/https'
|
3
3
|
require 'cgi/util'
|
4
4
|
require 'multi_json'
|
5
|
-
|
6
5
|
# helpers
|
7
6
|
require 'domoscio_rails/version'
|
8
7
|
require 'domoscio_rails/json'
|
9
8
|
require 'domoscio_rails/errors'
|
10
9
|
require 'domoscio_rails/authorization_token'
|
11
|
-
|
12
10
|
# resources
|
13
11
|
require 'domoscio_rails/http_calls'
|
14
12
|
require 'domoscio_rails/resource'
|
@@ -18,13 +16,12 @@ require 'domoscio_rails/adaptative/deterministic/rule_output'
|
|
18
16
|
require 'domoscio_rails/adaptative/deterministic/rule_condition'
|
19
17
|
require 'domoscio_rails/adaptative/predictive/objective'
|
20
18
|
require 'domoscio_rails/adaptative/predictive/objective_student'
|
21
|
-
require 'domoscio_rails/adaptative/predictive/objective_knowledge_node_student'
|
22
19
|
require 'domoscio_rails/adaptative/predictive/objective_knowledge_node'
|
20
|
+
require 'domoscio_rails/adaptative/predictive/objective_knowledge_node_student'
|
23
21
|
require 'domoscio_rails/adaptative/recommendation'
|
24
22
|
require 'domoscio_rails/path/learning_path'
|
25
23
|
require 'domoscio_rails/content/content'
|
26
24
|
require 'domoscio_rails/content/knowledge_node_content'
|
27
|
-
require 'domoscio_rails/admin/user'
|
28
25
|
require 'domoscio_rails/student/student'
|
29
26
|
require 'domoscio_rails/student/student_cluster'
|
30
27
|
require 'domoscio_rails/knowledge/knowledge_graph'
|
@@ -36,17 +33,16 @@ require 'domoscio_rails/metadata/tag_set'
|
|
36
33
|
require 'domoscio_rails/metadata/tag_edge'
|
37
34
|
require 'domoscio_rails/data/knowledge_node_student'
|
38
35
|
require 'domoscio_rails/data/event'
|
36
|
+
require 'domoscio_rails/data/learning_session'
|
39
37
|
require 'domoscio_rails/utils/review_util'
|
40
38
|
require 'domoscio_rails/utils/gameplay_util'
|
41
|
-
|
42
|
-
|
39
|
+
require 'domoscio_rails/utils/alerts_util'
|
40
|
+
require 'domoscio_rails/utils/recommendation_util'
|
41
|
+
require 'domoscio_rails/metadata/delta_object'
|
43
42
|
module DomoscioRails
|
44
|
-
|
45
43
|
class Configuration
|
46
|
-
attr_accessor :preproduction, :root_url,
|
47
|
-
|
48
|
-
:temp_dir, :disabled, :version
|
49
|
-
|
44
|
+
attr_accessor :preproduction, :test, :dev, :root_url, :client_id, :client_passphrase, :temp_dir, :disabled, :version
|
45
|
+
|
50
46
|
def disabled
|
51
47
|
@disabled || false
|
52
48
|
end
|
@@ -54,13 +50,31 @@ module DomoscioRails
|
|
54
50
|
def preproduction
|
55
51
|
@preproduction || false
|
56
52
|
end
|
57
|
-
|
53
|
+
|
54
|
+
def test
|
55
|
+
@test || false
|
56
|
+
end
|
57
|
+
|
58
|
+
def dev
|
59
|
+
@dev || false
|
60
|
+
end
|
61
|
+
|
58
62
|
def version
|
59
63
|
@version || 1
|
60
64
|
end
|
61
65
|
|
62
66
|
def root_url
|
63
|
-
|
67
|
+
if @preproduction == true
|
68
|
+
if @test == true
|
69
|
+
@root_url || "https://staging.adaptive-engine.domoscio.com"
|
70
|
+
elsif @dev == true
|
71
|
+
@root_url || "https://preprod.adaptive-engine.domoscio.com"
|
72
|
+
else
|
73
|
+
@root_url || "https://adaptive-engine.domoscio.com"
|
74
|
+
end
|
75
|
+
else
|
76
|
+
@root_url || "http://localhost:3001"
|
77
|
+
end
|
64
78
|
end
|
65
79
|
end
|
66
80
|
|
@@ -90,47 +104,62 @@ module DomoscioRails
|
|
90
104
|
def self.request(method, url, params={}, filters={}, headers = request_headers, before_request_proc = nil)
|
91
105
|
return false if @disabled
|
92
106
|
uri = api_uri(url)
|
93
|
-
uri.query = URI.encode_www_form(filters) unless filters.empty?
|
94
|
-
|
95
|
-
res
|
96
|
-
req = Net::HTTP::const_get(method.capitalize).new(uri.request_uri, headers)
|
97
|
-
req.body = DomoscioRails::JSON.dump(params)
|
98
|
-
before_request_proc.call(req) if before_request_proc
|
99
|
-
http.request req
|
100
|
-
end
|
101
|
-
|
102
|
-
# decode json data
|
107
|
+
uri.query = URI.encode_www_form(filters) unless filters.empty?
|
108
|
+
res = DomoscioRails.send_request(uri, method, params, headers, before_request_proc)
|
109
|
+
return res if res.kind_of? DomoscioRails::ProcessingError
|
103
110
|
begin
|
111
|
+
unless res.kind_of? Net::HTTPSuccess
|
112
|
+
data = DomoscioRails::JSON.load((res.body.nil? ? '' : res.body), :symbolize_keys => true)
|
113
|
+
raise ResponseError.new(uri, res.code.to_i, data, res.body)
|
114
|
+
end
|
104
115
|
data = DomoscioRails::JSON.load(res.body.nil? ? '' : res.body)
|
105
|
-
|
106
|
-
|
116
|
+
DomoscioRails::AuthorizationToken::Manager.storage.store({access_token: res['Accesstoken'], refresh_token: res['Refreshtoken']})
|
117
|
+
rescue MultiJson::LoadError => exception
|
118
|
+
data = ProcessingError.new(uri, 500, exception, res.body)
|
119
|
+
rescue ResponseError => exception
|
120
|
+
data = exception
|
107
121
|
end
|
108
122
|
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
123
|
+
if res['Total'] && !filters[:page]
|
124
|
+
pagetotal = (res['Total'].to_i / res['Per-Page'].to_f).ceil
|
125
|
+
for j in 2..pagetotal
|
126
|
+
res = DomoscioRails.send_request(uri, method, params.merge({page: j}), headers, before_request_proc)
|
127
|
+
return res if res.kind_of? DomoscioRails::ProcessingError
|
128
|
+
begin
|
129
|
+
unless res.kind_of? Net::HTTPSuccess
|
130
|
+
body = DomoscioRails::JSON.load((res.body.nil? ? '' : res.body), :symbolize_keys => true)
|
131
|
+
raise ResponseError.new(uri, res.code.to_i, body, res.body)
|
132
|
+
end
|
133
|
+
body = DomoscioRails::JSON.load(res.body.nil? ? '' : res.body)
|
134
|
+
data += body
|
135
|
+
data.flatten!
|
136
|
+
rescue MultiJson::LoadError => exception
|
137
|
+
return ProcessingError.new(uri, 500, exception, res.body)
|
138
|
+
rescue ResponseError => exception
|
139
|
+
return exception
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
126
143
|
data
|
127
144
|
end
|
128
145
|
|
146
|
+
def self.send_request(uri, method, params, headers, before_request_proc)
|
147
|
+
begin
|
148
|
+
res = Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == 'https') do |http|
|
149
|
+
req = Net::HTTP::const_get(method.capitalize).new(uri.request_uri, headers)
|
150
|
+
req.body = DomoscioRails::JSON.dump(params)
|
151
|
+
before_request_proc.call(req) if before_request_proc
|
152
|
+
http.request req
|
153
|
+
end
|
154
|
+
rescue Timeout::Error, Errno::EINVAL, Errno::ECONNREFUSED, Errno::ECONNRESET, EOFError, Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError => exception
|
155
|
+
ProcessingError.new(uri, 500, exception, res.body)
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
129
159
|
private
|
130
160
|
|
131
161
|
def self.user_agent
|
132
162
|
@uname ||= get_uname
|
133
|
-
|
134
163
|
{
|
135
164
|
bindings_version: DomoscioRails::VERSION,
|
136
165
|
lang: 'ruby',
|
@@ -148,17 +177,21 @@ module DomoscioRails
|
|
148
177
|
|
149
178
|
def self.request_headers
|
150
179
|
auth_token = DomoscioRails::AuthorizationToken::Manager.get_token
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
180
|
+
|
181
|
+
if !auth_token.is_a? String
|
182
|
+
headers = {
|
183
|
+
'user_agent' => "#{DomoscioRails.user_agent}",
|
184
|
+
'AccessToken' => "#{auth_token[:access_token]}",
|
185
|
+
'RefreshToken' => "#{auth_token[:refresh_token]}",
|
186
|
+
'Content-Type' => 'application/json'
|
187
|
+
}
|
188
|
+
else
|
189
|
+
headers = {
|
190
|
+
'user_agent' => "#{DomoscioRails.user_agent}",
|
191
|
+
'Authorization' => "Token token=#{DomoscioRails.configuration.client_passphrase}",
|
192
|
+
'Content-Type' => 'application/json'
|
193
|
+
}
|
194
|
+
end
|
195
|
+
headers
|
161
196
|
end
|
162
|
-
|
163
|
-
|
164
|
-
end
|
197
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module DomoscioRails
|
2
|
-
|
3
|
-
|
4
|
-
|
2
|
+
# An objective knowledge node.
|
3
|
+
class ObjectiveKnowledgeNode < Resource
|
4
|
+
include DomoscioRails::HTTPCalls::Fetch
|
5
|
+
end
|
5
6
|
end
|
6
|
-
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module DomoscioRails
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
end
|
2
|
+
class ObjectiveKnowledgeNodeStudent < Resource
|
3
|
+
include DomoscioRails::HTTPCalls::Fetch
|
4
|
+
include DomoscioRails::HTTPCalls::Update
|
5
|
+
end
|
6
|
+
end
|
@@ -1,11 +1,9 @@
|
|
1
1
|
module DomoscioRails
|
2
2
|
module AuthorizationToken
|
3
|
-
|
4
3
|
class Manager
|
5
|
-
|
6
4
|
class << self
|
7
5
|
def storage
|
8
|
-
@@storage ||=
|
6
|
+
@@storage ||= FileStorage.new
|
9
7
|
end
|
10
8
|
|
11
9
|
def storage= (storage)
|
@@ -13,22 +11,12 @@ module DomoscioRails
|
|
13
11
|
end
|
14
12
|
|
15
13
|
def get_token
|
16
|
-
|
17
|
-
|
18
|
-
# token = DomoscioRails.request(:post, '/api/oauth/token', {}, {}, {}, Proc.new do |req|
|
19
|
-
# cfg = DomoscioRails.configuration
|
20
|
-
# req.basic_auth cfg.client_id, cfg.client_passphrase
|
21
|
-
# req.body = 'grant_type=client_credentials'
|
22
|
-
# end)
|
23
|
-
# token['timestamp'] = Time.now + token['expires_in'].to_i
|
24
|
-
# storage.store token
|
25
|
-
# end
|
26
|
-
token = DomoscioRails.configuration.client_passphrase
|
14
|
+
token = storage.get
|
15
|
+
token = DomoscioRails.configuration.client_passphrase if token.nil?
|
27
16
|
token
|
28
17
|
end
|
29
18
|
end
|
30
19
|
end
|
31
|
-
|
32
20
|
class StaticStorage
|
33
21
|
def get
|
34
22
|
@@token ||= nil
|
@@ -72,6 +60,7 @@ module DomoscioRails
|
|
72
60
|
end
|
73
61
|
|
74
62
|
def file_path
|
63
|
+
@temp_dir = DomoscioRails.configuration.temp_dir
|
75
64
|
File.join(@temp_dir, "DomoscioRails.AuthorizationToken.FileStore.tmp")
|
76
65
|
end
|
77
66
|
end
|
@@ -1,24 +1,25 @@
|
|
1
1
|
module DomoscioRails
|
2
|
-
|
3
2
|
# Generic error superclass for MangoPay specific errors.
|
4
|
-
# Currently never instantiated directly.
|
5
|
-
# Currently only single subclass used.
|
6
3
|
class Error < StandardError
|
7
4
|
end
|
8
5
|
|
9
|
-
#
|
10
|
-
# it returns response with HTTP code != 200.
|
6
|
+
# Error Message from AdaptiveEngine
|
11
7
|
class ResponseError < Error
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
def initialize(request_url, code, details)
|
16
|
-
@request_url, @code, @details = request_url, code, details
|
8
|
+
attr_reader :request_url, :code, :details, :body
|
9
|
+
def initialize(request_url, code, details, body)
|
10
|
+
@request_url, @code, @details, @body = request_url, code, details, body
|
17
11
|
super(message) if message
|
18
12
|
end
|
13
|
+
def message; @details.dig(:error, :message) || @details; end
|
14
|
+
end
|
19
15
|
|
20
|
-
|
21
|
-
|
22
|
-
|
16
|
+
# Error Message from DomoscioRails
|
17
|
+
class ProcessingError < Error
|
18
|
+
attr_reader :request_url, :code, :details, :body
|
19
|
+
def initialize(request_url, code, details, body)
|
20
|
+
@request_url, @code, @details, @body = request_url, code, details, body
|
21
|
+
super(message) if message
|
22
|
+
end
|
23
|
+
def message; @details.message; end
|
23
24
|
end
|
24
25
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module DomoscioRails
|
2
2
|
module HTTPCalls
|
3
|
-
|
3
|
+
|
4
4
|
module Create
|
5
5
|
module ClassMethods
|
6
6
|
def create(*id, params)
|
@@ -25,7 +25,7 @@ module DomoscioRails
|
|
25
25
|
base.extend(ClassMethods)
|
26
26
|
end
|
27
27
|
end
|
28
|
-
|
28
|
+
|
29
29
|
module UpdateSelf
|
30
30
|
module ClassMethods
|
31
31
|
def update_self(params = {})
|
@@ -54,7 +54,7 @@ module DomoscioRails
|
|
54
54
|
id_or_filters.is_a?(Hash) ? [nil, id_or_filters] : [id_or_filters, {}]
|
55
55
|
end
|
56
56
|
end
|
57
|
-
|
57
|
+
|
58
58
|
module Destroy
|
59
59
|
module ClassMethods
|
60
60
|
def destroy(id = nil, params = {})
|
@@ -64,21 +64,24 @@ module DomoscioRails
|
|
64
64
|
|
65
65
|
def self.included(base)
|
66
66
|
base.extend(ClassMethods)
|
67
|
-
end
|
67
|
+
end
|
68
68
|
end
|
69
|
-
|
69
|
+
|
70
70
|
module Util
|
71
71
|
module ClassMethods
|
72
72
|
def util(id = nil, util_name = nil, params = {})
|
73
73
|
DomoscioRails.request(:get, url(id, util_name), params)
|
74
74
|
end
|
75
|
+
def util_post(id = nil, util_name = nil, params = {})
|
76
|
+
DomoscioRails.request(:post, url(id, util_name), params)
|
77
|
+
end
|
75
78
|
end
|
76
79
|
|
77
80
|
def self.included(base)
|
78
81
|
base.extend(ClassMethods)
|
79
|
-
end
|
82
|
+
end
|
80
83
|
end
|
81
|
-
|
82
|
-
|
84
|
+
|
85
|
+
|
83
86
|
end
|
84
|
-
end
|
87
|
+
end
|
@@ -1,16 +1,13 @@
|
|
1
1
|
module DomoscioRails
|
2
|
-
# @abstract
|
3
2
|
class Resource
|
4
3
|
class << self
|
5
4
|
def class_name
|
6
5
|
name.split('::')[-1]
|
7
6
|
end
|
8
|
-
|
9
7
|
def url(id = nil, util_name = nil, on_self = nil )
|
10
8
|
if self == Resource
|
11
9
|
raise NotImplementedError.new('Resource is an abstract class. Do not use it directly.')
|
12
10
|
end
|
13
|
-
|
14
11
|
build_url = "/v#{DomoscioRails.configuration.version}/instances/#{DomoscioRails.configuration.client_id}"
|
15
12
|
if !on_self
|
16
13
|
build_url << "/#{class_name.underscore}s"
|
@@ -25,4 +22,4 @@ module DomoscioRails
|
|
25
22
|
end
|
26
23
|
end
|
27
24
|
end
|
28
|
-
end
|
25
|
+
end
|
@@ -1,3 +1,3 @@
|
|
1
1
|
module DomoscioRails
|
2
|
-
VERSION = "0.
|
3
|
-
end
|
2
|
+
VERSION = "0.3.1"
|
3
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: domoscio_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.1
|
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: 2020-12-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -24,7 +24,7 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '3.2'
|
27
|
-
description:
|
27
|
+
description: Ruby client to interact with Domoscio API.
|
28
28
|
email:
|
29
29
|
- benoit.praly@domoscio.com
|
30
30
|
executables: []
|
@@ -46,12 +46,12 @@ files:
|
|
46
46
|
- lib/domoscio_rails/adaptative/predictive/objective_student.rb
|
47
47
|
- lib/domoscio_rails/adaptative/recommendation.rb
|
48
48
|
- lib/domoscio_rails/admin/instance.rb
|
49
|
-
- lib/domoscio_rails/admin/user.rb
|
50
49
|
- lib/domoscio_rails/authorization_token.rb
|
51
50
|
- lib/domoscio_rails/content/content.rb
|
52
51
|
- lib/domoscio_rails/content/knowledge_node_content.rb
|
53
52
|
- lib/domoscio_rails/data/event.rb
|
54
53
|
- lib/domoscio_rails/data/knowledge_node_student.rb
|
54
|
+
- lib/domoscio_rails/data/learning_session.rb
|
55
55
|
- lib/domoscio_rails/data/result.rb
|
56
56
|
- lib/domoscio_rails/errors.rb
|
57
57
|
- lib/domoscio_rails/http_calls.rb
|
@@ -59,6 +59,7 @@ files:
|
|
59
59
|
- lib/domoscio_rails/knowledge/knowledge_edge.rb
|
60
60
|
- lib/domoscio_rails/knowledge/knowledge_graph.rb
|
61
61
|
- lib/domoscio_rails/knowledge/knowledge_node.rb
|
62
|
+
- lib/domoscio_rails/metadata/delta_object.rb
|
62
63
|
- lib/domoscio_rails/metadata/tag.rb
|
63
64
|
- lib/domoscio_rails/metadata/tag_edge.rb
|
64
65
|
- lib/domoscio_rails/metadata/tag_set.rb
|
@@ -67,10 +68,11 @@ files:
|
|
67
68
|
- lib/domoscio_rails/resource.rb
|
68
69
|
- lib/domoscio_rails/student/student.rb
|
69
70
|
- lib/domoscio_rails/student/student_cluster.rb
|
71
|
+
- lib/domoscio_rails/utils/alerts_util.rb
|
70
72
|
- lib/domoscio_rails/utils/gameplay_util.rb
|
73
|
+
- lib/domoscio_rails/utils/recommendation_util.rb
|
71
74
|
- lib/domoscio_rails/utils/review_util.rb
|
72
75
|
- lib/domoscio_rails/version.rb
|
73
|
-
- lib/tasks/domoscio_rails_tasks.rake
|
74
76
|
homepage: http://www.domoscio.com
|
75
77
|
licenses:
|
76
78
|
- MIT
|
@@ -90,8 +92,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
90
92
|
- !ruby/object:Gem::Version
|
91
93
|
version: '0'
|
92
94
|
requirements: []
|
93
|
-
|
94
|
-
rubygems_version: 2.6.8
|
95
|
+
rubygems_version: 3.0.3
|
95
96
|
signing_key:
|
96
97
|
specification_version: 4
|
97
98
|
summary: Summary of DomoscioRails.
|