Module: DLME::Utils

Extended by:
ActiveSupport::Benchmarkable
Defined in:
lib/dlme_utils.rb

Overview

Misc. utilities for working with DLME data

Class Method Summary collapse

Class Method Details

.caching_faraday_clientObject


10
11
12
13
14
15
16
# File 'lib/dlme_utils.rb', line 10

def self.caching_faraday_client
  Faraday.new do |builder|
    builder.use :http_cache, store: Rails.cache

    builder.adapter Faraday.default_adapter
  end
end

.fetch_json(uri) ⇒ Object


18
19
20
21
22
23
# File 'lib/dlme_utils.rb', line 18

def self.fetch_json(uri)
  resp = benchmark("DLME::Utils.fetch_json(#{uri})", level: :debug) do
    caching_faraday_client.get uri
  end
  ::JSON.parse(resp.body) if resp.success?
end

.loggerObject


25
26
27
# File 'lib/dlme_utils.rb', line 25

def self.logger
  @logger ||= Logger.new(STDOUT)
end