Blame view

lib/syspro/business_objects/combrw.rb 1.09 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
  
  module Syspro
    module BusinessObjects
      class ComBrw < ApiResource
        include Syspro::ApiOperations::Query
        include Syspro::BusinessObjects::Parsers
  
8d1385a3   Sam Clopton   Update combrw que...
12
13
14
15
        attr_accessor :browse_name, :start_at_key, :start_condition, :return_rows,
                      :filters, :table_name, :title, :columns
  
        attr_writer :filters
96149efa   Isaac Lewis   working query browse
16
  
cdbe5509   Isaac Lewis   default raw to fa...
17
        def call(user_id, raw = false)
96149efa   Isaac Lewis   working query browse
18
          xml_in = template.result(binding)
dc8aa5b6   Joe Weakley   Rubocop corrections
19
          params = { 'UserId' => user_id, 'XmlIn' => xml_in }
96149efa   Isaac Lewis   working query browse
20
          resp = ComBrw.browse(params)
8d1385a3   Sam Clopton   Update combrw que...
21
  
b1c0def6   Samuel J Clopton   rubocop violation...
22
          if raw
c000d46c   Isaac Lewis   add raw xml output
23
            resp
b1c0def6   Samuel J Clopton   rubocop violation...
24
25
          else
            parse_response(resp)
c000d46c   Isaac Lewis   add raw xml output
26
          end
96149efa   Isaac Lewis   working query browse
27
28
29
        end
  
        def template
dc8aa5b6   Joe Weakley   Rubocop corrections
30
31
32
33
34
35
36
          ERB.new(
            File.read(
              File.expand_path('schemas/combrw.xml.erb', File.dirname(__FILE__))
            ),
            nil,
            '%'
          )
96149efa   Isaac Lewis   working query browse
37
38
39
40
        end
  
        def parse_response(resp)
          handle_errors(resp)
0f29247c   Isaac Lewis   add comfch and co...
41
42
          parser = ComBrwParser.new(resp[0].data)
          parser.parse
96149efa   Isaac Lewis   working query browse
43
        end
8d1385a3   Sam Clopton   Update combrw que...
44
45
46
47
  
        def filters
          @filters || []
        end
96149efa   Isaac Lewis   working query browse
48
49
50
      end
    end
  end