domoscio_rails 0.3.8 → 0.4.2
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/Rakefile +0 -4
- data/lib/domoscio_rails/authorization_token.rb +24 -22
- data/lib/domoscio_rails/data/content.rb +1 -3
- data/lib/domoscio_rails/data/event.rb +1 -3
- data/lib/domoscio_rails/data/instance.rb +0 -2
- data/lib/domoscio_rails/data/learning_session.rb +2 -3
- data/lib/domoscio_rails/data/recommendation.rb +1 -3
- data/lib/domoscio_rails/data/student.rb +2 -4
- data/lib/domoscio_rails/data/student_group.rb +8 -0
- data/lib/domoscio_rails/errors.rb +21 -5
- data/lib/domoscio_rails/http_calls.rb +3 -0
- data/lib/domoscio_rails/json.rb +1 -1
- data/lib/domoscio_rails/knowledge/knowledge_edge.rb +2 -4
- data/lib/domoscio_rails/knowledge/knowledge_graph.rb +2 -4
- data/lib/domoscio_rails/knowledge/knowledge_node.rb +2 -4
- data/lib/domoscio_rails/knowledge/knowledge_node_content.rb +2 -4
- data/lib/domoscio_rails/knowledge/knowledge_node_student.rb +1 -3
- data/lib/domoscio_rails/objective/objective.rb +2 -4
- data/lib/domoscio_rails/objective/objective_knowledge_node.rb +4 -3
- data/lib/domoscio_rails/objective/objective_knowledge_node_student.rb +3 -3
- data/lib/domoscio_rails/objective/objective_student.rb +1 -3
- data/lib/domoscio_rails/resource.rb +18 -14
- data/lib/domoscio_rails/tag/tag.rb +2 -4
- data/lib/domoscio_rails/tag/tag_edge.rb +2 -4
- data/lib/domoscio_rails/tag/tag_set.rb +2 -4
- data/lib/domoscio_rails/tag/tagging.rb +2 -4
- data/lib/domoscio_rails/utils/gameplay_util.rb +1 -3
- data/lib/domoscio_rails/utils/recommendation_util.rb +1 -3
- data/lib/domoscio_rails/utils/review_util.rb +1 -3
- data/lib/domoscio_rails/utils/stats_util.rb +5 -0
- data/lib/domoscio_rails/version.rb +2 -2
- data/lib/domoscio_rails.rb +88 -86
- metadata +29 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d84d18d926ff49fafe9bf5e48907f7e5ad5379660d1846f695e73b2f3b958029
|
4
|
+
data.tar.gz: 1fbc96e7c54dba8c7676a1933d35638f9767dcf9cb38f5df3b61fd5350f6b489
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a69b023608cf340083931858b547b74ee9c3da3f481a28d27f8dac638834b32372fb2856d57d1df0f002f255379649f985fcee907152084f044388ff09323b0d
|
7
|
+
data.tar.gz: f48ca74ee109d995e27f9c26d0567a3d4e1c92858fd65e62bd448a6c5ffef09903c5ad2bbcd05f79cfa2bf5b2e4e87e6313b4148ab36494e03d59453d5102bb8
|
data/Rakefile
CHANGED
@@ -14,9 +14,6 @@ RDoc::Task.new(:rdoc) do |rdoc|
|
|
14
14
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
15
|
end
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
17
|
Bundler::GemHelper.install_tasks
|
21
18
|
|
22
19
|
require 'rake/testtask'
|
@@ -28,5 +25,4 @@ Rake::TestTask.new(:test) do |t|
|
|
28
25
|
t.verbose = false
|
29
26
|
end
|
30
27
|
|
31
|
-
|
32
28
|
task default: :test
|
@@ -1,51 +1,53 @@
|
|
1
1
|
module DomoscioRails
|
2
2
|
module AuthorizationToken
|
3
|
+
# Token Manager
|
3
4
|
class Manager
|
4
5
|
class << self
|
5
6
|
def storage
|
6
|
-
|
7
|
+
@storage ||= DomoscioRails.configuration.file_storage ? FileStorage.new : ManualSetting.new
|
7
8
|
end
|
8
9
|
|
9
|
-
def
|
10
|
-
@@storage = storage
|
11
|
-
end
|
12
|
-
|
13
|
-
def get_token
|
10
|
+
def token
|
14
11
|
storage.get
|
15
12
|
end
|
16
13
|
end
|
17
14
|
end
|
18
|
-
|
15
|
+
|
16
|
+
# Manages tokens with configuration
|
17
|
+
class ManualSetting
|
19
18
|
def get
|
20
|
-
|
19
|
+
{
|
20
|
+
access_token: DomoscioRails.configuration.access_token,
|
21
|
+
refresh_token: DomoscioRails.configuration.refresh_token
|
22
|
+
}
|
21
23
|
end
|
22
24
|
|
23
25
|
def store(token)
|
24
|
-
|
26
|
+
DomoscioRails.configuration.access_token = token[:access_token]
|
27
|
+
DomoscioRails.configuration.refresh_token = token[:refresh_token]
|
25
28
|
end
|
26
29
|
end
|
27
30
|
|
31
|
+
# Manages tokens with local File
|
28
32
|
class FileStorage
|
29
33
|
require 'yaml'
|
30
34
|
|
31
35
|
def initialize
|
32
|
-
raise
|
36
|
+
raise 'Path to temporary folder is not defined' unless DomoscioRails.configuration.temp_dir
|
33
37
|
end
|
34
38
|
|
35
39
|
def get
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
nil
|
44
|
-
end
|
40
|
+
f = File.open(file_path, File::RDONLY)
|
41
|
+
f.flock(File::LOCK_SH)
|
42
|
+
txt = f.read
|
43
|
+
f.close
|
44
|
+
YAML.safe_load(txt) || nil
|
45
|
+
rescue Errno::ENOENT
|
46
|
+
nil
|
45
47
|
end
|
46
48
|
|
47
49
|
def store(token)
|
48
|
-
File.open(file_path, File::RDWR|File::CREAT,
|
50
|
+
File.open(file_path, File::RDWR|File::CREAT, 0o644) do |f|
|
49
51
|
f.flock(File::LOCK_EX)
|
50
52
|
f.truncate(0)
|
51
53
|
f.rewind
|
@@ -54,8 +56,8 @@ module DomoscioRails
|
|
54
56
|
end
|
55
57
|
|
56
58
|
def file_path
|
57
|
-
File.join(DomoscioRails.configuration.temp_dir,
|
59
|
+
File.join(DomoscioRails.configuration.temp_dir, 'DomoscioRails.AuthorizationToken.FileStore.tmp')
|
58
60
|
end
|
59
61
|
end
|
60
62
|
end
|
61
|
-
end
|
63
|
+
end
|
@@ -1,11 +1,9 @@
|
|
1
1
|
module DomoscioRails
|
2
2
|
class Content < Resource
|
3
|
-
|
4
3
|
include DomoscioRails::HTTPCalls::Create
|
5
4
|
include DomoscioRails::HTTPCalls::Fetch
|
6
5
|
include DomoscioRails::HTTPCalls::Update
|
7
6
|
include DomoscioRails::HTTPCalls::Destroy
|
8
7
|
include DomoscioRails::HTTPCalls::Util
|
9
|
-
|
10
8
|
end
|
11
|
-
end
|
9
|
+
end
|
@@ -1,10 +1,9 @@
|
|
1
1
|
module DomoscioRails
|
2
2
|
class LearningSession < Resource
|
3
|
-
|
4
3
|
include DomoscioRails::HTTPCalls::Create
|
5
4
|
include DomoscioRails::HTTPCalls::Fetch
|
6
5
|
include DomoscioRails::HTTPCalls::Destroy
|
6
|
+
include DomoscioRails::HTTPCalls::Update
|
7
7
|
include DomoscioRails::HTTPCalls::Util
|
8
|
-
|
9
8
|
end
|
10
|
-
end
|
9
|
+
end
|
@@ -1,10 +1,8 @@
|
|
1
1
|
module DomoscioRails
|
2
2
|
class Student < Resource
|
3
|
-
|
4
3
|
include DomoscioRails::HTTPCalls::Create
|
5
4
|
include DomoscioRails::HTTPCalls::Fetch
|
6
|
-
include DomoscioRails::HTTPCalls::Update
|
7
5
|
include DomoscioRails::HTTPCalls::Destroy
|
8
|
-
|
6
|
+
include DomoscioRails::HTTPCalls::Update
|
9
7
|
end
|
10
|
-
end
|
8
|
+
end
|
@@ -6,20 +6,36 @@ module DomoscioRails
|
|
6
6
|
# Error Message from AdaptiveEngine
|
7
7
|
class ResponseError < Error
|
8
8
|
attr_reader :request_url, :code, :details, :body, :request_params
|
9
|
+
|
9
10
|
def initialize(request_url, code, details = {}, body = nil, request_params = {})
|
10
|
-
@request_url
|
11
|
+
@request_url = request_url
|
12
|
+
@code = code
|
13
|
+
@details = details
|
14
|
+
@body = body
|
15
|
+
@request_params = request_params
|
11
16
|
super(message) if message
|
12
17
|
end
|
13
|
-
|
18
|
+
|
19
|
+
def message
|
20
|
+
@details.is_a?(Hash) && @details[:error].is_a?(Hash) ? @details.dig(:error, :message) : @details
|
21
|
+
end
|
14
22
|
end
|
15
23
|
|
16
24
|
# ProcessingError from DomoscioRails
|
17
25
|
class ProcessingError < Error
|
18
26
|
attr_reader :request_url, :code, :details, :body, :request_params
|
27
|
+
|
19
28
|
def initialize(request_url, code, details = {}, body = nil, request_params = {})
|
20
|
-
@request_url
|
29
|
+
@request_url = request_url
|
30
|
+
@code = code
|
31
|
+
@details = details
|
32
|
+
@body = body
|
33
|
+
@request_params = request_params
|
21
34
|
super(message) if message
|
22
35
|
end
|
23
|
-
|
36
|
+
|
37
|
+
def message
|
38
|
+
@details.message
|
39
|
+
end
|
24
40
|
end
|
25
|
-
end
|
41
|
+
end
|
@@ -8,6 +8,7 @@ module DomoscioRails
|
|
8
8
|
DomoscioRails.request(:post, url(id), params)
|
9
9
|
end
|
10
10
|
end
|
11
|
+
|
11
12
|
def self.included(base)
|
12
13
|
base.extend(ClassMethods)
|
13
14
|
end
|
@@ -19,6 +20,7 @@ module DomoscioRails
|
|
19
20
|
DomoscioRails.request(:put, url(id), params)
|
20
21
|
end
|
21
22
|
end
|
23
|
+
|
22
24
|
def self.included(base)
|
23
25
|
base.extend(ClassMethods)
|
24
26
|
end
|
@@ -64,6 +66,7 @@ module DomoscioRails
|
|
64
66
|
def util(id = nil, util_name = nil, params = {})
|
65
67
|
DomoscioRails.request(:get, url(id, util_name), params)
|
66
68
|
end
|
69
|
+
|
67
70
|
def util_post(id = nil, util_name = nil, params = {})
|
68
71
|
DomoscioRails.request(:post, url(id, util_name), params)
|
69
72
|
end
|
data/lib/domoscio_rails/json.rb
CHANGED
@@ -1,10 +1,8 @@
|
|
1
1
|
module DomoscioRails
|
2
2
|
class KnowledgeEdge < Resource
|
3
|
-
|
4
3
|
include DomoscioRails::HTTPCalls::Create
|
5
4
|
include DomoscioRails::HTTPCalls::Fetch
|
6
|
-
include DomoscioRails::HTTPCalls::Update
|
7
5
|
include DomoscioRails::HTTPCalls::Destroy
|
8
|
-
|
6
|
+
include DomoscioRails::HTTPCalls::Update
|
9
7
|
end
|
10
|
-
end
|
8
|
+
end
|
@@ -1,10 +1,8 @@
|
|
1
1
|
module DomoscioRails
|
2
2
|
class KnowledgeGraph < Resource
|
3
|
-
|
4
3
|
include DomoscioRails::HTTPCalls::Create
|
5
4
|
include DomoscioRails::HTTPCalls::Fetch
|
6
|
-
include DomoscioRails::HTTPCalls::Update
|
7
5
|
include DomoscioRails::HTTPCalls::Destroy
|
8
|
-
|
6
|
+
include DomoscioRails::HTTPCalls::Update
|
9
7
|
end
|
10
|
-
end
|
8
|
+
end
|
@@ -1,10 +1,8 @@
|
|
1
1
|
module DomoscioRails
|
2
2
|
class KnowledgeNode < Resource
|
3
|
-
|
4
3
|
include DomoscioRails::HTTPCalls::Create
|
5
4
|
include DomoscioRails::HTTPCalls::Fetch
|
6
|
-
include DomoscioRails::HTTPCalls::Update
|
7
5
|
include DomoscioRails::HTTPCalls::Destroy
|
8
|
-
|
6
|
+
include DomoscioRails::HTTPCalls::Update
|
9
7
|
end
|
10
|
-
end
|
8
|
+
end
|
@@ -1,10 +1,8 @@
|
|
1
1
|
module DomoscioRails
|
2
2
|
class KnowledgeNodeContent < Resource
|
3
|
-
|
4
3
|
include DomoscioRails::HTTPCalls::Create
|
5
4
|
include DomoscioRails::HTTPCalls::Fetch
|
6
|
-
include DomoscioRails::HTTPCalls::Update
|
7
5
|
include DomoscioRails::HTTPCalls::Destroy
|
8
|
-
|
6
|
+
include DomoscioRails::HTTPCalls::Update
|
9
7
|
end
|
10
|
-
end
|
8
|
+
end
|
@@ -1,10 +1,8 @@
|
|
1
1
|
module DomoscioRails
|
2
2
|
class Objective < Resource
|
3
|
-
|
4
3
|
include DomoscioRails::HTTPCalls::Create
|
5
4
|
include DomoscioRails::HTTPCalls::Fetch
|
6
|
-
include DomoscioRails::HTTPCalls::Update
|
7
5
|
include DomoscioRails::HTTPCalls::Destroy
|
8
|
-
|
6
|
+
include DomoscioRails::HTTPCalls::Update
|
9
7
|
end
|
10
|
-
end
|
8
|
+
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
module DomoscioRails
|
2
2
|
class ObjectiveKnowledgeNodeStudent < Resource
|
3
|
-
|
3
|
+
include DomoscioRails::HTTPCalls::Create
|
4
4
|
include DomoscioRails::HTTPCalls::Fetch
|
5
|
+
include DomoscioRails::HTTPCalls::Destroy
|
5
6
|
include DomoscioRails::HTTPCalls::Update
|
6
|
-
|
7
7
|
end
|
8
|
-
end
|
8
|
+
end
|
@@ -1,11 +1,9 @@
|
|
1
1
|
module DomoscioRails
|
2
2
|
class ObjectiveStudent < Resource
|
3
|
-
|
4
3
|
include DomoscioRails::HTTPCalls::Create
|
5
4
|
include DomoscioRails::HTTPCalls::Fetch
|
6
|
-
include DomoscioRails::HTTPCalls::Update
|
7
5
|
include DomoscioRails::HTTPCalls::Destroy
|
6
|
+
include DomoscioRails::HTTPCalls::Update
|
8
7
|
include DomoscioRails::HTTPCalls::Util
|
9
|
-
|
10
8
|
end
|
11
9
|
end
|
@@ -4,22 +4,26 @@ module DomoscioRails
|
|
4
4
|
def class_name
|
5
5
|
name.split('::')[-1]
|
6
6
|
end
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
7
|
+
|
8
|
+
def url(id = nil, util_name = nil, on_self = nil)
|
9
|
+
raise NotImplementedError, 'Resource is an abstract class. Do not use it directly.' if self == Resource
|
10
|
+
|
11
11
|
build_url = "/v#{DomoscioRails.configuration.version}/instances/#{DomoscioRails.configuration.client_id}"
|
12
|
-
|
13
|
-
build_url << "/#{class_name
|
14
|
-
if util_name
|
15
|
-
|
16
|
-
end
|
17
|
-
if id
|
18
|
-
build_url << "/#{CGI.escape(id.to_s)}"
|
19
|
-
end
|
12
|
+
unless on_self
|
13
|
+
build_url << "/#{underscore(class_name)}s"
|
14
|
+
build_url << "/#{util_name}" if util_name
|
15
|
+
build_url << "/#{CGI.escape(id.to_s)}" if id
|
20
16
|
end
|
21
|
-
|
17
|
+
build_url
|
18
|
+
end
|
19
|
+
|
20
|
+
def underscore(string)
|
21
|
+
string.gsub(/::/, '/')
|
22
|
+
.gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
|
23
|
+
.gsub(/([a-z\d])([A-Z])/, '\1_\2')
|
24
|
+
.tr('-', '_')
|
25
|
+
.downcase
|
22
26
|
end
|
23
27
|
end
|
24
28
|
end
|
25
|
-
end
|
29
|
+
end
|
@@ -1,10 +1,8 @@
|
|
1
1
|
module DomoscioRails
|
2
2
|
class Tag < Resource
|
3
|
-
|
4
3
|
include DomoscioRails::HTTPCalls::Create
|
5
4
|
include DomoscioRails::HTTPCalls::Fetch
|
6
|
-
include DomoscioRails::HTTPCalls::Update
|
7
5
|
include DomoscioRails::HTTPCalls::Destroy
|
8
|
-
|
6
|
+
include DomoscioRails::HTTPCalls::Update
|
9
7
|
end
|
10
|
-
end
|
8
|
+
end
|
@@ -1,10 +1,8 @@
|
|
1
1
|
module DomoscioRails
|
2
2
|
class TagEdge < Resource
|
3
|
-
|
4
3
|
include DomoscioRails::HTTPCalls::Create
|
5
4
|
include DomoscioRails::HTTPCalls::Fetch
|
6
|
-
include DomoscioRails::HTTPCalls::Update
|
7
5
|
include DomoscioRails::HTTPCalls::Destroy
|
8
|
-
|
6
|
+
include DomoscioRails::HTTPCalls::Update
|
9
7
|
end
|
10
|
-
end
|
8
|
+
end
|
@@ -1,10 +1,8 @@
|
|
1
1
|
module DomoscioRails
|
2
2
|
class TagSet < Resource
|
3
|
-
|
4
3
|
include DomoscioRails::HTTPCalls::Create
|
5
4
|
include DomoscioRails::HTTPCalls::Fetch
|
6
|
-
include DomoscioRails::HTTPCalls::Update
|
7
5
|
include DomoscioRails::HTTPCalls::Destroy
|
8
|
-
|
6
|
+
include DomoscioRails::HTTPCalls::Update
|
9
7
|
end
|
10
|
-
end
|
8
|
+
end
|
@@ -1,10 +1,8 @@
|
|
1
1
|
module DomoscioRails
|
2
2
|
class Tagging < Resource
|
3
|
-
|
4
3
|
include DomoscioRails::HTTPCalls::Create
|
5
4
|
include DomoscioRails::HTTPCalls::Fetch
|
6
|
-
include DomoscioRails::HTTPCalls::Update
|
7
5
|
include DomoscioRails::HTTPCalls::Destroy
|
8
|
-
|
6
|
+
include DomoscioRails::HTTPCalls::Update
|
9
7
|
end
|
10
|
-
end
|
8
|
+
end
|
@@ -1,3 +1,3 @@
|
|
1
1
|
module DomoscioRails
|
2
|
-
VERSION =
|
3
|
-
end
|
2
|
+
VERSION = '0.4.2'.freeze
|
3
|
+
end
|
data/lib/domoscio_rails.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
|
2
1
|
require 'net/https'
|
3
2
|
require 'cgi/util'
|
4
3
|
require 'multi_json'
|
@@ -10,40 +9,41 @@ require 'domoscio_rails/authorization_token'
|
|
10
9
|
# resources
|
11
10
|
require 'domoscio_rails/http_calls'
|
12
11
|
require 'domoscio_rails/resource'
|
13
|
-
require 'domoscio_rails/data/content
|
14
|
-
require 'domoscio_rails/data/event
|
15
|
-
require 'domoscio_rails/data/instance
|
16
|
-
require 'domoscio_rails/data/recommendation
|
17
|
-
require 'domoscio_rails/data/learning_session
|
18
|
-
require 'domoscio_rails/data/student
|
19
|
-
require 'domoscio_rails/
|
20
|
-
require 'domoscio_rails/knowledge/
|
21
|
-
require 'domoscio_rails/knowledge/
|
22
|
-
require 'domoscio_rails/knowledge/
|
23
|
-
require 'domoscio_rails/knowledge/
|
24
|
-
require 'domoscio_rails/
|
25
|
-
require 'domoscio_rails/objective/
|
26
|
-
require 'domoscio_rails/objective/
|
27
|
-
require 'domoscio_rails/objective/
|
28
|
-
require 'domoscio_rails/
|
29
|
-
require 'domoscio_rails/tag/
|
30
|
-
require 'domoscio_rails/tag/
|
31
|
-
require 'domoscio_rails/tag/
|
32
|
-
require 'domoscio_rails/
|
33
|
-
require 'domoscio_rails/utils/
|
34
|
-
require 'domoscio_rails/utils/
|
12
|
+
require 'domoscio_rails/data/content'
|
13
|
+
require 'domoscio_rails/data/event'
|
14
|
+
require 'domoscio_rails/data/instance'
|
15
|
+
require 'domoscio_rails/data/recommendation'
|
16
|
+
require 'domoscio_rails/data/learning_session'
|
17
|
+
require 'domoscio_rails/data/student'
|
18
|
+
require 'domoscio_rails/data/student_group'
|
19
|
+
require 'domoscio_rails/knowledge/knowledge_edge'
|
20
|
+
require 'domoscio_rails/knowledge/knowledge_graph'
|
21
|
+
require 'domoscio_rails/knowledge/knowledge_node_content'
|
22
|
+
require 'domoscio_rails/knowledge/knowledge_node_student'
|
23
|
+
require 'domoscio_rails/knowledge/knowledge_node'
|
24
|
+
require 'domoscio_rails/objective/objective_knowledge_node_student'
|
25
|
+
require 'domoscio_rails/objective/objective_knowledge_node'
|
26
|
+
require 'domoscio_rails/objective/objective_student'
|
27
|
+
require 'domoscio_rails/objective/objective'
|
28
|
+
require 'domoscio_rails/tag/tag_edge'
|
29
|
+
require 'domoscio_rails/tag/tag_set'
|
30
|
+
require 'domoscio_rails/tag/tag'
|
31
|
+
require 'domoscio_rails/tag/tagging'
|
32
|
+
require 'domoscio_rails/utils/gameplay_util'
|
33
|
+
require 'domoscio_rails/utils/recommendation_util'
|
34
|
+
require 'domoscio_rails/utils/review_util'
|
35
|
+
require 'domoscio_rails/utils/stats_util'
|
35
36
|
|
36
37
|
module DomoscioRails
|
38
|
+
# Configurable attributes and default values
|
37
39
|
class Configuration
|
38
|
-
attr_accessor :
|
39
|
-
|
40
|
-
# Refers to AdaptiveEngine Version
|
41
|
-
def version
|
42
|
-
@version ||= 2
|
43
|
-
end
|
40
|
+
attr_accessor :client_id, :client_passphrase, :temp_dir, :version,
|
41
|
+
:root_url, :file_storage, :access_token, :refresh_token
|
44
42
|
|
45
|
-
def
|
46
|
-
@
|
43
|
+
def initialize
|
44
|
+
@version = 2
|
45
|
+
@root_url = ''
|
46
|
+
@file_storage ||= true
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
@@ -56,7 +56,7 @@ module DomoscioRails
|
|
56
56
|
yield configuration
|
57
57
|
end
|
58
58
|
|
59
|
-
def self.api_uri(url='')
|
59
|
+
def self.api_uri(url = '')
|
60
60
|
URI(configuration.root_url + url)
|
61
61
|
end
|
62
62
|
|
@@ -72,76 +72,77 @@ module DomoscioRails
|
|
72
72
|
# Raises DomoscioRails::ProcessingError on Internal Error
|
73
73
|
#
|
74
74
|
def self.request(method, url, params={})
|
75
|
-
|
76
75
|
store_tokens, headers = request_headers
|
77
|
-
params.merge!({'per_page':
|
76
|
+
params.merge!({ 'per_page': 1000 }) unless params[:per_page]
|
78
77
|
uri = api_uri(url)
|
79
|
-
|
80
78
|
response = DomoscioRails.send_request(uri, method, params, headers)
|
81
|
-
return response if response.
|
79
|
+
return response if response.is_a? DomoscioRails::ProcessingError
|
82
80
|
|
83
81
|
begin
|
84
82
|
raise_http_failure(uri, response, params)
|
85
83
|
data = DomoscioRails::JSON.load(response.body.nil? ? '' : response.body)
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
84
|
+
if store_tokens
|
85
|
+
DomoscioRails::AuthorizationToken::Manager.storage.store({
|
86
|
+
access_token: response['Accesstoken'],
|
87
|
+
refresh_token: response['Refreshtoken']
|
88
|
+
})
|
89
|
+
end
|
90
|
+
rescue MultiJson::LoadError => e
|
91
|
+
data = ProcessingError.new(uri, 500, e, response.body, params)
|
92
|
+
rescue ResponseError => e
|
93
|
+
data = e
|
91
94
|
end
|
92
95
|
|
93
96
|
if response['Total']
|
94
97
|
pagetotal = (response['Total'].to_i / response['Per-Page'].to_f).ceil
|
95
|
-
|
96
|
-
response = DomoscioRails.send_request(uri, method, params.merge({page: j}), headers)
|
97
|
-
return response if response.
|
98
|
+
(2..pagetotal).each do |j|
|
99
|
+
response = DomoscioRails.send_request(uri, method, params.merge({ page: j }), headers)
|
100
|
+
return response if response.is_a? DomoscioRails::ProcessingError
|
101
|
+
|
98
102
|
begin
|
99
103
|
raise_http_failure(uri, response, params)
|
100
104
|
body = DomoscioRails::JSON.load(response.body.nil? ? '' : response.body)
|
101
105
|
data += body
|
102
106
|
data.flatten!
|
103
|
-
rescue MultiJson::LoadError =>
|
104
|
-
return ProcessingError.new(uri, 500,
|
105
|
-
rescue ResponseError =>
|
106
|
-
return
|
107
|
+
rescue MultiJson::LoadError => e
|
108
|
+
return ProcessingError.new(uri, 500, e, response.body, params)
|
109
|
+
rescue ResponseError => e
|
110
|
+
return e
|
107
111
|
end
|
108
112
|
end
|
109
113
|
end
|
110
114
|
data
|
111
115
|
end
|
112
116
|
|
113
|
-
|
114
|
-
|
115
|
-
# This function catches usual Http errors during calls
|
117
|
+
# This function catches usual Http errors during callsheaders
|
116
118
|
#
|
117
119
|
def self.send_request(uri, method, params, headers)
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
end
|
120
|
+
response = perform_call(uri, method, params, headers)
|
121
|
+
response = retry_call_and_store_tokens(uri, method, params) if %w[401 403].include? response.code
|
122
|
+
response
|
123
|
+
rescue Timeout::Error, Errno::EINVAL, Errno::ECONNREFUSED, Errno::ECONNRESET,
|
124
|
+
EOFError, Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError => e
|
125
|
+
ProcessingError.new(uri, 500, e, response)
|
125
126
|
end
|
126
127
|
|
127
128
|
# This helper will check the response status and build the correcponding DomoscioRails::ResponseError
|
128
129
|
#
|
129
130
|
def self.raise_http_failure(uri, response, params)
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
131
|
+
return if response.is_a? Net::HTTPSuccess
|
132
|
+
|
133
|
+
raise ResponseError.new(
|
134
|
+
uri,
|
135
|
+
response.code.to_i,
|
136
|
+
DomoscioRails::JSON.load((response.body.nil? ? '' : response.body), symbolize_keys: true),
|
137
|
+
response.body, params
|
138
|
+
)
|
138
139
|
end
|
139
140
|
|
140
141
|
# Actual HTTP call is performed here
|
141
142
|
#
|
142
143
|
def self.perform_call(uri, method, params, headers)
|
143
144
|
Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == 'https') do |http|
|
144
|
-
req = Net::HTTP
|
145
|
+
req = Net::HTTP.const_get(method.capitalize).new(uri.request_uri, headers)
|
145
146
|
req.body = DomoscioRails::JSON.dump(params)
|
146
147
|
http.request req
|
147
148
|
end
|
@@ -149,26 +150,29 @@ module DomoscioRails
|
|
149
150
|
|
150
151
|
# This method is called when AdaptiveEngine returns tokens errors
|
151
152
|
# Action on those errors is to retry and request new tokens, those new token are then stored
|
152
|
-
def self.retry_call_and_store_tokens(uri, method, params
|
153
|
+
def self.retry_call_and_store_tokens(uri, method, params)
|
153
154
|
headers = request_new_tokens
|
154
155
|
response = perform_call(uri, method, params, headers)
|
155
|
-
DomoscioRails::AuthorizationToken::Manager.storage.store({
|
156
|
+
DomoscioRails::AuthorizationToken::Manager.storage.store({
|
157
|
+
access_token: response['Accesstoken'],
|
158
|
+
refresh_token: response['Refreshtoken']
|
159
|
+
})
|
156
160
|
response
|
157
161
|
end
|
158
162
|
|
159
163
|
def self.user_agent
|
160
|
-
@uname ||=
|
164
|
+
@uname ||= uname
|
161
165
|
{
|
162
166
|
bindings_version: DomoscioRails::VERSION,
|
163
167
|
lang: 'ruby',
|
164
168
|
lang_version: "#{RUBY_VERSION} p#{RUBY_PATCHLEVEL} (#{RUBY_RELEASE_DATE})",
|
165
169
|
platform: RUBY_PLATFORM,
|
166
170
|
uname: @uname
|
167
|
-
}
|
171
|
+
}.to_s
|
168
172
|
end
|
169
173
|
|
170
|
-
def self.
|
171
|
-
`uname -a 2>/dev/null
|
174
|
+
def self.uname
|
175
|
+
`uname -a 2>/dev/null` if RUBY_PLATFORM =~ /linux|darwin/i
|
172
176
|
rescue Errno::ENOMEM
|
173
177
|
'uname lookup failed'
|
174
178
|
end
|
@@ -177,25 +181,23 @@ module DomoscioRails
|
|
177
181
|
# will return the processed headers and a token store flag
|
178
182
|
#
|
179
183
|
def self.request_headers
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
else
|
185
|
-
[true, request_new_tokens]
|
186
|
-
end
|
187
|
-
rescue SyntaxError, StandardError
|
184
|
+
auth_token = DomoscioRails::AuthorizationToken::Manager.token
|
185
|
+
if auth_token && auth_token[:access_token] && auth_token[:refresh_token]
|
186
|
+
[false, send_current_tokens(auth_token)]
|
187
|
+
else
|
188
188
|
[true, request_new_tokens]
|
189
189
|
end
|
190
|
+
rescue SyntaxError, StandardError
|
191
|
+
[true, request_new_tokens]
|
190
192
|
end
|
191
193
|
|
192
194
|
# If stored token successfully loaded we build the header with them
|
193
195
|
#
|
194
196
|
def self.send_current_tokens(auth_token)
|
195
197
|
{
|
196
|
-
'user_agent' =>
|
197
|
-
'AccessToken' =>
|
198
|
-
'RefreshToken' =>
|
198
|
+
'user_agent' => DomoscioRails.user_agent.to_s,
|
199
|
+
'AccessToken' => auth_token[:access_token].to_s,
|
200
|
+
'RefreshToken' => auth_token[:refresh_token].to_s,
|
199
201
|
'Content-Type' => 'application/json'
|
200
202
|
}
|
201
203
|
end
|
@@ -203,9 +205,9 @@ module DomoscioRails
|
|
203
205
|
# If we cant find tokens of they are corrupted / expired, then we set headers to request new ones
|
204
206
|
def self.request_new_tokens
|
205
207
|
{
|
206
|
-
'user_agent' =>
|
208
|
+
'user_agent' => DomoscioRails.user_agent.to_s,
|
207
209
|
'Authorization' => "Token token=#{DomoscioRails.configuration.client_passphrase}",
|
208
210
|
'Content-Type' => 'application/json'
|
209
211
|
}
|
210
212
|
end
|
211
|
-
end
|
213
|
+
end
|
metadata
CHANGED
@@ -1,29 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: domoscio_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Benoit Praly
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-02-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: multi_json
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 1.15.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 1.15.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: yaml
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.2.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.2.0
|
27
41
|
description: Ruby client to interact with Domoscio API.
|
28
42
|
email:
|
29
43
|
- benoit.praly@domoscio.com
|
@@ -43,6 +57,7 @@ files:
|
|
43
57
|
- lib/domoscio_rails/data/learning_session.rb
|
44
58
|
- lib/domoscio_rails/data/recommendation.rb
|
45
59
|
- lib/domoscio_rails/data/student.rb
|
60
|
+
- lib/domoscio_rails/data/student_group.rb
|
46
61
|
- lib/domoscio_rails/errors.rb
|
47
62
|
- lib/domoscio_rails/http_calls.rb
|
48
63
|
- lib/domoscio_rails/json.rb
|
@@ -63,12 +78,13 @@ files:
|
|
63
78
|
- lib/domoscio_rails/utils/gameplay_util.rb
|
64
79
|
- lib/domoscio_rails/utils/recommendation_util.rb
|
65
80
|
- lib/domoscio_rails/utils/review_util.rb
|
81
|
+
- lib/domoscio_rails/utils/stats_util.rb
|
66
82
|
- lib/domoscio_rails/version.rb
|
67
83
|
homepage: http://www.domoscio.com
|
68
84
|
licenses:
|
69
85
|
- MIT
|
70
86
|
metadata: {}
|
71
|
-
post_install_message:
|
87
|
+
post_install_message:
|
72
88
|
rdoc_options: []
|
73
89
|
require_paths:
|
74
90
|
- lib
|
@@ -76,15 +92,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
76
92
|
requirements:
|
77
93
|
- - ">="
|
78
94
|
- !ruby/object:Gem::Version
|
79
|
-
version:
|
95
|
+
version: 2.5.0
|
80
96
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
81
97
|
requirements:
|
82
98
|
- - ">="
|
83
99
|
- !ruby/object:Gem::Version
|
84
100
|
version: '0'
|
85
101
|
requirements: []
|
86
|
-
rubygems_version: 3.
|
87
|
-
signing_key:
|
102
|
+
rubygems_version: 3.2.22
|
103
|
+
signing_key:
|
88
104
|
specification_version: 4
|
89
|
-
summary: Summary of
|
105
|
+
summary: Summary of DomoscioRailspec.
|
90
106
|
test_files: []
|