Jump to content

Recommended Posts

Posted (edited)

Recently I was working on TeamVierwer API .
I had a little break, and wanted to check out another platform.
Here is the result of my attempt:

#include "GHAPI.au3"

_GHAPI_AccessToken('b3e8.....de..........bdc3a0c.....bd27c6f')
_GHAPI_GetUser("users/mLipok")
_GHAPI_GetUserOrganizations("users/mLipok")
_GHAPI_RootEndpoints()

and GHAPI.au3

#include-once
#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w 7
#Tidy_Parameters=/sort_funcs /reel

#Region GHAPI.au3 - Header
; #INDEX# =======================================================================================================================
; Title .........: GHAPI UDF
; AutoIt Version : 3.3.10.2++
; Language ......: English
; Description ...: This is an UDF for for communicate with https://api.github.com    via GitHub RESTful API
; Author(s) .....: mLipok
; Modified ......:
; ===============================================================================================================================
#cs
    Title:   GHAPI UDF
    Filename:  GHAPI.au3
    Description: This is an UDF for for communicate with https://api.github.com    via GitHub RESTful API
    Author:   mLipok
    Modified:
    Last Update: 2017/05/23
    Requirements:
    AutoIt 3.3.10.2 or higher
#ce
#EndRegion GHAPI.au3 - Header

#Region GHAPI.au3 - Include
#include <array.au3>
#include <FileConstants.au3>
#include <MsgBoxConstants.au3>
#EndRegion GHAPI.au3 - Include

#Region GHAPI.au3 - Declarations
Global $oErrorHandler = ObjEvent("AutoIt.Error", "_GHAPI_ErrFunc")
Global $__g_sGitHubAPI_BaseUrl = "https://api.github.com" ; URL of the GitHub API
Global $__g_sGitHubAPI_Version = "v3" ; Put the current API version in here

Global Enum _
        $GHAPI_ERR_SUCCESS, _
        $GHAPI_ERR_GENERAL, _
        $GHAPI_ERR_COMERROR, _
        $GHAPI_ERR_STATUS, _
        $GHAPI_ERR_COUNTER

Global Enum _
        $GHAPI_EXT_DEFAULT, _
        $GHAPI_EXT_PARAM1, _
        $GHAPI_EXT_PARAM2, _
        $GHAPI_EXT_PARAM3, _
        $GHAPI_EXT_COUNTER

Global Enum _
        $GHAPI_RET_SUCCESS, _
        $GHAPI_RET_FAILURE, _
        $GHAPI_RET_COUNTER

#EndRegion GHAPI.au3 - Declarations

#Region GHAPI.au3 - API Functions
Func _GHAPI_ErrFunc($oError)
    ; Do anything here.
    ConsoleWrite(@ScriptName & " (" & $oError.scriptline & ") : ==> COM Error intercepted !" & @CRLF & _
            @TAB & "err.number is: " & @TAB & @TAB & "0x" & Hex($oError.number) & @CRLF & _
            @TAB & "err.windescription:" & @TAB & $oError.windescription & @CRLF & _
            @TAB & "err.description is: " & @TAB & $oError.description & @CRLF & _
            @TAB & "err.source is: " & @TAB & @TAB & $oError.source & @CRLF & _
            @TAB & "err.helpfile is: " & @TAB & $oError.helpfile & @CRLF & _
            @TAB & "err.helpcontext is: " & @TAB & $oError.helpcontext & @CRLF & _
            @TAB & "err.lastdllerror is: " & @TAB & $oError.lastdllerror & @CRLF & _
            @TAB & "err.scriptline is: " & @TAB & $oError.scriptline & @CRLF & _
            @TAB & "err.retcode is: " & @TAB & "0x" & Hex($oError.retcode) & @CRLF & @CRLF)
EndFunc   ;==>_GHAPI_ErrFunc

Func _GHAPI_AccessToken($sParam = Default)
    ; https://help.github.com/articles/creating-a-personal-access-token-for-the-command-line/
    ; https://github.com/settings/tokens
    Local Static $sAccessToken = ''
    If $sParam <> Default Then $sAccessToken = $sParam
    Return $sAccessToken
EndFunc   ;==>_GHAPI_AccessToken

Func _GHAPI_GetUser($sUser)
    Local $oHTTP = __GHAPI_HTTP_Open("GET", $sUser)
    Local $oJSON = __GHAPI_HTTP_Send($oHTTP)
    If @error Then Return SetError(@error, @extended, False)
    #forceref $oJSON
EndFunc   ;==>_GHAPI_GetUser

Func _GHAPI_GetUserOrganizations($sUser)
    Local $oHTTP = __GHAPI_HTTP_Open("GET", $sUser & '/orgs')
    Local $oJSON = __GHAPI_HTTP_Send($oHTTP)
    If @error Then Return SetError(@error, @extended, False)
    #forceref $oJSON
EndFunc   ;==>_GHAPI_GetUserOrganizations

Func _GHAPI_RootEndpoints()
    Local $oHTTP = __GHAPI_HTTP_Open("GET", '')
    Local $oJSON = __GHAPI_HTTP_Send($oHTTP)
    If @error Then Return SetError(@error, @extended, False)
    #forceref $oJSON
EndFunc   ;==>_GHAPI_RootEndpoints
#EndRegion GHAPI.au3 - API Functions

#Region GHAPI.au3 - INTERNAL Functions

Func __GHAPI_HTTP_Open($sMethod, $sCommand, $sURLParameters = '')
    Local $oHTTP = ObjCreate("WinHttp.WinHttpRequest.5.1")
    Local $sURL = $__g_sGitHubAPI_BaseUrl & "/" & $sCommand & $sURLParameters
;~  __GHAPI_DebugOut("> $sURL=" & $sURL & @CRLF)
    $oHTTP.Open($sMethod, $sURL, False)
    If @error Then Return SetError(@error, @extended, Null)
    $oHTTP.setRequestHeader("Authorization", "Bearer " & _GHAPI_AccessToken())

    ; Accept: application/vnd.github.v3+json
    $oHTTP.setRequestHeader("Accept", "application/vnd.github." & $__g_sGitHubAPI_Version & "+json")

    ; User-Agent: Awesome-Octocat-App
    $oHTTP.setRequestHeader("User-Agent", "AutoIt UDF")

    Return $oHTTP
EndFunc   ;==>__GHAPI_HTTP_Open

Func __GHAPI_HTTP_Send(ByRef $oHTTP, $sSendParameter = Default)
    If $sSendParameter = Default Then
        $oHTTP.Send()
    Else
        $oHTTP.Send($sSendParameter)
    EndIf

    ConsoleWrite('+' & $oHTTP.Status & @CRLF)
    ConsoleWrite('>' & $oHTTP.StatusText & @CRLF)
    ConsoleWrite($oHTTP.ResponseText & @CRLF)
    ConsoleWrite(@CRLF)

    If @error Then Return SetError(@error, @extended, $GHAPI_RET_FAILURE)

;~  Return SetError($GHAPI_ERR_SUCCESS, $oJSON.Size, $oJSON)
EndFunc   ;==>__GHAPI_HTTP_Send
#EndRegion GHAPI.au3 - INTERNAL Functions

#Region GHAPI.au3 - HOWTO / DOCS / HELP
#cs
    https://developer.github.com/v3/
    https://developer.github.com/v3/guides/
    https://developer.github.com/program/
    https://github.com/contact?form%5Bsubject%5D=New+GitHub+Integration
    https://developer.github.com/
    http://stackoverflow.com/questions/28796941/github-api-authentication-with-msxml2-xmlhttp

#CE
#EndRegion GHAPI.au3 - HOWTO / DOCS / HELP

 

REMARKS:
This is just a modest start up and not a whole fully workable UDF, just so for a try, but maybe someone will be useful :)

Regards,
mLipok

 

EDIT 1:
If you need to make it workable just ask about specyfic feature.

EDIT 2:
Some changes in using word "GitHub" - to meet this rules: https://github.com/logos

Edited by mLipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

  • 4 months later...
Posted

Hi, 

 

I am looking for a way to do a version check with the GitHub release. When I compile a new version ready for production I create a new Release with the same version info.

There must be some way to check check via the API?

Posted (edited)

Today I'm tired 24 hour, work day.
Going to sleep.
Pleask ask me again in next 12 hours.

 

Edited by mLipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted

Yeasterday I just go and rest.

Now I'm using my smartphone to answer your question, as I'm on my travel to work.

I ask him to bump the same question again, as I'm going to answer, but I'm realy busy man.

 

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted (edited)

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

  • 3 weeks later...
Posted (edited)
  On 10/27/2017 at 1:46 PM, Emile said:
Expand  

Add this function 

Func _GHAPI_GetReposReleases($sOwner, $sRepo)
    Local $oHTTP = __GHAPI_HTTP_Open("GET", "repos/" & $sOwner & '/' & $sRepo & '/releases')
    Local $oJSON = __GHAPI_HTTP_Send($oHTTP)
    If @error Then Return SetError(@error, @extended, False)
    #forceref $oJSON
EndFunc   ;==>_GHAPI_GetReposReleases

and use them like this:

_GHAPI_AccessToken('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx')
_GHAPI_GetReposReleases("mlipok","TEST")

 

RESULT:

[{
		"url": "https://api.github.com/repos/mlipok/TEST/releases/8484228",
		"assets_url": "https://api.github.com/repos/mlipok/TEST/releases/8484228/assets",
		"upload_url": "https://uploads.github.com/repos/mlipok/TEST/releases/8484228/assets{?name,label}",
		"html_url": "https://github.com/mlipok/TEST/releases/tag/123",
		"id": 8484228,
		"tag_name": "123",
		"target_commitish": "master",
		"name": "TestingGitHubAPI ",
		"draft": false,
		"author": {
			"login": "mlipok",
			"id": 11089482,
			"avatar_url": "https://avatars2.githubusercontent.com/u/11089482?v=4",
			"gravatar_id": "",
			"url": "https://api.github.com/users/mlipok",
			"html_url": "https://github.com/mlipok",
			"followers_url": "https://api.github.com/users/mlipok/followers",
			"following_url": "https://api.github.com/users/mlipok/following{/other_user}",
			"gists_url": "https://api.github.com/users/mlipok/gists{/gist_id}",
			"starred_url": "https://api.github.com/users/mlipok/starred{/owner}{/repo}",
			"subscriptions_url": "https://api.github.com/users/mlipok/subscriptions",
			"organizations_url": "https://api.github.com/users/mlipok/orgs",
			"repos_url": "https://api.github.com/users/mlipok/repos",
			"events_url": "https://api.github.com/users/mlipok/events{/privacy}",
			"received_events_url": "https://api.github.com/users/mlipok/received_events",
			"type": "User",
			"site_admin": false
		},
		"prerelease": false,
		"created_at": "2015-02-20T11:44:27Z",
		"published_at": "2017-11-12T21:23:05Z",
		"assets": [],
		"tarball_url": "https://api.github.com/repos/mlipok/TEST/tarball/123",
		"zipball_url": "https://api.github.com/repos/mlipok/TEST/zipball/123",
		"body": "GET /repos/:owner/:repo/releases"
	}
]

 

Edited by mLipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted

Modyfication:
 

Func _GHAPI_GetReposReleases($sOwner, $sRepo, $sParams = "")
    $sParams = (($sParams) ? ("/" & $sParams) : (""))
    Local $oHTTP = __GHAPI_HTTP_Open( _
            "GET", _
            "repos/" & $sOwner & '/' & $sRepo & '/releases' & $sParams _
            )
    Local $oJSON = __GHAPI_HTTP_Send($oHTTP)
    If @error Then Return SetError(@error, @extended, False)
    #forceref $oJSON
EndFunc   ;==>_GHAPI_GetReposReleases
_GHAPI_AccessToken('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx')
_GHAPI_GetReposReleases("mlipok","TEST")
_GHAPI_GetReposReleases("mlipok","TEST", 'latest')
_GHAPI_GetReposReleases("mlipok","TEST", '8484228')
_GHAPI_GetReposReleases("mlipok","TEST", 'tags/123')

 

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

  • mLipok changed the title to GHAPI UDF - modest beginning - communication with GitHub REST API
  • 1 year later...
Posted

I wanted to say thank you for this, as it was the first script that made me understand the WinHTTPRequest object. Your code is simple enough that I can read and understand it while hitting enough points to get me started :) I extended this script a bit and I'd be happy to share it if you'd be interested 

All my code provided is Public Domain... but it may not work. ;) Use it, change it, break it, whatever you want.

  Reveal hidden contents
Posted

Cool.

Sure, show what you do. 

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

  • mLipok changed the title to GHAPI.au3 UDF - modest beginning - communication with GitHub REST API

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...