50 lines
1.6 KiB
Crystal
50 lines
1.6 KiB
Crystal
module TwAPI::Routes
|
|
extend self # To prevent writing self. at the start of every function
|
|
|
|
# Thanks Invidious devs
|
|
{% for http_method in {"get", "post", "delete", "options", "patch", "put"} %}
|
|
macro {{http_method.id}}(path, controller, method = :handle)
|
|
unless Kemal::Utils.path_starts_with_slash?(\{{path}})
|
|
raise Kemal::Exceptions::InvalidPathStartException.new({{http_method}}, \{{path}})
|
|
end
|
|
|
|
Kemal::RouteHandler::INSTANCE.add_route({{http_method.upcase}}, \{{path}}) do |env|
|
|
\{{ controller }}.\{{ method.id }}(env)
|
|
end
|
|
end
|
|
{% end %}
|
|
|
|
def register_misc
|
|
before_all "/v2/*" do |env|
|
|
env.response.content_type = "application/json"
|
|
end
|
|
|
|
get "/" do |env|
|
|
env.redirect "/v2"
|
|
end
|
|
|
|
get "/v2" do
|
|
{"message": "Welcome to v2, There is no docs!"}.to_json
|
|
end
|
|
end
|
|
|
|
def register_all_twitch
|
|
get "/v2/twitch/user", TwAPI::Routes::Twitch, :user
|
|
|
|
get "/v2/twitch/modvip/", TwAPI::Routes::Twitch, :modvip
|
|
get "/v2/twitch/modvip/:channel", TwAPI::Routes::Twitch, :modvip
|
|
|
|
get "/v2/twitch/founders", TwAPI::Routes::Twitch, :founders
|
|
get "/v2/twitch/founders/:login", TwAPI::Routes::Twitch, :founders
|
|
|
|
get "/v2/twitch/clip", TwAPI::Routes::Twitch, :clip
|
|
get "/v2/twitch/clip/:slug", TwAPI::Routes::Twitch, :clip
|
|
|
|
get "/v2/twitch/subage", TwAPI::Routes::Twitch, :subage
|
|
get "/v2/twitch/subage/:user/:channel", TwAPI::Routes::Twitch, :subage
|
|
|
|
get "/v2/twitch/emotes", TwAPI::Routes::Twitch, :emotes
|
|
get "/v2/twitch/emotes/:emote", TwAPI::Routes::Twitch, :emotes
|
|
# get "/v2/twitch/emotes/channel", TwAPI::Routes::Twitch, :channelEmotes
|
|
end
|
|
end
|