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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 578898574b898785e24a17847ba0d5ca5bab9f4d16cfde0d07beb248bab22576
4
- data.tar.gz: 8684d33aa002c0cc03126f930c72d9294e4b4f4020530b4c0d9677adc99c3382
3
+ metadata.gz: b0a7e03020d78226e29f7a2930c43cfb2fccbb4389b9d559b3bae047be4dbdf5
4
+ data.tar.gz: 63a5cfb591576eaa115737527a3f99f4d8140ae5eeb51403370bf970a0d7a438
5
5
  SHA512:
6
- metadata.gz: b56d9e5cfaacca82e7de548374c4f6961c67fba2747a64a4c26d2025ce99207320a743a8a670d777429b28890b178ec0ceab8236a580bcf8422045d8fa3c214f
7
- data.tar.gz: 20ca7f496caa70bb5b69454fb95b6eda21e0d77903062e4260e58f8878fbe2d03c9ccf62e7d5a6c79b5a4250d35418fe1a920c3793577a66c0c110d06965794b
6
+ metadata.gz: 809d75c75785aa76824e42caaed95c0ad5e4afabd07d06480ddec251d7813fdeb1383c259558ba87745b67aaf88bd1b6ed27784a70547b495c1b271893e1a3f6
7
+ data.tar.gz: ecebc9a43d22e8d835387a7632d0dedc3b29b156e4b48dfbb32666556eb87b202a5e23f70be29481d899013145d108414344d33d32a137cd56b92758cf8c7128
@@ -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://domoscio-adaptive-engine-staging.azurewebsites.net"
69
+ @root_url || "https://staging.adaptive-engine.domoscio.com"
75
70
  elsif @dev == true
76
- @root_url || "https://domoscio-adaptive-engine-preprod.azurewebsites.net"
71
+ @root_url || "https://preprod.adaptive-engine.domoscio.com"
77
72
  else
78
- @root_url || "https://domoscio-adaptive-engine.azurewebsites.net"
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
- unless (res.kind_of? Net::HTTPClientError) || (res.kind_of? Net::HTTPServerError)
120
- DomoscioRails::AuthorizationToken::Manager.storage.store({access_token: res['Accesstoken'], refresh_token: res['Refreshtoken']})
121
- end
122
- rescue MultiJson::LoadError
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
- params = params.merge({page: j})
131
- res = DomoscioRails.send_request(uri, method, params, headers, before_request_proc)
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
- data += DomoscioRails::JSON.load(res.body.nil? ? '' : res.body)
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
- data = {}
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
- res = Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == 'https') do |http| # , use_ssl: uri.scheme == 'https') do |http|
167
- req = Net::HTTP::const_get(method.capitalize).new(uri.request_uri, headers)
168
- req.body = DomoscioRails::JSON.dump(params)
169
- before_request_proc.call(req) if before_request_proc
170
- http.request req
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' => "DomoscioRails V2 RubyBindings/#{DomoscioRails::VERSION}",
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' => "DomoscioRails V2 RubyBindings/#{DomoscioRails::VERSION}",
207
- 'Authorization' => "Token token=#{DomoscioRails.configuration.client_passphrase}",#"#{auth_token['token_type']} #{auth_token['access_token']}",
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,7 +1,6 @@
1
1
  module DomoscioRails
2
- # An objective knowledge node student.
3
2
  class ObjectiveKnowledgeNodeStudent < Resource
4
3
  include DomoscioRails::HTTPCalls::Fetch
5
4
  include DomoscioRails::HTTPCalls::Update
6
5
  end
7
- end
6
+ 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
@@ -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,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
- # Thrown from any MangoPay API call whenever
10
- # it returns response with HTTP code != 200.
6
+ # Error Message from AdaptiveEngine
11
7
  class ResponseError < Error
12
-
13
- attr_reader :request_url, :code, :details
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
- def message; @details['Message']; end
21
- def type; @details['Type']; end
22
- def errors; @details['errors']; end
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(id_or_filters = nil)
44
- id, filters = DomoscioRails::HTTPCalls::Fetch.parse_id_or_filters(id_or_filters)
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.2.19"
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.2.19
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: 2019-09-05 00:00:00.000000000 Z
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.0.2
95
+ rubygems_version: 3.1.2
96
96
  signing_key:
97
97
  specification_version: 4
98
98
  summary: Summary of DomoscioRails.
@@ -1,4 +0,0 @@
1
- # desc "Explaining what the task does"
2
- # task :domoscio_rails do
3
- # # Task goes here
4
- # end