Sha256: a5ce0b79d5bf527ac794d4db9f799ab4bd562a657827a8a29421d6364a7d7f9b

Contents?: true

Size: 663 Bytes

Versions: 1

Compression:

Stored size: 663 Bytes

Contents

require 'mime/types'
module NCMB
  class NFile < NCMB::Object
    include NCMB
    def initialize(file_path = nil)
      @fields = {acl: NCMB::Acl.new, file: file_path}
      if file_path
        @fields[:fileName] = File.basename(file_path)
        @fields['mime-type'.to_sym] = MIME::Types.type_for(file_path)[0]
      end
      @content = nil
    end
    
    def save
      @fields[:file] = open(self.file)
      super
    end
    alias :update :save
    
    def get
      @content = @@client.get path
    end
    
    def path
      "#{base_path}/#{@fields[:fileName]}"
    end
    
    def base_path
      "/#{@@client.api_version}/files"
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ncmb-ruby-client-0.1.3 lib/ncmb/file.rb