Sha256: 153878c00138b1328931717110f3c7380a856ac8e4be9283219273dca2f06b2e

Contents?: true

Size: 689 Bytes

Versions: 5

Compression:

Stored size: 689 Bytes

Contents

module Schoolfinder
  class Response

    attr_accessor :body

    def initialize(response)
      rash_response(response)
      if self.body.respond_to?('fault_string')
        raise Schoolfinder::Error.new(self.body.fault_code, self.body.fault_string)
      end
    end

    private

    def rash_response(response)
      if response.is_a?(Array)
        self.body = []
        response.each do |b|
          if b.is_a?(Hash)
            self.body << Hashie::Rash.new(b)
          else
            self.body << b
          end
        end
      elsif response.is_a?(Hash)
        self.body = Hashie::Rash.new(response)
      else
        self.body = response
      end
    end

  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
schoolfinder-0.4.3 lib/schoolfinder/response.rb
schoolfinder-0.4.2 lib/schoolfinder/response.rb
schoolfinder-0.4.1 lib/schoolfinder/response.rb
schoolfinder-0.4.0 lib/schoolfinder/response.rb
schoolfinder-0.3.1 lib/schoolfinder/response.rb