Sha256: 24b17dab0538d4ab223aa48155f8bab3455d3db48de0b5f8b0878bbc1223872c

Contents?: true

Size: 1.1 KB

Versions: 149

Compression:

Stored size: 1.1 KB

Contents

dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
require File.join(dir, 'httparty')

class TripIt
  include HTTParty
  base_uri 'https://www.tripit.com'
  debug_output

  def initialize(email, password)
    @email = email
    get_response = self.class.get('/account/login')
    get_response_cookie = parse_cookie(get_response.headers['Set-Cookie'])

    post_response = self.class.post(
      '/account/login',
      body: {
        login_email_address: email,
        login_password: password
      },
      headers: {'Cookie' => get_response_cookie.to_cookie_string }
    )

    @cookie = parse_cookie(post_response.headers['Set-Cookie'])
  end

  def account_settings
    self.class.get('/account/edit', headers: { 'Cookie' => @cookie.to_cookie_string })
  end

  def logged_in?
    account_settings.include? "You're logged in as #{@email}"
  end

  private

  def parse_cookie(resp)
    cookie_hash = CookieHash.new
    resp.get_fields('Set-Cookie').each { |c| cookie_hash.add_cookies(c) }
    cookie_hash
  end
end

tripit = TripIt.new('email', 'password')
puts "Logged in: #{tripit.logged_in?}"

Version data entries

149 entries across 123 versions & 7 rubygems

Version Path
trusty-cms-7.0.9.1 vendor/bundle/ruby/3.1.0/gems/httparty-0.22.0/examples/tripit_sign_in.rb
trusty-cms-7.0.9.1 vendor/bundle/ruby/3.3.0/gems/httparty-0.22.0/examples/tripit_sign_in.rb
httparty-0.22.0 examples/tripit_sign_in.rb
harbr-2.8.1 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/examples/tripit_sign_in.rb
study_line-0.2.7 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/examples/tripit_sign_in.rb
study_line-0.2.6 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/examples/tripit_sign_in.rb
study_line-0.2.5 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/examples/tripit_sign_in.rb
study_line-0.2.4 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/examples/tripit_sign_in.rb
study_line-0.2.3 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/examples/tripit_sign_in.rb
study_line-0.2.2 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/examples/tripit_sign_in.rb
study_line-0.2.1 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/examples/tripit_sign_in.rb
study_line-0.2.0 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/examples/tripit_sign_in.rb
harbr-0.2.10 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/examples/tripit_sign_in.rb
harbr-0.2.9 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/examples/tripit_sign_in.rb
harbr-0.2.8 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/examples/tripit_sign_in.rb
harbr-0.2.7 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/examples/tripit_sign_in.rb
harbr-0.2.6 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/examples/tripit_sign_in.rb
harbr-0.2.5 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/examples/tripit_sign_in.rb
harbr-0.2.4 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/examples/tripit_sign_in.rb
harbr-0.2.3 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/examples/tripit_sign_in.rb