Class: CourseraDownloader::Course
- Inherits:
-
Object
- Object
- CourseraDownloader::Course
- Defined in:
- lib/coursera_downloader/course.rb
Instance Attribute Summary collapse
-
#cookie_file ⇒ Object
readonly
Returns the value of attribute cookie_file.
Instance Method Summary collapse
- #index_url ⇒ Object
-
#initialize(name) ⇒ Course
constructor
A new instance of Course.
- #login(email, password) ⇒ Object
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
#cookie_file ⇒ Object (readonly)
Returns the value of attribute cookie_file.
7 8 9 |
# File 'lib/coursera_downloader/course.rb', line 7 def @cookie_file end |
Instance Method Details
#index_url ⇒ Object
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 login(email, password) curl = Curl::Easy.new curl.verbose = false curl. = true curl. = @cookie_file.path curl. = @cookie_file.path curl.follow_location = true curl.url = login_redirect_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 |