Blame view

lib/syspro/business_objects/combrw.rb 1007 Bytes
96149efa   Isaac Lewis   working query browse
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
  require "syspro/business_objects/parsers/combrw_parser"
  require "erb"
  
  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)
          params = { "UserId" => user_id, "XmlIn" => xml_in }
          resp = ComBrw.browse(params)
          parse_response(resp)
        end
  
        def template
          ERB.new File.read(File.expand_path("schemas/combrw.xml.erb", File.dirname(__FILE__))), nil, "%"
        end
  
        def parse_response(resp)
          handle_errors(resp)
0f29247c   Isaac Lewis   add comfch and co...
26
27
          parser = ComBrwParser.new(resp[0].data)
          parser.parse
96149efa   Isaac Lewis   working query browse
28
29
30
31
32
33
34
35
36
37
38
        end
  
        def handle_errors(resp)
          body = resp[0].http_body
          if body.match(/^(ERROR)/)
            raise SysproError, body
          end
        end
      end
    end
  end