module ServiceCRUD

Public Instance Methods

action_url(object) click to toggle source
# File lib/quickeebooks/common/service_crud.rb, line 52
def action_url(object)
  url = "#{url_for_resource(model.resource_for_singular)}/#{object.id.value}"
end
create(object) click to toggle source
# File lib/quickeebooks/common/service_crud.rb, line 3
def create(object)
  raise InvalidModelException.new(object.errors.full_messages.join(',')) unless object.valid?
  xml = object.to_xml_ns
  response = do_http_post(url_for_resource(model.resource_for_singular), valid_xml_document(xml))
  if response.code.to_i == 200
    model.from_xml(response.body)
  else
    nil
  end
end
delete(object) click to toggle source
# File lib/quickeebooks/common/service_crud.rb, line 36
def delete(object)
  raise InvalidModelException.new("Missing required parameters for delete") unless object.valid_for_deletion?
  xml = valid_xml_document(object.to_xml_ns(:fields => ['Id', 'SyncToken']))
  url = action_url(object)
  response = do_http_post(url, xml, {:methodx => "delete"})
  response.code.to_i == 200
end
fetch_by_id(id) click to toggle source
# File lib/quickeebooks/common/service_crud.rb, line 14
def fetch_by_id(id)
  url = "#{url_for_resource(model.resource_for_singular)}/#{id}"
  response = do_http_get(url)
  if response && response.code.to_i == 200
    model.from_xml(response.body)
  else
    nil
  end
end
list(filters = [], page = 1, per_page = 20, sort = nil, options = {}) click to toggle source
# File lib/quickeebooks/common/service_crud.rb, line 44
def list(filters = [], page = 1, per_page = 20, sort = nil, options = {})
  fetch_collection(model, filters, page, per_page, sort, options)
end
model() click to toggle source
# File lib/quickeebooks/common/service_crud.rb, line 48
def model
  self.class.to_s.sub(/::Service::/,'::Model::').constantize
end
update(object) click to toggle source
# File lib/quickeebooks/common/service_crud.rb, line 24
def update(object)
  raise InvalidModelException.new("Missing required parameters for update") unless object.valid_for_update?
  url = action_url(object)
  xml = object.to_xml_ns
  response = do_http_post(url, valid_xml_document(xml))
  if response.code.to_i == 200
    model.from_xml(response.body)
  else
    nil
  end
end