Skip to content

Commit

Permalink
added resty
Browse files Browse the repository at this point in the history
  • Loading branch information
Allan-Nava authored Jul 25, 2024
1 parent af4246d commit 4e7865d
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 0 deletions.
27 changes: 27 additions & 0 deletions test/a_main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package test

import (
"os"
"testing"
"github.com/HiWay-Media/tiktok-go-sdk/tiktok"
)

func TestMain(m *testing.M) {
c, err := GetTikTok()
if err != nil {
t.Fatalf(err.Error())
}
c.IsDebug()
}


func GetTikTok() (tiktok.ITiktok, error) {
clientKey := os.GetEnv("clientKey")
clientSecret := os.GetEnv("clientSecret")
//
c, err := tiktok.NewTikTok(clientKey, clientSecret, false)
if err != nil {
return nil, err
}
return c, nil
}
44 changes: 44 additions & 0 deletions tiktok/resty.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package tiktok



func (o *tiktok) HealthCheck() error {
resp, err := o.restyPost("/", nil)
if err != nil {
return err
}
if resp.IsError() {
return fmt.Errorf("healthcheck error")

Check failure on line 11 in tiktok/resty.go

View workflow job for this annotation

GitHub Actions / build (1.19.x)

undefined: fmt

Check failure on line 11 in tiktok/resty.go

View workflow job for this annotation

GitHub Actions / build (1.20.x)

undefined: fmt

Check failure on line 11 in tiktok/resty.go

View workflow job for this annotation

GitHub Actions / build (1.21.x)

undefined: fmt
}
return nil
}

func (o *tiktok) IsDebug() bool {
return o.debug
}

// Resty Methods

func (o *tiktok) restyPost(url string, body interface{}) (*resty.Response, error) {

Check failure on line 22 in tiktok/resty.go

View workflow job for this annotation

GitHub Actions / build (1.19.x)

undefined: resty

Check failure on line 22 in tiktok/resty.go

View workflow job for this annotation

GitHub Actions / build (1.20.x)

undefined: resty

Check failure on line 22 in tiktok/resty.go

View workflow job for this annotation

GitHub Actions / build (1.21.x)

undefined: resty
resp, err := o.restClient.R().
SetHeader("Accept", "application/json").
SetHeader("Content-Type", "application/json").
SetBody(body).
Post(url)

if err != nil {
return nil, err
}
return resp, nil
}

func (o *tiktok) restyGet(url string, queryParams map[string]string) (*resty.Response, error) {

Check failure on line 35 in tiktok/resty.go

View workflow job for this annotation

GitHub Actions / build (1.19.x)

undefined: resty

Check failure on line 35 in tiktok/resty.go

View workflow job for this annotation

GitHub Actions / build (1.20.x)

undefined: resty

Check failure on line 35 in tiktok/resty.go

View workflow job for this annotation

GitHub Actions / build (1.21.x)

undefined: resty
resp, err := o.restClient.R().
SetQueryParams(queryParams).
Get(url)
//
if err != nil {
return nil, err
}
return resp, nil
}
4 changes: 4 additions & 0 deletions tiktok/tiktok.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ package tiktok
import "github.com/go-resty/resty/v2"

type ITiktok interface {
//
HealthCheck() error
IsDebug() bool
//
}

type tiktok struct {
Expand Down

0 comments on commit 4e7865d

Please sign in to comment.