domoscio_rails 0.2.10 → 0.2.24

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: 80036d711a50e0323cbd9f9fa260ebc9c9c6d194060f68b8be05d2ee7eab4206
4
+ data.tar.gz: 944991129c4a01704a0b24776d605ff926f408b48e17e998b1a525bcf43a469b
5
+ SHA512:
6
+ metadata.gz: ae6d858a4ca54802ff2504ee268fcacf8915cc45832fad48ba59c70daf1f49567112f5647b68dded5ab0056cef403cb77e52e9a06f341fc52f9ee45d52babd98
7
+ data.tar.gz: 01f77a383197e1e91b4b4c196d40098b44fec5a60eb2ec87a06ed34bde89633053000799b2920200d38b3b14266dda6e64cba292b34fdd726d54a4f1feb4109f
@@ -1,5 +1,5 @@
1
-
2
- require 'net/http'
1
+
2
+ require 'net/https'
3
3
  require 'cgi/util'
4
4
  require 'multi_json'
5
5
 
@@ -18,11 +18,12 @@ require 'domoscio_rails/adaptative/deterministic/rule_output'
18
18
  require 'domoscio_rails/adaptative/deterministic/rule_condition'
19
19
  require 'domoscio_rails/adaptative/predictive/objective'
20
20
  require 'domoscio_rails/adaptative/predictive/objective_student'
21
+ require 'domoscio_rails/adaptative/predictive/objective_knowledge_node'
22
+ require 'domoscio_rails/adaptative/predictive/objective_knowledge_node_student'
21
23
  require 'domoscio_rails/adaptative/recommendation'
22
24
  require 'domoscio_rails/path/learning_path'
23
25
  require 'domoscio_rails/content/content'
24
26
  require 'domoscio_rails/content/knowledge_node_content'
25
- require 'domoscio_rails/admin/user'
26
27
  require 'domoscio_rails/student/student'
27
28
  require 'domoscio_rails/student/student_cluster'
28
29
  require 'domoscio_rails/knowledge/knowledge_graph'
@@ -34,17 +35,18 @@ require 'domoscio_rails/metadata/tag_set'
34
35
  require 'domoscio_rails/metadata/tag_edge'
35
36
  require 'domoscio_rails/data/knowledge_node_student'
36
37
  require 'domoscio_rails/data/event'
38
+ require 'domoscio_rails/data/learning_session'
37
39
  require 'domoscio_rails/utils/review_util'
38
40
  require 'domoscio_rails/utils/gameplay_util'
39
-
41
+ require 'domoscio_rails/utils/alerts_util'
42
+ require 'domoscio_rails/utils/recommendation_util'
43
+ require 'domoscio_rails/metadata/delta_object'
40
44
 
41
45
  module DomoscioRails
42
46
 
43
47
  class Configuration
44
- attr_accessor :preproduction, :root_url,
45
- :client_id, :client_passphrase,
46
- :temp_dir, :disabled, :version
47
-
48
+ attr_accessor :preproduction, :test, :dev, :root_url, :client_id, :client_passphrase, :temp_dir, :disabled, :version
49
+
48
50
  def disabled
49
51
  @disabled || false
50
52
  end
@@ -52,13 +54,31 @@ module DomoscioRails
52
54
  def preproduction
53
55
  @preproduction || false
54
56
  end
55
-
57
+
58
+ def test
59
+ @test || false
60
+ end
61
+
62
+ def dev
63
+ @dev || false
64
+ end
65
+
56
66
  def version
57
67
  @version || 1
58
68
  end
59
69
 
60
70
  def root_url
61
- @root_url || (@preproduction == true ? ( @version > 1 ? "http://api.domoscio.com" : "http://stats-engine-api.domoscio.com" ) : "http://localhost:3001/")
71
+ if @preproduction == true
72
+ if @test == true
73
+ @root_url || "https://staging.adaptive-engine.domoscio.com"
74
+ elsif @dev == true
75
+ @root_url || "https://preprod.adaptive-engine.domoscio.com"
76
+ else
77
+ @root_url || "https://adaptive-engine.domoscio.com"
78
+ end
79
+ else
80
+ @root_url || "http://localhost:3001"
81
+ end
62
82
  end
63
83
  end
64
84
 
@@ -88,42 +108,50 @@ module DomoscioRails
88
108
  def self.request(method, url, params={}, filters={}, headers = request_headers, before_request_proc = nil)
89
109
  return false if @disabled
90
110
  uri = api_uri(url)
91
- uri.query = URI.encode_www_form(filters) unless filters.empty?
92
-
93
- res = Net::HTTP.start(uri.host, uri.port) do |http| # , use_ssl: uri.scheme == 'https') do |http|
94
- req = Net::HTTP::const_get(method.capitalize).new(uri.request_uri, headers)
95
- req.body = DomoscioRails::JSON.dump(params)
96
- before_request_proc.call(req) if before_request_proc
97
- http.request req
98
- end
111
+ uri.query = URI.encode_www_form(filters) unless filters.empty?
112
+
113
+ res = DomoscioRails.send_request(uri, method, params, headers, before_request_proc)
99
114
 
100
115
  # decode json data
101
116
  begin
102
117
  data = DomoscioRails::JSON.load(res.body.nil? ? '' : res.body)
118
+ unless (res.kind_of? Net::HTTPClientError) || (res.kind_of? Net::HTTPServerError)
119
+ DomoscioRails::AuthorizationToken::Manager.storage.store({access_token: res['Accesstoken'], refresh_token: res['Refreshtoken']})
120
+ end
103
121
  rescue MultiJson::LoadError
104
122
  data = {}
105
123
  end
106
124
 
107
- ############### TEMP!!!! #######################################################
108
- #pp method, uri.request_uri, params #, filters, headers
109
- #pp res, data
110
- #puts
125
+ if res['Total'] && !filters[:page]
126
+ pagetotal = (res['Total'].to_i / res['Per-Page'].to_f).ceil
111
127
 
112
- # if (!(res.is_a? Net::HTTPOK))
113
- # ex = DomoscioRails::ResponseError.new(uri, res.code, data)
114
- # ############## TEMP!!!! ########################################################
115
- # #pp ex, data
116
- # raise ex
117
- # end
128
+ for j in 2..pagetotal
129
+ params = params.merge({page: j})
130
+ res = DomoscioRails.send_request(uri, method, params, headers, before_request_proc)
118
131
 
119
- # copy pagination info if any
120
- # ['x-number-of-pages', 'x-number-of-items'].each { |k|
121
- # filters[k.gsub('x-number-of-', 'total_')] = res[k].to_i if res[k]
122
- # }
132
+ # decode json data
133
+ begin
134
+ data += DomoscioRails::JSON.load(res.body.nil? ? '' : res.body)
135
+ data.flatten!
136
+ rescue MultiJson::LoadError
137
+ data = {}
138
+ end
123
139
 
140
+ end
141
+ end
124
142
  data
125
143
  end
126
144
 
145
+
146
+ def self.send_request(uri, method, params, headers, before_request_proc)
147
+ res = Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == 'https') do |http| # , use_ssl: uri.scheme == 'https') do |http|
148
+ req = Net::HTTP::const_get(method.capitalize).new(uri.request_uri, headers)
149
+ req.body = DomoscioRails::JSON.dump(params)
150
+ before_request_proc.call(req) if before_request_proc
151
+ http.request req
152
+ end
153
+ end
154
+
127
155
  private
128
156
 
129
157
  def self.user_agent
@@ -146,17 +174,21 @@ module DomoscioRails
146
174
 
147
175
  def self.request_headers
148
176
  auth_token = DomoscioRails::AuthorizationToken::Manager.get_token
149
- headers = {
150
- 'user_agent' => "DomoscioRails V2 RubyBindings/#{DomoscioRails::VERSION}",
151
- 'Authorization' => "Token token=#{DomoscioRails.configuration.client_passphrase}",#"#{auth_token['token_type']} #{auth_token['access_token']}",
152
- 'Content-Type' => 'application/json'
153
- }
154
- # begin
155
- # headers.update('x_mangopay_client_user_agent' => DomoscioRails::JSON.dump(user_agent))
156
- # rescue => e
157
- # headers.update('x_mangopay_client_raw_user_agent' => user_agent.inspect, error: "#{e} (#{e.class})")
158
- # end
177
+
178
+ if !auth_token.is_a? String
179
+ headers = {
180
+ 'user_agent' => "DomoscioRails V2 RubyBindings/#{DomoscioRails::VERSION}",
181
+ 'AccessToken' => "#{auth_token[:access_token]}",
182
+ 'RefreshToken' => "#{auth_token[:refresh_token]}",
183
+ 'Content-Type' => 'application/json'
184
+ }
185
+ else
186
+ headers = {
187
+ 'user_agent' => "DomoscioRails V2 RubyBindings/#{DomoscioRails::VERSION}",
188
+ 'Authorization' => "Token token=#{DomoscioRails.configuration.client_passphrase}",#"#{auth_token['token_type']} #{auth_token['access_token']}",
189
+ 'Content-Type' => 'application/json'
190
+ }
191
+ end
192
+ headers
159
193
  end
160
-
161
-
162
194
  end
@@ -0,0 +1,6 @@
1
+ module DomoscioRails
2
+ # An objective knowledge node.
3
+ class ObjectiveKnowledgeNode < Resource
4
+ include DomoscioRails::HTTPCalls::Fetch
5
+ end
6
+ end
@@ -0,0 +1,7 @@
1
+ module DomoscioRails
2
+ # An objective knowledge node student.
3
+ class ObjectiveKnowledgeNodeStudent < Resource
4
+ include DomoscioRails::HTTPCalls::Fetch
5
+ include DomoscioRails::HTTPCalls::Update
6
+ end
7
+ end
@@ -5,5 +5,6 @@ module DomoscioRails
5
5
  include DomoscioRails::HTTPCalls::Fetch
6
6
  include DomoscioRails::HTTPCalls::Update
7
7
  include DomoscioRails::HTTPCalls::Destroy
8
+ include DomoscioRails::HTTPCalls::Util
8
9
  end
9
- end
10
+ end
@@ -5,7 +5,7 @@ module DomoscioRails
5
5
 
6
6
  class << self
7
7
  def storage
8
- @@storage ||= StaticStorage.new
8
+ @@storage ||= FileStorage.new
9
9
  end
10
10
 
11
11
  def storage= (storage)
@@ -13,17 +13,8 @@ module DomoscioRails
13
13
  end
14
14
 
15
15
  def get_token
16
- # token = storage.get
17
- # if token.nil? || token['timestamp'].nil? || token['timestamp'] <= Time.now
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
16
+ token = storage.get
17
+ token = DomoscioRails.configuration.client_passphrase if token.nil?
27
18
  token
28
19
  end
29
20
  end
@@ -72,6 +63,7 @@ module DomoscioRails
72
63
  end
73
64
 
74
65
  def file_path
66
+ @temp_dir = DomoscioRails.configuration.temp_dir if @temp_dir != DomoscioRails.configuration.temp_dir
75
67
  File.join(@temp_dir, "DomoscioRails.AuthorizationToken.FileStore.tmp")
76
68
  end
77
69
  end
@@ -0,0 +1,10 @@
1
+ module DomoscioRails
2
+ # A LearningSession is basicly a group of events.
3
+ class LearningSession < Resource
4
+
5
+ include DomoscioRails::HTTPCalls::Create
6
+ include DomoscioRails::HTTPCalls::Fetch
7
+ include DomoscioRails::HTTPCalls::Destroy
8
+
9
+ end
10
+ 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
@@ -0,0 +1,6 @@
1
+ module DomoscioRails
2
+ # A delta object.
3
+ class DeltaObject < Resource
4
+ include DomoscioRails::HTTPCalls::Fetch
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ module DomoscioRails
2
+ # A company.
3
+ class AlertsUtil < Resource
4
+ include DomoscioRails::HTTPCalls::Util
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ module DomoscioRails
2
+ # A company.
3
+ class RecommendationUtil < Resource
4
+ include DomoscioRails::HTTPCalls::Util
5
+ end
6
+ end
@@ -1,3 +1,3 @@
1
1
  module DomoscioRails
2
- VERSION = "0.2.10"
2
+ VERSION = "0.2.24"
3
3
  end
metadata CHANGED
@@ -1,51 +1,57 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: domoscio_rails
3
- version: !ruby/object:Gem::Version
4
- version: 0.2.10
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.24
5
5
  platform: ruby
6
- authors:
6
+ authors:
7
7
  - Benoit Praly
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
-
12
- date: 2017-01-18 00:00:00 +01:00
13
- default_executable:
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
11
+ date: 2020-11-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
16
14
  name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '3.2'
17
20
  type: :runtime
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
20
- requirements:
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
21
24
  - - ">="
22
- - !ruby/object:Gem::Version
23
- version: "3.2"
24
- version:
25
- description: Description of DomoscioRails.
26
- email:
25
+ - !ruby/object:Gem::Version
26
+ version: '3.2'
27
+ description: Ruby client to interact with Domoscio API.
28
+ email:
27
29
  - benoit.praly@domoscio.com
28
30
  executables: []
29
-
30
31
  extensions: []
31
-
32
32
  extra_rdoc_files: []
33
-
34
- files:
33
+ files:
34
+ - MIT-LICENSE
35
+ - README.rdoc
36
+ - Rakefile
37
+ - lib/domoscio_rails.rb
38
+ - lib/domoscio_rails.tbz
35
39
  - lib/domoscio_rails/adaptative/deterministic/path_rule.rb
36
40
  - lib/domoscio_rails/adaptative/deterministic/rule_condition.rb
37
41
  - lib/domoscio_rails/adaptative/deterministic/rule_input.rb
38
42
  - lib/domoscio_rails/adaptative/deterministic/rule_output.rb
39
43
  - lib/domoscio_rails/adaptative/predictive/objective.rb
44
+ - lib/domoscio_rails/adaptative/predictive/objective_knowledge_node.rb
45
+ - lib/domoscio_rails/adaptative/predictive/objective_knowledge_node_student.rb
40
46
  - lib/domoscio_rails/adaptative/predictive/objective_student.rb
41
47
  - lib/domoscio_rails/adaptative/recommendation.rb
42
48
  - lib/domoscio_rails/admin/instance.rb
43
- - lib/domoscio_rails/admin/user.rb
44
49
  - lib/domoscio_rails/authorization_token.rb
45
50
  - lib/domoscio_rails/content/content.rb
46
51
  - lib/domoscio_rails/content/knowledge_node_content.rb
47
52
  - lib/domoscio_rails/data/event.rb
48
53
  - lib/domoscio_rails/data/knowledge_node_student.rb
54
+ - lib/domoscio_rails/data/learning_session.rb
49
55
  - lib/domoscio_rails/data/result.rb
50
56
  - lib/domoscio_rails/errors.rb
51
57
  - lib/domoscio_rails/http_calls.rb
@@ -53,6 +59,7 @@ files:
53
59
  - lib/domoscio_rails/knowledge/knowledge_edge.rb
54
60
  - lib/domoscio_rails/knowledge/knowledge_graph.rb
55
61
  - lib/domoscio_rails/knowledge/knowledge_node.rb
62
+ - lib/domoscio_rails/metadata/delta_object.rb
56
63
  - lib/domoscio_rails/metadata/tag.rb
57
64
  - lib/domoscio_rails/metadata/tag_edge.rb
58
65
  - lib/domoscio_rails/metadata/tag_set.rb
@@ -61,42 +68,33 @@ files:
61
68
  - lib/domoscio_rails/resource.rb
62
69
  - lib/domoscio_rails/student/student.rb
63
70
  - lib/domoscio_rails/student/student_cluster.rb
71
+ - lib/domoscio_rails/utils/alerts_util.rb
64
72
  - lib/domoscio_rails/utils/gameplay_util.rb
73
+ - lib/domoscio_rails/utils/recommendation_util.rb
65
74
  - lib/domoscio_rails/utils/review_util.rb
66
75
  - lib/domoscio_rails/version.rb
67
- - lib/domoscio_rails.rb
68
- - lib/domoscio_rails.tbz
69
76
  - lib/tasks/domoscio_rails_tasks.rake
70
- - MIT-LICENSE
71
- - Rakefile
72
- - README.rdoc
73
- has_rdoc: true
74
77
  homepage: http://www.domoscio.com
75
- licenses:
78
+ licenses:
76
79
  - MIT
80
+ metadata: {}
77
81
  post_install_message:
78
82
  rdoc_options: []
79
-
80
- require_paths:
83
+ require_paths:
81
84
  - lib
82
- required_ruby_version: !ruby/object:Gem::Requirement
83
- requirements:
85
+ required_ruby_version: !ruby/object:Gem::Requirement
86
+ requirements:
84
87
  - - ">="
85
- - !ruby/object:Gem::Version
86
- version: "0"
87
- version:
88
- required_rubygems_version: !ruby/object:Gem::Requirement
89
- requirements:
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ requirements:
90
92
  - - ">="
91
- - !ruby/object:Gem::Version
92
- version: "0"
93
- version:
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
94
95
  requirements: []
95
-
96
- rubyforge_project:
97
- rubygems_version: 1.3.5
96
+ rubygems_version: 3.1.2
98
97
  signing_key:
99
- specification_version: 3
98
+ specification_version: 4
100
99
  summary: Summary of DomoscioRails.
101
100
  test_files: []
102
-
@@ -1,10 +0,0 @@
1
- module DomoscioRails
2
- # A user of the API.
3
- class User < Resource
4
-
5
- include DomoscioRails::HTTPCalls::Create
6
- include DomoscioRails::HTTPCalls::Fetch
7
- include DomoscioRails::HTTPCalls::Update
8
-
9
- end
10
- end