lib/telegram/bot/api.rb in telegram-bot-ruby-0.3.4 vs lib/telegram/bot/api.rb in telegram-bot-ruby-0.3.5
- old
+ new
@@ -23,11 +23,14 @@
def initialize(token)
@token = token
end
def method_missing(method_name, *args, &block)
- ENDPOINTS.include?(method_name.to_s) ? call(method_name, *args) : super
+ endpoint = method_name.to_s
+ endpoint = camelize(endpoint) if endpoint.include?('_')
+
+ ENDPOINTS.include?(endpoint) ? call(endpoint, *args) : super
end
def call(endpoint, raw_params = {})
params = build_params(raw_params)
response = self.class.post("/bot#{token}/#{endpoint}", query: params)
@@ -52,9 +55,15 @@
end
def jsonify_reply_markup(value)
return value unless REPLY_MARKUP_TYPES.include?(value.class)
value.to_h.to_json
+ end
+
+ def camelize(method_name)
+ words = method_name.split('_')
+ words.drop(1).map(&:capitalize!)
+ words.join
end
end
end
end