Sha256: 95267814756bb4a0097a5cb692874b7098294ee9447c28981de661fc504343b6

Contents?: true

Size: 778 Bytes

Versions: 8

Compression:

Stored size: 778 Bytes

Contents

module Eucalyptus
  class Response < OpenStruct
    # extend OpenStruct to work with nested hashes
    def initialize(hash)
      @table = {}
      @hash_table = {}

      hash.each do |k, v|
        @table[k.to_sym] = (v.is_a?(Hash) ? self.class.new(v) : v)
        @hash_table[k.to_sym] = v

        new_ostruct_member(k)
      end
    end
  end

  class ResponseCollection < Array
    def initialize(klass, koala_response)
      @koala_response = koala_response
      @klass = klass
      self.concat elements(@koala_response)
    end


    def next_page
      next_p = @koala_response.next_page
      if next_p
        self.class.new(@klass, next_p)
      end
    end

    private
    def elements(response)
      response.collect{ |res| @klass.new(res) }
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
eucalyptus-1.2.4 lib/eucalyptus/response.rb
eucalyptus-1.2.3 lib/eucalyptus/response.rb
eucalyptus-1.2.2 lib/eucalyptus/response.rb
eucalyptus-1.2.1 lib/eucalyptus/response.rb
eucalyptus-1.2.0 lib/eucalyptus/response.rb
eucalyptus-1.1.0 lib/eucalyptus/response.rb
eucalyptus-1.0.0 lib/eucalyptus/response.rb
eucalyptus-0.3.3 lib/eucalyptus/response.rb