Class: Quickbooks::Service::Upload

Inherits:
BaseService show all
Defined in:
lib/quickbooks/service/upload.rb

Constant Summary collapse

XML_NODE =
"AttachableResponse"

Constants inherited from BaseService

BaseService::BASE_DOMAIN, BaseService::HTTP_ACCEPT, BaseService::HTTP_ACCEPT_ENCODING, BaseService::HTTP_CONTENT_TYPE, BaseService::SANDBOX_DOMAIN, BaseService::XML_NS

Instance Attribute Summary

Attributes inherited from BaseService

#after_request, #around_request, #base_uri, #before_request, #company_id, #last_response_intuit_tid, #last_response_xml, #oauth

Instance Method Summary collapse

Methods inherited from BaseService

#access_token=, #default_model_query, #initialize, #is_json?, #is_pdf?, #realm_id=, #rebuild_connection!, #url_for_base, #url_for_query, #url_for_resource

Methods included from ServiceCrud

#all, #create, #delete, #delete_by_query_string, #exists?, #fetch_by_id, #find_by, #query, #query_in_batches

Methods included from Util::Logging

#log, #log?, #log_xml

Constructor Details

This class inherits a constructor from Quickbooks::Service::BaseService

Instance Method Details

#class_for_ioObject



22
23
24
# File 'lib/quickbooks/service/upload.rb', line 22

def class_for_io
  oauth.is_a?(OAuth2::AccessToken) ? Faraday::UploadIO : UploadIO
end

#download(uploadId) ⇒ Object



26
27
28
29
# File 'lib/quickbooks/service/upload.rb', line 26

def download(uploadId)
  url = url_for_resource("download/#{uploadId}")
  do_http_get(url, {}, headers)
end

#upload(path_to_file, mime_type, attachable = nil) ⇒ Object

path_to_file: String - path to file mime_type: String - the MIME type of the file, e.g. image/jpeg attachable: Quickbooks::Model::Attachable meta-data details, can be null



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/quickbooks/service/upload.rb', line 10

def upload(path_to_file, mime_type, attachable = nil)
  url = url_for_resource("upload")
  uploadIO = class_for_io.new(path_to_file, mime_type)
  response = do_http_file_upload(uploadIO, url, attachable)
  prefix = "AttachableResponse/xmlns:Attachable"
  if response.code.to_i == 200
    model.from_xml(parse_singular_entity_response(model, response.plain_body, prefix))
  else
    nil
  end
end