From 22873f5667d00e226d2128f8e7c6f5ab7d672ceb Mon Sep 17 00:00:00 2001 From: sarthakjdev Date: Sat, 1 Jun 2024 17:58:12 +0530 Subject: [PATCH] chore: WIP Signed-off-by: sarthakjdev --- .github/workflows/release.yaml | 20 ++++++++++++++++++++ internal/request_client/request_client.go | 16 ++++++++++++---- 2 files changed, 32 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/release.yaml diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000..4c31984 --- /dev/null +++ b/.github/workflows/release.yaml @@ -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 + + diff --git a/internal/request_client/request_client.go b/internal/request_client/request_client.go index 6f7cc66..a333205 100644 --- a/internal/request_client/request_client.go +++ b/internal/request_client/request_client.go @@ -13,6 +13,7 @@ const ( REQUEST_PROTOCOL = "https" ) +// RequestClient represents a client for making requests to a cloud API. type RequestClient struct { apiVersion string PhoneNumberId string @@ -20,6 +21,7 @@ type RequestClient struct { apiAccessToken string } +// NewRequestClient creates a new instance of RequestClient. func NewRequestClient(phoneNumberId string, apiAccessToken string) *RequestClient { return &RequestClient{ apiVersion: API_VERSION, @@ -29,15 +31,18 @@ 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)) @@ -45,12 +50,15 @@ func (requestClientInstance *RequestClient) RequestCloudApi(params RequestCloudA 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 }