Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions articles.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,11 +329,11 @@ func (s *ArticlesService) GetDraft(ctx context.Context, articleID string) (*Arti
if err != nil {
return nil, err
}
res, err := s.client.generated.RetrieveArticleDraftWithResponse(ctx, id, nil)
res, err := s.client.generated.RetrieveArticleDraft(ctx, id, nil)
if err != nil {
return nil, err
}
article, err := requireOK("get article draft", res.StatusCode(), res.Body, res.JSON200, responseHeaders(res.HTTPResponse))
article, err := requireHTTPJSON[gen.ArticleSchema]("get article draft", res)
return articleFromGenerated(article), err
}

Expand Down
39 changes: 23 additions & 16 deletions contacts.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,28 @@ func (s *ContactsService) ListMergeHistory(ctx context.Context, contactID string
if err != nil {
return nil, err
}
return requireOK("list contact merge history", res.StatusCode(), res.Body, res.JSON200, responseHeaders(res.HTTPResponse))
history, err := requireOK("list contact merge history", res.StatusCode(), res.Body, res.JSON200, responseHeaders(res.HTTPResponse))
if err == nil || !IsNotFound(err) {
return history, err
}

includeMergeHistory := true
contactResponse, fallbackErr := s.client.generated.ShowContactWithResponse(ctx, contactID, &gen.ShowContactParams{IncludeMergeHistory: &includeMergeHistory})
if fallbackErr != nil {
return nil, fallbackErr
}
contact, fallbackErr := requireOK("get contact merge history", contactResponse.StatusCode(), contactResponse.Body, contactResponse.JSON200, responseHeaders(contactResponse.HTTPResponse))
if fallbackErr != nil {
return nil, fallbackErr
}

historyType := gen.MergeHistoryListType("list")
hasMore := false
return &ContactMergeHistory{
Data: contact.MergeHistory,
HasMore: &hasMore,
Type: &historyType,
}, nil
}

// ContactSearchOperator is an Intercom contact search operator.
Expand Down Expand Up @@ -521,17 +542,12 @@ func (s *ContactsService) CreateNote(ctx context.Context, contactID string, body
return nil, fmt.Errorf("intercom: note body is required")
}

id, err := contactIDToInt(contactID)
if err != nil {
return nil, err
}

req := gen.CreateNoteJSONRequestBody{Body: body}
if adminID != "" {
req.AdminId = &adminID
}

res, err := s.client.generated.CreateNoteWithResponse(ctx, id, nil, req)
res, err := s.client.generated.CreateNoteWithResponse(ctx, contactID, nil, req)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -733,12 +749,3 @@ func marshalBody(v any) (*bytes.Reader, error) {
}
return bytes.NewReader(b), nil
}

// contactIDToInt converts a string contact ID to int as required by some generated endpoints.
func contactIDToInt(contactID string) (int, error) {
id, err := strconv.Atoi(contactID)
if err != nil {
return 0, fmt.Errorf("intercom: contact ID %q is not a valid integer: %w", contactID, err)
}
return id, nil
}
14 changes: 0 additions & 14 deletions contacts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -880,20 +880,6 @@ func TestContactsValidation(t *testing.T) {
return err
},
},
{
name: "create note: non-numeric contact ID",
call: func(ctx context.Context, client *Client) error {
_, err := client.Contacts.CreateNote(ctx, "not-an-int", "body", "")
return err
},
},
{
name: "create note: partial-numeric contact ID",
call: func(ctx context.Context, client *Client) error {
_, err := client.Contacts.CreateNote(ctx, "123abc", "body", "")
return err
},
},
{
name: "list segments: empty contact ID",
call: func(ctx context.Context, client *Client) error {
Expand Down
6 changes: 2 additions & 4 deletions conversations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import (
"net/http"
"testing"

openapi_types "github.com/oapi-codegen/runtime/types"

gen "github.com/uffejaeger/intercom-go/internal/generated/intercom"
)

Expand Down Expand Up @@ -75,9 +73,9 @@ func TestConversationsServiceRequests(t *testing.T) {
msg, err := client.Conversations.Create(ctx, ConversationCreate{
Body: "hello",
From: struct {
Id openapi_types.UUID `json:"id"`
Id string `json:"id"`
Type gen.CreateConversationRequestFromType `json:"type"`
}{Type: "user"},
}{Id: "536e564f316c83104c000020", Type: "user"},
})
if err != nil {
return err
Expand Down
5 changes: 1 addition & 4 deletions fuzz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func FuzzParseErrorResponse(f *testing.F) {
})
}

func FuzzIntegerIDConversionHelpers(f *testing.F) {
func FuzzConversationIDConversion(f *testing.F) {
f.Add("1")
f.Add("0")
f.Add("-1")
Expand All @@ -41,9 +41,6 @@ func FuzzIntegerIDConversionHelpers(f *testing.F) {
f.Fuzz(func(t *testing.T, id string) {
want, wantErr := strconv.Atoi(id)

contactID, contactErr := contactIDToInt(id)
assertFuzzIDConversion(t, "contactIDToInt", contactID, contactErr, want, wantErr)

conversationID, conversationErr := conversationIDToInt(id)
assertFuzzIDConversion(t, "conversationIDToInt", conversationID, conversationErr, want, wantErr)
})
Expand Down
28 changes: 14 additions & 14 deletions internal/generated/intercom/client.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading