Class: AtomicLti::Services::Score

Inherits:
Base
  • Object
show all
Defined in:
app/lib/atomic_lti/services/score.rb

Overview

Direct Known Subclasses

ScoreCanvas

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#get_next_url, #headers, #logged_service_call, #service_delete, #service_get, #service_post, #service_put

Constructor Details

#initialize(id_token_decoded: nil, iss: nil, deployment_id: nil, id: nil) ⇒ Score

Returns a new instance of Score.



8
9
10
11
# File 'app/lib/atomic_lti/services/score.rb', line 8

def initialize(id_token_decoded: nil, iss: nil, deployment_id: nil, id: nil)
  super(id_token_decoded: id_token_decoded, iss: iss, deployment_id: deployment_id)
  @id = id
end

Instance Attribute Details

#idObject

Returns the value of attribute id.



6
7
8
# File 'app/lib/atomic_lti/services/score.rb', line 6

def id
  @id
end

Instance Method Details

#endpointObject



17
18
19
20
21
22
23
24
25
# File 'app/lib/atomic_lti/services/score.rb', line 17

def endpoint
  if id.blank?
    raise ::AtomicLti::Exceptions::ScoreError,
          "Invalid id or no id provided. Unable to access scores. id should be in the form of a url."
  end
  uri = URI(id)
  uri.path = "#{uri.path}/scores"
  uri
end

#generate(user_id:, score:, max_score:, comment: nil, timestamp: Time.now, activity_progress: "Completed", grading_progress: "FullyGraded") ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'app/lib/atomic_lti/services/score.rb', line 27

def generate(
  user_id:,
  score:,
  max_score:,
  comment: nil,
  timestamp: Time.now,
  activity_progress: "Completed",
  grading_progress: "FullyGraded"
)
  {
    # The lti_user_id or the Canvas user_id
    userId: user_id,
    # The Current score received in the tool for this line item and user, scaled to
    # the scoreMaximum
    scoreGiven: score,
    # Maximum possible score for this result; it must be present if scoreGiven is
    # present.
    scoreMaximum: max_score,
    # Comment visible to the student about this score.
    comment: comment,
    # Date and time when the score was modified in the tool. Should use subsecond
    # precision.
    timestamp: timestamp.iso8601(3),
    # Indicate to Canvas the status of the user towards the activity's completion.
    # Must be one of Initialized, Started, InProgress, Submitted, Completed
    activityProgress: activity_progress,
    # Indicate to Canvas the status of the grading process. A value of
    # PendingManual will require intervention by a grader. Values of NotReady,
    # Failed, and Pending will cause the scoreGiven to be ignored. FullyGraded
    # values will require no action. Possible values are NotReady, Failed, Pending,
    # PendingManual, FullyGraded
    gradingProgress: grading_progress,
  }.compact
end

#scopesObject



13
14
15
# File 'app/lib/atomic_lti/services/score.rb', line 13

def scopes
  [AtomicLti::Definitions::AGS_SCOPE_SCORE]
end

#send(attrs) ⇒ Object



62
63
64
65
66
67
68
69
# File 'app/lib/atomic_lti/services/score.rb', line 62

def send(attrs)
  content_type = { "Content-Type" => "application/vnd.ims.lis.v1.score+json" }
  HTTParty.post(
    endpoint,
    body: attrs.to_json,
    headers: headers(content_type),
  )
end