Class: CommitLive::Current

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCurrent

Returns a new instance of Current.



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

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

Instance Attribute Details

#lessonObject

Returns the value of attribute lesson.



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

def lesson
  @lesson
end

#netrcObject

Returns the value of attribute netrc.



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

def netrc
  @netrc
end

Instance Method Details

#getAttr(attr) ⇒ Object



36
37
38
39
40
# File 'lib/commit-live/lesson/current.rb', line 36

def getAttr(attr)
	if !attr.nil?
		lesson.fetch(attr)
	end
end

#getCurrentLesson(*puzzle_name) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/commit-live/lesson/current.rb', line 13

def getCurrentLesson(*puzzle_name)
	begin
		Timeout::timeout(15) do
			netrc.read
			token = netrc.password
			response = CommitLive::API.new().get(
				'/v1/current_lesson',
				headers: { 'access-token' => "#{token}" }
			)
			if response.status == 200
				@lesson = JSON.parse(response.body)
			else
				puts "Something went wrong. Please try again."
				exit 1
			end
		end
	rescue Timeout::Error
		puts "Error while getting current lesson."
		puts "Please check your internet connection."
		exit
	end
end