Documentation How to use the Discover Network.

Documentation List Menu

API Introduction

What is the Lua API?

The Lua API is a coded object for Lua that allows you to interact with the Discover Network, where it handles all the requests for you, all you have to do is pass it the right variables and boom it will work!! Please also note that this is in ALPHA which means it is very likely there will be bugs, if so, please use the contact form on my main page, to send me bug fixes. Please keep an eye on this page, and always check the version, most of the time compatability will come first but some times the functions may need to be updated so always make sure you keep on-top of the version, we shall be putting in version support soon.

Downloading the Lua API

The Lua API can be downloaded but we recommend you require it on load via the HTTP API. To require the program use the below code snippet and place this at the top of your program.

local ok, err = pcall( function()
    if http then
        aa = aa or {}
        local a = http.get("http://api.dannysmc.com/files/apis/discover.lua")
        a = a.readAll()
        local env = {}
        a = loadstring(a)
        local env = getfenv()
        setfenv(a,env)
        local status, err = pcall(a, unpack(aa))
        if (not status) and err then
            printError("Error loading api")
            return false
        end
        local returned = err
        env = env
        _G["discover"] = env
    end
end)
if not ok then
    error("Could not install API")
end

Core (Discover.Core)

These are core functions that are useful for you to interact with the API. Please try not to reference the Discover object directly. If you want a new function to be added again, please use the form on my main site.


Discover.Core:GetStats()

Get statistics snippet this will just output some stats about the DiscoverAPI:

local status, data = Discover.Core:GetStats()
for k,v in ipairs(data) do
    print(tostring(k) .. ": " .. tostring(v))
end

Discover.Core:GetVersion()

Get version snippet, here you can actually get the version of the Discover API, or supply a field either (Version/Release/Build) to see that part of the version:

local status, data = Discover.Core:GetVersion()
for k,v in ipairs(data) do
    print(tostring(k) .. ": " .. tostring(v))
end

-- Example of just the version:
local status, data = Discover.Core:GetVersion("Version")
for k,v in ipairs(data) do
    print(tostring(k) .. ": " .. tostring(v))
end

Discover.Core:GetLatestError()

Get latest error message snippet, here you can see the lastest error that may have been passed to this variable:

local errormessage = Discover.Core:GetLatestError()
print(tostring(errormessage))

Discover.Core:GetLatestMessage()

Get latest success message snippet, this will just be a success message so you can use it as well:

local message = Discover.Core:GetLatestMessage()
print(tostring(message))

Discover.Core:Report()

Report snippet, this function just exposes a report option that allows you to send up a serialised table of information and of course the error code that will be stored to my database so I can check it for you (DiscoverAPI related only!):

local data = {
    ["Error"] = "startup:attempt to call nil";
}
-- Add anything else you want
local status = Discover.Core:Report(data)
print(tostring(status))

User (Discover.User)

First of all lets start off with the user functions, this is still expanding, but below are the implemented functions. Everything spans of the first connector really, so any type of account management as well as upload apps, and using some of the other systems that require authentication you will need to login. The authkeys are managed by the object itself, so you do not need to worry about that, they are saved into a table, if you wish to save the information then please refer to Discover.Core for functions to do that.


Discover.User:Login()

Login snippet (Will log you in, and init all the fields needed to use the Discover object:

local status, err = Discover.User:Login("username", "password")
if not status then
    print(tostring(err))
end

Discover.User:LoggedIn()

LoggedIn snippet, just allows you to see if the user is logged in:

local status = Discover.User:LoggedIn()
if status then
    print("User is logged in!")
else
    print("User is not logged in!")
end

Discover.User:GetField()

Get field snippet, just allows you to get some data from the logged in user, the field can be AuthKey, Username, or Password, Password is hashed:

local username = Discover.User:GetField("Username")
print(username)

Discover.User:Register()

Register snippet, make sure to supply an email, this will then register your account:

local status = Discover.User:Register("username", "password", "email")
if not status then
    print(tostring(err))
end

Discover.User:GetRank()

The get rank command allows you to retrieve the users rank within the Discover Network, whether that be user, moderator, admin, or guest.

local rank = Discover.User:GetRank()
print(rank)

Discover.User:CheckIP()

This system is part of the rate-limiting service, where you can see if an IP is banned or not before even logging in.

local status, err = Discover.User:CheckIP()
if status then
    print(tostring(err))
end

Discover.User:Reset()

This is an internal function that allows you to reset the internal user data.

local status = Discover.User:Reset()

Discover.User:ManualLogin()

This allows for manual login override, as usually when using the normal Login method, it will hash the password, where as ManualLogin won't hash it, meaning you can store the hash of the password and then login using that instead of plain password storage.

local status, err = Discover.User:ManualLogin("username", "password")
if not status then
    print(tostring(err))
end

Discover.User:Modify()

Allows you to change your password and/or email.

local status, err = Discover.User:Modify("email/password", "new-email/new-password")
if not status then
    print(tostring(err))
end

Discover.User:GetStatistics()

This retrieves all your statistics data including apps download/uploads count, and snippets also.

local status, data = Discover.User:GetStatistics()
if status then
    print(textutils.serialize(data))
end

Discover.User:GetData()

This retrieves your user data, username, email and other.

local status, data = Discover.User:GetData()
if status then
    print(textutils.serialize(data))
end

Discover.User:Validate()

Validate snippet, this just validates your authkey to make sure you are still valid to use the API, good to use instead of re-logging in, as authkeys are valid for 24 hours:

local status = Discover.User:Validate()
if not status then
    print(tostring(err))
end

Discover.User:Logout()

Logout snippet, this simply will log you out, it's always good to do this:

local status = Discover.User:Logout()
if not status then
    print(tostring(err))
end

Apps (Discover.Apps)

This is the App store part of the API, this allows you to interact with the app store, to upload, download, edit, update, delete and comment on apps. This is fairly powerful and a lot of data goes to and from this, so always make sure you check error messages in case something does go wrong.


Discover.Apps:Upload()

This will allow you to upload an app to the store. Remember to pass all the correct parameters.

local status, err = Discover.Apps:Upload("name", "description", "version", "category", "status", "data", "bRaw")
-- data should be the file path of the file, otherwise to give the API the file data
-- make data the file data and put true for bRaw.
if not status then
    print(err)
end

Discover.Apps:Update()

Will allow you to update the content of the App, allowing you to update and change version.

local status, err = Discover.Apps:Upload("id", "version", "status", "data")
-- data should be the file path of the file
if not status then
    print(err)
end

Discover.Apps:Edit()

This allows you to edit the meta data for the app.

local status, err = Discover.Apps:Upload("id", "name", "description", "category", "status")
if not status then
    print(err)
end

Discover.Apps:List()

Supply a parameter for what you want to list from the app store either apps, for all apps, categories for a list of the categories, versions for a list of all versions used or owned for your owned apps.

local status, apps = Discover.Apps:List("apps")
for k,v in ipairs(apps) do
    print(tostring(v.name))
end

Discover.Apps:Download()

This will allow you to download an app and save it to file.

local status = Discover.Apps:Download(10, "compress.lua")
if status then
    print("App was downloaded and saved")
end

Discover.Apps:Delete()

Once given an ID you can then delete an app as long as it belongs to you! Otherwise it will error with a permission problem.

local status, err = Discover.Apps:Delete(10)
if not status then
    print(tostring(err))
end

Discover.Apps:Comment()

[view/add], appid, comment

-- View Comments for app:
local status, comments = Discover.Apps:Comment("view", 10)
if status then
    print(textutils.serialize(comments))
end
-- Add new comment
local status = Discover.Apps:Comment("add", 10, "Nice app!!")
print(tostring(status))

Profiles (Discover.Profiles)

This is your online Discover profile, where users can search profiles and read up information about you, this includes, your app/snippet stats, uploads and downloads, latest posts on the newsfeed, and your chosen information. Profiles are optional, and you don't have to create one.


Discover.Profiles:View()

Allows you to view someones profile.

local status, data = Discover.Profiles:View("username")
if status then
    print(textutils.serialize(data))
end

Discover.Profiles:Update()

Allows you to update your profile information.

local status, err = Discover.Profiles:Edit("display_name", "birthday", "location", "bio", "website")
if status then
    print("Successful")
else
    print("Error: " .. tostring(err))
end

Discover.Profiles:List()

List all available profiles.

local status, data = Discover.Profiles:List()
if status then
    for k,v in ipairs(data) do
        print(k .. ": " .. v)
    end
end

Tickets (Discover.Tickets)

This hasn't been documented just yet!

Chat (Discover.Chat)

This hasn't been documented just yet!

Snippets (Discover.Snippets)

Snippets (Discover.Snippets)

The snippets store is like the App Store with basically the same meta data but instead it is meant to store snippets of code, this is useful and will soon be embeddable to programs.

Discover.Snippets:List()

[all/owned]

local status, data = Discover.Snippets:List("all")
print(textutils.serialize(data))
Discover.Snippets:Upload()

Will allow you to create and upload a new snippet, make sure to supply all parameters.

local status, err = Discover.Snippets:Upload("name", "description", "version", "status", "data")
-- data should be the file path of the file
if not status then
    print(err)
end
Discover.Snippets:Download()

Will download and save a snippet to file, once an ID and filename is supplied.

local status = Discover.Snippets:Download(4, "read.lua")
if status then
    print("Snippet was downloaded and saved")
end
Discover.Snippets:Delete()

Once given an ID you can then delete that snippet as long as you have permission.

local status, err = Discover.Snippets:Delete(10)
if not status then
    print(tostring(err))
end

Cloud (Discover.Cloud)

Cloud (Discover.Cloud)

The cloud is my favourite part of the Discover Network, this adds support for uploading, downloading files to and from an online folder, this is powerful because you can swap files to and from a computer on different servers, or even on a single-player world!

Discover.Cloud:List()

This will list all your files that are stored in the cloud.

local status, files = Discover.Cloud:List()
if status then
    print(textutils.serialize(files))
end
Discover.Cloud:Delete()

Once an ID is given you can delete the file from the server.

local status = Discover.Cloud:Delete(2)
print(tostring(status))
Discover.Cloud:Create()

Give the filepath of your file and it will create and upload the file to the cloud. Please note this could take a few moments as it has to encode the file before sending it up.

local status = Discover.Cloud:Create("file.lua")
if status then
    print("File was uploaded")
end
Discover.Cloud:Rename()

You can supply an ID then a new name and it will rename the file with the same ID with the new name as long as you have permission.

local status = Discover.Cloud:Rename(3, "Newfile.lua")
print(tostring(status))
Discover.Cloud:Install()

If you supply this function with the meta data for that file, it will decode the file and save it fo file for you.

-- So get the list
local list = Discover.Cloud:List();
-- Choose your file so for example it will be the first app in the table:
local status = Discove.Cloud:Install(list[1])
print(tostring(status))
-- Voile file saved!

Feed (Discover.Feed)

Feed (Discover.Feed)

The feed is actually adds only a few functions to allow you to interact with an online news feed, where you can post updates and anything you want to talk about.

Discover.Feed:Create()

Supply this with a message and it will create a new post for you.

local status = Discover.Feed:Create("Hello world!")
print(tostring(status))
Discover.Feed:List()

This will list the last 50 items of the feed for you as feeds may get big so this is to protect from large wait times.

local status, feed = Discover.Feed:List()
if status then
    print(textutils.serialize(feed))
end

Mail (Discover.Mail)

Mail (Discover.Mail)

The mail feature is a mail system allowing you to send emails to users of the Discover Network, It supports attachments and read messages.

Discover.Mail:Create()

recipient, subject, message, attachments

local status = Discover.Mail:Create("recipient", "subject", "message", "attachments")
-- attachments is optional, if you do make sure it is the source of the file, more than one file should be compressed with something like creator's compress program.
print(tostring(status))
Discover.Mail:List()

[inbox/sent]

local status, inbox = Discover.Mail:List("inbox");
print(textutils.serialize(inbox))
Discover.Mail:Read()

This will just change the read status of an email in the database so when you view your inbox you can see what is read and isn't. Just supply the email's id.

local status = Discover.Mail:Read(4)
print(tostring(status))
Discover.Mail:Delete()

This will just delete an email from the database, supply the ID of the email which will be in the table of that mail item.

local status = Discover.Mail:Delete(8)
print(tostring(status))

Notifications (Discover.Notifications)

Notifications (Discover.Notifications)

The notifications system is a work in progress but in essence it allows other parts of Discover to send you notifications like getting a new email, or someone commenting on your app.

Discover.Notifications:List()

This will simply list all the user's notifications in a table format.

local status, list = Discover.Notifications:List()
if status then
    print(textutils.serialize(list))
end
Discover.Notifications:Delete()

This will just delete a notification from the database, supply the ID of the notification which will be in the table of that notification.

local status = Discover.Notifications:Delete(10)
print(tostring(status))

Crypto (Discover.Crypto)

Crypto (Discover.Crypto)

This is just a basic block for anything used by the rest of the object, it includes Base64 encoding and decoding and Sha256 hashing.

Discover.Crypto:Base64()

[encode/decode], data

local text ="Hello World!";
local encoded = Discover.Crypto:Base64("encode", text);
print(encoded)
local decoded = Discover.Crypto:Base64("Decode", encoded);
print(decoded)
Discover.Crypto:Sha256()

This is just a SHA256 hashing method, all you have to do is supply a string of text to it to hash.

local password = "A-Secure-Password";
local hashed = Discover.Crypto:Sha256(password);
print(password);