module SkullIsland::Helpers::APIClient

Simple helper methods for the API Client

Public Instance Methods

about_service() click to toggle source
# File lib/skull_island/helpers/api_client.rb, line 7
def about_service
  get '/'
end
cache(key) { |self| ... } click to toggle source
# File lib/skull_island/helpers/api_client.rb, line 15
def cache(key)
  symbolized_key = key.to_sym
  if !@cache.has?(symbolized_key) && block_given?
    result = yield(self)
    @cache.store(symbolized_key, result)
  elsif !@cache.has?(symbolized_key)
    return nil
  end
  @cache.retrieve(symbolized_key)
end
invalidate_cache_for(key) click to toggle source
# File lib/skull_island/helpers/api_client.rb, line 26
def invalidate_cache_for(key)
  symbolized_key = key.to_sym
  @cache.invalidate(symbolized_key)
end
json_escape(string) click to toggle source

Substitute characters with their JSON-supported versions @return [String]

# File lib/skull_island/helpers/api_client.rb, line 37
def json_escape(string)
  json_escape = {
    '&' => '\u0026',
    '>' => '\u003e',
    '<' => '\u003c',
    '%' => '\u0025',
    "\u2028" => '\u2028',
    "\u2029" => '\u2029'
  }
  json_escape_regex = /[\u2028\u2029&><%]/u

  string.to_s.gsub(json_escape_regex, json_escape)
end
lru_cache() click to toggle source
# File lib/skull_island/helpers/api_client.rb, line 31
def lru_cache
  @cache
end
raw() click to toggle source

Provides access to the “raw” underlying rest-client @return [RestClient::Resource]

# File lib/skull_island/helpers/api_client.rb, line 53
def raw
  connection
end
server_status() click to toggle source
# File lib/skull_island/helpers/api_client.rb, line 11
def server_status
  get '/status'
end
version() click to toggle source

The API Client version (uses Semantic Versioning) @return [String]

# File lib/skull_island/helpers/api_client.rb, line 59
def version
  VERSION
end