Class: Quickeebooks::Online::Service::Customer

Inherits:
ServiceBase
  • Object
show all
Defined in:
lib/quickeebooks/online/service/customer.rb

Constant Summary

Constants inherited from ServiceBase

ServiceBase::QB_BASE_URI, ServiceBase::XML_NS

Instance Attribute Summary

Attributes inherited from ServiceBase

#base_uri, #oauth, #realm_id

Instance Method Summary collapse

Methods inherited from ServiceBase

#access_token=, #base_url=, #initialize, #login_name, #url_for_base, #url_for_resource

Constructor Details

This class inherits a constructor from Quickeebooks::Online::Service::ServiceBase

Instance Method Details

#create(customer) ⇒ Object



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

def create(customer)
  raise InvalidModelException unless customer.valid?
  xml = customer.to_xml_ns
  response = do_http_post(url_for_resource(Quickeebooks::Online::Model::Customer.resource_for_singular), valid_xml_document(xml))
  if response.code.to_i == 200
    Quickeebooks::Online::Model::Customer.from_xml(response.body)
  else
    nil
  end
end

#delete(customer) ⇒ Object



42
43
44
45
46
47
48
# File 'lib/quickeebooks/online/service/customer.rb', line 42

def delete(customer)
  raise InvalidModelException.new("Missing required parameters for delete") unless customer.valid_for_deletion?
  xml = valid_xml_document(customer.to_xml_ns(:fields => ['Id', 'SyncToken']))
  url = "#{url_for_resource(Quickeebooks::Online::Model::Customer.resource_for_singular)}/#{customer.id.value}"
  response = do_http_post(url, xml, {:methodx => "delete"})
  response.code.to_i == 200
end

#fetch_by_id(id) ⇒ Object



20
21
22
23
24
25
26
27
28
# File 'lib/quickeebooks/online/service/customer.rb', line 20

def fetch_by_id(id)
  url = "#{url_for_resource(Quickeebooks::Online::Model::Customer.resource_for_singular)}/#{id}"
  response = do_http_get(url)
  if response && response.code.to_i == 200
    Quickeebooks::Online::Model::Customer.from_xml(response.body)
  else
    nil
  end
end

#list(filters = [], page = 1, per_page = 20, sort = nil, options = {}) ⇒ Object



50
51
52
# File 'lib/quickeebooks/online/service/customer.rb', line 50

def list(filters = [], page = 1, per_page = 20, sort = nil, options = {})
  fetch_collection(Quickeebooks::Online::Model::Customer, filters, page, per_page, sort, options)
end

#update(customer) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/quickeebooks/online/service/customer.rb', line 30

def update(customer)
  raise InvalidModelException.new("Missing required parameters for update") unless customer.valid_for_update?
  url = "#{url_for_resource(Quickeebooks::Online::Model::Customer.resource_for_singular)}/#{customer.id.value}"
  xml = customer.to_xml_ns
  response = do_http_post(url, valid_xml_document(xml))
  if response.code.to_i == 200
    Quickeebooks::Online::Model::Customer.from_xml(response.body)
  else
    nil
  end
end