File: tripit_sign_in.rb

package info (click to toggle)
ruby-httparty 0.13.7-1%2Bdeb9u1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 736 kB
  • sloc: ruby: 4,741; xml: 425; sh: 35; makefile: 11
file content (33 lines) | stat: -rw-r--r-- 839 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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?}"