Module: QboApi::Finder

Included in:
QboApi
Defined in:
lib/qbo_api/finder.rb

Instance Method Summary collapse

Instance Method Details

#get(entity, type, params: nil) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/qbo_api/finder.rb', line 10

def get(entity, type, params: nil)
  if type.is_a?(Array)
    query_str = get_query_str(entity, type)
    if resp = query(query_str, params: params)
      resp.size == 1 ? resp[0] : resp
    else
      false
    end
  else
    path = "#{entity_path(entity)}/#{type}"
    request(:get, entity: entity, path: path, params: params)
  end
end

#query(query, params: nil) ⇒ Object



4
5
6
7
8
# File 'lib/qbo_api/finder.rb', line 4

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

#to_quote_or_not(str) ⇒ Object



24
25
26
27
28
29
30
31
# File 'lib/qbo_api/finder.rb', line 24

def to_quote_or_not(str)
  inside_parens_regex = '\(.*\)'
  if str.match(/^(#{inside_parens_regex}|true|false|CURRENT_DATE)$/)
    str
  else
    %{'#{esc(str)}'}
  end
end