Module: DomoscioRails

Defined in:
lib/domoscio_rails.rb,
lib/domoscio_rails/json.rb,
lib/domoscio_rails/errors.rb,
lib/domoscio_rails/tag/tag.rb,
lib/domoscio_rails/version.rb,
lib/domoscio_rails/resource.rb,
lib/domoscio_rails/data/event.rb,
lib/domoscio_rails/http_calls.rb,
lib/domoscio_rails/tag/tag_set.rb,
lib/domoscio_rails/tag/tagging.rb,
lib/domoscio_rails/data/content.rb,
lib/domoscio_rails/data/student.rb,
lib/domoscio_rails/tag/tag_edge.rb,
lib/domoscio_rails/data/instance.rb,
lib/domoscio_rails/utils/review_util.rb,
lib/domoscio_rails/authorization_token.rb,
lib/domoscio_rails/objective/objective.rb,
lib/domoscio_rails/utils/gameplay_util.rb,
lib/domoscio_rails/data/learning_session.rb,
lib/domoscio_rails/knowledge/knowledge_edge.rb,
lib/domoscio_rails/knowledge/knowledge_node.rb,
lib/domoscio_rails/knowledge/knowledge_graph.rb,
lib/domoscio_rails/utils/recommendation_util.rb,
lib/domoscio_rails/objective/objective_student.rb,
lib/domoscio_rails/knowledge/knowledge_node_content.rb,
lib/domoscio_rails/knowledge/knowledge_node_student.rb,
lib/domoscio_rails/objective/objective_knowledge_node.rb,
lib/domoscio_rails/objective/objective_knowledge_node_student.rb

Defined Under Namespace

Modules: AuthorizationToken, HTTPCalls, JSON Classes: Configuration, Content, Error, Event, GameplayUtil, Instance, KnowledgeEdge, KnowledgeGraph, KnowledgeNode, KnowledgeNodeContent, KnowledgeNodeStudent, LearningSession, Objective, ObjectiveKnowledgeNode, ObjectiveKnowledgeNodeStudent, ObjectiveStudent, ProcessingError, RecommendationUtil, Resource, ResponseError, ReviewUtil, Student, Tag, TagEdge, TagSet, Tagging

Constant Summary collapse

VERSION =
"0.3.6"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.configurationObject

Returns the value of attribute configuration.



50
51
52
# File 'lib/domoscio_rails.rb', line 50

def configuration
  @configuration
end

Class Method Details

.api_uri(url = '') ⇒ Object



58
59
60
# File 'lib/domoscio_rails.rb', line 58

def self.api_uri(url='')
  URI(configuration.root_url + url)
end

.configure {|configuration| ... } ⇒ Object

Yields:



53
54
55
56
# File 'lib/domoscio_rails.rb', line 53

def self.configure
  self.configuration ||= Configuration.new
  yield configuration
end

.request(method, url, params = {}) ⇒ Object

  • method: HTTP method; lowercase symbol, e.g. :get, :post etc.

  • url: the part after Configuration#root_url

  • params: hash; entity data for creation, update etc.; will dump it by JSON and assign to Net::HTTPRequest#body

Performs HTTP requests to Adaptive Engine On token issues, will try once to get a new token then will output a DomoscioRails::ReponseError with details

Raises DomoscioRails::ResponseError on Adaptive Error Status Raises DomoscioRails::ProcessingError on Internal Error



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/domoscio_rails.rb', line 73

def self.request(method, url, params={})

  store_tokens, headers = request_headers
  params.merge!({'per_page': 2000}) unless params[:per_page]
  uri = api_uri(url)

  response = DomoscioRails.send_request(uri, method, params, headers)
  return response if response.kind_of? DomoscioRails::ProcessingError

  begin
    raise_http_failure(uri, response, params)
    data = DomoscioRails::JSON.load(response.body.nil? ? '' : response.body)
    DomoscioRails::AuthorizationToken::Manager.storage.store({access_token: response['Accesstoken'], refresh_token: response['Refreshtoken']}) if store_tokens
  rescue MultiJson::LoadError => exception
    data = ProcessingError.new(uri, 500, exception, response.body, params)
  rescue ResponseError => exception
    data = exception
  end

  if response['Total']
    pagetotal = (response['Total'].to_i / response['Per-Page'].to_f).ceil
    for j in 2..pagetotal
      response = DomoscioRails.send_request(uri, method, params.merge({page: j}), headers)
      return response if response.kind_of? DomoscioRails::ProcessingError
      begin
        raise_http_failure(uri, response, params)
        body = DomoscioRails::JSON.load(response.body.nil? ? '' : response.body)
        data += body
        data.flatten!
      rescue MultiJson::LoadError => exception
        return ProcessingError.new(uri, 500, exception, response.body, params)
      rescue ResponseError => exception
        return exception
      end
    end
  end
  data
end