Class: Basecamp::Attachment
- Inherits:
-
Object
- Object
- Basecamp::Attachment
- Defined in:
- lib/basecamp.rb
Instance Attribute Summary collapse
-
#content ⇒ Object
Returns the value of attribute content.
-
#filename ⇒ Object
Returns the value of attribute filename.
-
#id ⇒ Object
Returns the value of attribute id.
Class Method Summary collapse
Instance Method Summary collapse
- #attributes ⇒ Object
-
#initialize(filename, content) ⇒ Attachment
constructor
A new instance of Attachment.
- #inspect ⇒ Object
- #save ⇒ Object
- #to_xml(options = {}) ⇒ Object
Constructor Details
#initialize(filename, content) ⇒ Attachment
Returns a new instance of Attachment.
223 224 225 |
# File 'lib/basecamp.rb', line 223 def initialize(filename, content) @filename, @content = filename, content end |
Instance Attribute Details
#content ⇒ Object
Returns the value of attribute content.
215 216 217 |
# File 'lib/basecamp.rb', line 215 def content @content end |
#filename ⇒ Object
Returns the value of attribute filename.
215 216 217 |
# File 'lib/basecamp.rb', line 215 def filename @filename end |
#id ⇒ Object
Returns the value of attribute id.
215 216 217 |
# File 'lib/basecamp.rb', line 215 def id @id end |
Class Method Details
.create(filename, content) ⇒ Object
217 218 219 220 221 |
# File 'lib/basecamp.rb', line 217 def self.create(filename, content) returning new(filename, content) do || .save end end |
Instance Method Details
#attributes ⇒ Object
227 228 229 |
# File 'lib/basecamp.rb', line 227 def attributes { :file => id, :original_filename => filename } end |
#inspect ⇒ Object
235 236 237 |
# File 'lib/basecamp.rb', line 235 def inspect to_s end |
#save ⇒ Object
239 240 241 242 243 244 245 246 247 248 |
# File 'lib/basecamp.rb', line 239 def save response = Basecamp.connection.post('/upload', content, 'Content-Type' => 'application/octet-stream') if response.code == '200' self.id = Hash.from_xml(response.body)['upload']['id'] true else raise "Could not save attachment: #{response.} (#{response.code})" end end |
#to_xml(options = {}) ⇒ Object
231 232 233 |
# File 'lib/basecamp.rb', line 231 def to_xml( = {}) { :file => attributes }.to_xml() end |