Module: Springnote::ImportFile
- Included in:
- Attachment, Page
- Defined in:
- lib/springnote/import_file.rb
Defined Under Namespace
Modules: ClassMethod
Constant Summary collapse
- BOUNDARY =
'AaB03x'
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.included(base) ⇒ Object
25 26 27 |
# File 'lib/springnote/import_file.rb', line 25 def self.included(base) base.extend(ClassMethod) end |
Instance Method Details
#import_file(path) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/springnote/import_file.rb', line 10 def import_file(path) body = File.open(path) do |f| create_query_multipart_str({:Filedata => f}, BOUNDARY) end headers = self.class.headers.merge 'Content-Transfer-Encoding' => 'binary', 'Content-Length' => body.length.to_s, 'Content-Type' => "multipart/form-data; boundary=#{BOUNDARY}" returning connection.post(collection_path, body, headers) do |response| # self.id = id_from_response(response) load_attributes_from_response(response) end self end |