Module: Quickbooks::Service::ServiceCrud
Instance Method Summary collapse
- #create(entity, options = {}) ⇒ Object
- #delete(entity) ⇒ Object
- #delete_by_query_string(entity, options = {}) ⇒ Object
- #fetch_by_id(id, options = {}) ⇒ Object
- #query(object_query = nil, options = {}) ⇒ Object
- #update(entity, options = {}) ⇒ Object
Instance Method Details
#create(entity, options = {}) ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/quickbooks/service/service_crud.rb', line 18 def create(entity, = {}) raise InvalidModelException.new(entity.errors..join(',')) unless entity.valid? xml = entity.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(parse_singular_entity_response(model, response.body)) else nil end end |
#delete(entity) ⇒ Object
29 30 31 |
# File 'lib/quickbooks/service/service_crud.rb', line 29 def delete(entity) raise "Not implemented for this Entity" end |
#delete_by_query_string(entity, options = {}) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/quickbooks/service/service_crud.rb', line 33 def delete_by_query_string(entity, = {}) url = "#{url_for_resource(model::REST_RESOURCE)}?operation=delete" xml = entity.to_xml_ns() response = do_http_post(url, valid_xml_document(xml)) if response.code.to_i == 200 parse_singular_entity_response_for_delete(model, response.body) else false end end |
#fetch_by_id(id, options = {}) ⇒ Object
13 14 15 16 |
# File 'lib/quickbooks/service/service_crud.rb', line 13 def fetch_by_id(id, = {}) url = "#{url_for_resource(model.resource_for_singular)}/#{id}" fetch_object(model, url, ) end |
#query(object_query = nil, options = {}) ⇒ Object
5 6 7 8 9 10 11 |
# File 'lib/quickbooks/service/service_crud.rb', line 5 def query(object_query = nil, = {}) object_query ||= default_model_query [:page] ||= 1 [:per_page] ||= 20 fetch_collection(object_query, model, ) end |
#update(entity, options = {}) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/quickbooks/service/service_crud.rb', line 45 def update(entity, = {}) unless entity.valid? raise InvalidModelException.new(entity.errors..join(',')) end xml = entity.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(parse_singular_entity_response(model, response.body)) else nil end end |