Blame view

lib/syspro/business_objects/combrw.rb 1.05 KB
dc8aa5b6   Joe Weakley   Rubocop corrections
1
2
3
4
  # frozen_string_literal: true
  
  require 'syspro/business_objects/parsers/combrw_parser'
  require 'erb'
96149efa   Isaac Lewis   working query browse
5
6
7
8
9
10
11
12
13
14
15
16
  
  module Syspro
    module BusinessObjects
      class ComBrw < ApiResource
        include Syspro::ApiOperations::Query
        include Syspro::BusinessObjects::Parsers
  
        attr_accessor :browse_name, :start_condition, :return_rows, :filters,
                      :table_name, :title, :columns
  
        def call(user_id)
          xml_in = template.result(binding)
dc8aa5b6   Joe Weakley   Rubocop corrections
17
          params = { 'UserId' => user_id, 'XmlIn' => xml_in }
96149efa   Isaac Lewis   working query browse
18
19
20
21
22
          resp = ComBrw.browse(params)
          parse_response(resp)
        end
  
        def template
dc8aa5b6   Joe Weakley   Rubocop corrections
23
24
25
26
27
28
29
          ERB.new(
            File.read(
              File.expand_path('schemas/combrw.xml.erb', File.dirname(__FILE__))
            ),
            nil,
            '%'
          )
96149efa   Isaac Lewis   working query browse
30
31
32
33
        end
  
        def parse_response(resp)
          handle_errors(resp)
0f29247c   Isaac Lewis   add comfch and co...
34
35
          parser = ComBrwParser.new(resp[0].data)
          parser.parse
96149efa   Isaac Lewis   working query browse
36
37
38
39
        end
  
        def handle_errors(resp)
          body = resp[0].http_body
dc8aa5b6   Joe Weakley   Rubocop corrections
40
          raise SysproError, body if body =~ /^(ERROR)/
96149efa   Isaac Lewis   working query browse
41
42
43
44
        end
      end
    end
  end