Module: MosEisley::Helper

Defined in:
lib/http-server/helper.rb

Instance Method Summary collapse

Instance Method Details

#json_with_object(obj, pretty: true, opts: nil) ⇒ String

Convert object into JSON, optionally pretty-format

Parameters:

  • obj (Object)

    any Ruby object

  • opts (Hash) (defaults to: nil)

    any JSON options

Returns:

  • (String)

    JSON string



28
29
30
# File 'lib/http-server/helper.rb', line 28

def json_with_object(obj, pretty: true, opts: nil)
  MosEisley::S3PO.json_with_object(obj, pretty: pretty, opts: opts)
end

#loggerObject



5
6
7
# File 'lib/http-server/helper.rb', line 5

def logger
  MosEisley.logger
end

#parse_command(params) ⇒ Object



9
10
11
12
13
# File 'lib/http-server/helper.rb', line 9

def parse_command(params)
  cmd = {}
  params.each { |k, v| cmd[k.to_sym] = v }
  return cmd
end

#parse_json(json) ⇒ Object

Parse JSON to Hash with key symbolization by default



16
17
18
# File 'lib/http-server/helper.rb', line 16

def parse_json(json)
  MosEisley::S3PO.parse_json(json)
end

#valid_token?(token) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/http-server/helper.rb', line 20

def valid_token?(token)
  token == Config.shared.verification_token
end