mirror of
https://github.com/FlipsideCrypto/go-data-bridge-client.git
synced 2026-02-06 10:48:12 +00:00
Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7a8513e754 | ||
|
|
cd9c4b3233 | ||
|
|
53c24ea952 |
@ -4,6 +4,7 @@ package databridge
|
||||
type Config struct {
|
||||
APIKey string
|
||||
TopicSlug string
|
||||
BaseURL string
|
||||
}
|
||||
|
||||
// Client allows access to the Databridge API
|
||||
@ -17,7 +18,11 @@ type Client struct {
|
||||
func NewClient(config Config) (Client, error) {
|
||||
c := Client{}
|
||||
c.APIKey = config.APIKey
|
||||
c.BaseURL = "https://data-bridge.flipsidecrypto.com/api/v1"
|
||||
if config.BaseURL != "" {
|
||||
c.BaseURL = config.BaseURL
|
||||
} else {
|
||||
c.BaseURL = "https://data-bridge.flipsidecrypto.com/api/v1"
|
||||
}
|
||||
c.TopicSlug = config.TopicSlug
|
||||
|
||||
return c, nil
|
||||
|
||||
12
record.go
12
record.go
@ -58,13 +58,6 @@ func (c Client) GetUnreadCount() (*int32, error) {
|
||||
|
||||
// GetNextRecord returns the topic's next record. Will return nil without an error when there are no more records.
|
||||
func (c Client) GetNextRecord(consumerID string) (*Record, error) {
|
||||
count, err := c.GetUnreadCount()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else if *count == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
url := fmt.Sprintf("%s/topics/%s/records/next?consumer_id=%s&api_key=%s", c.BaseURL, c.TopicSlug, consumerID, c.APIKey)
|
||||
req, _ := http.NewRequest("GET", url, nil)
|
||||
req.Header.Add("content-type", "application/json")
|
||||
@ -75,6 +68,11 @@ func (c Client) GetNextRecord(consumerID string) (*Record, error) {
|
||||
return nil, errors.Wrap(err, fmt.Sprintf("error making databridge http request for %s", url))
|
||||
}
|
||||
|
||||
// capture 404 and return nils
|
||||
if res.StatusCode == 404 {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
if res.StatusCode != 200 {
|
||||
return nil, errors.New(fmt.Sprintf("databridge responded with non-200 for %s", url))
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user