2011-01-18 15:37:12 -05:00
|
|
|
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',
|
2014-05-15 16:45:32 -04:00
|
|
|
body: {
|
|
|
|
login_email_address: email,
|
|
|
|
login_password: password
|
2011-01-18 15:37:12 -05:00
|
|
|
},
|
2014-05-15 16:45:32 -04:00
|
|
|
headers: {'Cookie' => response.headers['Set-Cookie']}
|
2011-01-18 15:37:12 -05:00
|
|
|
)
|
|
|
|
@cookie = response.request.options[:headers]['Cookie']
|
|
|
|
end
|
|
|
|
|
|
|
|
def account_settings
|
2014-05-15 16:45:32 -04:00
|
|
|
self.class.get('/account/edit', headers: {'Cookie' => @cookie})
|
2011-01-18 15:37:12 -05:00
|
|
|
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?}"
|