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, #initialize_attributes, list, member, #new_record?, output_attribute_as_json, #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



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

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



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

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



130
131
132
133
134
135
136
137
# File 'lib/podio/models/file_attachment.rb', line 130

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



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

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

.find(id) ⇒ Object



71
72
73
# File 'lib/podio/models/file_attachment.rb', line 71

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

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



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

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



103
104
105
106
107
# File 'lib/podio/models/file_attachment.rb', line 103

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

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



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

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



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

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



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

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



75
76
77
# File 'lib/podio/models/file_attachment.rb', line 75

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

.replace(old_file_id, new_file_id) ⇒ Object



109
110
111
112
113
114
# File 'lib/podio/models/file_attachment.rb', line 109

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



140
141
142
# File 'lib/podio/models/file_attachment.rb', line 140

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

.update(id, description) ⇒ Object



116
117
118
119
120
121
# File 'lib/podio/models/file_attachment.rb', line 116

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
44
# File 'lib/podio/models/file_attachment.rb', line 35

def upload(file_stream, file_name)
  response = Podio.client.connection.post do |req|
    req.options[:timeout] = 1200
    req.url "/file/v2/"
    req.headers['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



46
47
48
49
50
51
52
53
# File 'lib/podio/models/file_attachment.rb', line 46

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_typeObject



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

def api_friendly_ref_type
  'file'
end

#has_thumbnail?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/podio/models/file_attachment.rb', line 21

def has_thumbnail?
  self.thumbnail_link.present?
end

#image?Boolean

Returns:

  • (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