Class: Basecamp::Attachment
- Inherits:
-
Object
- Object
- Basecamp::Attachment
- Defined in:
- lib/basecamp/resources/attachment.rb
Instance Attribute Summary collapse
-
#category_id ⇒ Object
Returns the value of attribute category_id.
-
#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.
10 11 12 |
# File 'lib/basecamp/resources/attachment.rb', line 10 def initialize(filename, content) @filename, @content = filename, content end |
Instance Attribute Details
#category_id ⇒ Object
Returns the value of attribute category_id.
2 3 4 |
# File 'lib/basecamp/resources/attachment.rb', line 2 def category_id @category_id end |
#content ⇒ Object
Returns the value of attribute content.
2 3 4 |
# File 'lib/basecamp/resources/attachment.rb', line 2 def content @content end |
#filename ⇒ Object
Returns the value of attribute filename.
2 3 4 |
# File 'lib/basecamp/resources/attachment.rb', line 2 def filename @filename end |
#id ⇒ Object
Returns the value of attribute id.
2 3 4 |
# File 'lib/basecamp/resources/attachment.rb', line 2 def id @id end |
Class Method Details
.create(filename, content) ⇒ Object
4 5 6 7 8 |
# File 'lib/basecamp/resources/attachment.rb', line 4 def self.create(filename, content) returning new(filename, content) do || .save end end |
Instance Method Details
#attributes ⇒ Object
14 15 16 |
# File 'lib/basecamp/resources/attachment.rb', line 14 def attributes { :file => id, :original_filename => filename } end |
#inspect ⇒ Object
22 23 24 |
# File 'lib/basecamp/resources/attachment.rb', line 22 def inspect to_s end |
#save ⇒ Object
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/basecamp/resources/attachment.rb', line 26 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
18 19 20 |
# File 'lib/basecamp/resources/attachment.rb', line 18 def to_xml( = {}) { :file => attributes, :category_id => category_id }.to_xml() end |