1
0
Fork 0
mirror of https://github.com/jnunemaker/httparty synced 2023-03-27 23:23:07 -04:00
httparty/examples/tripit_sign_in.rb
2011-01-18 15:42:18 -05:00

33 lines
854 B
Ruby

dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
require File.join(dir, 'httparty')
class TripIt
include HTTParty
base_uri 'http://www.tripit.com'
debug_output
def initialize(email, password)
@email = email
response = self.class.get('/account/login')
response = self.class.post(
'/account/login',
:body => {
:login_email_address => email,
:login_password => password
},
:headers => {'Cookie' => response.headers['Set-Cookie']}
)
@cookie = response.request.options[:headers]['Cookie']
end
def account_settings
self.class.get('/account/edit', :headers => {'Cookie' => @cookie})
end
def logged_in?
account_settings.include? "You're logged in as #{@email}"
end
end
tripit = TripIt.new('email', 'password')
puts "Logged in: #{tripit.logged_in?}"