Class: Dotloop::Document
- Inherits:
-
Object
- Object
- Dotloop::Document
- Defined in:
- lib/dotloop/document.rb
Constant Summary collapse
- DOTLOOP_FILE_UPLOAD_BOUNDARY =
"AaB03x"
Instance Attribute Summary collapse
-
#client ⇒ Object
Returns the value of attribute client.
Instance Method Summary collapse
- #all(profile_id:, loop_id:, folder_id:) ⇒ Object
- #find(profile_id:, loop_id:, folder_id:, document_id:) ⇒ Object
- #get(profile_id:, loop_id:, folder_id:, document_id:) ⇒ Object
-
#initialize(client:) ⇒ Document
constructor
A new instance of Document.
- #upload(profile_id:, loop_id:, folder_id:, params: {}) ⇒ Object
Constructor Details
#initialize(client:) ⇒ Document
Returns a new instance of Document.
9 10 11 |
# File 'lib/dotloop/document.rb', line 9 def initialize(client:) @client = client end |
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client.
7 8 9 |
# File 'lib/dotloop/document.rb', line 7 def client @client end |
Instance Method Details
#all(profile_id:, loop_id:, folder_id:) ⇒ Object
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/dotloop/document.rb', line 13 def all(profile_id:, loop_id:, folder_id:) @client.get("/profile/#{profile_id.to_i}/loop/#{loop_id.to_i}/folder/#{folder_id.to_i}/document")[:data].map do |document_attrs| doc = Dotloop::Models::Document.new(document_attrs) doc.client = client doc.profile_id = profile_id.to_i doc.loop_id = loop_id.to_i doc.folder_id = folder_id.to_i doc end end |
#find(profile_id:, loop_id:, folder_id:, document_id:) ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/dotloop/document.rb', line 24 def find(profile_id:, loop_id:, folder_id:, document_id:) document_data = @client.get("/profile/#{profile_id.to_i}/loop/#{loop_id.to_i}/folder/#{folder_id.to_i}/document/#{document_id.to_i}")[:data] document = Dotloop::Models::Document.new(document_data) document.client = client document.profile_id = profile_id.to_i document.loop_id = loop_id.to_i document.folder_id = folder_id.to_i document end |
#get(profile_id:, loop_id:, folder_id:, document_id:) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/dotloop/document.rb', line 34 def get(profile_id:, loop_id:, folder_id:, document_id:) sio = StringIO.new sio.set_encoding(Encoding::ASCII_8BIT) sio.write( @client.download( "/profile/#{profile_id.to_i}/loop/#{loop_id.to_i}/folder/#{folder_id.to_i}/document/#{document_id.to_i}" ) ) sio.flush sio.close sio end |
#upload(profile_id:, loop_id:, folder_id:, params: {}) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/dotloop/document.rb', line 47 def upload(profile_id:, loop_id:, folder_id:, params: {}) file_name = params["file_name"] file_content = params["file_content"] post_body = [] post_body << "--#{DOTLOOP_FILE_UPLOAD_BOUNDARY}\r\n" post_body << "Content-Disposition: form-data; name=\"file\"; filename=\"#{file_name}\"\r\n" post_body << "Content-Type: application/pdf\r\n" post_body << "\r\n" post_body << file_content post_body << "\r\n--#{DOTLOOP_FILE_UPLOAD_BOUNDARY}--\r\n" document_data = @client.upload("/profile/#{profile_id.to_i}/loop/#{loop_id.to_i}/folder/#{folder_id.to_i}/document/", post_body.join)[:data] document = Dotloop::Models::Document.new(document_data) document.client = client document.profile_id = profile_id.to_i document.loop_id = loop_id.to_i document.folder_id = folder_id.to_i document end |