Module: Xero::Api::Attachment
- Included in:
- Xero::Api
- Defined in:
- lib/xero/api/attachment.rb
Instance Method Summary collapse
- #attachment_connection(headers:) ⇒ Object
- #upload_attachment(entity, id:, file_name:, content_type:, attachment:, include_online: false) ⇒ Object
Instance Method Details
#attachment_connection(headers:) ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/xero/api/attachment.rb', line 15 def (headers:) build_connection(endpoint_url, headers: headers) do |conn| (conn) add_exception_middleware(conn) conn.request :url_encoded add_connection_adapter(conn) end end |
#upload_attachment(entity, id:, file_name:, content_type:, attachment:, include_online: false) ⇒ Object
4 5 6 7 8 9 10 11 12 13 |
# File 'lib/xero/api/attachment.rb', line 4 def (entity, id:, file_name:, content_type:, attachment:, include_online: false) url = "#{entity_handler(entity)}/#{id}/Attachments/#{file_name}" url += "?IncludeOnline=true" if include_online headers = { 'Content-Type' => content_type, 'Accept' => 'application/json' } raw_response = (headers: headers).post do |request| request.url url request.body = Faraday::UploadIO.new(, content_type, file_name) end response(raw_response, entity: entity) end |