summaryrefslogtreecommitdiffstats
path: root/internal/client/breachforum.go
blob: 66fa1feded8bbef8bcd54f8b7bf66f4d4aa94699 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package client

import (
	"encoding/json"
	"fmt"
	"git.db.org.ai/dborg/internal/models"
	"net/url"
)

func (c *Client) SearchBreachForum(params *models.BreachForumSearchParams) (*models.BreachForumSearchResponse, error) {
	path := "/breachforum/search"

	queryParams := url.Values{}
	queryParams.Add("search", params.Search)
	if params.MaxHits > 0 {
		queryParams.Add("max_hits", fmt.Sprintf("%d", params.MaxHits))
	}

	data, err := c.Get(path, queryParams)
	if err != nil {
		return nil, err
	}

	var response models.BreachForumSearchResponse
	if err := json.Unmarshal(data, &response); err != nil {
		return nil, fmt.Errorf("failed to parse BreachForum search response: %w", err)
	}

	return &response, nil
}