growthtribe_xapi 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -0,0 +1,36 @@
1
+ # encoding: utf-8
2
+ module Xapi
3
+ class TeamAnalyticsQuery
4
+
5
+ attr_accessor :version, :verb_id
6
+ attr_accessor :activity_id, :registration, :activity_type, :team_name, :agent_email
7
+
8
+ def initialize(&block)
9
+ self.version = TCAPIVersion::V101
10
+ if block_given?
11
+ block[self]
12
+ end
13
+ end
14
+
15
+ def verb_id=(value)
16
+ if value.is_a?(Verb)
17
+ @verb_id = value.id
18
+ else
19
+ @verb_id =value
20
+ end
21
+ end
22
+
23
+ def parameter_map
24
+ params = {}
25
+ params['verb'] = verb_id.to_s if verb_id
26
+ params['activity'] = activity_id.to_s if activity_id
27
+ params['registration'] = registration if registration
28
+ params['activity_type'] = activity_type if activity_type
29
+ params['team_name'] = team_name if team_name
30
+ params['agent_email'] = agent_email if agent_email
31
+
32
+ params
33
+ end
34
+
35
+ end
36
+ end
data/lib/xapi/verb.rb ADDED
@@ -0,0 +1,35 @@
1
+ # encoding: utf-8
2
+ module Xapi
3
+ class Verb
4
+
5
+ attr_accessor :id, :display
6
+
7
+ def initialize(options={}, &block)
8
+ json = options.fetch(:json, nil)
9
+ if json
10
+ attributes = JSON.parse(json)
11
+ self.id = attributes['id'] if attributes['id']
12
+ self.display = attributes['display'] if attributes['display']
13
+ else
14
+ self.id = options.fetch(:id, nil)
15
+ self.display = options.fetch(:display, nil)
16
+
17
+ if block_given?
18
+ block[self]
19
+ end
20
+ end
21
+ end
22
+
23
+ def id=(value)
24
+ @id = value if value
25
+ end
26
+
27
+ def serialize(version)
28
+ node = {}
29
+ node['id'] = id.to_s if id
30
+ node['display'] = display if display
31
+ node
32
+ end
33
+
34
+ end
35
+ end
@@ -0,0 +1,4 @@
1
+ # encoding: utf-8
2
+ module Xapi
3
+ VERSION = "0.0.1"
4
+ end
@@ -0,0 +1,10 @@
1
+ {
2
+ "extensions" : {
3
+ "http://id.Xapi.com/extension/powered-by" : {
4
+ "name" : "Tin Can Engine",
5
+ "homePage" : "http://Xapi.com/lrs-lms/lrs-for-lmss-home/",
6
+ "version" : "2012.1.0.8c644"
7
+ }
8
+ },
9
+ "version" : [ "0.9", "0.95", "1.0.1" ]
10
+ }
@@ -0,0 +1,33 @@
1
+ {
2
+ "id": "06a6cbbb-b09c-4618-88a8-e8aa6884ad42",
3
+ "actor": {
4
+ "mbox": "mailto:tincanruby@Xapi.com",
5
+ "objectType": "Agent"
6
+ },
7
+ "verb": {
8
+ "id": "http://adlnet.gov/expapi/verbs/experienced",
9
+ "display": {
10
+ "en-GB": "experienced",
11
+ "en-US": "experienced"
12
+ }
13
+ },
14
+ "timestamp": "2015-03-27T13:14:42.081Z",
15
+ "stored": "2015-03-27T13:14:42.081Z",
16
+ "authority": {
17
+ "account": {
18
+ "homePage": "http://example.com/",
19
+ "name": "ABCDEFGHI"
20
+ },
21
+ "objectType": "Agent"
22
+ },
23
+ "version": "1.0.1",
24
+ "object": {
25
+ "id": "http://Xapi.com/TinCanRuby/Test/Unit/0",
26
+ "definition": {
27
+ "name": {"en-US": "TinCanJava Tests: Unit 0"},
28
+ "description": {"en-US": "Unit test 0 in the test suite for the Tin Can Ruby library."},
29
+ "type": "http://id.Xapi.com/activitytype/unit-test"
30
+ },
31
+ "objectType": "Activity"
32
+ }
33
+ }
@@ -0,0 +1,107 @@
1
+ require 'webmock/rspec'
2
+ require 'securerandom'
3
+ require 'growthtribe_xapi'
4
+ # This file was generated by the `rspec --init` command. Conventionally, all
5
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
6
+ # The generated `.rspec` file contains `--require spec_helper` which will cause
7
+ # this file to always be loaded, without a need to explicitly require it in any
8
+ # files.
9
+ #
10
+ # Given that it is always loaded, you are encouraged to keep this file as
11
+ # light-weight as possible. Requiring heavyweight dependencies from this file
12
+ # will add to the boot time of your test suite on EVERY test run, even for an
13
+ # individual file that may not need all of that loaded. Instead, consider making
14
+ # a separate helper file that requires the additional dependencies and performs
15
+ # the additional setup, and require it from the spec files that actually need
16
+ # it.
17
+ #
18
+ # The `.rspec` file also contains a few flags that are not defaults but that
19
+ # users commonly want.
20
+ #
21
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
22
+
23
+ # Requires supporting files with custom matchers and macros, etc,
24
+ # in ./support/ and its subdirectories.
25
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
26
+
27
+ RSpec.configure do |config|
28
+ # rspec-expectations config goes here. You can use an alternate
29
+ # assertion/expectation library such as wrong or the stdlib/minitest
30
+ # assertions if you prefer.
31
+ config.expect_with :rspec do |expectations|
32
+ # This option will default to `true` in RSpec 4. It makes the `description`
33
+ # and `failure_message` of custom matchers include text for helper methods
34
+ # defined using `chain`, e.g.:
35
+ # be_bigger_than(2).and_smaller_than(4).description
36
+ # # => "be bigger than 2 and smaller than 4"
37
+ # ...rather than:
38
+ # # => "be bigger than 2"
39
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
40
+ end
41
+
42
+ # rspec-mocks config goes here. You can use an alternate test double
43
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
44
+ config.mock_with :rspec do |mocks|
45
+ # Prevents you from mocking or stubbing a method that does not exist on
46
+ # a real object. This is generally recommended, and will default to
47
+ # `true` in RSpec 4.
48
+ mocks.verify_partial_doubles = true
49
+ end
50
+
51
+ # The settings below are suggested to provide a good initial experience
52
+ # with RSpec, but feel free to customize to your heart's content.
53
+ =begin
54
+ # These two settings work together to allow you to limit a spec run
55
+ # to individual examples or groups you care about by tagging them with
56
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
57
+ # get run.
58
+ config.filter_run :focus
59
+ config.run_all_when_everything_filtered = true
60
+
61
+ # Limits the available syntax to the non-monkey patched syntax that is
62
+ # recommended. For more details, see:
63
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
64
+ # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
65
+ # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
66
+ config.disable_monkey_patching!
67
+
68
+ # This setting enables warnings. It's recommended, but in some cases may
69
+ # be too noisy due to issues in dependencies.
70
+ config.warnings = true
71
+
72
+ # Many RSpec users commonly either run the entire suite or an individual
73
+ # file, and it's useful to allow more verbose output when running an
74
+ # individual spec file.
75
+ if config.files_to_run.one?
76
+ # Use the documentation formatter for detailed output,
77
+ # unless a formatter has already been configured
78
+ # (e.g. via a command-line flag).
79
+ config.default_formatter = 'doc'
80
+ end
81
+
82
+ # Print the 10 slowest examples and example groups at the
83
+ # end of the spec run, to help surface which specs are running
84
+ # particularly slow.
85
+ config.profile_examples = 10
86
+
87
+ # Run specs in random order to surface order dependencies. If you find an
88
+ # order dependency and want to debug it, you can fix the order by providing
89
+ # the seed, which is printed after each run.
90
+ # --seed 1234
91
+ config.order = :random
92
+
93
+ # Seed global randomization in this process using the `--seed` CLI option.
94
+ # Setting this allows you to use `--seed` to deterministically reproduce
95
+ # test failures related to randomization by passing the same `--seed` value
96
+ # as the one that triggered the failure.
97
+ Kernel.srand config.seed
98
+ =end
99
+ end
100
+
101
+ def fixture_path
102
+ File.expand_path("../fixtures", __FILE__)
103
+ end
104
+
105
+ def fixture(file)
106
+ File.new(File.join(fixture_path, '/', file))
107
+ end
@@ -0,0 +1,60 @@
1
+ module Helpers
2
+ def get_agent(name, type, value)
3
+ agent = Xapi::Agent.new(name: name)
4
+ case type
5
+ when :mbox
6
+ agent.mbox = value
7
+ when :open_id
8
+ agent.open_id = value
9
+ when :mbox_sha1_sum
10
+ agent.mbox_sha1_sum = value
11
+ when :account
12
+ parts = value.split('|')
13
+ account = Xapi::AgentAccount.new(home_page: parts.first, name: parts.last)
14
+ agent.account = account
15
+ end
16
+ agent
17
+ end
18
+
19
+ def get_team(name, type, value)
20
+ agent = Xapi::Team.new(name: name)
21
+ case type
22
+ when :mbox
23
+ agent.mbox = value
24
+ when :open_id
25
+ agent.open_id = value
26
+ when :mbox_sha1_sum
27
+ agent.mbox_sha1_sum = value
28
+ when :account
29
+ parts = value.split('|')
30
+ account = Xapi::AgentAccount.new(home_page: parts.first, name: parts.last)
31
+ agent.account = account
32
+ end
33
+ agent
34
+ end
35
+
36
+ def create_interaction_component(id, description)
37
+ component = Xapi::InteractionComponent.new
38
+ component.id = id
39
+ map = {}
40
+ map['en-US'] = description
41
+ component.description = map
42
+ [component]
43
+ end
44
+
45
+ def assert_serialize_and_deserialize(object)
46
+ Xapi::TCAPIVersion.values.each do |version|
47
+ assert_serialize_and_deserialize_for_version(object, version)
48
+ end
49
+ end
50
+
51
+ def assert_serialize_and_deserialize_for_version(object, version)
52
+ hash = object.serialize(version)
53
+ new_definition = object.class.new(json: hash.to_json)
54
+ expect(hash).to eq(new_definition.serialize(version))
55
+ end
56
+
57
+ def default_request_headers
58
+ {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization'=>'Basic dXNlcjpwYXNzd29yZA==', 'User-Agent'=>'Faraday v1.3.0', 'X-Experience-Api-Version'=>'1.0.1'}
59
+ end
60
+ end
@@ -0,0 +1,37 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe Xapi::ActivityDefinition do
5
+ include Helpers
6
+
7
+ it 'should serialize and deserialize' do
8
+ definition = Xapi::ActivityDefinition.new
9
+ definition.choices = create_interaction_component('choice1', 'Choice 1')
10
+ definition.correct_responses_pattern = ['correct_response']
11
+
12
+ map = {}
13
+ map['en-US'] = 'Activity Definition Description'
14
+ definition.description = map
15
+
16
+ extensions = {}
17
+ extensions['http://example.com/extensions'] = 'extensionValue'
18
+ definition.extensions = extensions
19
+
20
+ map = {}
21
+ map['en-US'] = 'Activity Definition'
22
+ definition.name = map
23
+
24
+ definition.scale = create_interaction_component('scale1', 'Scale 1')
25
+ definition.source = create_interaction_component('source1', 'Source 1')
26
+ definition.steps = create_interaction_component('steps1', 'Steps 1')
27
+ definition.target = create_interaction_component('target1', 'Target 1')
28
+
29
+ definition.type = 'http://adlnet.gov/expapi/activities/assessment'
30
+
31
+ Xapi::InteractionType.values.each do |type|
32
+ definition.interaction_type = type
33
+ assert_serialize_and_deserialize(definition)
34
+ end
35
+
36
+ end
37
+ end
@@ -0,0 +1,23 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe Xapi::Activity do
5
+ include Helpers
6
+
7
+ it 'sets the object type' do
8
+ activity = Xapi::Activity.new
9
+ expect(activity.object_type).to eq('Activity')
10
+ end
11
+
12
+ it 'should serialize and deserialize' do
13
+ activity = Xapi::Activity.new
14
+ activity.id = 'http://example.com/activity'
15
+ definition = Xapi::ActivityDefinition.new
16
+ map = {}
17
+ map['en-US'] = 'Activity Definition'
18
+ definition.name = map
19
+ activity.definition = definition
20
+ assert_serialize_and_deserialize(activity)
21
+ end
22
+
23
+ end
@@ -0,0 +1,13 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe Xapi::AgentAccount do
5
+ include Helpers
6
+
7
+ it 'should serialize and deserialize' do
8
+ account = Xapi::AgentAccount.new
9
+ account.homePage = 'http://example.com'
10
+ account.name = 'joeuser'
11
+ assert_serialize_and_deserialize(account)
12
+ end
13
+ end
@@ -0,0 +1,24 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe Xapi::Agent do
5
+ include Helpers
6
+ it 'should serialize and deserialize' do
7
+ agent = Xapi::Agent.new
8
+ name = 'Joe User'
9
+ ids = {
10
+ mbox: 'mailto:joeuser@example.com',
11
+ open_id: 'http://openid.org/joeuser',
12
+ mbox_sha1_sum: 'b623062e19c5608ab0e1342e5011d48292ce00e3',
13
+ account: 'http://example.com|joeuser'
14
+ }
15
+ ids.each_pair do |key, value|
16
+ Xapi::TCAPIVersion.values.each do |version|
17
+ agent = get_agent(name, key, value)
18
+ hash = agent.serialize(version)
19
+ new_agent = Xapi::Agent.new(json: hash.to_json)
20
+ expect(hash).to eq(new_agent.serialize(version))
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,26 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe Xapi::Attachment do
5
+ include Helpers
6
+
7
+ it 'should serialize and deserialize' do
8
+ attachment = Xapi::Attachment.new
9
+ attachment.content_type = 'text/plain'
10
+ map = {}
11
+ map['en-US'] = 'Some attachment'
12
+ attachment.display = map
13
+
14
+ map = {}
15
+ map['en-US'] = 'Some attachment description'
16
+ attachment.description = map
17
+
18
+ attachment.file_url = URI.parse('http://example.com/somefile')
19
+ attachment.length = 27
20
+ attachment.sha2 = '495395e777cd98da653df9615d09c0fd6bb2f8d4788394cd53c56a3bfdcd848a'
21
+ attachment.usage_type = Addressable::URI.parse('http://example.com/attachment-usage/test')
22
+
23
+ assert_serialize_and_deserialize(attachment)
24
+
25
+ end
26
+ end
@@ -0,0 +1,57 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe Xapi::ContextActivities do
5
+ include Helpers
6
+
7
+ it 'should serialize and deserialize' do
8
+ context = Xapi::ContextActivities.new
9
+ activity = Xapi::Activity.new
10
+ activity.id = 'http://example.com/parent'
11
+ context.parent = [activity]
12
+
13
+ activity = Xapi::Activity.new
14
+ activity.id = 'http://example.com/grouping'
15
+ context.grouping = [activity]
16
+
17
+ activity = Xapi::Activity.new
18
+ activity.id = 'http://example.com/other'
19
+ context.other = [activity]
20
+
21
+ assert_serialize_and_deserialize(context)
22
+ end
23
+
24
+ # 'category' arrived in 1.0.0, so confirm it works in everything after that point, which is to say not 0.95
25
+ it 'should work with category in version 1.0.0 and later' do
26
+ context = Xapi::ContextActivities.new
27
+ activity = Xapi::Activity.new
28
+ activity.id = 'http://example.com/parent'
29
+ context.parent = [activity]
30
+
31
+ activity = Xapi::Activity.new
32
+ activity.id = 'http://example.com/grouping'
33
+ context.grouping = [activity]
34
+
35
+ activity = Xapi::Activity.new
36
+ activity.id = 'http://example.com/other'
37
+ context.other = [activity]
38
+
39
+ activity = Xapi::Activity.new
40
+ activity.id = 'http://example.com/category'
41
+ context.category = [activity]
42
+
43
+ assert_serialize_and_deserialize_for_version(context, Xapi::TCAPIVersion::V101)
44
+ assert_serialize_and_deserialize_for_version(context, Xapi::TCAPIVersion::V100)
45
+ end
46
+
47
+ # 'category' is not supported in 0.95, make sure it isn't
48
+ it 'should fail with category in version 0.95 and later' do
49
+ context = Xapi::ContextActivities.new
50
+
51
+ activity = Xapi::Activity.new
52
+ activity.id = 'http://example.com/category'
53
+ context.category = [activity]
54
+
55
+ expect{assert_serialize_and_deserialize_for_version(context, Xapi::TCAPIVersion::V095)}.to raise_error(Xapi::Errors::IncompatibleTCAPIVersion)
56
+ end
57
+ end