Sha256: 954d60a61dd8fbe3409ad9614276e096ba46a70f7b34da2d4c3c4c7931e713b7

Contents?: true

Size: 897 Bytes

Versions: 4

Compression:

Stored size: 897 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, :password

      def password
        @password ||= nil
      end

      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

4 entries across 4 versions & 1 rubygems

Version Path
goodwill-0.4.6 lib/goodwill/mechanize.rb
goodwill-0.4.4 lib/goodwill/mechanize.rb
goodwill-0.4.3 lib/goodwill/mechanize.rb
goodwill-0.4.1 lib/goodwill/mechanize.rb