Class: Podio::FileAttachment

Inherits:
ActivePodio::Base show all
Defined in:
lib/podio/models/file_attachment.rb

Instance Attribute Summary

Attributes inherited from ActivePodio::Base

#attributes, #error_code, #error_message, #error_parameters, #error_propagate

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ActivePodio::Base

#==, #[], #[]=, #as_json, collection, delegate_to_hash, handle_api_errors_for, has_many, has_one, #hash, #initialize, list, member, #new_record?, #persisted?, property, #to_param

Constructor Details

This class inherits a constructor from ActivePodio::Base

Class Method Details

.attach(id, ref_type, ref_id) ⇒ Object

Attach a file to an existing reference



43
44
45
46
47
48
# File 'lib/podio/models/file_attachment.rb', line 43

def attach(id, ref_type, ref_id)
  Podio.connection.post do |req|
    req.url "/file/#{id}/attach"
    req.body = {:ref_type => ref_type, :ref_id => ref_id}
  end
end

.copy(id) ⇒ Object



50
51
52
# File 'lib/podio/models/file_attachment.rb', line 50

def copy(id)
  Podio.connection.post("/file/#{id}/copy").body['file_id']
end

.create(name, content_type) ⇒ Object

Uploading a file is a two-step operation First, the file must be created to get a file id and the path to move it to



111
112
113
114
115
116
117
118
# File 'lib/podio/models/file_attachment.rb', line 111

def create(name, content_type)
  response = Podio.connection.post do |req|
    req.url "/file/"
    req.body = { :name => name, :mimetype => content_type }
  end

  response.body
end

.delete(id) ⇒ Object



54
55
56
# File 'lib/podio/models/file_attachment.rb', line 54

def delete(id)
  Podio.connection.delete("/file/#{id}")
end

.find(id) ⇒ Object



58
59
60
# File 'lib/podio/models/file_attachment.rb', line 58

def find(id)
  member Podio.connection.get("/file/#{id}").body
end

.find_for_app(app_id, options = {}) ⇒ Object



66
67
68
69
70
# File 'lib/podio/models/file_attachment.rb', line 66

def find_for_app(app_id, options={})
  list Podio.connection.get { |req|
    req.url("/file/app/#{app_id}/", options)
  }.body
end

.find_for_space(space_id, options = {}) ⇒ Object



72
73
74
75
76
# File 'lib/podio/models/file_attachment.rb', line 72

def find_for_space(space_id, options={})
  list Podio.connection.get { |req|
    req.url("/file/space/#{space_id}/", options)
  }.body
end

.find_latest_for_app(app_id, options = {}) ⇒ Object



78
79
80
81
82
# File 'lib/podio/models/file_attachment.rb', line 78

def find_latest_for_app(app_id, options={})
  list Podio.connection.get { |req|
    req.url("/file/app/#{app_id}/latest/", options)
  }.body
end

.find_latest_for_space(space_id, options = {}) ⇒ Object



84
85
86
87
88
# File 'lib/podio/models/file_attachment.rb', line 84

def find_latest_for_space(space_id, options={})
  list Podio.connection.get { |req|
    req.url("/file/space/#{space_id}/latest/", options)
  }.body
end

.find_raw(id) ⇒ Object



62
63
64
# File 'lib/podio/models/file_attachment.rb', line 62

def find_raw(id)
  Podio.client.raw_connection.get("/file/#{id}/raw").body
end

.replace(old_file_id, new_file_id) ⇒ Object



90
91
92
93
94
95
# File 'lib/podio/models/file_attachment.rb', line 90

def replace(old_file_id, new_file_id)
  Podio.connection.post { |req|
    req.url "/file/#{new_file_id}/replace"
    req.body = { :old_file_id => old_file_id }
  }.body
end

.set_available(id) ⇒ Object

Then, when the file has been moved, it must be marked as available



121
122
123
# File 'lib/podio/models/file_attachment.rb', line 121

def set_available(id)
  Podio.connection.post "/file/#{id}/available"
end

.update(id, description) ⇒ Object



97
98
99
100
101
102
# File 'lib/podio/models/file_attachment.rb', line 97

def update(id, description)
  Podio.connection.put { |req|
    req.url "/file/#{file_id}"
    req.body = { :description => description }
  }.body
end

.upload(file_stream, file_name) ⇒ Object

Accepts an open file stream along with a file name and uploads the file to Podio



23
24
25
26
27
28
29
30
31
# File 'lib/podio/models/file_attachment.rb', line 23

def upload(file_stream, file_name)
  response = Podio.client.raw_connection.post do |req|
    req.options[:timeout] = 1200
    req.url "/file/v2/"
    req.body = {:source => Faraday::UploadIO.new(file_stream, nil, nil), :filename => file_name}
  end

  member response.body
end

.upload_from_url(url) ⇒ Object



33
34
35
36
37
38
39
40
# File 'lib/podio/models/file_attachment.rb', line 33

def upload_from_url(url)
  response = Podio.client.connection.post do |req|
    req.url "/file/from_url/"
    req.body = {:url => url}
  end

  member response.body
end

Instance Method Details

#image?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/podio/models/file_attachment.rb', line 17

def image?
  ['image/png', 'image/jpeg', 'image/gif', 'image/bmp'].include?(self.mimetype)
end