Sha256: 1c2a726f2a20bf5302b97f65ab971b7fa6ee2da61da729217ff1d52a26382121

Contents?: true

Size: 917 Bytes

Versions: 3

Compression:

Stored size: 917 Bytes

Contents

module Grendel
  class Document
    attr_accessor :user, :name, :uri, :data, :content_type

    def initialize(user, params)
      params = Mash.new(params)
      @user = user
      @client = user.client
      @name = params[:name]
      @data = params[:data]
      @content_type = params[:content_type]
      @uri = params[:uri] ?
        URI.parse(params[:uri]).path :
        "/documents/" + @name # escape this?
    end

    # delete this document from Grendel
    def delete
      @user.delete(@uri)
    end

    # send link operations to the Link class
    def links
      LinkManager.new(self)
    end

    def content_type
      @content_type ||= begin
        @user.head(@uri).headers['content-type'].first
      end
    end

    def data
      @data ||= begin
        response = @user.get(@uri)
        @content_type = response.headers['content-type'].first
        response.body
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
grendel-ruby-0.1.5 lib/grendel/document.rb
grendel-ruby-0.1.4 lib/grendel/document.rb
grendel-ruby-0.1.3 lib/grendel/document.rb