Class: Podio::FileAttachment
Instance Attribute Summary
#attributes, #error_code, #error_message, #error_parameters, #error_propagate
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.
-
.delete(id) ⇒ Object
-
.find(id) ⇒ 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, handle_api_errors_for, has_many, has_one, #hash, #initialize, list, member, #new_record?, #persisted?, property, #to_param
Class Method Details
.attach(id, ref_type, ref_id) ⇒ Object
Attach a file to an existing reference
55
56
57
58
59
60
|
# File 'lib/podio/models/file_attachment.rb', line 55
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
62
63
64
|
# File 'lib/podio/models/file_attachment.rb', line 62
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
129
130
131
132
133
134
135
136
|
# File 'lib/podio/models/file_attachment.rb', line 129
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
66
67
68
|
# File 'lib/podio/models/file_attachment.rb', line 66
def delete(id)
Podio.connection.delete("/file/#{id}")
end
|
.find(id) ⇒ Object
70
71
72
|
# File 'lib/podio/models/file_attachment.rb', line 70
def find(id)
member Podio.connection.get("/file/#{id}").body
end
|
.find_for_app(app_id, options = {}) ⇒ Object
78
79
80
81
82
|
# File 'lib/podio/models/file_attachment.rb', line 78
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
102
103
104
105
106
|
# File 'lib/podio/models/file_attachment.rb', line 102
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
84
85
86
87
88
|
# File 'lib/podio/models/file_attachment.rb', line 84
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
90
91
92
93
94
|
# File 'lib/podio/models/file_attachment.rb', line 90
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
96
97
98
99
100
|
# File 'lib/podio/models/file_attachment.rb', line 96
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
74
75
76
|
# File 'lib/podio/models/file_attachment.rb', line 74
def find_raw(id)
Podio.client.raw_connection.get("/file/#{id}/raw").body
end
|
.replace(old_file_id, new_file_id) ⇒ Object
108
109
110
111
112
113
|
# File 'lib/podio/models/file_attachment.rb', line 108
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
139
140
141
|
# File 'lib/podio/models/file_attachment.rb', line 139
def set_available(id)
Podio.connection.post "/file/#{id}/available"
end
|
.update(id, description) ⇒ Object
115
116
117
118
119
120
|
# File 'lib/podio/models/file_attachment.rb', line 115
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
35
36
37
38
39
40
41
42
43
|
# File 'lib/podio/models/file_attachment.rb', line 35
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
45
46
47
48
49
50
51
52
|
# File 'lib/podio/models/file_attachment.rb', line 45
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
29
30
31
|
# File 'lib/podio/models/file_attachment.rb', line 29
def api_friendly_ref_type
'file'
end
|
#has_thumbnail? ⇒ Boolean
21
22
23
|
# File 'lib/podio/models/file_attachment.rb', line 21
def has_thumbnail?
self.thumbnail_link.present?
end
|
#image? ⇒ Boolean
25
26
27
|
# File 'lib/podio/models/file_attachment.rb', line 25
def image?
['image/png', 'image/jpeg', 'image/gif', 'image/bmp'].include?(self.mimetype)
end
|