This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
mibac138's profile picture

GitHubAPI

Started by mibac138, 27 December 2013 - 03:19 PM
mibac138 #1
Posted 27 December 2013 - 04:19 PM
GitHubAPI

Version 1.2


1. Introduction

My, [mibac138] GitHubAPI.


Were you ever looking for a Git Hub API ?
It's just waiting for you!

If you want you can also watch other my programs! (On GitHub)

Post your suggestions on GitHub! (Here) (Or optionaly in comments - i will move them to GitHub requests or issues)


2. Documentation
SpoilerGetters and Setters
SpoilersetGitHubUserName(New Git Hub User Name) - Sets new Git Hub User Name
getGitHubUserName() - Returns Git Hub User Name

setGitHubURLAddress(New Site URL Address) - Sets new Git Hub URL Address
getGitHubURLAddress() - Returns Git Hub URL Address

setGitHubSourceURLAddress(New Site Source URL Address) - Sets new Git Hub Source URL Address
getGitHubSourceURLAddress() - Returns Git Hub Source URL Address

setGitHubRepo[sitory]Name(New Git Hub Repo[sitory] Name) - Sets new Git Hub Repo[sitory] Name
getGitHubRepo[sitory]Name() - Returns Git Hub Repo[sitory] Name

setGitHubFileName(New Git Hub File To Download Name) - Sets New Git Hub File Name (To Download)
getGitHubFileName() - Returns Git Hub File Name (To Download)

setGitHubBranchName(New Git Hub Branch Name) - Sets New Git Hub Branch Name
getGitHubBranchName() - Returns Git Hub Branch Name

setGitHubVersionFileName(New Git Hub Versions File Name) - Sets New Git Hub Versions File Name
getGitHubVersionFileName() - Returns Git Hub Versions File Name
Downloaders
Spoiler

GitHubFileDownload() - Downloads file from GitHub with given parameters or parameters from vars (changable with Getters & Setters).




3. Code

Link to Code

Code:

Spoiler

--[[
My, mibac138 GitHub API.
]]

local Version = 1.2
local GitHubURL = "https://github.com"
local GitHubSourceURL = "https://raw.github.com"
local GitHubUserName = "mibac138"
local GitHubRepoName = "CC"
local GitHubBranchName = "master"
local GitHubVersionsFileName = "Versions"
local GitHubFileName


--[[ Helper Functions ]]--

local function getWebsite(httpAddress)
if not http then return false, "HTTP API Not Enabled!" end
ok, data = false, nil

ok, data = pcall(function() return http.get(httpAddress).readAll() end)

return ok, data
end

--[[ Getters And Setters ]]--

--+ GitHubUserName +--

function setGitHubUserName(_GitHubUserName)
if not (_GitHubUserName == nil and _GitHubUserName == "") then
  GitHubUserName = tostring(_GitHubUserName)

  return true
end

return false
end

function getGitHubUserName()
return GitHubUserName
end

--+ GitHubURLAddress +--

function setGitHubURLAddress(_GitHubURL)
if not _GitHubURL:sub(1, 7) == "http://" then
  _GitHubURL = "http://" .. _GitHubURL
end

if not (_GitHubURL == nil and _GitHubURL == "" and _GitHubURL == "http://" and _GitHubURL == "https://") then  
  GitHubURL = tostring(_GitHubURL)

  return true
end

return false
end

function getGitHubURLAddress()
return GitHubURL
end

--+ GitHubSourceURLAddress +--

function setGitHubSourceURLAddress(_GitHubSourceURL)  
if not string.sub(_GitHubSourceURL, 1, 7) == "http://" then
  _GitHubSourceURL = "http://" .. _GitHubSourceURL
end

if not (_GitHubSourceURL == nil and _GitHubSourceURL == "" and _GitHubSourceURL == "http://" and _GitHubSourceURL == "https://") then
  GitHubSourceURL = _GitHubSourceURL

  return true
end

return false
end

function getGitHubSourceURLAddress()
return GitHubSourceURL
end

--+ GitHubRepo[sitory]Name +--

function setGitHubRepoName(_GitHubRepoName)
if not (_GitHubURL == nil and _GitHubURL == "") then  
  GitHubRepoName = tostring(_GitHubRepoName)

  return true
end

return false
end

function getGitHubRepoName()
return GitHubRepoName
end

setGitHubRepositoryName = setGitHubRepoName
getGitHubRepositoryName = getGitHubRepoName

--+ GitHubFileName +--

function setGitHubFileName(_GitHubFileName)
if not (_GitHubFileName == nil and _GitHubFileName == "") then
  GitHubFileName = _GitHubFileName

  return true
end

return false
end

function getGitHubFileName()
return GitHubFileName
end

--+ GitHubBranchName +--

function setGitHubBranchName(_GitHubBranchName)
if not (_GitHubBranchName == nil and _GitHubBranchName == "") then
  GitHubBranchName = _GitHubBranchName

  return true
end

return false
end

function getGitHubBranchName()
return GitHubBranchName
end

--+ GitHubVersionsFileName +--

function setGitHubVersionsFileName(_GitHubVersionsFileName)
if not (_GitHubVersionsFileName == nil and _GitHubVersionsFileName == "") then
  GitGitHubVersionsFileName = _GitHubVersionsFileName

  return true
end

return false
end

function getGitHubVersionsFileName()
return GitHubBranchName
end

--+ Version +--

function getGitHubAPIVersion()
return Version
end

--[[ Functions ]]--

function GitHubFileDownload( _GitHubFileName, _GitHubSourceURL, _GitHubUserName, _GitHubRepoName, _GitHubBranchName)
local _GitHubFileName, _GitHubSourceURL, _GitHubUserName, _GitHubRepoName, _GitHubBranchName = _GitHubFileName or GitHubFileName, _GitHubSourceURL or GitHubSourceURL, _GitHubUserName or GitHubUserName, _GitHubRepoName or GitHubRepoName, _GitHubBranchName or GitHubBranchName

if not _GitHubFileName or _GitHubFileName == "" then error("GitHubAPI: REQUIRED arg [1] - Git Hub File Name" ,0) end

local ok, data = getWebsite(_GitHubSourceURL .. "/" .. _GitHubUserName .. "/" .. _GitHubRepoName .. "/" .. _GitHubBranchName .. "/" .. _GitHubFileName)

if not ok then return ok, data end

return data
end

function GitHubFileDownloadIf(p1, p2, p3, _GitHubFileName, _GitHubSourceURL, _GitHubUserName, _GitHubRepoName, _GitHubBranchName)
local _GitHubSourceURL, _GitHubUserName, _GitHubRepoName, _GitHubFileName, _GitHubBranchName, canDownload = _GitHubSourceURL or GitHubSourceURL, _GitHubUserName or GitHubUserName, _GitHubRepoName or GitHubRepoName, _GitHubFileName or GitHubFileName, _GitHubBranchName or GitHubBranchName , false

if not p1 or not p2 or not p3 then return false, "p1, p2, or p3 is nil" end

if p3 == "==" and p1 == p2 then canDownload = true
elseif p3 == ">=" and p1 >= p2 then canDownload = true
elseif p3 == "<=" and p1 <= p2 then canDownload = true
elseif p3 == "~=" and p1 ~= p2 then canDownload = true
elseif p3 == ">" and p1 > p2 then canDownload = true
elseif p3 == "<" and p1 < p2 then canDownload = true
end

if canDownload then

  local ok, data = getWebsite(_GitHubSourceURL .. "/" .. _GitHubUserName .. "/" .. _GitHubRepoName .. "/" .. _GitHubBranchName .. "/" .. _GitHubFileName)

  if not ok then return ok, data end

  return canDownload, data
else

  return canDownload
end
end

function GitHubFileDownloadIfExistsUpdate(_FileWhereToSave, _FileName, _FileVersion, _GitHubVersionsFileName, _GitHubSourceURL, _GitHubUserName, _GitHubRepoName, _GitHubBranchName)
local _GitHubSourceURL, _GitHubUserName, _GitHubRepoName, _GitHubBranchName, __GitHubVersionsFileName, _FileName, _FileVersion = _GitHubSourceURL or GitHubSourceURL, _GitHubUserName or GitHubUserName, _GitHubRepoName or GitHubRepoName, _GitHubBranchName or GitHubBranchName, _GitHubVersionsFileName or GitHubVersionsFileName, _FileName or GitHubFileName, _FileVersion or 1.0

local ok, data = getWebsite(_GitHubSourceURL .. "/" .. _GitHubUserName .. "/" .. _GitHubRepoName .. "/" .. _GitHubBranchName .. "/" .. _GitHubVersionsFileName)

if not ok then return ok, data end

data = textutils.unserialize(data)

if not data[tostring(_FileName)] then return false, "File isnt existing in " .. _GitHubVersionsFileName .. " db file (" .. _GitHubSourceURL .. "/" .. _GitHubUserName .. "/" .. _GitHubRepoName .. "/" .. _GitHubBranchName .. "/" .. _GitHubVersionsFileName)" end

if data[tostring(_FileName)].Version > _FileVersion then

  local ok, data = getWebsite(VersionCheck[_FileName].GitURL)

  if not ok then return ok, data end

  return ok, data, "Update Founded And Downloaded"
else
  return ok, "No update found"
end
end


4. Download


pastebin get 5reackVG GitHubAPI (Installer - BETA)


5. The End



Enojoy! I hope it will be usefully for you :)/>
Edited on 05 February 2014 - 05:44 AM
mibac138 #2
Posted 28 December 2013 - 08:31 AM
Why you arent posting anything? :c
awsmazinggenius #3
Posted 28 December 2013 - 10:30 AM
Why you arent posting anything? :c
It has only been a day since you created your topic. Be patient, somebody will use this (not me, atm).

EDIT: Also, remove all formatting on your code (the eraser button in the editor) and place [.code] and [./code] (without the '.') around the code; it will automatically syntax highlight, like this:

while true do
  print("Hai")
  sleep(1)
end
Edited on 28 December 2013 - 09:32 AM
mibac138 #4
Posted 28 December 2013 - 10:58 AM
Changed! :)/>
Symmetryc #5
Posted 29 December 2013 - 10:50 AM
I'm wondering how you managed to get all of those capitals in the topic title :P/>.
mibac138 #6
Posted 29 December 2013 - 12:12 PM
Heh :P/>

@Edit: LOL? I didnt know about it (@down)
Edited on 05 February 2014 - 06:18 AM
MudkipTheEpic #7
Posted 29 December 2013 - 05:06 PM
I'm wondering how you managed to get all of those capitals in the topic title :P/>/>.

http://www.computercraft.info/forums2/index.php?/topic/15057-topic-titles-and-letter-case/page__view__findpost__p__154018




Also, how does it handle private repos?
mibac138 #8
Posted 30 December 2013 - 04:40 AM
Untested, for now i cannot actually test it :(/> (GitHub wants to pay him for private repos ! :angry:/> )

If private repos works as public then it will work. (I mean if the https addres is the same and you can access it without required login before - GitHubSourceURL .. "/" .. GitHubUserName .. "/" .. GitHubRepoName .. "/" .. GitHubBranchName .."/" .. GitHubFileName)
Edited on 31 December 2013 - 06:14 AM
mibac138 #9
Posted 31 December 2013 - 11:00 AM
Anyone?
mibac138 #10
Posted 04 January 2014 - 07:01 AM
Why here is soo small count of replies?! ;c
distantcam #11
Posted 04 January 2014 - 07:27 AM
Why here is soo small count of replies?! ;c
Because you don't have any documentation so we have to read the source code to figure out what your API does.

And because GitHub is not a commonly used thing, so most people won't have a use for this.
mibac138 #12
Posted 05 January 2014 - 06:04 AM
Oh, ok i will add documentation :)/>
Edited on 05 January 2014 - 06:25 AM
Agoldfish #13
Posted 21 January 2014 - 07:14 PM
I'm wondering how you managed to get all of those capitals in the topic title :P/>.
He broke the website with that. :P/>
mibac138 #14
Posted 05 February 2014 - 06:06 AM
Version 1.2 released! New upgraded and lighter version of my GitHubAPI released! Enjoy! :)/>
SherlockHolmes #15
Posted 03 March 2014 - 03:56 AM
This is just what I was looking for! :D/> I'll head over to github and fork/star your repo. This will help a lot with my larger projects.
mibac138 #16
Posted 03 March 2014 - 03:56 PM
No problem! :)/>
apemanzilla #17
Posted 05 March 2014 - 08:10 PM
I like the idea of this, however I don't like having to manually set/get each and every value with a different function. I would much prefer something like GitHub.download(user, repo, [branch, [destination]]) or GitHub.download({user="user",repo="repo",destination="destination"})
mibac138 #18
Posted 09 March 2014 - 05:02 PM
Actually you can do something like this:

GitHubFileDownload( _GitHubFileName, _GitHubSourceURL, _GitHubUserName, _GitHubRepoName, _GitHubBranchName)

@Edit
Any value, can be nil
Edited on 09 March 2014 - 04:03 PM