growthtribe_xapi 0.0.1

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.
Files changed (68) hide show
  1. checksums.yaml +7 -0
  2. data/.github/workflows/ci.yml +28 -0
  3. data/CHANGELOG.md +2 -0
  4. data/CONTRIBUTING.md +7 -0
  5. data/Gemfile +4 -0
  6. data/Gemfile.lock +78 -0
  7. data/LICENSE.txt +22 -0
  8. data/README.md +299 -0
  9. data/Rakefile +12 -0
  10. data/bin/rspec +29 -0
  11. data/lib/growthtribe_xapi.rb +2 -0
  12. data/lib/xapi.rb +224 -0
  13. data/lib/xapi/about.rb +15 -0
  14. data/lib/xapi/activity.rb +37 -0
  15. data/lib/xapi/activity_definition.rb +131 -0
  16. data/lib/xapi/agent.rb +44 -0
  17. data/lib/xapi/agent_account.rb +33 -0
  18. data/lib/xapi/attachment.rb +64 -0
  19. data/lib/xapi/context.rb +54 -0
  20. data/lib/xapi/context_activities.rb +102 -0
  21. data/lib/xapi/documents/activity_profile_document.rb +15 -0
  22. data/lib/xapi/documents/agent_profile_document.rb +15 -0
  23. data/lib/xapi/documents/document.rb +20 -0
  24. data/lib/xapi/documents/state_document.rb +15 -0
  25. data/lib/xapi/enum.rb +42 -0
  26. data/lib/xapi/errors.rb +9 -0
  27. data/lib/xapi/group.rb +37 -0
  28. data/lib/xapi/interaction_component.rb +32 -0
  29. data/lib/xapi/interaction_type.rb +58 -0
  30. data/lib/xapi/lrs_response.rb +14 -0
  31. data/lib/xapi/query_result_format.rb +6 -0
  32. data/lib/xapi/remote_lrs.rb +416 -0
  33. data/lib/xapi/result.rb +46 -0
  34. data/lib/xapi/score.rb +39 -0
  35. data/lib/xapi/statement.rb +53 -0
  36. data/lib/xapi/statement_ref.rb +31 -0
  37. data/lib/xapi/statements/statements_base.rb +70 -0
  38. data/lib/xapi/statements_query.rb +42 -0
  39. data/lib/xapi/statements_query_v095.rb +42 -0
  40. data/lib/xapi/statements_result.rb +17 -0
  41. data/lib/xapi/sub_statement.rb +19 -0
  42. data/lib/xapi/tcapi_version.rb +27 -0
  43. data/lib/xapi/team.rb +44 -0
  44. data/lib/xapi/team_analytics_query.rb +36 -0
  45. data/lib/xapi/verb.rb +35 -0
  46. data/lib/xapi/version.rb +4 -0
  47. data/spec/fixtures/about.json +10 -0
  48. data/spec/fixtures/statement.json +33 -0
  49. data/spec/spec_helper.rb +107 -0
  50. data/spec/support/helpers.rb +60 -0
  51. data/spec/xapi/activity_definition_spec.rb +37 -0
  52. data/spec/xapi/activity_spec.rb +23 -0
  53. data/spec/xapi/agent_account_spec.rb +13 -0
  54. data/spec/xapi/agent_spec.rb +24 -0
  55. data/spec/xapi/attachment_spec.rb +26 -0
  56. data/spec/xapi/context_activities_spec.rb +57 -0
  57. data/spec/xapi/context_spec.rb +32 -0
  58. data/spec/xapi/group_spec.rb +15 -0
  59. data/spec/xapi/interaction_component_spec.rb +18 -0
  60. data/spec/xapi/remote_lrs_spec.rb +46 -0
  61. data/spec/xapi/result_spec.rb +24 -0
  62. data/spec/xapi/score_spec.rb +12 -0
  63. data/spec/xapi/statement_ref_spec.rb +19 -0
  64. data/spec/xapi/statement_spec.rb +73 -0
  65. data/spec/xapi/sub_statement_spec.rb +30 -0
  66. data/spec/xapi/verb_spec.rb +17 -0
  67. data/xapi.gemspec +30 -0
  68. metadata +244 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 9b6d643a742050f1112095743443f4862b73578c88191ac1112a78fc416df1d4
4
+ data.tar.gz: 0f8164d18c901ac7831af7b731ff669a29e41fc916b06629ddd5d86b7c38a706
5
+ SHA512:
6
+ metadata.gz: d5eb2b588c4ee802db633f115b17279c2000e832d2b5d6844253ea8509882aed0bd4dcbb7b6bc9b9fa42db5b087553b135afc674f0c6e7ee9f1145682af26f00
7
+ data.tar.gz: d017dd430beec18a9ddb4218a65b69a1c7ab64499d147ca222a440ac86c1104a50ff177352b30b1f0a31336895229fa553eb80dd653ca0319a94db1fce0be07e
@@ -0,0 +1,28 @@
1
+ name: Continuous Integration
2
+
3
+ on:
4
+ push:
5
+ branches: ['*']
6
+ pull_request:
7
+ branches: [ master ]
8
+
9
+ jobs:
10
+ tests:
11
+ runs-on: ${{ matrix.os }}
12
+ if: "!contains(github.event.head_commit.message, 'skip ci')"
13
+ strategy:
14
+ fail-fast: false
15
+ matrix:
16
+ include:
17
+ - ruby: ruby-3.0
18
+ os: ubuntu-20.04
19
+ - ruby: ruby-2.7
20
+ os: ubuntu-20.04
21
+ steps:
22
+ - uses: actions/checkout@v2
23
+ - run: test -e Gemfile.lock
24
+ - uses: ruby/setup-ruby@v1
25
+ with:
26
+ ruby-version: ${{ matrix.ruby }}
27
+ bundler-cache: true
28
+ - run: bin/rspec
data/CHANGELOG.md ADDED
@@ -0,0 +1,2 @@
1
+ ## 0.0.1
2
+ * Initial public release
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,7 @@
1
+ ## Contributing
2
+
3
+ 1. Fork it ( https://github.com/growthtribeacademy/Xapi/fork )
4
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
5
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
6
+ 4. Push to the branch (`git push origin my-new-feature`)
7
+ 5. Create a new Pull Request
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in xapi.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,78 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ growthtribe_xapi (0.0.1)
5
+ activesupport (>= 5.1)
6
+ addressable (~> 2.3)
7
+ faraday (~> 1.3.0)
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ activesupport (6.1.2.1)
13
+ concurrent-ruby (~> 1.0, >= 1.0.2)
14
+ i18n (>= 1.6, < 2)
15
+ minitest (>= 5.1)
16
+ tzinfo (~> 2.0)
17
+ zeitwerk (~> 2.3)
18
+ addressable (2.7.0)
19
+ public_suffix (>= 2.0.2, < 5.0)
20
+ coderay (1.1.3)
21
+ concurrent-ruby (1.1.8)
22
+ crack (0.4.5)
23
+ rexml
24
+ diff-lcs (1.4.4)
25
+ faraday (1.3.0)
26
+ faraday-net_http (~> 1.0)
27
+ multipart-post (>= 1.2, < 3)
28
+ ruby2_keywords
29
+ faraday-net_http (1.0.1)
30
+ hashdiff (1.0.1)
31
+ i18n (1.8.9)
32
+ concurrent-ruby (~> 1.0)
33
+ method_source (1.0.0)
34
+ minitest (5.14.3)
35
+ multipart-post (2.1.1)
36
+ pry (0.14.0)
37
+ coderay (~> 1.1)
38
+ method_source (~> 1.0)
39
+ public_suffix (4.0.6)
40
+ rake (10.5.0)
41
+ rexml (3.2.4)
42
+ rspec (3.10.0)
43
+ rspec-core (~> 3.10.0)
44
+ rspec-expectations (~> 3.10.0)
45
+ rspec-mocks (~> 3.10.0)
46
+ rspec-core (3.10.1)
47
+ rspec-support (~> 3.10.0)
48
+ rspec-expectations (3.10.1)
49
+ diff-lcs (>= 1.2.0, < 2.0)
50
+ rspec-support (~> 3.10.0)
51
+ rspec-mocks (3.10.2)
52
+ diff-lcs (>= 1.2.0, < 2.0)
53
+ rspec-support (~> 3.10.0)
54
+ rspec-support (3.10.2)
55
+ ruby2_keywords (0.0.4)
56
+ tzinfo (2.0.4)
57
+ concurrent-ruby (~> 1.0)
58
+ webmock (3.0.1)
59
+ addressable (>= 2.3.6)
60
+ crack (>= 0.3.2)
61
+ hashdiff
62
+ zeitwerk (2.4.2)
63
+
64
+ PLATFORMS
65
+ x86_64-darwin-19
66
+ x86_64-darwin-20
67
+ x86_64-linux
68
+
69
+ DEPENDENCIES
70
+ bundler
71
+ growthtribe_xapi!
72
+ pry
73
+ rake
74
+ rspec
75
+ webmock (~> 3.0.0)
76
+
77
+ BUNDLED WITH
78
+ 2.2.4
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2016 Deakin Prime
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,299 @@
1
+ # xAPI
2
+
3
+ A Ruby library for implementing xAPIs Statements, Profiles and Querying Statements for LRS in simple way.
4
+
5
+ For more information about the Tin Can API visit:
6
+
7
+ http://Xapi.com/
8
+
9
+ For more information about the xAPI Statements Specficiations and Components visit:
10
+
11
+ https://github.com/adlnet/xAPI-Spec
12
+
13
+ ## Installation
14
+
15
+ Add this line to your application's Gemfile:
16
+
17
+ ```ruby
18
+ gem 'growthtribe_xapi'
19
+ ```
20
+
21
+ And then execute:
22
+
23
+ $ bundle
24
+
25
+ Or install it yourself as:
26
+
27
+ $ gem install growthtribe_xapi
28
+
29
+ This gem provided classes in `Xapi` namespace as in original `Xapi`gem,
30
+ from which it has been forked from.
31
+
32
+ ## Usage
33
+
34
+ Create a remote LRS using Account credentials
35
+ ```ruby
36
+ remote_lrs = Xapi.create_remote_lrs( end_point: ''https://some.lrsdomain.com'', user_name: 'username', password: 'password' )
37
+ ```
38
+
39
+ Connect to the 'about' endpoint to get version information
40
+
41
+ ```ruby
42
+ # use the remote LRS from above
43
+ response = remote_lrs.about
44
+ # check if it is successful
45
+ if response.success
46
+ # access the Xapi::About instance
47
+ response.content
48
+ end
49
+ ```
50
+
51
+ #Creating the Properties of a Statement
52
+
53
+ For more information about the Properties of a xAPI Statement visit:
54
+
55
+ https://github.com/adlnet/xAPI-Spec/blob/master/xAPI-Data.md
56
+
57
+ Create a Agent for a Statement
58
+
59
+ ```ruby
60
+ # Parameters can be passed for create_agent are:
61
+ # agent_type which is either Agent or Group
62
+ # Passing email, name - if agent_type is Agent
63
+ # Passing members Array with hashes having name and email as keys - if agent_type is Group
64
+
65
+ agent = Xapi.create_agent(agent_type: 'Agent', email: 'email', name: 'name')
66
+
67
+ agent = Xapi.create_agent(agent_type: 'Group', members: [ {email: 'email1', name: 'name1'},{email: 'email2', name: 'name2'}] )
68
+ ```
69
+
70
+ Create a Team for Context of a Statement
71
+
72
+ ```ruby
73
+ # Parameters can be passed for create_team are: object_type, statement_id
74
+
75
+ team = Xapi.create_team(home_page: "http://some.learnactivity.com/", name: 'team_name')
76
+ ```
77
+
78
+ Create a Verb for a Statement
79
+
80
+ ```ruby
81
+ # Parameters can be passed for create_verb are: id, name
82
+
83
+ verb = Xapi.create_verb(id: 'http://adlnet.gov/expapi/verbs/launched', name: 'launched')
84
+ ```
85
+
86
+ Create a Object for a Statement which is either Activity, Agent, or another Statement that is the Object of the Statement.
87
+
88
+ ```ruby
89
+ # Parameters can be passed for create_activity are: id, name, description, extensions
90
+
91
+ object = Xapi.create_activity(id: "http://some.learnactivity.com/conversation",
92
+ name: 'Learning conversation', type: 'http://adlnet.gov/expapi/activities/assessment',
93
+ description: 'Conversational Learning tool',
94
+ extensions: { "http://id.tincanapi.com/extension/planned-duration" => 'PT50M' }
95
+ )
96
+ ```
97
+
98
+ Create a Context Activities for Given Context of a Statement
99
+
100
+ ```ruby
101
+ # Parameters can be passed for create_context_activities are: grouping, category, parent, other which are Array of Objects/Activitites realted to Context of a Statement
102
+
103
+ grouping_array = []
104
+ grouping_array << Xapi.create_activity( id: "http://some.learnactivity.com/topics/1",
105
+ name: 'topic title', type: "http://activitystrea.ms/schema/1.0/task"
106
+ )
107
+ context_activities = Xapi.create_context_activities(grouping: grouping_array)
108
+ ```
109
+
110
+ Create a Context for a Statement
111
+
112
+ ```ruby
113
+ # Parameters can be passed for create_context are: registration, extensions, team, instructor, statement, context_activities
114
+
115
+ context = Xapi.create_context(registration: 'registration_id',
116
+ extensions: { "http://some.learnactivity.com/extension/tags" => ["domain1", "domain2"],
117
+ team: team, instructor: instructor_agent,
118
+ context_activities: context_activities
119
+ )
120
+ ```
121
+
122
+ Create a Result for a Statement
123
+
124
+ ```ruby
125
+ # Parameters can be passed for create_result are: scaled_score or score_details, duration, response, success, completion, extensions
126
+
127
+ result = Xapi.create_result(response: 'response details', score_details: {min: 1, raw: 7, max: 10}, success: true, extensions: {""http://some.learnactivity.com/extension/questions" => ['question1', 'question2']})
128
+ ```
129
+
130
+ Create a Statement
131
+
132
+ ```ruby
133
+ # Parameters can be passed for create_remote_lrs are: actor, verb, object, context, result
134
+
135
+ statement = Xapi.create_statement(actor: agent, verb: verb, object: object, context: context, result: result)
136
+ ```
137
+
138
+ Post a statement to LRS
139
+
140
+ ```ruby
141
+ # Parameters can be passed for create_remote_lrs are: remote_lrs, statement
142
+
143
+ response = Xapi.post_statement(remote_lrs: remote_lrs, statement: statement)
144
+
145
+ if response.success
146
+ # access the statement
147
+ response.content
148
+ end
149
+
150
+ ```
151
+
152
+ ## Querying Statements required from LRS
153
+
154
+ Get Statement based on statement ID
155
+
156
+ ```ruby
157
+ # Parameters can be passed for get_statements_by_query are: remote_lrs, statement_query
158
+
159
+ Xapi.get_statements_by_id(remote_lrs: remote_lrs, statement_id: '2a8785a0-8ee8-41ad-9172-e194a82e30a4')
160
+ ```
161
+
162
+ Get Statements based on Queries
163
+
164
+ ```ruby
165
+ # Parameters can be passed for create_statement_query are: registration_id, verb_id, activity_id
166
+ # Eithe agent details: agent_email, agent_name
167
+ # or Team details: team_home_page, team_name
168
+ # Searching related statements by passing boolean values to these: search_related_agents, search_related_activities
169
+
170
+ #Based on Team
171
+ statement_query = Xapi.create_statement_query(verb_id: 'http://id.tincanapi.com/verb rated', activity_id: 'http://some.learnactivity.com/conversation', team_home_page: 'http://some.learnactivity.com', team_name: 'team_name')
172
+
173
+ #Based on Agent
174
+ statement_query = Xapi.create_statement_query(verb_id: 'http://id.tincanapi.com/verb rated', activity_id: 'http://some.learnactivity.com/conversation', agent_email: 'email', agent_name: 'name')
175
+
176
+ result_statements_response = Xapi.get_statements_by_query(remote_lrs: remote_lrs, statement_query: statement_query)
177
+
178
+ #Knowing result statements count
179
+ result_statements_response[:statements_count]
180
+
181
+ #Knowing the result statements
182
+ JSON.parse(result_statements_response[:statements].to_json) if result_statements_response[:statements_count] > 0
183
+ ```
184
+
185
+ ## Creating or updating the Profiles in LRS
186
+
187
+ Create/Update Activity Profile
188
+
189
+ ```ruby
190
+ # Parameters can be passed for create_activity_profile are: remote_lrs, profile_id, activity_object, profile_content
191
+
192
+ activity_object = Xapi.create_activity(id: 'http://some.leranactivity.com/topics/1', name: 'title', type: 'http://activitystrea.ms/schema/1.0/task' )
193
+
194
+ profile_content = { "name"=> "title", "description" => "description", "relevance" => "relevance", "type" => "http://some.leranactivity.com/evidences/document"
195
+ }
196
+ Xapi.create_activity_profile(remote_lrs: remote_lrs, profile_id: 'topic profile', activity_object: activity_object, profile_content: profile_activity_content)
197
+
198
+ Xapi.update_activity_profile(remote_lrs: remote_lrs, profile_id: 'topic profile', activity_object: activity_object, profile_content: profile_activity_content)
199
+
200
+ ```
201
+
202
+ Create/Update Agent Profile
203
+
204
+ ```ruby
205
+ # Parameters can be passed for create_agent_profile are: remote_lrs, profile_id, agent_object, profile_content
206
+
207
+ agent_details = Xapi.create_agent(agent_type: "Agent", email: 'email', name: 'name')
208
+
209
+ profile_content = { "objectType" => "Agent", "name" => "name", "avatar" => "avatar image url", "age" => "age", "roles" => ["role1", "rol2"], "teams" => ["team name"] }
210
+
211
+ Xapi.create_agent_profile(remote_lrs: remote_lrs, profile_id: "user profile", agent_object: agent_details, profile_content: profile_content)
212
+
213
+ Xapi.update _agent_profile(remote_lrs: remote_lrs, profile_id: "user profile", agent_object: agent_details, profile_content: profile_content)
214
+
215
+ ```
216
+
217
+ ## Get the Profiles from LRS
218
+
219
+ Get Activity Profile
220
+
221
+ ```ruby
222
+ # Parameters can be passed for get_activity_profile are: remote_lrs, profile_id, activity_object
223
+
224
+ activity_object = Xapi.create_activity(id: 'http://some.leranactivity.com/topics/1', name: 'title', type: 'http://activitystrea.ms/schema/1.0/task' )
225
+
226
+ Xapi.get_activity_profile(remote_lrs: remote_lrs, profile_id: "topic profile", activity_object: activity_object)
227
+ ```
228
+
229
+ Get Multiple Activity Profiles for given Activity
230
+
231
+ ```ruby
232
+ # Parameters can be passed for get_activity_profile are: remote_lrs, profile_id, activity_object
233
+
234
+ activity_object = Xapi.create_activity(id: 'http://some.leranactivity.com/topics/1', name: 'title', type: 'http://activitystrea.ms/schema/1.0/task' )
235
+
236
+ Xapi.get_activity_profile(remote_lrs: remote_lrs, profile_id: ["profile1", "profile2"], activity_object: activity_object)
237
+ ```
238
+
239
+ Get Agent Profile
240
+
241
+ ```ruby
242
+ # Parameters can be passed for get_agent_profile are: remote_lrs, profile_id, agent_object
243
+
244
+ agent_details = Xapi.create_agent(agent_type: "Agent", email: 'email', name: 'name')
245
+
246
+ Xapi.get_agent_profile(remote_lrs: remote_lrs, profile_id: "agent profile", agent_object: agent_details)
247
+
248
+ ```
249
+
250
+ Get Multiple Agent Profiles for given agent
251
+
252
+ ```ruby
253
+ # Parameters can be passed for get_agent_profile are: remote_lrs, profile_id, agent_object
254
+
255
+ agent_details = Xapi.create_agent(agent_type: "Agent", email: 'email', name: 'name')
256
+
257
+ Xapi.get_agent_profile(remote_lrs: remote_lrs, profile_id: ["profile1", "profile2"], agent_object: agent_details)
258
+
259
+ ```
260
+
261
+ ## Analytics related to Team and its Team members related to Assessment
262
+
263
+ Get Team and its members Average scores
264
+
265
+ ```ruby
266
+ # Parameters can be passed for it: verb_id, activity_id, activity_type, team_name
267
+
268
+ team_analytics_query = Xapi.create_team_analytics_query(verb_id: "http://id.tincanapi.com/verb/rated", activity_type: "http://activitystrea.ms/schema/1.0/task", team_name: "Digital Learning" )
269
+
270
+ analytics_response = Xapi.get_analytics_by_query(remote_lrs: remote_lrs, team_analytics_query: team_analytics_query)
271
+
272
+ ```
273
+
274
+ Get Team and its members Average scores, Activity frequency For given activity
275
+
276
+ ```ruby
277
+ # Parameters can be passed for it: verb_id, activity_id, activity_type, team_name
278
+
279
+ team_analytics_query = Xapi.create_team_analytics_query(verb_id: "http://id.tincanapi.com/verb/rated", activity_type: "http://activitystrea.ms/schema/1.0/task", team_name: "Digital Learning", activity_id: "http://some.leranactivity.com/activities/1" )
280
+
281
+ analytics_response = Xapi.get_analytics_by_query(remote_lrs: remote_lrs, team_analytics_query: team_analytics_query)
282
+
283
+ ```
284
+
285
+ Get Agent or Team member related all activities along with agent and its team average scores
286
+
287
+ ```ruby
288
+ # Parameters can be passed for it: verb_id, agent_email, activity_type, team_name
289
+
290
+ team_analytics_query = Xapi.create_team_analytics_query(verb_id: "http://id.tincanapi.com/verb/rated", activity_type: "http://activitystrea.ms/schema/1.0/task", team_name: "Digital Learning", agent_email: "123@test.com" )
291
+
292
+ analytics_response = Xapi.get_analytics_by_query(remote_lrs: remote_lrs, team_analytics_query: team_analytics_query)
293
+
294
+ ```
295
+
296
+ For more API calls check out the Xapi Module Class methods
297
+
298
+ For more API calls check out the Xapi::RemoteLRS class
299
+