Blame view

lib/syspro/api_operations/request.rb 1.03 KB
dc8aa5b6   Joe Weakley   Rubocop corrections
1
2
  # frozen_string_literal: true
  
db76748d   Isaac Lewis   cop a bunch of St...
3
4
5
  module Syspro
    module ApiOperations
      module Request
3d0157a5   Isaac Lewis   add logoff
6
7
8
9
10
11
        module ClassMethods
          def request(method, url, params = {}, opts = {})
            warn_on_opts_in_params(params)
  
            opts = Util.normalize_opts(opts)
            opts[:client] ||= SysproClient.active_client
db76748d   Isaac Lewis   cop a bunch of St...
12
13
  
            headers = opts.clone
3d0157a5   Isaac Lewis   add logoff
14
15
16
            user_id = headers.delete(:user_id)
            client = headers.delete(:client)
            # Assume all remaining opts must be headers
db76748d   Isaac Lewis   cop a bunch of St...
17
18
19
20
  
            resp = client.execute_request(
              method, url,
              headers: headers,
3d0157a5   Isaac Lewis   add logoff
21
              user_id: user_id,
db76748d   Isaac Lewis   cop a bunch of St...
22
23
24
25
              params: params
            )
  
            resp
3d0157a5   Isaac Lewis   add logoff
26
          end
db76748d   Isaac Lewis   cop a bunch of St...
27
  
3d0157a5   Isaac Lewis   add logoff
28
29
30
          private
  
          def warn_on_opts_in_params(params)
db76748d   Isaac Lewis   cop a bunch of St...
31
32
            Util::OPTS_USER_SPECIFIED.each do |opt|
              if params.key?(opt)
dc8aa5b6   Joe Weakley   Rubocop corrections
33
                warn("WARNING: #{opt} should be in opts instead of params.")
db76748d   Isaac Lewis   cop a bunch of St...
34
35
              end
            end
3d0157a5   Isaac Lewis   add logoff
36
37
38
39
40
41
          end
        end # ClassMethods
  
        def self.included(base)
          base.extend(ClassMethods)
        end
db76748d   Isaac Lewis   cop a bunch of St...
42
43
44
      end
    end
  end