domoscio_rails 0.2.19 → 0.3.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 +4 -4
- data/lib/domoscio_rails.rb +47 -60
- data/lib/domoscio_rails/adaptative/predictive/objective_knowledge_node_student.rb +1 -2
- data/lib/domoscio_rails/authorization_token.rb +1 -3
- 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 +2 -12
- data/lib/domoscio_rails/resource.rb +1 -4
- data/lib/domoscio_rails/version.rb +2 -2
- metadata +4 -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: b0a7e03020d78226e29f7a2930c43cfb2fccbb4389b9d559b3bae047be4dbdf5
|
4
|
+
data.tar.gz: 63a5cfb591576eaa115737527a3f99f4d8140ae5eeb51403370bf970a0d7a438
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 809d75c75785aa76824e42caaed95c0ad5e4afabd07d06480ddec251d7813fdeb1383c259558ba87745b67aaf88bd1b6ed27784a70547b495c1b271893e1a3f6
|
7
|
+
data.tar.gz: ecebc9a43d22e8d835387a7632d0dedc3b29b156e4b48dfbb32666556eb87b202a5e23f70be29481d899013145d108414344d33d32a137cd56b92758cf8c7128
|
data/lib/domoscio_rails.rb
CHANGED
@@ -2,13 +2,11 @@
|
|
2
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'
|
@@ -35,18 +33,15 @@ require 'domoscio_rails/metadata/tag_set'
|
|
35
33
|
require 'domoscio_rails/metadata/tag_edge'
|
36
34
|
require 'domoscio_rails/data/knowledge_node_student'
|
37
35
|
require 'domoscio_rails/data/event'
|
36
|
+
require 'domoscio_rails/data/learning_session'
|
38
37
|
require 'domoscio_rails/utils/review_util'
|
39
38
|
require 'domoscio_rails/utils/gameplay_util'
|
40
39
|
require 'domoscio_rails/utils/alerts_util'
|
41
40
|
require 'domoscio_rails/utils/recommendation_util'
|
42
41
|
require 'domoscio_rails/metadata/delta_object'
|
43
|
-
|
44
42
|
module DomoscioRails
|
45
|
-
|
46
43
|
class Configuration
|
47
|
-
attr_accessor :preproduction, :test, :dev, :root_url,
|
48
|
-
:client_id, :client_passphrase,
|
49
|
-
:temp_dir, :disabled, :version
|
44
|
+
attr_accessor :preproduction, :test, :dev, :root_url, :client_id, :client_passphrase, :temp_dir, :disabled, :version
|
50
45
|
|
51
46
|
def disabled
|
52
47
|
@disabled || false
|
@@ -71,11 +66,11 @@ module DomoscioRails
|
|
71
66
|
def root_url
|
72
67
|
if @preproduction == true
|
73
68
|
if @test == true
|
74
|
-
@root_url || "https://
|
69
|
+
@root_url || "https://staging.adaptive-engine.domoscio.com"
|
75
70
|
elsif @dev == true
|
76
|
-
@root_url || "https://
|
71
|
+
@root_url || "https://preprod.adaptive-engine.domoscio.com"
|
77
72
|
else
|
78
|
-
@root_url || "https://
|
73
|
+
@root_url || "https://adaptive-engine.domoscio.com"
|
79
74
|
end
|
80
75
|
else
|
81
76
|
@root_url || "http://localhost:3001"
|
@@ -108,74 +103,70 @@ module DomoscioRails
|
|
108
103
|
#
|
109
104
|
def self.request(method, url, params={}, filters={}, headers = request_headers, before_request_proc = nil)
|
110
105
|
return false if @disabled
|
106
|
+
#sets a default page size of 50
|
107
|
+
params.merge!({'per_page': 50}) unless params['per_page']
|
111
108
|
uri = api_uri(url)
|
112
109
|
uri.query = URI.encode_www_form(filters) unless filters.empty?
|
113
|
-
|
114
110
|
res = DomoscioRails.send_request(uri, method, params, headers, before_request_proc)
|
115
|
-
|
116
|
-
# decode json data
|
111
|
+
return res if res.kind_of? DomoscioRails::ProcessingError
|
117
112
|
begin
|
113
|
+
raise_http_failure(uri, res, params)
|
118
114
|
data = DomoscioRails::JSON.load(res.body.nil? ? '' : res.body)
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
rescue
|
123
|
-
data =
|
115
|
+
DomoscioRails::AuthorizationToken::Manager.storage.store({access_token: res['Accesstoken'], refresh_token: res['Refreshtoken']})
|
116
|
+
rescue MultiJson::LoadError => exception
|
117
|
+
data = ProcessingError.new(uri, 500, exception, res.body, params)
|
118
|
+
rescue ResponseError => exception
|
119
|
+
data = exception
|
124
120
|
end
|
125
121
|
|
126
122
|
if res['Total'] && !filters[:page]
|
127
123
|
pagetotal = (res['Total'].to_i / res['Per-Page'].to_f).ceil
|
128
|
-
|
129
124
|
for j in 2..pagetotal
|
130
|
-
|
131
|
-
res
|
132
|
-
|
133
|
-
# decode json data
|
125
|
+
res = DomoscioRails.send_request(uri, method, params.merge({page: j}), headers, before_request_proc)
|
126
|
+
return res if res.kind_of? DomoscioRails::ProcessingError
|
134
127
|
begin
|
135
|
-
|
128
|
+
raise_http_failure(uri, res, params)
|
129
|
+
body = DomoscioRails::JSON.load(res.body.nil? ? '' : res.body)
|
130
|
+
data += body
|
136
131
|
data.flatten!
|
137
|
-
rescue MultiJson::LoadError
|
138
|
-
|
132
|
+
rescue MultiJson::LoadError => exception
|
133
|
+
return ProcessingError.new(uri, 500, exception, res.body, params)
|
134
|
+
rescue ResponseError => exception
|
135
|
+
return exception
|
139
136
|
end
|
140
|
-
|
141
137
|
end
|
142
138
|
end
|
143
|
-
|
144
|
-
############### TEMP!!!! #######################################################
|
145
|
-
#pp method, uri.request_uri, params #, filters, headers
|
146
|
-
#pp res, data
|
147
|
-
#puts
|
148
|
-
|
149
|
-
# if (!(res.is_a? Net::HTTPOK))
|
150
|
-
# ex = DomoscioRails::ResponseError.new(uri, res.code, data)
|
151
|
-
# ############## TEMP!!!! ########################################################
|
152
|
-
# #pp ex, data
|
153
|
-
# raise ex
|
154
|
-
# end
|
155
|
-
|
156
|
-
# copy pagination info if any
|
157
|
-
# ['x-number-of-pages', 'x-number-of-items'].each { |k|
|
158
|
-
# filters[k.gsub('x-number-of-', 'total_')] = res[k].to_i if res[k]
|
159
|
-
# }
|
160
|
-
|
161
139
|
data
|
162
140
|
end
|
163
141
|
|
164
|
-
|
165
142
|
def self.send_request(uri, method, params, headers, before_request_proc)
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
143
|
+
begin
|
144
|
+
res = Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == 'https') do |http|
|
145
|
+
req = Net::HTTP::const_get(method.capitalize).new(uri.request_uri, headers)
|
146
|
+
req.body = DomoscioRails::JSON.dump(params)
|
147
|
+
before_request_proc.call(req) if before_request_proc
|
148
|
+
http.request req
|
149
|
+
end
|
150
|
+
rescue Timeout::Error, Errno::EINVAL, Errno::ECONNREFUSED, Errno::ECONNRESET, EOFError, Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError => exception
|
151
|
+
ProcessingError.new(uri, 500, exception, res)
|
171
152
|
end
|
172
153
|
end
|
173
154
|
|
174
155
|
private
|
175
156
|
|
157
|
+
def self.raise_http_failure(uri, res, params)
|
158
|
+
unless res.kind_of? Net::HTTPSuccess
|
159
|
+
if res.blank?
|
160
|
+
raise ResponseError.new(uri, 500, {error: {status: 500, message: 'AdaptiveEngine not available'}}, {}, params)
|
161
|
+
else
|
162
|
+
body = DomoscioRails::JSON.load((res.body.nil? ? '' : res.body), :symbolize_keys => true)
|
163
|
+
raise ResponseError.new(uri, res.code.to_i, body, res.body, params)
|
164
|
+
end
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
176
168
|
def self.user_agent
|
177
169
|
@uname ||= get_uname
|
178
|
-
|
179
170
|
{
|
180
171
|
bindings_version: DomoscioRails::VERSION,
|
181
172
|
lang: 'ruby',
|
@@ -193,24 +184,20 @@ module DomoscioRails
|
|
193
184
|
|
194
185
|
def self.request_headers
|
195
186
|
auth_token = DomoscioRails::AuthorizationToken::Manager.get_token
|
196
|
-
|
197
187
|
if !auth_token.is_a? String
|
198
188
|
headers = {
|
199
|
-
'user_agent' => "
|
189
|
+
'user_agent' => "#{DomoscioRails.user_agent}",
|
200
190
|
'AccessToken' => "#{auth_token[:access_token]}",
|
201
191
|
'RefreshToken' => "#{auth_token[:refresh_token]}",
|
202
192
|
'Content-Type' => 'application/json'
|
203
193
|
}
|
204
194
|
else
|
205
195
|
headers = {
|
206
|
-
'user_agent' => "
|
207
|
-
'Authorization' => "Token token=#{DomoscioRails.configuration.client_passphrase}"
|
196
|
+
'user_agent' => "#{DomoscioRails.user_agent}",
|
197
|
+
'Authorization' => "Token token=#{DomoscioRails.configuration.client_passphrase}",
|
208
198
|
'Content-Type' => 'application/json'
|
209
199
|
}
|
210
200
|
end
|
211
201
|
headers
|
212
|
-
|
213
202
|
end
|
214
|
-
|
215
|
-
|
216
|
-
end
|
203
|
+
end
|
@@ -1,8 +1,6 @@
|
|
1
1
|
module DomoscioRails
|
2
2
|
module AuthorizationToken
|
3
|
-
|
4
3
|
class Manager
|
5
|
-
|
6
4
|
class << self
|
7
5
|
def storage
|
8
6
|
@@storage ||= FileStorage.new
|
@@ -19,7 +17,6 @@ module DomoscioRails
|
|
19
17
|
end
|
20
18
|
end
|
21
19
|
end
|
22
|
-
|
23
20
|
class StaticStorage
|
24
21
|
def get
|
25
22
|
@@token ||= nil
|
@@ -63,6 +60,7 @@ module DomoscioRails
|
|
63
60
|
end
|
64
61
|
|
65
62
|
def file_path
|
63
|
+
@temp_dir = DomoscioRails.configuration.temp_dir
|
66
64
|
File.join(@temp_dir, "DomoscioRails.AuthorizationToken.FileStore.tmp")
|
67
65
|
end
|
68
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, :request_params
|
9
|
+
def initialize(request_url, code, details = {}, body = nil, request_params = {})
|
10
|
+
@request_url, @code, @details, @body, @request_params = request_url, code, details, body, request_params
|
17
11
|
super(message) if message
|
18
12
|
end
|
13
|
+
def message; @details.is_a?(Hash) ? @details.dig(:error, :message) : @details; end
|
14
|
+
end
|
19
15
|
|
20
|
-
|
21
|
-
|
22
|
-
|
16
|
+
# ProcessingError from DomoscioRails
|
17
|
+
class ProcessingError < Error
|
18
|
+
attr_reader :request_url, :code, :details, :body, :request_params
|
19
|
+
def initialize(request_url, code, details = {}, body = nil, request_params = {})
|
20
|
+
@request_url, @code, @details, @body, @request_params = request_url, code, details, body, request_params
|
21
|
+
super(message) if message
|
22
|
+
end
|
23
|
+
def message; @details.message; end
|
23
24
|
end
|
24
25
|
end
|
@@ -8,7 +8,6 @@ module DomoscioRails
|
|
8
8
|
DomoscioRails.request(:post, url(id), params)
|
9
9
|
end
|
10
10
|
end
|
11
|
-
|
12
11
|
def self.included(base)
|
13
12
|
base.extend(ClassMethods)
|
14
13
|
end
|
@@ -20,7 +19,6 @@ module DomoscioRails
|
|
20
19
|
DomoscioRails.request(:put, url(id), params)
|
21
20
|
end
|
22
21
|
end
|
23
|
-
|
24
22
|
def self.included(base)
|
25
23
|
base.extend(ClassMethods)
|
26
24
|
end
|
@@ -32,7 +30,6 @@ module DomoscioRails
|
|
32
30
|
DomoscioRails.request(:put, url(nil, nil, true), params)
|
33
31
|
end
|
34
32
|
end
|
35
|
-
|
36
33
|
def self.included(base)
|
37
34
|
base.extend(ClassMethods)
|
38
35
|
end
|
@@ -40,19 +37,14 @@ module DomoscioRails
|
|
40
37
|
|
41
38
|
module Fetch
|
42
39
|
module ClassMethods
|
43
|
-
def fetch(
|
44
|
-
|
45
|
-
response = DomoscioRails.request(:get, url(id), {}, filters)
|
40
|
+
def fetch(id = nil, params = {})
|
41
|
+
DomoscioRails.request(:get, url(id), params)
|
46
42
|
end
|
47
43
|
end
|
48
44
|
|
49
45
|
def self.included(base)
|
50
46
|
base.extend(ClassMethods)
|
51
47
|
end
|
52
|
-
|
53
|
-
def self.parse_id_or_filters(id_or_filters = nil)
|
54
|
-
id_or_filters.is_a?(Hash) ? [nil, id_or_filters] : [id_or_filters, {}]
|
55
|
-
end
|
56
48
|
end
|
57
49
|
|
58
50
|
module Destroy
|
@@ -81,7 +73,5 @@ module DomoscioRails
|
|
81
73
|
base.extend(ClassMethods)
|
82
74
|
end
|
83
75
|
end
|
84
|
-
|
85
|
-
|
86
76
|
end
|
87
77
|
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.3"
|
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.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:
|
11
|
+
date: 2021-01-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -51,6 +51,7 @@ files:
|
|
51
51
|
- lib/domoscio_rails/content/knowledge_node_content.rb
|
52
52
|
- lib/domoscio_rails/data/event.rb
|
53
53
|
- lib/domoscio_rails/data/knowledge_node_student.rb
|
54
|
+
- lib/domoscio_rails/data/learning_session.rb
|
54
55
|
- lib/domoscio_rails/data/result.rb
|
55
56
|
- lib/domoscio_rails/errors.rb
|
56
57
|
- lib/domoscio_rails/http_calls.rb
|
@@ -72,7 +73,6 @@ files:
|
|
72
73
|
- lib/domoscio_rails/utils/recommendation_util.rb
|
73
74
|
- lib/domoscio_rails/utils/review_util.rb
|
74
75
|
- lib/domoscio_rails/version.rb
|
75
|
-
- lib/tasks/domoscio_rails_tasks.rake
|
76
76
|
homepage: http://www.domoscio.com
|
77
77
|
licenses:
|
78
78
|
- MIT
|
@@ -92,7 +92,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
92
92
|
- !ruby/object:Gem::Version
|
93
93
|
version: '0'
|
94
94
|
requirements: []
|
95
|
-
rubygems_version: 3.
|
95
|
+
rubygems_version: 3.1.2
|
96
96
|
signing_key:
|
97
97
|
specification_version: 4
|
98
98
|
summary: Summary of DomoscioRails.
|