Class: ActiveSP::File

Inherits:
Object
  • Object
show all
Includes:
InSite
Defined in:
lib/activesp/file.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(item, url, destroyable) ⇒ File

Returns a new instance of File.



34
35
36
37
# File 'lib/activesp/file.rb', line 34

def initialize(item, url, destroyable)
  @item, @url, @destroyable = item, url, destroyable
  @site = @item.list.site
end

Instance Attribute Details

#urlObject (readonly)

Returns the value of attribute url.



32
33
34
# File 'lib/activesp/file.rb', line 32

def url
  @url
end

Instance Method Details

#content_sizeObject



51
52
53
# File 'lib/activesp/file.rb', line 51

def content_size
  head_data["content-length"].to_i
end

#content_typeObject



47
48
49
# File 'lib/activesp/file.rb', line 47

def content_type
  head_data["content-type"]
end

#dataObject



43
44
45
# File 'lib/activesp/file.rb', line 43

def data
  @item.list.site.connection.fetch(@url).body
end

#destroyObject



55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/activesp/file.rb', line 55

def destroy
  if @destroyable
    result = call("Lists", "delete_attachment", "listName" => @item.list.id, "listItemID" => @item.ID, "url" => @url)
    if delete_result = result.xpath("//sp:DeleteAttachmentResponse", NS).first
      @item.clear_cache_for(:attachment_urls)
      self
    else
      raise "file could not be deleted"
    end
  else
    raise TypeError, "this file cannot be destroyed"
  end
end

#file_nameObject



39
40
41
# File 'lib/activesp/file.rb', line 39

def file_name
  ::File.basename(@url)
end

#to_sObject Also known as: inspect



70
71
72
# File 'lib/activesp/file.rb', line 70

def to_s
  "#<ActiveSP::File url=#{@url}>"
end