class SnowflakeAPI

Public Class Methods

new(api_key) click to toggle source
# File lib/snowflakeapirb.rb, line 15
def initialize(api_key)
        @token = api_key
        @connection = Faraday.new(
                url: "https://api.snowflakedev.org/api",
                headers: {
                        "Content-Type" => "application/json",
                        "Authorization" => @token
                }
        )
end

Public Instance Methods

base64_decode(message) click to toggle source

Decode the given text to base64 string @param message [String] The message to decode @return [String]

# File lib/snowflakeapirb.rb, line 199
def base64_decode(message)
        resp = @connection.get("base64/decode", { "data" => message })
        data = JSON.parse(resp.body)

        if data["error"] and data["code"] and data["code"] != 200
                raise RuntimeError.new("[#{data["code"]}] #{data["error"] or "Rejected with status code #{data["code"]}"}")
        else
                return data["data"]
        end
end
base64_encode(message) click to toggle source

Encode the given text to base64 string @param message [String] The message to encode @return [String]

# File lib/snowflakeapirb.rb, line 185
def base64_encode(message)
        resp = @connection.get("base64/encode", { "data" => message })
        data = JSON.parse(resp.body)

        if data["error"] and data["code"] and data["code"] != 200
                raise RuntimeError.new("[#{data["code"]}] #{data["error"] or "Rejected with status code #{data["code"]}"}")
        else
                return data["data"]
        end
end
chatbot(message, name: nil, age: nil, gender: nil, user: nil) click to toggle source

Get response from the chatbot @param message [String] The message @param name [String] The chatbot's name @param age [String] The chatbot's age @param gender [String] The bot's gender @param user [String] The user identifier @return [String]

# File lib/snowflakeapirb.rb, line 33
def chatbot(message, name: nil, age: nil, gender: nil, user: nil)
        resp = @connection.get("chatbot", { message: message, name: name, age: age, gender: gender, user: user })
        data = JSON.parse(resp.body)
        
        if data["error"] and data["code"] and data["code"] != 200
                raise RuntimeError.new("[#{data["code"]}] #{data["error"] or "Rejected with status code #{data["code"]}"}")
        else
                return data["message"]
        end
end
deno(package) click to toggle source

Returns package information from denoland registry @param module [String] The module name @return [Spreader::Deno]

# File lib/snowflakeapirb.rb, line 129
def deno(package)
        resp = @connection.get("registry/deno", { "module" => package })
        data = JSON.parse(resp.body)

        if data["error"] and data["code"] and data["code"] != 200
                raise RuntimeError.new("[#{data["code"]}] #{data["error"] or "Rejected with status code #{data["code"]}"}")
        else
                Spreader::Deno.new(data)
        end
end
fake_discord_token() click to toggle source

Generates fake discord bot token @return [String]

# File lib/snowflakeapirb.rb, line 46
def fake_discord_token
        resp = @connection.get("token")
        data = JSON.parse(resp.body)

        if data["error"] and data["code"] and data["code"] != 200
                raise RuntimeError.new("[#{data["code"]}] #{data["error"] or "Rejected with status code #{data["code"]}"}")
        else
                return data["token"]
        end
end
githubstats(user) click to toggle source

Returns information about a github user @param user [String] The user's name @return [Spreader::Github_Stats]

# File lib/snowflakeapirb.rb, line 253
def githubstats(user)
        resp = @connection.get("githubstats", { "username" => user })
        data = JSON.parse(resp.body)

        if data["error"] and data["code"] and data["code"] != 200
                raise RuntimeError.new("[#{data["code"]}] #{data["error"] or "Rejected with status code #{data["code"]}"}")
        else
                Spreader::Github_Stats.new(data)
        end
end
me() click to toggle source

Returns information about current user @return [Spreader::Me]

# File lib/snowflakeapirb.rb, line 239
def me
        resp = @connection.get("me")
        data = JSON.parse(resp.body)

        if data["error"] and data["code"] and data["code"] != 200
                raise RuntimeError.new("[#{data["code"]}] #{data["error"] or "Rejected with status code #{data["code"]}"}")
        else
                Spreader::Me.new(data)
        end
end
meme(subreddit) click to toggle source

Returns meme from @param subreddit [String] subreddit to fetch meme from @return [Hash]

# File lib/snowflakeapirb.rb, line 60
def meme(subreddit)
        resp = @connection.get("meme", { "sbr" => subreddit })
        data = JSON.parse(resp.body)

        if data["error"] and data["code"] and data["code"] != 200
                raise RuntimeError.new("[#{data["code"]}] #{data["error"] or "Rejected with status code #{data["code"]}"}")
        else
                Spreader::Meme.new(data)
        end
end
morse_decode(message) click to toggle source

Decodes the given morse code to regular text @param message [String] The morse code to decode @return [String]

# File lib/snowflakeapirb.rb, line 115
def morse_decode(message)
        resp = @connection.get("morse/decode", { "text" => message })
        data = JSON.parse(resp.body)

        if data["error"] and data["code"] and data["code"] != 200
                raise RuntimeError.new("[#{data["code"]}] #{data["error"] or "Rejected with status code #{data["code"]}"}")
        else
                return data["data"]
        end
end
morse_encode(message) click to toggle source

Encodes the given text to morse code @param message [String] The message to encode @return [String]

# File lib/snowflakeapirb.rb, line 101
def morse_encode(message)
        resp = @connection.get("morse/encode", { "text" => message })
        data = JSON.parse(resp.body)

        if data["error"] and data["code"] and data["code"] != 200
                raise RuntimeError.new("[#{data["code"]}] #{data["error"] or "Rejected with status code #{data["code"]}"}")
        else
                return data["data"]
        end
end
npm(package) click to toggle source

Returns package information from npmjs registry @param module [String] The module name @return [Spreader::Npm]

# File lib/snowflakeapirb.rb, line 143
def npm(package)
        resp = @connection.get("registry/npm", { "module" => package })
        data = JSON.parse(resp.body)

        if data["error"] and data["code"] and data["code"] != 200
                raise RuntimeError.new("[#{data["code"]}] #{data["error"] or "Rejected with status code #{data["code"]}"}")
        else
                Spreader::Npm.new(data)
        end
end
pokemon(name) click to toggle source

Returns Pokemon info @param name [String] Pokemon name @return [Spreader::Pokemon]

# File lib/snowflakeapirb.rb, line 87
def pokemon(name)
        resp = @connection.get("pokemon", { "name" => name })
        data = JSON.parse(resp.body)

        if data["error"] and data["code"] and data["code"] != 200
                raise RuntimeError.new("[#{data["code"]}] #{data["error"] or "Rejected with status code #{data["code"]}"}")
        else
                Spreader::Pokemon.new(data)
        end
end
pypi(package) click to toggle source

Returns package information from pypi registry @param module [String] The module name @return [Spreader::Pypi]

# File lib/snowflakeapirb.rb, line 157
def pypi(package)
        resp = @connection.get("registry/pypi", { "module" => package })
        data = JSON.parse(resp.body)

        if data["error"] and data["code"] and data["code"] != 200
                raise RuntimeError.new("[#{data["code"]}] #{data["error"] or "Rejected with status code #{data["code"]}"}")
        else
                Spreader::Pypi.new(data)
        end
end
reverse(message) click to toggle source

Reverse the given text @param message [String] The message to reverse @return [String]

# File lib/snowflakeapirb.rb, line 171
def reverse(message)
        resp = @connection.get("reverse", { "message" => message })
        data = JSON.parse(resp.body)

        if data["error"] and data["code"] and data["code"] != 200
                raise RuntimeError.new("[#{data["code"]}] #{data["error"] or "Rejected with status code #{data["code"]}"}")
        else
                return data["message"]
        end
end
roast() click to toggle source

Returns random roast message @return [String]

# File lib/snowflakeapirb.rb, line 73
def roast
        resp = @connection.get("roast")
        data = JSON.parse(resp.body)

        if data["error"] and data["code"] and data["code"] != 200
                raise RuntimeError.new("[#{data["code"]}] #{data["error"] or "Rejected with status code #{data["code"]}"}")
        else
                return data["roast"]
        end
end
stats() click to toggle source

Returns API server status @return [Hash]

# File lib/snowflakeapirb.rb, line 226
def stats
        resp = @connection.get("stats")
        data = JSON.parse(resp.body)

        if data["error"] and data["code"] and data["code"] != 200
                raise RuntimeError.new("[#{data["code"]}] #{data["error"] or "Rejected with status code #{data["code"]}"}")
        else
                return data
        end
end
tokeninfo(token) click to toggle source

Returns information about a discord token @param token [String] The discord token @return [Spreader::Token_info]

# File lib/snowflakeapirb.rb, line 213
def tokeninfo(token)
        resp = @connection.get("tokeninfo", { "token" => token })
        data = JSON.parse(resp.body)

        if data["error"] and data["code"] and data["code"] != 200
                raise RuntimeError.new("[#{data["code"]}] #{data["error"] or "Rejected with status code #{data["code"]}"}")
        else
                Spreader::Token_info.new(data)
        end
end