Blame view

lib/syspro/api_operations/request.rb 1.01 KB
db76748d   Isaac Lewis   cop a bunch of St...
1
2
3
  module Syspro
    module ApiOperations
      module Request
3d0157a5   Isaac Lewis   add logoff
4
5
6
7
8
9
        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...
10
11
  
            headers = opts.clone
3d0157a5   Isaac Lewis   add logoff
12
13
14
            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...
15
16
17
18
  
            resp = client.execute_request(
              method, url,
              headers: headers,
3d0157a5   Isaac Lewis   add logoff
19
              user_id: user_id,
db76748d   Isaac Lewis   cop a bunch of St...
20
21
22
23
              params: params
            )
  
            resp
3d0157a5   Isaac Lewis   add logoff
24
          end
db76748d   Isaac Lewis   cop a bunch of St...
25
  
3d0157a5   Isaac Lewis   add logoff
26
27
28
          private
  
          def warn_on_opts_in_params(params)
db76748d   Isaac Lewis   cop a bunch of St...
29
30
31
32
33
            Util::OPTS_USER_SPECIFIED.each do |opt|
              if params.key?(opt)
                $stderr.puts("WARNING: #{opt} should be in opts instead of params.")
              end
            end
3d0157a5   Isaac Lewis   add logoff
34
35
36
37
38
39
          end
        end # ClassMethods
  
        def self.included(base)
          base.extend(ClassMethods)
        end
db76748d   Isaac Lewis   cop a bunch of St...
40
41
42
      end
    end
  end