Class: CommitLive::Current
- Inherits:
-
Object
- Object
- CommitLive::Current
- Defined in:
- lib/commit-live/lesson/current.rb
Instance Attribute Summary collapse
-
#lesson ⇒ Object
Returns the value of attribute lesson.
-
#netrc ⇒ Object
Returns the value of attribute netrc.
-
#sentry ⇒ Object
Returns the value of attribute sentry.
Instance Method Summary collapse
- #getAttr(attr) ⇒ Object
- #getCurrentLesson(puzzle_name) ⇒ Object
- #getLesson(track_slug) ⇒ Object
- #getValue(key) ⇒ Object
-
#initialize ⇒ Current
constructor
A new instance of Current.
- #token ⇒ Object
Constructor Details
#initialize ⇒ Current
Returns a new instance of Current.
10 11 12 13 |
# File 'lib/commit-live/lesson/current.rb', line 10 def initialize() @netrc = CommitLive::NetrcInteractor.new() @sentry = CommitLive::Sentry.new() end |
Instance Attribute Details
#lesson ⇒ Object
Returns the value of attribute lesson.
8 9 10 |
# File 'lib/commit-live/lesson/current.rb', line 8 def lesson @lesson end |
#netrc ⇒ Object
Returns the value of attribute netrc.
8 9 10 |
# File 'lib/commit-live/lesson/current.rb', line 8 def netrc @netrc end |
#sentry ⇒ Object
Returns the value of attribute sentry.
8 9 10 |
# File 'lib/commit-live/lesson/current.rb', line 8 def sentry @sentry end |
Instance Method Details
#getAttr(attr) ⇒ Object
53 54 55 56 57 |
# File 'lib/commit-live/lesson/current.rb', line 53 def getAttr(attr) if !attr.nil? lesson.fetch(attr) end end |
#getCurrentLesson(puzzle_name) ⇒ Object
15 16 17 |
# File 'lib/commit-live/lesson/current.rb', line 15 def getCurrentLesson(puzzle_name) getLesson(puzzle_name) end |
#getLesson(track_slug) ⇒ Object
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 |
# File 'lib/commit-live/lesson/current.rb', line 24 def getLesson(track_slug) begin Timeout::timeout(15) do response = CommitLive::API.new().get( "/v2/user/track/#{track_slug}", headers: { 'Authorization' => "#{token}" } ) if response.status == 200 @lesson = JSON.parse(response.body) elsif response.status == 404 puts "Oops you are trying to access a non-existent lesson." exit else sentry.("Get Lesson Failed", { 'url' => "/v2/user/track/#{track_slug}", 'response-body' => response.body, 'response-status' => response.status } ) end end rescue Timeout::Error puts "Error while getting current lesson." puts "Please check your internet connection." exit end end |
#getValue(key) ⇒ Object
59 60 61 62 |
# File 'lib/commit-live/lesson/current.rb', line 59 def getValue(key) lessonData = getAttr('data') lessonData[key] end |
#token ⇒ Object
19 20 21 22 |
# File 'lib/commit-live/lesson/current.rb', line 19 def token netrc.read netrc.password end |