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.



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

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.



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

def api
  @api
end

#netrcObject (readonly)

Returns the value of attribute netrc.



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

def netrc
  @netrc
end

#sentryObject (readonly)

Returns the value of attribute sentry.



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

def sentry
  @sentry
end

Instance Method Details

#tokenObject



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

def token
  netrc.read
  netrc.password
end

#update(type, trackName) ⇒ Object



21
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
# File 'lib/commit-live/lesson/status.rb', line 21

def update(type, trackName)
  begin
    Timeout::timeout(15) do
      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
        sentry.log_message("Update Lesson Status Failed",
          {
            'url' => enc_url,
            'track_name' => trackName,
            'params' => {
              'method' => 'assignment_status',
              'action' => type
            },
            'response-body' => response.body,
            'response-status' => response.status
          }
        )
      end
    end
  rescue Timeout::Error
    puts "Error while updating lesson status."
    puts "Please check your internet connection."
    exit
  end
end