Module: Xapi
- Defined in:
- lib/xapi.rb,
lib/xapi/enum.rb,
lib/xapi/team.rb,
lib/xapi/verb.rb,
lib/xapi/about.rb,
lib/xapi/agent.rb,
lib/xapi/group.rb,
lib/xapi/score.rb,
lib/xapi/errors.rb,
lib/xapi/result.rb,
lib/xapi/context.rb,
lib/xapi/version.rb,
lib/xapi/activity.rb,
lib/xapi/statement.rb,
lib/xapi/attachment.rb,
lib/xapi/remote_lrs.rb,
lib/xapi/lrs_response.rb,
lib/xapi/agent_account.rb,
lib/xapi/statement_ref.rb,
lib/xapi/sub_statement.rb,
lib/xapi/tcapi_version.rb,
lib/xapi/interaction_type.rb,
lib/xapi/statements_query.rb,
lib/xapi/statements_result.rb,
lib/xapi/context_activities.rb,
lib/xapi/documents/document.rb,
lib/xapi/activity_definition.rb,
lib/xapi/query_result_format.rb,
lib/xapi/team_analytics_query.rb,
lib/xapi/interaction_component.rb,
lib/xapi/statements_query_v095.rb,
lib/xapi/documents/state_document.rb,
lib/xapi/statements/statements_base.rb,
lib/xapi/documents/agent_profile_document.rb,
lib/xapi/documents/activity_profile_document.rb
Defined Under Namespace
Modules: Documents, Enum, Errors, InteractionType, QueryResultFormat, Statements, TCAPIVersion Classes: About, Activity, ActivityDefinition, Agent, AgentAccount, Attachment, Context, ContextActivities, Group, InteractionComponent, LrsResponse, RemoteLRS, Result, Score, Statement, StatementRef, StatementsQuery, StatementsQueryV095, StatementsResult, SubStatement, Team, TeamAnalyticsQuery, Verb
Constant Summary collapse
- VERSION =
"0.0.1"
Class Method Summary collapse
-
.create_activity(opts = {}) ⇒ Object
Parameters can be passed for create_activity are: id, name, description, extensions.
-
.create_activity_profile(opts = {}) ⇒ Object
Parameters can be passed for create_activity_profile are: remote_lrs, profile_id, activity_object, profile_content.
-
.create_agent(opts = {}) ⇒ Object
Parameters can be passed for create_agent are: agent_type which is either Agent or Group email, name members[] with hashes having name and email details.
-
.create_agent_profile(opts = {}) ⇒ Object
Parameters can be passed for create_agent_profile are: remote_lrs, profile_id, agent_object, profile_content.
-
.create_context(opts = {}) ⇒ Object
Parameters can be passed for create_context are: registration, extensions, team, instructor, statement, context_activities.
-
.create_context_activities(opts = {}) ⇒ Object
Parameters can be passed for create_context_activities are: grouping, category, parent, other.
-
.create_remote_lrs(opts = {}) ⇒ Object
Parameters can be passed for create_remote_lrs are: end_point, user_name, password.
-
.create_result(opts = {}) ⇒ Object
Parameters can be passed for create_result are: scaled_score or score_details, duration, response, success, completion, extensions.
-
.create_statement(opts = {}) ⇒ Object
Parameters can be passed for create_remote_lrs are: actor, verb, object, context, result.
-
.create_statement_query(opts = {}) ⇒ Object
Parameters can be passed for create_statement_query are: registration_id, verb_id, activity_id, agent_email, agent_name, team_home_page, team_name, search_related_agents, search_related_activities.
-
.create_statement_ref(opts = {}) ⇒ Object
Parameters can be passed for create_team are: object_type, statement_id.
-
.create_team(opts = {}) ⇒ Object
Parameters can be passed for create_team are: home_page, name.
-
.create_team_analytics_query(opts = {}) ⇒ Object
Parameters can be passed for create_team_analytics_query are: registration_id, verb_id, activity_id, activity_type, team_name, agent_email.
-
.create_verb(opts = {}) ⇒ Object
Parameters can be passed for create_verb are: id, name.
-
.get_activity_profile(opts = {}) ⇒ Object
Parameters can be passed for get_activity_profile are: remote_lrs, profile_id, activity_object.
-
.get_agent_profile(opts = {}) ⇒ Object
Parameters can be passed for get_agent_profile are: remote_lrs, profile_id, agent_object.
-
.get_statements_by_id(opts = {}) ⇒ Object
Parameters can be passed for get_statement_by_id are: remote_lrs, statement_id.
-
.get_statements_by_query(opts = {}) ⇒ Object
Parameters can be passed for get_statements_by_query are: remote_lrs, statement_query.
-
.get_team_analytics_by_query(opts = {}) ⇒ Object
Parameters can be passed for get_team_analytics_by_query are: remote_lrs, team_analytics_query.
-
.post_statement(opts = {}) ⇒ Object
Parameters can be passed for create_remote_lrs are: remote_lrs, statement.
-
.update_activity_profile(opts = {}) ⇒ Object
Parameters can be passed for update_activity_profile are: remote_lrs, profile_id, activity_object, profile_content.
-
.update_agent_profile(opts = {}) ⇒ Object
Parameters can be passed for create_agent_profile are: remote_lrs, profile_id, agent_object, profile_content.
Class Method Details
.create_activity(opts = {}) ⇒ Object
Parameters can be passed for create_activity are: id, name, description, extensions
52 53 54 55 56 57 |
# File 'lib/xapi.rb', line 52 def self.create_activity(opts={}) activity_definition = ActivityDefinition.new(name: {"en-US"=>opts[:name]}, type: opts[:type]) activity_definition.description = {"en-US" => opts[:description]} if opts[:description].present? activity_definition.extensions = opts[:extensions] if opts[:extensions].present? Activity.new(id: opts[:id], definition: activity_definition) end |
.create_activity_profile(opts = {}) ⇒ Object
Parameters can be passed for create_activity_profile are: remote_lrs, profile_id, activity_object, profile_content
163 164 165 166 167 168 169 170 171 |
# File 'lib/xapi.rb', line 163 def self.create_activity_profile(opts={}) profile_data = Documents::ActivityProfileDocument.new do |pdata| pdata.id = opts[:profile_id] pdata.activity = opts[:activity_object] pdata.content_type = "application/json" pdata.content =opts[:profile_content] .to_json end opts[:remote_lrs].save_activity_profile(profile_data) end |
.create_agent(opts = {}) ⇒ Object
Parameters can be passed for create_agent are: agent_type which is either Agent or Group email, name members[] with hashes having name and email details. This will be given if agent_type is Group
38 39 40 41 42 43 44 |
# File 'lib/xapi.rb', line 38 def self.create_agent(opts={}) if opts[:agent_type].eql?("Agent") Agent.new(mbox: "mailto:#{opts[:email]}", name: "#{opts[:name]}") else Group.new(members: opts[:members].map{|member| Agent.new(mbox: "mailto:#{member[:email]}", name: "#{member[:name]}") }) end end |
.create_agent_profile(opts = {}) ⇒ Object
Parameters can be passed for create_agent_profile are: remote_lrs, profile_id, agent_object, profile_content
194 195 196 197 198 199 200 201 202 |
# File 'lib/xapi.rb', line 194 def self.create_agent_profile(opts={}) profile_data = Documents::AgentProfileDocument.new do |pdata| pdata.id = opts[:profile_id] pdata.agent = opts[:agent_object] pdata.content_type = "application/json" pdata.content = opts[:profile_content] .to_json end opts[:remote_lrs].save_agent_profile(profile_data) end |
.create_context(opts = {}) ⇒ Object
Parameters can be passed for create_context are: registration, extensions, team, instructor, statement, context_activities
65 66 67 68 |
# File 'lib/xapi.rb', line 65 def self.create_context(opts={}) opts[:language] = 'en-US' Context.new(opts) end |
.create_context_activities(opts = {}) ⇒ Object
Parameters can be passed for create_context_activities are: grouping, category, parent, other
60 61 62 |
# File 'lib/xapi.rb', line 60 def self.create_context_activities(opts={}) ContextActivities.new(opts) end |
.create_remote_lrs(opts = {}) ⇒ Object
Parameters can be passed for create_remote_lrs are: end_point, user_name, password
99 100 101 102 103 |
# File 'lib/xapi.rb', line 99 def self.create_remote_lrs(opts={}) RemoteLRS.new(end_point: opts[:end_point], user_name: opts[:user_name], password: opts[:password]) # lrs_auth_response = remote_lrs.about # lrs_auth_response.success ? remote_lrs : nil end |
.create_result(opts = {}) ⇒ Object
Parameters can be passed for create_result are: scaled_score or score_details, duration, response, success, completion, extensions
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/xapi.rb', line 82 def self.create_result(opts={}) score = nil if opts[:scaled_score].present? score = Score.new(scaled: opts[:scaled_score]) elsif opts[:score_details].present? score = Score.new(raw: opts[:score_details][:raw], min: opts[:score_details][:min], max: opts[:score_details][:max]) end duration = opts[:duration].present? ? opts[:duration] : nil result = Result.new(duration: duration, score: score) result.response = opts[:response] if opts[:response].present? result.success = opts[:success] if opts[:success].present? result.completion = opts[:completion] if opts[:completion].present? result.extensions = opts[:extensions] if opts[:extensions].present? result end |
.create_statement(opts = {}) ⇒ Object
Parameters can be passed for create_remote_lrs are: actor, verb, object, context, result
106 107 108 109 110 111 |
# File 'lib/xapi.rb', line 106 def self.create_statement(opts={}) statement = Statement.new(actor: opts[:actor], verb: opts[:verb], object: opts[:object]) statement.context = opts[:context] if opts[:context].present? statement.result = opts[:result] if opts[:result].present? statement end |
.create_statement_query(opts = {}) ⇒ Object
Parameters can be passed for create_statement_query are: registration_id, verb_id, activity_id, agent_email, agent_name, team_home_page, team_name, search_related_agents, search_related_activities
119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/xapi.rb', line 119 def self.create_statement_query(opts={}) StatementsQuery.new do |s| s.registration = opts[:registration_id] if opts[:registration_id].present? s.activity_id = opts[:activity_id] if opts[:activity_id].present? s. = opts[:search_related_activities] if opts[:search_related_activities].present? agent_object = opts[:agent_email].present? ? create_agent(agent_type: "Agent", email: opts[:agent_email], name: opts[:agent_name]) : create_team(home_page: opts[:team_home_page], name: opts[:team_name]) s.agent = agent_object if agent_object.present? s. = opts[:team_name].present? ? true : opts[:search_related_agents] s.verb_id = opts[:verb_id] if opts[:verb_id].present? end end |
.create_statement_ref(opts = {}) ⇒ Object
Parameters can be passed for create_team are: object_type, statement_id
77 78 79 |
# File 'lib/xapi.rb', line 77 def self.create_statement_ref(opts={}) StatementRef.new(object_type: opts[:object_type], id: opts[:statement_id]) end |
.create_team(opts = {}) ⇒ Object
Parameters can be passed for create_team are: home_page, name
71 72 73 74 |
# File 'lib/xapi.rb', line 71 def self.create_team(opts={}) team_account = AgentAccount.new(home_page: opts[:home_page], name: opts[:name]) Team.new(object_type: "Group", account: team_account) end |
.create_team_analytics_query(opts = {}) ⇒ Object
Parameters can be passed for create_team_analytics_query are: registration_id, verb_id, activity_id, activity_type, team_name, agent_email
145 146 147 148 149 150 151 152 153 154 |
# File 'lib/xapi.rb', line 145 def self.create_team_analytics_query(opts={}) TeamAnalyticsQuery.new do |s| s.registration = opts[:registration_id] if opts[:registration_id].present? s.activity_id = opts[:activity_id] if opts[:activity_id].present? s.activity_type = opts[:activity_type] if opts[:activity_type].present? s.verb_id = opts[:verb_id] if opts[:verb_id].present? s.team_name = opts[:team_name] if opts[:team_name].present? s.agent_email = opts[:agent_email] if opts[:agent_email].present? end end |
.create_verb(opts = {}) ⇒ Object
Parameters can be passed for create_verb are: id, name
47 48 49 |
# File 'lib/xapi.rb', line 47 def self.create_verb(opts={}) Verb.new(id: opts[:id], display: {"en-US": opts[:name]}) end |
.get_activity_profile(opts = {}) ⇒ Object
Parameters can be passed for get_activity_profile are: remote_lrs, profile_id, activity_object
174 175 176 177 |
# File 'lib/xapi.rb', line 174 def self.get_activity_profile(opts={}) response = opts[:remote_lrs].retrieve_activity_profile(opts[:profile_id], opts[:activity_object]) response.status == 200 ? response.content : nil end |
.get_agent_profile(opts = {}) ⇒ Object
Parameters can be passed for get_agent_profile are: remote_lrs, profile_id, agent_object
205 206 207 208 |
# File 'lib/xapi.rb', line 205 def self.get_agent_profile(opts={}) response = opts[:remote_lrs].retrieve_agent_profile(opts[:profile_id], opts[:agent_object]) response.status == 200 ? response.content : nil end |
.get_statements_by_id(opts = {}) ⇒ Object
Parameters can be passed for get_statement_by_id are: remote_lrs, statement_id
132 133 134 135 |
# File 'lib/xapi.rb', line 132 def self.get_statements_by_id(opts={}) response = opts[:remote_lrs].retrieve_statement(opts[:statement_id]) response.status == 200 ? response.content : nil end |
.get_statements_by_query(opts = {}) ⇒ Object
Parameters can be passed for get_statements_by_query are: remote_lrs, statement_query
138 139 140 141 142 |
# File 'lib/xapi.rb', line 138 def self.get_statements_by_query(opts={}) response = opts[:remote_lrs].query_statements(opts[:statement_query]) statements = response.content.statements if response.status == 200 && response.content.present? statements.present? ? {statements_count: statements.count, statements: statements} : {statements_count: 0, statements: nil} end |
.get_team_analytics_by_query(opts = {}) ⇒ Object
Parameters can be passed for get_team_analytics_by_query are: remote_lrs, team_analytics_query
157 158 159 160 |
# File 'lib/xapi.rb', line 157 def self.get_team_analytics_by_query(opts={}) response = opts[:remote_lrs].query_team_analytics(opts[:team_analytics_query]) response.content end |
.post_statement(opts = {}) ⇒ Object
Parameters can be passed for create_remote_lrs are: remote_lrs, statement
114 115 116 |
# File 'lib/xapi.rb', line 114 def self.post_statement(opts={}) opts[:remote_lrs].save_statement(opts[:statement]) end |
.update_activity_profile(opts = {}) ⇒ Object
Parameters can be passed for update_activity_profile are: remote_lrs, profile_id, activity_object, profile_content
180 181 182 183 184 185 186 187 188 189 190 191 |
# File 'lib/xapi.rb', line 180 def self.update_activity_profile(opts={}) profile_data = Documents::ActivityProfileDocument.new do |pdata| pdata.id = opts[:profile_id] pdata.activity = opts[:activity_object] pdata.content_type = "application/json" pdata.content = opts[:profile_content] .to_json end existing_activity_profile = get_activity_profile(remote_lrs: opts[:remote_lrs], profile_id: opts[:profile_id], activity_object: opts[:activity_object]) opts[:remote_lrs].delete_activity_profile(profile_data) if existing_activity_profile.present? profile_data.content = opts[:profile_content].to_json opts[:remote_lrs].save_activity_profile(profile_data) end |
.update_agent_profile(opts = {}) ⇒ Object
Parameters can be passed for create_agent_profile are: remote_lrs, profile_id, agent_object, profile_content
211 212 213 214 215 216 217 218 219 220 221 222 |
# File 'lib/xapi.rb', line 211 def self.update_agent_profile(opts={}) profile_data = Documents::AgentProfileDocument.new do |pdata| pdata.id = opts[:profile_id] pdata.agent = opts[:agent_object] pdata.content_type = "application/json" pdata.content = opts[:profile_content] .to_json end existing_agent_profile = get_agent_profile(remote_lrs: opts[:remote_lrs], profile_id: opts[:profile_id], agent_object: opts[:agent_object]) opts[:remote_lrs].delete_agent_profile(profile_data) if existing_agent_profile.present? profile_data.content = opts[:profile_content].to_json opts[:remote_lrs].save_agent_profile(profile_data) end |