Skip to content

Commit

Permalink
chore: WIP
Browse files Browse the repository at this point in the history
Signed-off-by: sarthakjdev <[email protected]>
  • Loading branch information
sarthakjdev committed Jun 1, 2024
1 parent 82a3fda commit 22873f5
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Release

on:
push:
branches:
- master

concurrency:
group: check-pr-title-${{ github.head_ref || github.run_id }}
cancel-in-progress: true

jobs:
release:
name: Release
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v3


16 changes: 12 additions & 4 deletions internal/request_client/request_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ const (
REQUEST_PROTOCOL = "https"
)

// RequestClient represents a client for making requests to a cloud API.
type RequestClient struct {
apiVersion string
PhoneNumberId string
baseUrl string
apiAccessToken string
}

// NewRequestClient creates a new instance of RequestClient.
func NewRequestClient(phoneNumberId string, apiAccessToken string) *RequestClient {
return &RequestClient{
apiVersion: API_VERSION,
Expand All @@ -29,28 +31,34 @@ func NewRequestClient(phoneNumberId string, apiAccessToken string) *RequestClien
}
}

// RequestCloudApiParams represents the parameters for making a request to the cloud API.
type RequestCloudApiParams struct {
Body string
Path string
}

func (requestClientInstance *RequestClient) RequestCloudApi(params RequestCloudApiParams) {
// RequestCloudApi makes a request to the cloud API with the given parameters.
// It returns the response body as a string and any error encountered.
func (requestClientInstance *RequestClient) RequestCloudApi(params RequestCloudApiParams) (string, error) {
httpRequest, err := http.NewRequest("POST", fmt.Sprintf("%s://%s/%s", REQUEST_PROTOCOL, requestClientInstance.baseUrl, params.Path), strings.NewReader(params.Body))
if err != nil {
return
return "", err
}
httpRequest.Header.Set("Content-Type", "application/json")
httpRequest.Header.Set("Authorization", fmt.Sprintf("Bearer %s", requestClientInstance.apiAccessToken))
client := &http.Client{}
response, err := client.Do(httpRequest)
if err != nil {
fmt.Println("Error while requesting cloud api", err)
return
return "", err
}
defer response.Body.Close()
body, err := io.ReadAll(response.Body)
if err != nil {
return
return "", err
}

fmt.Println("Response from cloud api is", string(body))

return string(body), nil
}

0 comments on commit 22873f5

Please sign in to comment.