module Boty module Slack module URL def self.included(base) class << base attr_reader :_url end base.instance_eval do def url(url) @_url = url end end end def self.get(url) JSON.parse Net::HTTP.get(URI(url)) || "{}" end private def parameterize(user_parameters, path: nil) url = path ? self.class._url + path : self.class._url parameters = { token: ENV["SLACK_BOT_API_TOKEN"] }.merge user_parameters parameters.reduce(url + "?") { |final_url, param| parameter = param[0] value = URI.encode param[1].to_s "#{final_url}#{parameter}=#{value}&" }.gsub(/&$/, "") end end end end