Permalink
Browse files

connection using iostream to post data

  • Loading branch information...
1 parent 1787a9b commit cb8accced49363221f553177ee5901edef86d267 Ewan McDougall committed Oct 6, 2011
Showing with 13 additions and 6 deletions.
  1. +8 −3 README.rdoc
  2. +5 −3 lib/basecamp/connection.rb
View
@@ -137,14 +137,19 @@ you want to delete. Example:
If the resource accepts file attachments, the +attachments+ parameter should
be an array of Basecamp::Attachment objects. Example:
- a1 = Basecamp::Attachment.create('primary', File.read('primary.doc'))
- a2 = Basecamp::Attachment.create('another', File.read('another.doc'))
+ f1 = File.open('primary.doc')
+ s1 = StringIO('a string')
+
+ a1 = Basecamp::Attachment.create('primary', f1)
+ a2 = Basecamp::Attachment.create('another', s1))
m = Basecamp::Message.new(:project_id => 1037)
...
m.attachments = [a1, a2]
m.save # => true
+ f1.close
+
=== Milestones
Is not implemented as an active resource, it uses the non-REST interface.
@@ -188,4 +193,4 @@ You can access other resources not included in this wrapper yet using "record" a
* jamesarosen
* defeated
* justinbarry
-* fmiopensource
+* fmiopensource
@@ -6,15 +6,17 @@ def initialize(master)
@connection.verify_mode = OpenSSL::SSL::VERIFY_NONE if master.use_ssl
end
- def post(path, body, headers = {})
+ def post(path, iostream, headers = {})
request = Net::HTTP::Post.new(path, headers.merge('Accept' => 'application/xml'))
request.basic_auth(@master.user, @master.password)
- @connection.request(request, body)
+ request.body_stream = iostream
+ request.content_length = iostream.size
+ @connection.request(request)
end
def get(path, headers = {})
request = Net::HTTP::Get.new(path, headers.merge('Accept' => 'application/xml'))
request.basic_auth(@master.user, @master.password)
@connection.request(request)
end
-end; end
+end; end

0 comments on commit cb8accc

Please sign in to comment.