Module: QboApi::Util
- Included in:
- QboApi
- Defined in:
- lib/qbo_api/util.rb
Instance Method Summary collapse
- #add_minor_version_to(path) ⇒ Object
- #add_params_to_path(path:, params:) ⇒ Object
- #add_request_id_to(path) ⇒ Object
- #build_all_query(entity, select: nil, inactive: false) ⇒ Object
- #cdc_time(time) ⇒ Object
- #esc(query) ⇒ Object
- #finalize_path(path, method:, params: nil) ⇒ Object
- #join_or_start_where_clause!(select:) ⇒ Object
- #uuid ⇒ Object
Instance Method Details
#add_minor_version_to(path) ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/qbo_api/util.rb', line 35 def add_minor_version_to(path) if minor_version = QboApi.minor_version add_params_to_path(path: path, params: { "minorversion" => minor_version }) else path end end |
#add_params_to_path(path:, params:) ⇒ Object
43 44 45 46 47 48 49 50 |
# File 'lib/qbo_api/util.rb', line 43 def add_params_to_path(path:, params:) uri = URI.parse(path) params.each do |p| new_query_ar = URI.decode_www_form(uri.query || '') << p.to_a uri.query = URI.encode_www_form(new_query_ar) end uri.to_s end |
#add_request_id_to(path) ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/qbo_api/util.rb', line 27 def add_request_id_to(path) if QboApi.request_id add_params_to_path(path: path, params: { "requestid" => uuid }) else path end end |
#build_all_query(entity, select: nil, inactive: false) ⇒ Object
61 62 63 64 65 |
# File 'lib/qbo_api/util.rb', line 61 def build_all_query(entity, select: nil, inactive: false) select ||= "SELECT * FROM #{singular(entity)}" select += join_or_start_where_clause!(select: select) + 'Active IN ( true, false )' if inactive select end |
#cdc_time(time) ⇒ Object
8 9 10 11 12 13 14 |
# File 'lib/qbo_api/util.rb', line 8 def cdc_time(time) if time.is_a?(String) time else time.iso8601 end end |
#esc(query) ⇒ Object
4 5 6 |
# File 'lib/qbo_api/util.rb', line 4 def esc(query) query.gsub("'", "\\\\'") end |
#finalize_path(path, method:, params: nil) ⇒ Object
20 21 22 23 24 25 |
# File 'lib/qbo_api/util.rb', line 20 def finalize_path(path, method:, params: nil) path = add_request_id_to(path) if method == :post path = add_minor_version_to(path) path = add_params_to_path(path: path, params: params) if params path end |
#join_or_start_where_clause!(select:) ⇒ Object
52 53 54 55 56 57 58 59 |
# File 'lib/qbo_api/util.rb', line 52 def join_or_start_where_clause!(select:) if select.match(/where/i) str = ' AND ' else str = ' WHERE ' end str end |
#uuid ⇒ Object
16 17 18 |
# File 'lib/qbo_api/util.rb', line 16 def uuid SecureRandom.uuid end |