﻿)clear
]box on
]load HttpCommand
HttpCommand.Upgrade
&'
&'
&'
⍝ use a RESTful web service (GitHub)
]open https://docs.github.com/en/rest/releases/releases?apiVersion=2022-11-28#list-releases
&'
&'
&'
h←HttpCommand.New 'get' 'https://api.github.com/repos/Dyalog/HttpCommand/releases'
h.Show
⎕←r←h.Run
200↑r.Data
h.TranslateData←1
⊢r←h.Run 
r.Data
r.Data[1].⎕NL ¯2
10↑ ↑r.Data.(tag_name created_at)
r.Headers ⍝ notice rate limits
GitHubAPIKey←'YOUR-GITHUB-API-KEY-HERE'
h.(AuthType Auth)←'Bearer' GitHubAPIKey
⎕←r←h.Run
r.Headers
&'
&'
&'
⍝ Let's create and modify a repository
]open https://docs.github.com/en/rest/repos/repos?apiVersion=2022-11-28#create-a-repository-for-the-authenticated-user
h ← HttpCommand.New ''
h.Command←'post'
h.BaseURL←'https://api.github.com/'
h.URL←'user/repos'
h.(AuthType Auth)←'Bearer' GitHubAPIKey
h.TranslateData←1
p←⎕NS ''  ⍝ create a namespace for parameters to be passed
p.(name description)←'Test-Repo' 'This is a test'
p.license_template←'MIT'
h.Params←p
h.Show
⎕←r←h.Run       
r.IsOK
&'
&'
&'
&⍎⎕←'      ]open ',r.Data.html_url
]open https://docs.github.com/en/rest/repos/repos?apiVersion=2022-11-28#update-a-repository
h.Command←'patch'
h.URL←r.Data.url
h.Params←'{"description":"This is a test repository"}'
h.Show
⎕←r←h.Run
r.IsOK
&'
&'
&'      
h.Command←'delete'
⍝ uses the same URL that we just created 
h.Params←''
h.Show
⎕←r←h.Run
r.IsOK
&'
&'
&'
]demo /DYNA24/OpenAI

