Sha256: 33d94b48f00db2550ad520e611da59baa8f6dc6ee547ebc030b15e108efc630e

Contents?: true

Size: 1 KB

Versions: 13

Compression:

Stored size: 1 KB

Contents

# frozen_string_literal: true

module AutotaskRuby
  module Response
    include Constants
    attr_accessor :entity_type, :errors, :return_code, :entities

    def initialize(client, response)
      @client = client
      @entities = []
      @errors = response.xpath('//Autotask:Errors', Autotask: AutotaskRuby.configuration.namespace).text
      @return_code = response.xpath('//Autotask:ReturnCode', Autotask: AutotaskRuby.configuration.namespace).text.to_i
      @entity_type = response.xpath('//Autotask:EntityResultType', Autotask: AutotaskRuby.configuration.namespace).text.classify
      parse_entities(response.xpath('//Autotask:Entity', Autotask: AutotaskRuby.configuration.namespace))
    end

    private

    def parse_entities(results)
      return [] if results.blank?

      klass = ('AutotaskRuby::' + results.first.attribute('type').to_s).constantize
      results.collect do |entity|
        obj = klass.new(client: @client)
        obj.build(entity)
        @entities.push(obj)
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
autotask_ruby-2.4.2 lib/autotask_ruby/response.rb
autotask_ruby-2.4.1 lib/autotask_ruby/response.rb
autotask_ruby-2.4.0 lib/autotask_ruby/response.rb
autotask_ruby-2.3.2 lib/autotask_ruby/response.rb
autotask_ruby-2.3.1 lib/autotask_ruby/response.rb
autotask_ruby-2.3.0 lib/autotask_ruby/response.rb
autotask_ruby-2.2.0 lib/autotask_ruby/response.rb
autotask_ruby-2.1.3 lib/autotask_ruby/response.rb
autotask_ruby-2.1.2 lib/autotask_ruby/response.rb
autotask_ruby-2.1.1 lib/autotask_ruby/response.rb
autotask_ruby-2.1.0 lib/autotask_ruby/response.rb
autotask_ruby-2.0.1 lib/autotask_ruby/response.rb
autotask_ruby-2.0.0 lib/autotask_ruby/response.rb