Sha256: 3241c296e8ca18ad3d6890dc9ee82ebe8200492594d1e18f89ea90e2219e84c8

Contents?: true

Size: 915 Bytes

Versions: 1

Compression:

Stored size: 915 Bytes

Contents

# frozen_string_literal: true

require 'mechanize'

require 'goodwill/urlpaths'

module Goodwill
  module Mechanize
    def mechanize
      Mechanize.mechanize
    end

    class << self
      include URLPaths

      def username
        @username ||= nil
      end

      attr_writer :username

      def password
        @password ||= nil
      end

      attr_writer :password

      def logged_in?
        @logged_in ||= false
      end

      def mechanize
        @mechanize ||= ::Mechanize.new
        login
        @mechanize
      end

      def login
        return true if logged_in?

        @mechanize.get(LOGIN_URL) do |page|
          my_page = page.form_with(action: '/SignIn') do |f|
            f.Username = @username
            f.Password = @password
          end.click_button
          @logged_in = my_page.links.map(&:to_s).include? 'My Shopgoodwill '
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
goodwill-0.4.0 lib/goodwill/mechanize.rb