Class: Podio::FileAttachment
Overview
Instance Attribute Summary
#attributes
Class Method Summary
collapse
-
.attach(id, ref_type, ref_id) ⇒ Object
Attach a file to an existing reference.
-
.copy(id) ⇒ Object
-
.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.
-
.create_from_external_file_id(linked_account_id, external_file_id, preserve_permissions = false, options = {}) ⇒ Object
-
.delete(id) ⇒ Object
-
.find(id) ⇒ Object
-
.find_all(options = {}) ⇒ Object
-
.find_for_app(app_id, options = {}) ⇒ Object
-
.find_for_google(linked_account_id, options = {}) ⇒ Object
-
.find_for_space(space_id, options = {}) ⇒ Object
-
.find_latest_for_app(app_id, options = {}) ⇒ Object
-
.find_latest_for_space(space_id, options = {}) ⇒ Object
-
.find_raw(id) ⇒ Object
-
.replace(old_file_id, new_file_id) ⇒ Object
-
.set_available(id) ⇒ Object
Then, when the file has been moved, it must be marked as available.
-
.update(id, description) ⇒ Object
-
.upload(file_stream, file_name) ⇒ Object
Accepts an open file stream along with a file name and uploads the file to Podio.
-
.upload_from_url(url) ⇒ Object
Instance Method Summary
collapse
#==, #[], #[]=, #as_json, collection, delegate_to_hash, has_many, has_one, #hash, #initialize, #initialize_attributes, klass_from_string, list, member, #new_record?, output_attribute_as_json, #parent_model, #persisted?, property, #to_param
Class Method Details
.attach(id, ref_type, ref_id) ⇒ Object
Attach a file to an existing reference
85
86
87
88
89
90
|
# File 'lib/podio/models/file_attachment.rb', line 85
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
93
94
95
|
# File 'lib/podio/models/file_attachment.rb', line 93
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
176
177
178
179
180
181
182
183
|
# File 'lib/podio/models/file_attachment.rb', line 176
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
|
.create_from_external_file_id(linked_account_id, external_file_id, preserve_permissions = false, options = {}) ⇒ Object
71
72
73
74
75
76
77
78
79
80
81
|
# File 'lib/podio/models/file_attachment.rb', line 71
def create_from_external_file_id(linked_account_id, external_file_id, preserve_permissions=false, options={})
response = Podio.client.connection.post do |req|
req.url("/file/linked_account/#{linked_account_id}/", options)
req.body = {
:external_file_id => external_file_id,
:preserve_permissions => preserve_permissions
}
end
member response.body
end
|
.delete(id) ⇒ Object
98
99
100
|
# File 'lib/podio/models/file_attachment.rb', line 98
def delete(id)
Podio.connection.delete("/file/#{id}")
end
|
.find(id) ⇒ Object
103
104
105
|
# File 'lib/podio/models/file_attachment.rb', line 103
def find(id)
member Podio.connection.get("/file/#{id}").body
end
|
.find_all(options = {}) ⇒ Object
113
114
115
116
117
|
# File 'lib/podio/models/file_attachment.rb', line 113
def find_all(options={})
list Podio.connection.get { |req|
req.url("/file/", options)
}.body
end
|
.find_for_app(app_id, options = {}) ⇒ Object
120
121
122
123
124
|
# File 'lib/podio/models/file_attachment.rb', line 120
def find_for_app(app_id, options={})
list Podio.connection.get { |req|
req.url("/file/app/#{app_id}/", options)
}.body
end
|
.find_for_google(linked_account_id, options = {}) ⇒ Object
147
148
149
150
151
|
# File 'lib/podio/models/file_attachment.rb', line 147
def find_for_google(linked_account_id, options={})
list Podio.connection.get { |req|
req.url("/file/google/#{linked_account_id}/", options)
}.body
end
|
.find_for_space(space_id, options = {}) ⇒ Object
127
128
129
130
131
|
# File 'lib/podio/models/file_attachment.rb', line 127
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
134
135
136
137
138
|
# File 'lib/podio/models/file_attachment.rb', line 134
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
141
142
143
144
145
|
# File 'lib/podio/models/file_attachment.rb', line 141
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
108
109
110
|
# File 'lib/podio/models/file_attachment.rb', line 108
def find_raw(id)
Podio.client.connection.get("/file/#{id}/raw").body
end
|
.replace(old_file_id, new_file_id) ⇒ Object
154
155
156
157
158
159
|
# File 'lib/podio/models/file_attachment.rb', line 154
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
186
187
188
|
# File 'lib/podio/models/file_attachment.rb', line 186
def set_available(id)
Podio.connection.post "/file/#{id}/available"
end
|
.update(id, description) ⇒ Object
162
163
164
165
166
167
|
# File 'lib/podio/models/file_attachment.rb', line 162
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
51
52
53
54
55
56
57
58
59
60
|
# File 'lib/podio/models/file_attachment.rb', line 51
def upload(file_stream, file_name)
response = Podio.client.connection.post do |req|
req.options[:timeout] = 1200
req.url "/file/v2/"
req.['Content-Type'] = 'multipart/form-data'
req.body = {:source => Faraday::UploadIO.new(file_stream, nil, nil), :filename => file_name}
end
member response.body
end
|
.upload_from_url(url) ⇒ Object
62
63
64
65
66
67
68
69
|
# File 'lib/podio/models/file_attachment.rb', line 62
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
#api_friendly_ref_type ⇒ Object
37
38
39
|
# File 'lib/podio/models/file_attachment.rb', line 37
def api_friendly_ref_type
'file'
end
|
#has_thumbnail? ⇒ Boolean
29
30
31
|
# File 'lib/podio/models/file_attachment.rb', line 29
def has_thumbnail?
self.thumbnail_link.present?
end
|
#image? ⇒ Boolean
33
34
35
|
# File 'lib/podio/models/file_attachment.rb', line 33
def image?
['image/png', 'image/jpeg', 'image/gif', 'image/bmp'].include?(self.mimetype)
end
|
#raw_data(size = nil) ⇒ Object
43
44
45
46
|
# File 'lib/podio/models/file_attachment.rb', line 43
def raw_data(size=nil)
link = size ? "#{self.link}/#{size}" : self.link
Podio.connection.get(link).body
end
|