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.



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

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

Instance Attribute Details

#apiObject (readonly)

Returns the value of attribute api.



7
8
9
# File 'lib/commit-live/lesson/status.rb', line 7

def api
  @api
end

#netrcObject (readonly)

Returns the value of attribute netrc.



7
8
9
# File 'lib/commit-live/lesson/status.rb', line 7

def netrc
  @netrc
end

Instance Method Details

#update(type, trackName) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/commit-live/lesson/status.rb', line 14

def update(type, trackName)
	begin
		Timeout::timeout(15) do
			netrc.read
			token = netrc.password
			enc_url = URI.escape("/v1/user/track/#{trackName}")
			response = api.post(
				enc_url,
				headers: { 'access-token' => "#{token}" },
				params: { 
					'method' => 'assignment_status',
					'action' => type
				}
			)
			if response.status == 202
				puts "Lesson Status updated!"
			else
				puts "Something went wrong. Please try again."
				exit 1
			end
		end
	rescue Timeout::Error
		puts "Error while updating lesson status."
		puts "Please check your internet connection."
		exit
	end
end