Module: Sinicum::Jcr::ApiClient

Instance Method Summary collapse

Methods included from Logger

included, #logger

Instance Method Details

#api_get(path, *args, &block) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/sinicum/jcr/api_client.rb', line 5

def api_get(path, *args, &block)
  full_path = api_full_path(path)
  log_get_path(full_path, args)

  instrumentation_query = args[0] && args[0]["query"] ? args[0]["query"] : path

  ActiveSupport::Notifications.instrument(
    "jcr_query.sinicum",
    query: instrumentation_query,
    context: "Sinicum API GET:") do
    start = Time.now
    result = ApiQueries.http_client.get(full_path, *args, &block)
    elapsed_time = ((Time.now - start).to_f * 1000).round(1)
    logger.debug("      Completed request in #{elapsed_time}ms")
    result
  end
end

#api_post(path, *args, &block) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/sinicum/jcr/api_client.rb', line 23

def api_post(path, *args, &block)
  full_path = api_full_path(path)
  log = "    Sinicum API POST: " + full_path
  [:body, :query].each do |key|
    if args[0] && args[0].respond_to?(:[]) && args[0][key]
      log << "\n      Parameters (#{key.to_s.capitalize}): " + args[0][key].inspect
    end
  end
  logger.debug(log)
  ApiQueries.http_client.post(full_path, *args, &block)
end