Module: SkullIsland::Helpers::APIClient
- Included in:
- APIClientBase, RSpec::FakeAPIClient
- Defined in:
- lib/skull_island/helpers/api_client.rb
Overview
Simple helper methods for the API Client
Instance Method Summary collapse
- #about_service ⇒ Object
- #cache(key) ⇒ Object
- #invalidate_cache_for(key) ⇒ Object
-
#json_escape(string) ⇒ String
Substitute characters with their JSON-supported versions.
- #lru_cache ⇒ Object
-
#raw ⇒ RestClient::Resource
Provides access to the “raw” underlying rest-client.
- #server_status ⇒ Object
-
#version ⇒ String
The API Client version (uses Semantic Versioning).
Instance Method Details
#about_service ⇒ Object
7 8 9 |
# File 'lib/skull_island/helpers/api_client.rb', line 7 def about_service get '/' end |
#cache(key) ⇒ Object
15 16 17 18 19 20 21 22 23 24 |
# 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) ⇒ Object
26 27 28 29 |
# 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) ⇒ String
Substitute characters with their JSON-supported versions
37 38 39 40 41 42 43 44 45 46 47 48 49 |
# 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 ⇒ Object
31 32 33 |
# File 'lib/skull_island/helpers/api_client.rb', line 31 def lru_cache @cache end |
#raw ⇒ RestClient::Resource
Provides access to the “raw” underlying rest-client
53 54 55 |
# File 'lib/skull_island/helpers/api_client.rb', line 53 def raw connection end |
#server_status ⇒ Object
11 12 13 |
# File 'lib/skull_island/helpers/api_client.rb', line 11 def server_status get '/status' end |
#version ⇒ String
The API Client version (uses Semantic Versioning)
59 60 61 |
# File 'lib/skull_island/helpers/api_client.rb', line 59 def version VERSION end |