Module: KnuVerse::Knufactor::Helpers::APIClient

Included in:
APIClientBase
Defined in:
lib/knuverse/knufactor/helpers/api_client.rb

Overview

Simple helper methods for the API Client

Instance Method Summary collapse

Instance Method Details

#json_escape(s) ⇒ String

Substitute characters with their JSON-supported versions

Returns:

  • (String)


8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/knuverse/knufactor/helpers/api_client.rb', line 8

def json_escape(s)
  json_escape = {
    '&' => '\u0026',
    '>' => '\u003e',
    '<' => '\u003c',
    '%' => '\u0025',
    "\u2028" => '\u2028',
    "\u2029" => '\u2029'
  }
  json_escape_regex = /[\u2028\u2029&><%]/u

  s.to_s.gsub(json_escape_regex, json_escape)
end

#rawRestClient::Resource

Provides access to the “raw” underlying rest-client

Returns:

  • (RestClient::Resource)


24
25
26
# File 'lib/knuverse/knufactor/helpers/api_client.rb', line 24

def raw
  connection
end

#versionString

The API Client version (uses Semantic Versioning)

Returns:

  • (String)


30
31
32
# File 'lib/knuverse/knufactor/helpers/api_client.rb', line 30

def version
  VERSION
end