Module: ChatbotHelper::Telegram::Toolbox

Defined in:
lib/chatbot_helper/telegram/toolbox.rb

Overview

A toolbox which provides useful internal helpers for this library.

Please don’t use these methods as they are subject to chhange any time and are not documented in any way.

Class Method Summary collapse

Class Method Details

.generate_json(hash, opts = {}) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/chatbot_helper/telegram/toolbox.rb', line 18

def self.generate_json(hash, opts = {})
  opts[:max_nesting] = false unless opts[:max_nesting]
  p = JSON.generate(hash, opts)
  return p
rescue JSON::GeneratorError => e
  return nil
end

.parse_json(string, opts = {}) ⇒ Object



10
11
12
13
14
15
16
# File 'lib/chatbot_helper/telegram/toolbox.rb', line 10

def self.parse_json(string, opts = {})
  opts[:max_nesting] = false unless opts[:max_nesting]
  p = JSON.parse(string, opts)
  return p
rescue TypeError, JSON::ParserError => e
  return nil
end