Module: Hawkular::ClientUtils

Included in:
BaseClient, Inventory::CanonicalPath
Defined in:
lib/hawkular/client_utils.rb

Instance Method Summary collapse

Instance Method Details

#hawk_escape(url_part) ⇒ String

Escapes the passed url part. This is necessary, as many ids inside Hawkular can contain characters that are invalid for an url/uri. The passed value is duplicated Does not escape the = character

Parameters:

  • url_part (String)

    Part of an url to be escaped

Returns:

  • (String)

    escaped url_part as new string



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/hawkular/client_utils.rb', line 10

def hawk_escape(url_part)
  return url_part.to_s if url_part.is_a?(Numeric)

  url_part
    .to_s
    .dup
    .gsub('%', '%25')
    .gsub(' ', '%20')
    .gsub('[', '%5b')
    .gsub(']', '%5d')
    .gsub('|', '%7c')
    .gsub('(', '%28')
    .gsub(')', '%29')
    .gsub('/', '%2f')
end

#hawk_escape_id(url_part) ⇒ String

Escapes the passed url part. This is necessary, as many ids inside Hawkular can contain characters that are invalid for an url/uri. The passed value is duplicated Does escape the = character

Parameters:

  • url_part (String)

    Part of an url to be escaped

Returns:

  • (String)

    escaped url_part as new string



33
34
35
36
37
# File 'lib/hawkular/client_utils.rb', line 33

def hawk_escape_id(url_part)
  hawk_escape(url_part)
    .gsub('=', '%3d')
    .gsub(';', '%3b')
end