From c2511d845977acda09fd688c602fed8de204cd79 Mon Sep 17 00:00:00 2001 From: ilmari-h <52321471+ilmari-h@users.noreply.github.com> Date: Mon, 11 Nov 2024 09:37:43 +0100 Subject: [PATCH] Fix create comment function --- client.go | 12 ++++++------ comments.go | 3 +++ contents.go | 8 ++++---- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/client.go b/client.go index 83bdcd4..eb9e1e3 100644 --- a/client.go +++ b/client.go @@ -3,19 +3,19 @@ package tapestry type TapestryClient struct { tapestryApiBaseUrl string apiKey string - execution TapestryExecutionType + execution Execution blockchain string } -type TapestryExecutionType string +type Execution string const ( - FastUnconfirmed TapestryExecutionType = "FAST_UNCONFIRMED" - QuickSignature TapestryExecutionType = "QUICK_SIGNATURE" - ConfirmedParsed TapestryExecutionType = "CONFIRMED_AND_PARSED" + ExecutionFastUnconfirmed Execution = "FAST_UNCONFIRMED" + ExecutionQuickSignature Execution = "QUICK_SIGNATURE" + ExecutionConfirmedParsed Execution = "CONFIRMED_AND_PARSED" ) -func NewTapestryClient(apiKey string, tapestryApiBaseUrl string, execution TapestryExecutionType, blockchain string) TapestryClient { +func NewTapestryClient(apiKey string, tapestryApiBaseUrl string, execution Execution, blockchain string) TapestryClient { return TapestryClient{ tapestryApiBaseUrl: tapestryApiBaseUrl, apiKey: apiKey, diff --git a/comments.go b/comments.go index be4b48d..91e377a 100644 --- a/comments.go +++ b/comments.go @@ -81,6 +81,9 @@ type UpdateCommentResponse struct { func (c *TapestryClient) CreateComment(options CreateCommentOptions) (*CreateCommentResponse, error) { url := fmt.Sprintf("%s/comments?apiKey=%s", c.tapestryApiBaseUrl, c.apiKey) + if options.Properties == nil { + options.Properties = []CommentProperty{} + } req := CreateCommentRequest{ CreateCommentOptions: options, Execution: string(c.execution), diff --git a/contents.go b/contents.go index 0490b0c..b8b270c 100644 --- a/contents.go +++ b/contents.go @@ -12,7 +12,7 @@ type ContentProperty struct { Value string `json:"value"` } -type CreateContentRequest struct { +type FindOrCreateContentRequest struct { ProfileID string `json:"profileId"` ID string `json:"id,omitempty"` Properties []ContentProperty `json:"properties"` @@ -66,13 +66,13 @@ type SocialCounts struct { CommentCount int `json:"commentCount"` } -func (c *TapestryClient) FindOrCreateContent(profileId, id string, content []ContentProperty) (*CreateOrUpdateContentResponse, error) { +func (c *TapestryClient) FindOrCreateContent(profileId, id string, properties []ContentProperty) (*CreateOrUpdateContentResponse, error) { url := fmt.Sprintf("%s/contents/findOrCreate?apiKey=%s", c.tapestryApiBaseUrl, c.apiKey) - jsonBody, err := json.Marshal(CreateContentRequest{ + jsonBody, err := json.Marshal(FindOrCreateContentRequest{ ProfileID: profileId, ID: id, - Properties: content, + Properties: properties, }) if err != nil { return nil, fmt.Errorf("error marshaling request: %w", err)