Class: PupilfirstXapi::Statements::TargetCompleted

Inherits:
Object
  • Object
show all
Defined in:
lib/pupilfirst_xapi/statements/target_completed.rb

Instance Method Summary collapse

Constructor Details

#initialize(repository, uri_for) ⇒ TargetCompleted

Returns a new instance of TargetCompleted.



4
5
6
7
# File 'lib/pupilfirst_xapi/statements/target_completed.rb', line 4

def initialize(repository, uri_for)
  @repository = repository
  @uri_for = uri_for
end

Instance Method Details

#call(actor_id:, resource_id:) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/pupilfirst_xapi/statements/target_completed.rb', line 9

def call(actor_id:, resource_id:)
  submission = @repository.call(:timeline_event, resource_id)
  return unless submission.passed?

  actor = @repository.call(:user, actor_id)
  target = submission.target

  Xapi.create_statement(
    actor: Actors.agent(actor),
    verb: Verbs::COMPLETED_ASSIGNMENT,
    object: Objects.target(target, @uri_for)
  )
end