Class: FileAttachment

Inherits:
Flareshow::Resource show all
Extended by:
Flareshow::Searchable
Defined in:
lib/file_attachment.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Flareshow::Searchable

search

Methods inherited from Flareshow::Resource

#cache, cache_response, #changes, create, default_params, #destroy, #destroyed?, find, first, #get, get_from_cache, #id, #initialize, list_cache, #method_missing, #method_name, #refresh, #resource_key, #save, #set, store, #update

Constructor Details

This class inherits a constructor from Flareshow::Resource

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Flareshow::Resource

Class Method Details

.resource_keyObject

file attachments has a resource key of files for querying the server



13
14
15
# File 'lib/file_attachment.rb', line 13

def resource_key
  "files"
end

Instance Method Details

#downloadObject

download the file contents



19
20
21
22
23
24
25
26
# File 'lib/file_attachment.rb', line 19

def download
  url = self.url
  unless url.match(/http/)
    url = "http://#{Flareshow::Service.server.host}/#{Flareshow::Service.server.domain}#{url}"
  end
  Flareshow::Util.log_info("getting #{url}")
  Flareshow::Service.http_get(url)
end

#postObject

post for this file



29
30
31
32
# File 'lib/file_attachment.rb', line 29

def post
  return false unless post_id
  Post.find({:id => post_id})
end

#userObject

get the user for this file



35
36
37
38
# File 'lib/file_attachment.rb', line 35

def user
  p = post && post.first
  p.user && p.user.first
end