Module: QboApi::ApiMethods
- Included in:
- QboApi
- Defined in:
- lib/qbo_api/api_methods.rb
Instance Method Summary collapse
- #all(entity, max: 1000, select: nil, inactive: false, params: nil, &block) ⇒ Object
- #create(entity, payload:, params: nil) ⇒ Object
- #deactivate(entity, id:) ⇒ Object
- #delete(entity, id:) ⇒ Object
- #get(entity, id_or_query_filter_args, params: nil) ⇒ Object
- #get_by_query_filter(entity, query_filter_args, params: nil) ⇒ Object
- #query(query, params: nil) ⇒ Object
- #update(entity, id:, payload:, params: nil) ⇒ Object
- #void(entity, id:) ⇒ Object
Instance Method Details
#all(entity, max: 1000, select: nil, inactive: false, params: nil, &block) ⇒ Object
3 4 5 6 7 8 9 10 11 |
# File 'lib/qbo_api/api_methods.rb', line 3 def all(entity, max: 1000, select: nil, inactive: false, params: nil, &block) enumerator = create_all_enumerator(entity, max: max, select: select, inactive: inactive, params: params) if block_given? enumerator.each(&block) else enumerator end end |
#create(entity, payload:, params: nil) ⇒ Object
37 38 39 |
# File 'lib/qbo_api/api_methods.rb', line 37 def create(entity, payload:, params: nil) request(:post, entity: entity, path: entity_path(entity), payload: payload, params: params) end |
#deactivate(entity, id:) ⇒ Object
54 55 56 57 58 59 |
# File 'lib/qbo_api/api_methods.rb', line 54 def deactivate(entity, id:) err_msg = "Deactivate is only for name list entities. Use .delete instead" raise QboApi::NotImplementedError.new, err_msg unless is_name_list_entity?(entity) payload = set_deactivate(entity, id) request(:post, entity: entity, path: entity_path(entity), payload: payload) end |
#delete(entity, id:) ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/qbo_api/api_methods.rb', line 46 def delete(entity, id:) err_msg = "Delete is only for transaction entities. Use .deactivate instead" raise QboApi::NotImplementedError.new, err_msg unless is_transaction_entity?(entity) path = add_params_to_path(path: entity_path(entity), params: { operation: :delete }) payload = set_update(entity, id) request(:post, entity: entity, path: path, payload: payload) end |
#get(entity, id_or_query_filter_args, params: nil) ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'lib/qbo_api/api_methods.rb', line 19 def get(entity, id_or_query_filter_args, params: nil) if id_or_query_filter_args.is_a?(Array) get_by_query_filter(entity, id_or_query_filter_args, params: params) else path = "#{entity_path(entity)}/#{id_or_query_filter_args}" request(:get, entity: entity, path: path, params: params) end end |
#get_by_query_filter(entity, query_filter_args, params: nil) ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'lib/qbo_api/api_methods.rb', line 28 def get_by_query_filter(entity, query_filter_args, params: nil) query_str = get_query_str(entity, query_filter_args) if resp = query(query_str, params: params) resp.size == 1 ? resp[0] : resp else false end end |
#query(query, params: nil) ⇒ Object
13 14 15 16 17 |
# File 'lib/qbo_api/api_methods.rb', line 13 def query(query, params: nil) path = "#{realm_id}/query?query=#{CGI.escape(query)}" entity = extract_entity_from_query(query, to_sym: true) request(:get, entity: entity, path: path, params: params) end |
#update(entity, id:, payload:, params: nil) ⇒ Object
41 42 43 44 |
# File 'lib/qbo_api/api_methods.rb', line 41 def update(entity, id:, payload:, params: nil) payload.merge!(set_update(entity, id)) request(:post, entity: entity, path: entity_path(entity), payload: payload, params: params) end |
#void(entity, id:) ⇒ Object
61 62 63 64 65 66 67 |
# File 'lib/qbo_api/api_methods.rb', line 61 def void(entity, id:) err_msg = "Void is only for voidable transaction entities. Use .delete or .deactivate instead" raise QboApi::NotImplementedError.new, err_msg unless is_voidable_transaction_entity?(entity) path = add_params_to_path(path: entity_path(entity), params: { operation: :void }) payload = set_update(entity, id) request(:post, entity: entity, path: path, payload: payload) end |