Class: CourseraDownloader::Course

Inherits:
Object
  • Object
show all
Defined in:
lib/coursera_downloader/course.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Course

Returns a new instance of Course.



9
10
11
12
# File 'lib/coursera_downloader/course.rb', line 9

def initialize(name)
  @name = name
  @cookie_file = Tempfile.new('coursera_cookies')
end

Instance Attribute Details

Returns the value of attribute cookie_file.



7
8
9
# File 'lib/coursera_downloader/course.rb', line 7

def cookie_file
  @cookie_file
end

Instance Method Details

#index_urlObject



43
44
45
# File 'lib/coursera_downloader/course.rb', line 43

def index_url
  URI.parse("#{host_url}/#{@name}/class/index")
end

#login(email, password) ⇒ 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
41
# File 'lib/coursera_downloader/course.rb', line 14

def (email, password)
  curl = Curl::Easy.new

  curl.verbose = false
  curl.enable_cookies = true
  curl.cookiefile = @cookie_file.path
  curl.cookiejar = @cookie_file.path
  curl.follow_location = true

  curl.url = 
  curl.http_get

  curl.url = curl.last_effective_url
  curl.http_post([
    Curl::PostField.content('email', email),
    Curl::PostField.content('password', password),
    Curl::PostField.content('login', "Login")
  ])

  curl.follow_location = false
  curl.url = index_url.to_s
  curl.http_get

  response_code = curl.response_code
  curl.close

  response_code == 200
end