Sha256: 61599ffd9ed36fed4da55b664e394b93e72c8cd02bc8faf98019bfef2e034988

Contents?: true

Size: 704 Bytes

Versions: 4

Compression:

Stored size: 704 Bytes

Contents

class Iknow::Base

  def self.attributes; self::ATTRIBUTES end

  def attributes; self.class.attributes  end

  def self.deserialize(response, params = {})
    return nil if response.nil? or
                 (response.is_a?(Hash) and
                 !response['error'].nil? and
                  response['error']['code'].to_i == 404)

    klass = params[:as] ? params[:as] : self
    if response.is_a?(Array)
      response.inject([]) { |results, hash|
        hash.symbolize_keys!
        results << klass.new(hash)
      }
    else
      response.symbolize_keys!
      klass.new(response)
    end
  end

  def deserialize(response, params = {})
    self.class.deserialize(response, params)
  end

end

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
nov-iknow-0.0.4 lib/iknow/model/base.rb
nov-iknow-0.1.0 lib/iknow/model/base.rb
iknow-0.1.0 lib/iknow/model/base.rb
iknow-0.0.4 lib/iknow/model/base.rb