Class: CommitLive::Status

Inherits:
Object
  • Object
show all
Defined in:
lib/commit-live/lesson/status.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeStatus

Returns a new instance of Status.



11
12
13
14
15
# File 'lib/commit-live/lesson/status.rb', line 11

def initialize()
	@api = CommitLive::API.new
	@netrc = CommitLive::NetrcInteractor.new()
	@sentry = CommitLive::Sentry.new()
end

Instance Attribute Details

#apiObject (readonly)

Returns the value of attribute api.



9
10
11
# File 'lib/commit-live/lesson/status.rb', line 9

def api
  @api
end

#netrcObject (readonly)

Returns the value of attribute netrc.



9
10
11
# File 'lib/commit-live/lesson/status.rb', line 9

def netrc
  @netrc
end

#sentryObject (readonly)

Returns the value of attribute sentry.



9
10
11
# File 'lib/commit-live/lesson/status.rb', line 9

def sentry
  @sentry
end

Instance Method Details

#tokenObject



17
18
19
20
# File 'lib/commit-live/lesson/status.rb', line 17

def token
	netrc.read
	netrc.password
end

#update(type, trackName, shouldAnalyze = false, dump_data = {}, file_path = "") ⇒ Object



22
23
24
25
26
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
61
62
63
64
65
66
67
68
69
70
# File 'lib/commit-live/lesson/status.rb', line 22

def update(type, trackName, shouldAnalyze = false, dump_data = {}, file_path = "")
	enc_url = URI.escape("/v2/user/track/#{trackName}")
	begin
		Timeout::timeout(60) do
			response = api.post(
				enc_url,
				headers: {
					'Authorization' => "#{token}",
					'Content-Type' => 'application/json'
				},
				body: {
					'action' => type,
					'analysis' => shouldAnalyze ? 1 : 0,
					'data' => Oj.dump(dump_data, mode: :compat),
					'filePath' => file_path
				}
			)
			if response.status != 201
				sentry.log_message("Update Lesson Status Failed",
					{
						'url' => enc_url,
						'track_name' => trackName,
						'params' => {
							'method' => 'assignment_status',
							'action' => type,
							'analysis' => shouldAnalyze ? 1 : 0,
							'data' => Oj.dump(dump_data, mode: :compat),
							'filePath' => file_path
						},
						'response-body' => response.body,
						'response-status' => response.status
					}
				)
			end
		end
	rescue Timeout::Error
		puts "Error while updating lesson status."
		sentry.log_message("Update Lesson Status Failed",
			{
				'url' => enc_url,
				'track_name' => trackName,
				'params' => {
					'method' => 'assignment_status',
					'action' => type
				},
			}
		)
	end
end