domoscio_rails 0.3.8a → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- 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 +1 -3
- data/lib/domoscio_rails/data/recommendation.rb +1 -3
- data/lib/domoscio_rails/data/student.rb +1 -3
- 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 +1 -3
- data/lib/domoscio_rails/knowledge/knowledge_graph.rb +1 -3
- data/lib/domoscio_rails/knowledge/knowledge_node.rb +1 -3
- data/lib/domoscio_rails/knowledge/knowledge_node_content.rb +1 -3
- data/lib/domoscio_rails/knowledge/knowledge_node_student.rb +1 -3
- data/lib/domoscio_rails/objective/objective.rb +1 -3
- data/lib/domoscio_rails/objective/objective_knowledge_node.rb +1 -3
- data/lib/domoscio_rails/objective/objective_knowledge_node_student.rb +1 -3
- data/lib/domoscio_rails/objective/objective_student.rb +0 -2
- data/lib/domoscio_rails/resource.rb +18 -14
- data/lib/domoscio_rails/tag/tag.rb +1 -3
- data/lib/domoscio_rails/tag/tag_edge.rb +1 -3
- data/lib/domoscio_rails/tag/tag_set.rb +1 -3
- data/lib/domoscio_rails/tag/tagging.rb +1 -3
- 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 +87 -85
- metadata +26 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '08866a1127ae568832a117fb457edb8e4226e7bb44a43ac44c6ea1fce170b93e'
|
4
|
+
data.tar.gz: c14755b4ae0c66e4689c92782c516350fed8f7c09531a1d96e760d1dad01f04d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7acb60e8e5b7a9e028e996ced65d694f32d72cebac1706d22a264a8b75e83afabb1992605f191f0d0ef167d6a95a24ec7e6d18e78705cd7386202d96a1aa7cb2
|
7
|
+
data.tar.gz: 3b19813c8511d09ee6e52ed3946580ba2975ecb32d7b94318319e4c4b434195883e2b6ca7de549b0a45164e723d8254993a357b7f718bb30e439aac24dc288e7
|
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,11 +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
|
7
6
|
include DomoscioRails::HTTPCalls::Update
|
8
7
|
include DomoscioRails::HTTPCalls::Util
|
9
|
-
|
10
8
|
end
|
11
|
-
end
|
9
|
+
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 ObjectiveKnowledgeNodeStudent < Resource
|
3
|
-
|
4
3
|
include DomoscioRails::HTTPCalls::Create
|
5
4
|
include DomoscioRails::HTTPCalls::Fetch
|
6
5
|
include DomoscioRails::HTTPCalls::Destroy
|
7
6
|
include DomoscioRails::HTTPCalls::Update
|
8
|
-
|
9
7
|
end
|
10
|
-
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
5
|
include DomoscioRails::HTTPCalls::Destroy
|
7
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,3 +1,3 @@
|
|
1
1
|
module DomoscioRails
|
2
|
-
VERSION =
|
3
|
-
end
|
2
|
+
VERSION = '0.4.1'.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,40 @@ 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/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
|
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/knowledge/knowledge_edge'
|
19
|
+
require 'domoscio_rails/knowledge/knowledge_graph'
|
20
|
+
require 'domoscio_rails/knowledge/knowledge_node_content'
|
21
|
+
require 'domoscio_rails/knowledge/knowledge_node_student'
|
22
|
+
require 'domoscio_rails/knowledge/knowledge_node'
|
23
|
+
require 'domoscio_rails/objective/objective_knowledge_node_student'
|
24
|
+
require 'domoscio_rails/objective/objective_knowledge_node'
|
25
|
+
require 'domoscio_rails/objective/objective_student'
|
26
|
+
require 'domoscio_rails/objective/objective'
|
27
|
+
require 'domoscio_rails/tag/tag_edge'
|
28
|
+
require 'domoscio_rails/tag/tag_set'
|
29
|
+
require 'domoscio_rails/tag/tag'
|
30
|
+
require 'domoscio_rails/tag/tagging'
|
31
|
+
require 'domoscio_rails/utils/gameplay_util'
|
32
|
+
require 'domoscio_rails/utils/recommendation_util'
|
33
|
+
require 'domoscio_rails/utils/review_util'
|
34
|
+
require 'domoscio_rails/utils/stats_util'
|
35
35
|
|
36
36
|
module DomoscioRails
|
37
|
+
# Configurable attributes and default values
|
37
38
|
class Configuration
|
38
|
-
attr_accessor :
|
39
|
-
|
40
|
-
# Refers to AdaptiveEngine Version
|
41
|
-
def version
|
42
|
-
@version ||= 2
|
43
|
-
end
|
39
|
+
attr_accessor :client_id, :client_passphrase, :temp_dir, :version,
|
40
|
+
:root_url, :file_storage, :access_token, :refresh_token
|
44
41
|
|
45
|
-
def
|
46
|
-
@
|
42
|
+
def initialize
|
43
|
+
@version = 2
|
44
|
+
@root_url = ''
|
45
|
+
@file_storage ||= true
|
47
46
|
end
|
48
47
|
end
|
49
48
|
|
@@ -56,7 +55,7 @@ module DomoscioRails
|
|
56
55
|
yield configuration
|
57
56
|
end
|
58
57
|
|
59
|
-
def self.api_uri(url='')
|
58
|
+
def self.api_uri(url = '')
|
60
59
|
URI(configuration.root_url + url)
|
61
60
|
end
|
62
61
|
|
@@ -72,75 +71,77 @@ module DomoscioRails
|
|
72
71
|
# Raises DomoscioRails::ProcessingError on Internal Error
|
73
72
|
#
|
74
73
|
def self.request(method, url, params={})
|
75
|
-
|
76
74
|
store_tokens, headers = request_headers
|
77
|
-
params.merge!({'per_page':
|
75
|
+
params.merge!({ 'per_page': 1000 }) unless params[:per_page]
|
78
76
|
uri = api_uri(url)
|
79
|
-
|
80
77
|
response = DomoscioRails.send_request(uri, method, params, headers)
|
81
|
-
return response if response.
|
78
|
+
return response if response.is_a? DomoscioRails::ProcessingError
|
82
79
|
|
83
80
|
begin
|
84
81
|
raise_http_failure(uri, response, params)
|
85
82
|
data = DomoscioRails::JSON.load(response.body.nil? ? '' : response.body)
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
83
|
+
if store_tokens
|
84
|
+
DomoscioRails::AuthorizationToken::Manager.storage.store({
|
85
|
+
access_token: response['Accesstoken'],
|
86
|
+
refresh_token: response['Refreshtoken']
|
87
|
+
})
|
88
|
+
end
|
89
|
+
rescue MultiJson::LoadError => e
|
90
|
+
data = ProcessingError.new(uri, 500, e, response.body, params)
|
91
|
+
rescue ResponseError => e
|
92
|
+
data = e
|
91
93
|
end
|
92
94
|
|
93
95
|
if response['Total']
|
94
96
|
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.
|
97
|
+
(2..pagetotal).each do |j|
|
98
|
+
response = DomoscioRails.send_request(uri, method, params.merge({ page: j }), headers)
|
99
|
+
return response if response.is_a? DomoscioRails::ProcessingError
|
100
|
+
|
98
101
|
begin
|
99
102
|
raise_http_failure(uri, response, params)
|
100
103
|
body = DomoscioRails::JSON.load(response.body.nil? ? '' : response.body)
|
101
104
|
data += body
|
102
105
|
data.flatten!
|
103
|
-
rescue MultiJson::LoadError =>
|
104
|
-
return ProcessingError.new(uri, 500,
|
105
|
-
rescue ResponseError =>
|
106
|
-
return
|
106
|
+
rescue MultiJson::LoadError => e
|
107
|
+
return ProcessingError.new(uri, 500, e, response.body, params)
|
108
|
+
rescue ResponseError => e
|
109
|
+
return e
|
107
110
|
end
|
108
111
|
end
|
109
112
|
end
|
110
113
|
data
|
111
114
|
end
|
112
115
|
|
113
|
-
|
114
|
-
|
115
|
-
# This function catches usual Http errors during calls
|
116
|
+
# This function catches usual Http errors during callsheaders
|
116
117
|
#
|
117
118
|
def self.send_request(uri, method, params, headers)
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
end
|
119
|
+
response = perform_call(uri, method, params, headers)
|
120
|
+
response = retry_call_and_store_tokens(uri, method, params) if %w[401 403].include? response.code
|
121
|
+
response
|
122
|
+
rescue Timeout::Error, Errno::EINVAL, Errno::ECONNREFUSED, Errno::ECONNRESET,
|
123
|
+
EOFError, Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError => e
|
124
|
+
ProcessingError.new(uri, 500, e, response)
|
125
125
|
end
|
126
126
|
|
127
127
|
# This helper will check the response status and build the correcponding DomoscioRails::ResponseError
|
128
128
|
#
|
129
129
|
def self.raise_http_failure(uri, response, params)
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
130
|
+
return if response.is_a? Net::HTTPSuccess
|
131
|
+
|
132
|
+
raise ResponseError.new(
|
133
|
+
uri,
|
134
|
+
response.code.to_i,
|
135
|
+
DomoscioRails::JSON.load((response.body.nil? ? '' : response.body), symbolize_keys: true),
|
136
|
+
response.body, params
|
137
|
+
)
|
137
138
|
end
|
138
139
|
|
139
140
|
# Actual HTTP call is performed here
|
140
141
|
#
|
141
142
|
def self.perform_call(uri, method, params, headers)
|
142
143
|
Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == 'https') do |http|
|
143
|
-
req = Net::HTTP
|
144
|
+
req = Net::HTTP.const_get(method.capitalize).new(uri.request_uri, headers)
|
144
145
|
req.body = DomoscioRails::JSON.dump(params)
|
145
146
|
http.request req
|
146
147
|
end
|
@@ -148,26 +149,29 @@ module DomoscioRails
|
|
148
149
|
|
149
150
|
# This method is called when AdaptiveEngine returns tokens errors
|
150
151
|
# Action on those errors is to retry and request new tokens, those new token are then stored
|
151
|
-
def self.retry_call_and_store_tokens(uri, method, params
|
152
|
+
def self.retry_call_and_store_tokens(uri, method, params)
|
152
153
|
headers = request_new_tokens
|
153
154
|
response = perform_call(uri, method, params, headers)
|
154
|
-
DomoscioRails::AuthorizationToken::Manager.storage.store({
|
155
|
+
DomoscioRails::AuthorizationToken::Manager.storage.store({
|
156
|
+
access_token: response['Accesstoken'],
|
157
|
+
refresh_token: response['Refreshtoken']
|
158
|
+
})
|
155
159
|
response
|
156
160
|
end
|
157
161
|
|
158
162
|
def self.user_agent
|
159
|
-
@uname ||=
|
163
|
+
@uname ||= uname
|
160
164
|
{
|
161
165
|
bindings_version: DomoscioRails::VERSION,
|
162
166
|
lang: 'ruby',
|
163
167
|
lang_version: "#{RUBY_VERSION} p#{RUBY_PATCHLEVEL} (#{RUBY_RELEASE_DATE})",
|
164
168
|
platform: RUBY_PLATFORM,
|
165
169
|
uname: @uname
|
166
|
-
}
|
170
|
+
}.to_s
|
167
171
|
end
|
168
172
|
|
169
|
-
def self.
|
170
|
-
`uname -a 2>/dev/null
|
173
|
+
def self.uname
|
174
|
+
`uname -a 2>/dev/null` if RUBY_PLATFORM =~ /linux|darwin/i
|
171
175
|
rescue Errno::ENOMEM
|
172
176
|
'uname lookup failed'
|
173
177
|
end
|
@@ -176,25 +180,23 @@ module DomoscioRails
|
|
176
180
|
# will return the processed headers and a token store flag
|
177
181
|
#
|
178
182
|
def self.request_headers
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
else
|
184
|
-
[true, request_new_tokens]
|
185
|
-
end
|
186
|
-
rescue SyntaxError, StandardError
|
183
|
+
auth_token = DomoscioRails::AuthorizationToken::Manager.token
|
184
|
+
if auth_token && auth_token[:access_token] && auth_token[:refresh_token]
|
185
|
+
[false, send_current_tokens(auth_token)]
|
186
|
+
else
|
187
187
|
[true, request_new_tokens]
|
188
188
|
end
|
189
|
+
rescue SyntaxError, StandardError
|
190
|
+
[true, request_new_tokens]
|
189
191
|
end
|
190
192
|
|
191
193
|
# If stored token successfully loaded we build the header with them
|
192
194
|
#
|
193
195
|
def self.send_current_tokens(auth_token)
|
194
196
|
{
|
195
|
-
'user_agent' =>
|
196
|
-
'AccessToken' =>
|
197
|
-
'RefreshToken' =>
|
197
|
+
'user_agent' => DomoscioRails.user_agent.to_s,
|
198
|
+
'AccessToken' => auth_token[:access_token].to_s,
|
199
|
+
'RefreshToken' => auth_token[:refresh_token].to_s,
|
198
200
|
'Content-Type' => 'application/json'
|
199
201
|
}
|
200
202
|
end
|
@@ -202,9 +204,9 @@ module DomoscioRails
|
|
202
204
|
# If we cant find tokens of they are corrupted / expired, then we set headers to request new ones
|
203
205
|
def self.request_new_tokens
|
204
206
|
{
|
205
|
-
'user_agent' =>
|
207
|
+
'user_agent' => DomoscioRails.user_agent.to_s,
|
206
208
|
'Authorization' => "Token token=#{DomoscioRails.configuration.client_passphrase}",
|
207
209
|
'Content-Type' => 'application/json'
|
208
210
|
}
|
209
211
|
end
|
210
|
-
end
|
212
|
+
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.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: 2022-01-26 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
|
@@ -63,6 +77,7 @@ files:
|
|
63
77
|
- lib/domoscio_rails/utils/gameplay_util.rb
|
64
78
|
- lib/domoscio_rails/utils/recommendation_util.rb
|
65
79
|
- lib/domoscio_rails/utils/review_util.rb
|
80
|
+
- lib/domoscio_rails/utils/stats_util.rb
|
66
81
|
- lib/domoscio_rails/version.rb
|
67
82
|
homepage: http://www.domoscio.com
|
68
83
|
licenses:
|
@@ -76,15 +91,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
76
91
|
requirements:
|
77
92
|
- - ">="
|
78
93
|
- !ruby/object:Gem::Version
|
79
|
-
version:
|
94
|
+
version: 2.5.0
|
80
95
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
81
96
|
requirements:
|
82
|
-
- - "
|
97
|
+
- - ">="
|
83
98
|
- !ruby/object:Gem::Version
|
84
|
-
version:
|
99
|
+
version: '0'
|
85
100
|
requirements: []
|
86
101
|
rubygems_version: 3.1.2
|
87
102
|
signing_key:
|
88
103
|
specification_version: 4
|
89
|
-
summary: Summary of
|
104
|
+
summary: Summary of DomoscioRailspec.
|
90
105
|
test_files: []
|