Blame view

lib/syspro/logon.rb 672 Bytes
dc8aa5b6   Joe Weakley   Rubocop corrections
1
2
  # frozen_string_literal: true
  
49716587   Isaac Lewis   refactor object s...
3
  module Syspro
3d0157a5   Isaac Lewis   add logoff
4
5
6
    class Logon < ApiResource
      def self.logon(username, password, company_id, company_password = nil)
        params = {
dc8aa5b6   Joe Weakley   Rubocop corrections
7
8
9
10
          'Operator' => username,
          'OperatorPassword' => password,
          'CompanyId' => company_id,
          'CompanyPassword' => company_password
3d0157a5   Isaac Lewis   add logoff
11
        }
dc8aa5b6   Joe Weakley   Rubocop corrections
12
        resp = request(:get, resource_url, params)
d2edfc73   Isaac Lewis   handle logon errors
13
        handle_errors(resp)
697a8854   Isaac Lewis   update tests
14
        UserIdObject.new(resp[0].http_body)
3d0157a5   Isaac Lewis   add logoff
15
      end
49716587   Isaac Lewis   refactor object s...
16
  
3d0157a5   Isaac Lewis   add logoff
17
      def resource_url
dc8aa5b6   Joe Weakley   Rubocop corrections
18
        '/Logon'
49716587   Isaac Lewis   refactor object s...
19
      end
3d0157a5   Isaac Lewis   add logoff
20
  
d2edfc73   Isaac Lewis   handle logon errors
21
22
23
24
25
      def handle_errors(resp)
        body = resp[0].http_body
        raise AuthenticationError, body if body =~ /^(ERROR)/
      end
  
3d0157a5   Isaac Lewis   add logoff
26
      UserIdObject = Struct.new(:guid)
49716587   Isaac Lewis   refactor object s...
27
28
    end
  end