Skip to content

Commit

Permalink
Merge pull request #14 from WilfredAlmeida/apis
Browse files Browse the repository at this point in the history
Apis
  • Loading branch information
WilfredAlmeida authored Jul 22, 2023
2 parents 4bb3d8f + 35e5ae3 commit b71f02c
Show file tree
Hide file tree
Showing 15 changed files with 543 additions and 3 deletions.
40 changes: 40 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Bug report
description: Create a report to help us improve
title: '[bug]'
labels: ['bug']
body:
- type: textarea
attributes:
label: Describe the bug
description: A clear and concise description of what the bug is
validations:
required: false
- type: textarea
attributes:
label: To Reproduce
description: |
Steps to reproduce the behavior.
1. Go to '...'
2. Click on '...'
3. Scroll down to '...'
4. See error
validations:
required: false
- type: textarea
attributes:
label: Expected Behavior
description: A clear and concise description of what you expected to happen.
validations:
required: false
- type: textarea
attributes:
label: Screenshot/ Video
description: If applicable, add screenshots to help explain your problem.
validations:
required: false
- type: textarea
attributes:
label: Additional context
description: Add any other context about the problem here.
validations:
required: false
5 changes: 5 additions & 0 deletions .github/ISSUE_TEMPLATE/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
blank_issues_enabled: false
contact_links:
- name: Discord community support
url: https://unkey.dev/discord
about: Need any help? Found any bug? Please chat with us via Discord.
18 changes: 18 additions & 0 deletions .github/ISSUE_TEMPLATE/doc_report.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Documentation request
description: Change regarding improving the docs to be more accessible
title: '[docs]'
labels: ['documentation']
body:
- type: textarea
attributes:
label: Category of documentation update
description: |
What category does this change fall under.For example Typo error, New category addition, Rephrasing the sentences, fixing broken links etc
validations:
required: true
- type: textarea
attributes:
label: Describe the change you think might work
description: Please describe the change & need of change in atmost detail possible.
validations:
required: false
24 changes: 24 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Feature request
description: Suggest an idea for this project
title: '[feat]'
labels: ['enhancement']
body:
- type: textarea
attributes:
label: Would you like to have a new feature? Please describe.
description: A clear and concise description of what the feature is
placeholder: Ex. Whenever I try to do (xyz) then [...]
validations:
required: false
- type: textarea
attributes:
label: How would this feature be beneficial for the project
description: A clear and concise description about the importance of the feature
validations:
required: false
- type: textarea
attributes:
label: Additional context
description: Add any other context or screenshots about the feature request here.
validations:
required: false
22 changes: 22 additions & 0 deletions .github/ISSUE_TEMPLATE/others.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Other
description: Use this for any other issues. PLEASE do not create blank issues
title: "[other]"
labels: ["random"]
body:
- type: markdown
attributes:
value: "# Other issue"
- type: textarea
id: issuedescription
attributes:
label: What would you like to share?
description: Provide a clear and concise explanation of your issue.
validations:
required: true
- type: textarea
id: extrainfo
attributes:
label: Additional information
description: Is there anything else we should know about this issue?
validations:
required: false
32 changes: 32 additions & 0 deletions .github/pull_request_template.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<!--Type in all the issues that have been fixed through this pull request ex : #1 -->

## Fixes Issue

This PR fixes the following issues:

#example

<!-- Write down all the changes made-->
## Changes proposed

Here comes all the changes proposed through this PR

<!-- Check all the boxes which are applicable to check the box correct follow the following conventions-->
<!--
[x] - Correct
[X] - Correct
-->

## Check List (Check all the boxes which are applicable) <!--Follow the above conventions to check the box-->

- [ ] My code follows the code style of this project.
- [ ] My change requires a change to the documentation.
- [ ] I have updated the documentation accordingly.
- [ ] All new and existing tests passed.
- [ ] This PR does not contain plagiarized content.
- [ ] The title of my pull request is a short description of the requested changes.


<!--Add screen shots of the changed output-->
## Screenshots
Add all the screenshots which support your changes
15 changes: 15 additions & 0 deletions .github/workflows/greetings.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: Greetings

on: [pull_request_target, issues]

jobs:
welcome:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: EddieHubCommunity/gh-action-community/src/welcome@main
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
issue-message: '<h3>Hello 👋 Thank you very much for raising an issue 🙌 The maintainers will get back to you soon for discussion over the issue! Thank you for your contributions. 🚀</h3>'
pr-message: '<h3>Yeah! You did it 🎉 Now, Relax 😉 -> Grab a drink ☕ -> And wait for the maintainers to check your contributions. Meanwhile, you can discuss on other issues and solve them 😀</h3>'
footer: 'Meanwhile you can discuss about the project in our <a href="https://unkey.dev/discord/">Discord</a> Server 😀</h3>'
29 changes: 29 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Changelog
on:
push:
branches:
- main

jobs:
changelog:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Conventional Changelog Action
id: changelog
uses: TriPSs/conventional-changelog-action@v3
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
output-file: "false"

- name: Create Release
uses: actions/create-release@v1
if: ${{ steps.changelog.outputs.skipped == 'false' }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.changelog.outputs.tag }}
release_name: ${{ steps.changelog.outputs.tag }}
body: ${{ steps.changelog.outputs.clean_changelog }}
70 changes: 70 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,48 @@ func main() {
```
> Note: The API returns `{}` as a success response for revkoking key. For user convenience, unkey-go returns boolean
**Get API Information**
```go
package main

import (
"fmt"

unkey "github.com/WilfredAlmeida/unkey-go/features"
)

func main() {
response, err := features.APIGet("API_ID","AUTH_TOKEN")
if err != nil {
fmt.Println("Error:", err)
return
}

fmt.Printf("Response: %+v\n", response)
}
```

**Get List Keys**
```go
package main

import (
"fmt"

unkey "github.com/WilfredAlmeida/unkey-go/features"
)

func main() {
response, err := features.APIListKeys("API_ID","AUTH_TOKEN")
if err != nil {
fmt.Println("Error:", err)
return
}

fmt.Printf("Response: %+v\n", response)
}
```

---
### Structs Reference
The structs used in code for you to get a better idea of the request & response bodies.
Expand Down Expand Up @@ -179,6 +221,34 @@ type KeyCreateResponse struct {
}
```

**APIGet**
```go
type APIGetResponse struct {
ID string `json:"id"`
Name string `json:"name"`
WorkspaceID string `json:"workspaceId"`
}
```

**APIListKeys**
```go
type Key struct {
ID string `json:"id,omitempty"`
APIID string `json:"apiId,omitempty"`
WorkspaceID string `json:"workspaceId,omitempty"`
Start string `json:"start,omitempty"`
CreatedAt int64 `json:"createdAt,omitempty"`
Expires *int64 `json:"expires,omitempty"`
Ratelimit ratelimitResponse `json:"ratelimit,omitempty"`
}

type APIListKeysResponse struct {
Keys []Key `json:"keys,omitempty"`
Total int `json:"total,omitempty"`
}
```
> Note: `ratelimitResponse` is defined in `KeyVerify` struct reference
---
## Contributing
Refer the [CONTRIBUTING.md](https://github.com/WilfredAlmeida/unkey-go/blob/main/CONTRIBUTING.md) file for more information.
58 changes: 58 additions & 0 deletions features/api_get.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package features

import (
"encoding/json"
"fmt"
"io"
"net/http"

"github.com/WilfredAlmeida/unkey-go/utils"
)

type APIGetResponse struct {
ID string `json:"id"`
Name string `json:"name"`
WorkspaceID string `json:"workspaceId"`
}

func APIGet(apiID, authToken string) (APIGetResponse, error) {

// Create a new HTTP client
client := &http.Client{}

// Create a new GET request
req, err := http.NewRequest("GET", utils.UNKEY_API_URL+"/apis/"+apiID, nil)
if err != nil {
return APIGetResponse{}, err
}

// Set the authorization header
req.Header.Set("Authorization", authToken)

// Send the request
resp, err := client.Do(req)
if err != nil {
return APIGetResponse{}, err
}
defer resp.Body.Close()

// Read the response body
body, err := io.ReadAll(resp.Body)
if err != nil {
return APIGetResponse{}, err
}

// Check the response status code
if resp.StatusCode != http.StatusOK {
return APIGetResponse{}, fmt.Errorf(string(body))
}

// Parse the response JSON
var response APIGetResponse
err = json.Unmarshal(body, &response)
if err != nil {
return APIGetResponse{}, err
}

return response, nil
}
Loading

0 comments on commit b71f02c

Please sign in to comment.