Class: CommitLive::Status
- Inherits:
-
Object
- Object
- CommitLive::Status
- Defined in:
- lib/commit-live/lesson/status.rb
Instance Attribute Summary collapse
-
#api ⇒ Object
readonly
Returns the value of attribute api.
-
#netrc ⇒ Object
readonly
Returns the value of attribute netrc.
Instance Method Summary collapse
-
#initialize ⇒ Status
constructor
A new instance of Status.
- #update(type, trackName) ⇒ Object
Constructor Details
#initialize ⇒ Status
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
#api ⇒ Object (readonly)
Returns the value of attribute api.
7 8 9 |
# File 'lib/commit-live/lesson/status.rb', line 7 def api @api end |
#netrc ⇒ Object (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 |