mirror of
https://github.com/FlipsideCrypto/go-data-bridge-client.git
synced 2026-02-06 10:48:12 +00:00
Merge pull request #7 from FlipsideCrypto/check-for-unread-count
remove consumer from config
This commit is contained in:
commit
7e2bc8c8ac
19
README.md
19
README.md
@ -7,13 +7,28 @@ https://data-bridge-docs.flipsidecrypto.com/#section/Introduction
|
||||
|
||||
### Initialization
|
||||
```
|
||||
config := Config{APIKey: "api-key", TopicSlug: "my-topic-slug", ConsumerID: "consumer-id"}
|
||||
config := Config{APIKey: "api-key", TopicSlug: "my-topic-slug"}
|
||||
client, err := NewClient(config)
|
||||
```
|
||||
|
||||
### Get Registered Consumers
|
||||
```
|
||||
consumers, err := client.GetRegisteredConsumers()
|
||||
```
|
||||
|
||||
### Get Available Consumers
|
||||
```
|
||||
consumers, err := client.GetAvailableConsumers()
|
||||
```
|
||||
|
||||
### Register Consumer
|
||||
```
|
||||
consumer, err := client.RegisterConsumer()
|
||||
```
|
||||
|
||||
### Get Next Record
|
||||
```
|
||||
record, err := client.GetNextRecord()
|
||||
record, err := client.GetNextRecord(consumerID)
|
||||
```
|
||||
|
||||
### Mark Record Completed
|
||||
|
||||
13
client.go
13
client.go
@ -2,17 +2,15 @@ package databridge
|
||||
|
||||
// Config allows a consuming app to set up API Key, Consumer ID, and Topic Slug
|
||||
type Config struct {
|
||||
APIKey string
|
||||
ConsumerID string
|
||||
TopicSlug string
|
||||
APIKey string
|
||||
TopicSlug string
|
||||
}
|
||||
|
||||
// Client allows access to the Databridge API
|
||||
type Client struct {
|
||||
BaseURL string
|
||||
APIKey string
|
||||
TopicSlug string
|
||||
ConsumerID string
|
||||
BaseURL string
|
||||
APIKey string
|
||||
TopicSlug string
|
||||
}
|
||||
|
||||
// NewClient returns a new Databridge Client
|
||||
@ -21,7 +19,6 @@ func NewClient(config Config) (Client, error) {
|
||||
c.APIKey = config.APIKey
|
||||
c.BaseURL = "https://data-bridge.flipsidecrypto.com/api/v1"
|
||||
c.TopicSlug = config.TopicSlug
|
||||
c.ConsumerID = config.ConsumerID
|
||||
|
||||
return c, nil
|
||||
}
|
||||
|
||||
@ -22,7 +22,7 @@ func TestClient_GetUnreadCount(t *testing.T) {
|
||||
|
||||
func TestClient_GetNextRecord(t *testing.T) {
|
||||
client := getClient(t)
|
||||
r, err := client.GetNextRecord()
|
||||
r, err := client.GetNextRecord("b053b974-608e-4f1b-9969-871a02cfbf92")
|
||||
if err != nil {
|
||||
t.Fatalf("Unexpected error: %v", err)
|
||||
}
|
||||
@ -69,7 +69,7 @@ func TestClient_RegisterConsumer(t *testing.T) {
|
||||
}
|
||||
|
||||
func getClient(t *testing.T) Client {
|
||||
config := Config{APIKey: "15d4fbbc-d12e-4b08-a4d6-b55b92200649", TopicSlug: "dev-alert-fcas-events", ConsumerID: "84d3cba6-8be8-4848-b759-59093f2e74e6"}
|
||||
config := Config{APIKey: "15d4fbbc-d12e-4b08-a4d6-b55b92200649", TopicSlug: "dev-alert-fcas-events"}
|
||||
client, err := NewClient(config)
|
||||
if err != nil {
|
||||
t.Fatalf("Unexpected error: %v", err)
|
||||
|
||||
@ -51,7 +51,7 @@ 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() (*json.RawMessage, error) {
|
||||
func (c Client) GetNextRecord(consumerID string) (*json.RawMessage, error) {
|
||||
count, err := c.GetUnreadCount()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -59,7 +59,7 @@ func (c Client) GetNextRecord() (*json.RawMessage, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
url := fmt.Sprintf("%s/topics/%s/records/next?consumer_id=%s&api_key=%s", c.BaseURL, c.TopicSlug, c.ConsumerID, c.APIKey)
|
||||
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")
|
||||
req.Header.Add("api_key", c.APIKey)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user