Class: BasecampAPI::Attachment
- Inherits:
-
Object
- Object
- BasecampAPI::Attachment
- Defined in:
- lib/basecamp/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.
367 368 369 |
# File 'lib/basecamp/basecamp.rb', line 367 def initialize(filename, content) @filename, @content = filename, content end |
Instance Attribute Details
#content ⇒ Object
Returns the value of attribute content.
359 360 361 |
# File 'lib/basecamp/basecamp.rb', line 359 def content @content end |
#filename ⇒ Object
Returns the value of attribute filename.
359 360 361 |
# File 'lib/basecamp/basecamp.rb', line 359 def filename @filename end |
#id ⇒ Object
Returns the value of attribute id.
359 360 361 |
# File 'lib/basecamp/basecamp.rb', line 359 def id @id end |
Class Method Details
.create(filename, content) ⇒ Object
361 362 363 364 365 |
# File 'lib/basecamp/basecamp.rb', line 361 def self.create(filename, content) returning new(filename, content) do || .save end end |
Instance Method Details
#attributes ⇒ Object
371 372 373 |
# File 'lib/basecamp/basecamp.rb', line 371 def attributes { :file => id, :original_filename => filename } end |
#inspect ⇒ Object
379 380 381 |
# File 'lib/basecamp/basecamp.rb', line 379 def inspect to_s end |
#save ⇒ Object
383 384 385 386 387 388 389 390 391 392 |
# File 'lib/basecamp/basecamp.rb', line 383 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
375 376 377 |
# File 'lib/basecamp/basecamp.rb', line 375 def to_xml( = {}) { :file => attributes }.to_xml() end |