Commit 12af3bef authored by Jake LaFountain's avatar Jake LaFountain
Browse files

feat: allow passing in of URL array to allow other variables to be sent through.

Explicitly error out on empty status code to allow clients to better handle.
parent 79084b8c
......@@ -7,15 +7,14 @@ import (
"net/http"
)
func (c *Client) Discovered(URLs []string, URLType string, bypassSeencheck bool) (discoveredResponse *DiscoveredResponse, err error) {
func (c *Client) Discovered(URLs []URL, URLType string, bypassSeencheck bool) (discoveredResponse *DiscoveredResponse, err error) {
expectedStatusCode := 201
discoveredResponse = new(DiscoveredResponse)
// build payload
var URLsPayload []URL
for _, URLString := range URLs {
URLsPayload = append(URLsPayload, URL{Value: URLString})
}
URLsPayload = append(URLsPayload, URLs...)
payload := DiscoveredPayload{
Project: c.Project,
......
......@@ -2,6 +2,7 @@ package gocrawlhq
import (
"encoding/json"
"errors"
"fmt"
"net/http"
"strconv"
......@@ -9,6 +10,7 @@ import (
func (c *Client) Feed(size int) (feedResponse *FeedResponse, err error) {
expectedStatusCode := 200
emptyStatusCode := 204
feedResponse = new(FeedResponse)
// build request
......@@ -32,7 +34,12 @@ func (c *Client) Feed(size int) (feedResponse *FeedResponse, err error) {
}
defer resp.Body.Close()
// check response status code
// check response status code for 'empty' or 204
if resp.StatusCode == emptyStatusCode {
return feedResponse, errors.New("gocrawlhq: feed is empty")
}
// check response status code for 200
if resp.StatusCode != expectedStatusCode {
return feedResponse, fmt.Errorf("non-%d status code: %d", expectedStatusCode, resp.StatusCode)
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment