Class: Quickbooks::Service::Invoice

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

Constant Summary

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

#base_uri, #company_id, #last_response_body, #last_response_xml, #oauth

Instance Method Summary collapse

Methods inherited from BaseService

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

Methods included from ServiceCrud

#all, #create, #delete_by_query_string, #fetch_by_id, #find_by, #query, #query_in_batches

Methods included from Util::Logging

#log, #log_xml

Constructor Details

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

Instance Method Details

#delete(invoice) ⇒ Object



5
6
7
# File 'lib/quickbooks/service/invoice.rb', line 5

def delete(invoice)
  delete_by_query_string(invoice)
end

#pdf(invoice) ⇒ Object



20
21
22
23
24
# File 'lib/quickbooks/service/invoice.rb', line 20

def pdf(invoice)
  url = "#{url_for_resource(model::REST_RESOURCE)}/#{invoice.id}/pdf"
  response = do_http_raw_get(url, {}, {'Accept' => 'application/pdf'})
  response.plain_body
end

#send(invoice, email_address = nil) ⇒ Object



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

def send(invoice, email_address=nil)
  query = email_address.present? ? "?sendTo=#{email_address}" : ""
  url = "#{url_for_resource(model::REST_RESOURCE)}/#{invoice.id}/send#{query}"
  response = do_http_post(url,{})
  if response.code.to_i == 200
    model.from_xml(parse_singular_entity_response(model, response.plain_body))
  else
    nil
  end
end

#void(invoice, options = {}) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/quickbooks/service/invoice.rb', line 26

def void(invoice, options = {})
  url = "#{url_for_resource(model::REST_RESOURCE)}?operation=void"

  xml = invoice.to_xml_ns(options)
  response = do_http_post(url, valid_xml_document(xml))
  if response.code.to_i == 200
    model.from_xml(parse_singular_entity_response(model, response.plain_body))
  else
    false
  end
end