Class: Pedophile::Login
- Inherits:
-
Object
- Object
- Pedophile::Login
- Defined in:
- lib/pedophile/login.rb
Instance Attribute Summary collapse
-
#downloader ⇒ Object
readonly
Returns the value of attribute downloader.
Instance Method Summary collapse
- #devise_login(url, email, password) ⇒ Object
-
#initialize(downloader) ⇒ Login
constructor
A new instance of Login.
Constructor Details
#initialize(downloader) ⇒ Login
Returns a new instance of Login.
9 10 11 |
# File 'lib/pedophile/login.rb', line 9 def initialize(downloader) @downloader = downloader end |
Instance Attribute Details
#downloader ⇒ Object (readonly)
Returns the value of attribute downloader.
7 8 9 |
# File 'lib/pedophile/login.rb', line 7 def downloader @downloader end |
Instance Method Details
#devise_login(url, email, password) ⇒ Object
13 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 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/pedophile/login.rb', line 13 def devise_login(url, email, password) uri = URI.parse(url) string = @downloader.wget.download(url) token = nil if string =~ /name=\"authenticity_token"\.* value=\"([^"]+)\"/ token = $1 puts "got devise token #{token.to_s.blue}" end action_url = nil if string =~ /action=\"([^"]+)\"/ action_url = $1 puts "got action url #{action_url.to_s.blue}" end sign_url = "http://#{uri.host}#{action_url}" puts "sign action url #{sign_url.to_s.blue}" post_params = { "authenticity_token" => token, "user" => { "email" => email, "password" => password, "remember_me" => 1 } } post_params = { "utf8"=>"✓", "authenticity_token" => token, "user[email]" => email, "user[password]" => password, "user[remember_me]" => 1 } string = @downloader.wget.post(url, post_params) string end |