Blame view

lib/syspro/business_objects/comfch.rb 947 Bytes
dc8aa5b6   Joe Weakley   Rubocop corrections
1
2
3
4
  # frozen_string_literal: true
  
  require 'syspro/business_objects/parsers/comfch_parser'
  require 'erb'
0f29247c   Isaac Lewis   add comfch and co...
5
6
7
8
9
10
11
12
13
14
15
16
  
  module Syspro
    module BusinessObjects
      class ComFch < ApiResource
        include Syspro::ApiOperations::Query
        include Syspro::BusinessObjects::Parsers
  
        attr_accessor :table_name, :key, :optional_keys, :full_key_provided,
                      :default_type, :espresso_fetch
  
        def call(user_id)
          xml_in = template.result(binding)
dc8aa5b6   Joe Weakley   Rubocop corrections
17
          params = { 'UserId' => user_id, 'XmlIn' => xml_in }
0f29247c   Isaac Lewis   add comfch and co...
18
19
20
21
22
          resp = ComFch.fetch(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/comfch.xml.erb', File.dirname(__FILE__))
            ),
            nil,
            '%'
          )
0f29247c   Isaac Lewis   add comfch and co...
30
31
32
33
34
35
36
        end
  
        def parse_response(resp)
          handle_errors(resp)
          parser = ComFchParser.new(resp[0].data)
          parser.parse
        end
0f29247c   Isaac Lewis   add comfch and co...
37
38
39
      end
    end
  end