Blame view

lib/syspro/business_objects/combrw.rb 1.01 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
  
e12f0c9d   Isaac Lewis   add start_at_key ...
12
        attr_accessor :browse_name, :start_at_key, :start_condition, :return_rows, :filters,
96149efa   Isaac Lewis   working query browse
13
14
                      :table_name, :title, :columns
  
cdbe5509   Isaac Lewis   default raw to fa...
15
        def call(user_id, raw = false)
96149efa   Isaac Lewis   working query browse
16
          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
          resp = ComBrw.browse(params)
b1c0def6   Samuel J Clopton   rubocop violation...
19
          if raw
c000d46c   Isaac Lewis   add raw xml output
20
            resp
b1c0def6   Samuel J Clopton   rubocop violation...
21
22
          else
            parse_response(resp)
c000d46c   Isaac Lewis   add raw xml output
23
          end
96149efa   Isaac Lewis   working query browse
24
25
26
        end
  
        def template
dc8aa5b6   Joe Weakley   Rubocop corrections
27
28
29
30
31
32
33
          ERB.new(
            File.read(
              File.expand_path('schemas/combrw.xml.erb', File.dirname(__FILE__))
            ),
            nil,
            '%'
          )
96149efa   Isaac Lewis   working query browse
34
35
36
37
        end
  
        def parse_response(resp)
          handle_errors(resp)
0f29247c   Isaac Lewis   add comfch and co...
38
39
          parser = ComBrwParser.new(resp[0].data)
          parser.parse
96149efa   Isaac Lewis   working query browse
40
        end
96149efa   Isaac Lewis   working query browse
41
42
43
      end
    end
  end