class Telegrambot::Api
Constants
- REPLY_MARKUP_TYPES
Attributes
token[R]
Public Class Methods
new(token)
click to toggle source
# File lib/telegrambot/api.rb, line 13 def initialize(token) @token = token end
snakecase(endpoint)
click to toggle source
Convierte un camelCase a snake_case @return String
# File lib/telegrambot/api.rb, line 20 def self.snakecase(endpoint) endpoint.to_s.gsub(/::/, '/'). gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2'). gsub(/([a-z\d])([A-Z])/,'\1_\2'). tr("-", "_"). downcase end
Private Instance Methods
build_params(hash)
click to toggle source
# File lib/telegrambot/api.rb, line 60 def build_params(hash) hash.each_with_object({}) do |(key, value), params| params[key] = sanitize_value(value) end end
camelcase(endpoint)
click to toggle source
Convierte un snake_case a camelCase @return String
# File lib/telegrambot/api.rb, line 54 def camelcase(endpoint) words = endpoint.split('_') words.drop(1).map(&:capitalize!) words.join end
json_inline_query_results(value)
click to toggle source
# File lib/telegrambot/api.rb, line 75 def json_inline_query_results(value) return value unless value.is_a?(Array) && value.all? { |i| INLINE_QUERY_RESULT_TYPES.include?(i.class) } value.map { |i| i.to_compact_hash.select { |_, v| v } }.to_json end
json_reply_markup(value)
click to toggle source
# File lib/telegrambot/api.rb, line 70 def json_reply_markup(value) return value unless REPLY_MARKUP_TYPES.include?(value.class) value.to_compact_hash.to_json end
rest_client()
click to toggle source
# File lib/telegrambot/api.rb, line 80 def rest_client Faraday.new(url: 'https://api.telegram.org') do |faraday| faraday.request :multipart faraday.request :url_encoded faraday.adapter Faraday.default_adapter end end
sanitize_value(value)
click to toggle source
# File lib/telegrambot/api.rb, line 66 def sanitize_value(value) json_inline_query_results(json_reply_markup(value)) end