Sha256: 1be579ab8bf54967befdf5ab320d7abab3f3d42875c1ea106cb324e0d846903b

Contents?: true

Size: 1003 Bytes

Versions: 8

Compression:

Stored size: 1003 Bytes

Contents

require 'mechanize'

module Adyen
  module Admin
    module Client
      LOGIN       = "https://ca-test.adyen.com/ca/ca/login.shtml"
      DASHBOARD   = "https://ca-test.adyen.com/ca/ca/overview/default.shtml"

      def login(accountname, username, password)
        @authenticated = false
        page = Adyen::Admin.client.get(LOGIN)
        page = Adyen::Admin.client.submit(page.form.tap do |form|
          form.j_account  = accountname
          form.j_username  = username
          form.j_password = password
        end)
        raise "Wrong username + password combination" if page.uri.to_s != DASHBOARD
        @authenticated = true
      end

      def get(url)
        client.get(url).tap do |page|
          if !page.uri.to_s.include?(url)
            @authenticated = false
            raise AuthenticationError
          end
        end
      end

      def client
        @agent ||= Mechanize.new
      end

      def authenticated?
        @authenticated
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
adyen-admin-0.0.18 lib/adyen-admin/client.rb
adyen-admin-0.0.17 lib/adyen-admin/client.rb
adyen-admin-0.0.16 lib/adyen-admin/client.rb
adyen-admin-0.0.15 lib/adyen-admin/client.rb
adyen-admin-0.0.14 lib/adyen-admin/client.rb
adyen-admin-0.0.13 lib/adyen-admin/client.rb
adyen-admin-0.0.12 lib/adyen-admin/client.rb
adyen-admin-0.0.11 lib/adyen-admin/client.rb