getstream

package
v1.0.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 3, 2023 License: MIT Imports: 15 Imported by: 0

README

Feeds Library

This is a Go wrapper for the GetStream API. The GetStream API is a service for building scalable newsfeeds and activity streams. The wrapper is designed to make it easy for Go developers to interact with the GetStream API by providing a simple and easy-to-use interface.

Installation

To use this wrapper, you need to have Go installed on your machine. You can install Go by following the instructions on the official website.

Once you have Go installed, you can install the GetStream wrapper by running the following command:

go get github.com/SimifiniiCTO/simfiny-core-lib/third-party/getstream

Usage

To use the GetStream wrapper, you need to first create a new client by providing your API credentials. You can then use this client to interact with the GetStream API by calling various methods.

Here's an example of how to create a new client:

import (
    "github.com/SimifiniiCTO/simfiny-core-lib/third-party/getstream"
)

func main() {
    opts := []getstream.Options{
        getstream.WithLogger(zap.L()),
        getstream.WithKey("key"),
        getstream.WithSecret("secret"),
        getstream.WithInstrumentationClient(&instrumentation.Client{})
    }
    client, err := getstream.New(opts...)
    if err != nil {
        // handle error
    }
}

You can then use the client to interact with the GetStream API. Here are some examples of what you can do:

Creating a new activity

feedId := "feed-id"
ctx := context.Background()
actor := stream.NewUser("user:1")
object := stream.NewObject("product:1")
verb := "purchased"

activity := stream.NewActivity(actor, verb, object)
if _, err := client.CreateActivity(ctx, feedId, activity); err != nil {
    // handle error
}

Fetching Activities

feedId := "feed-id"
ctx := context.Background()
if activities, err := client.GetTimeline(ctx, feedId); err != nil {
    // handle error
} else {
    // do something with activities
}

Follow Activities

source := "feed-id-source"
target := "feed-id-target"
ctx := context.Background()
if err := client.FollowFeed(ctx, source, target); err != nil {
    ...
}

Testing

To test the GetStream wrapper, you can use the built-in testing framework in Go. The tests are located in the *_test.go files in the repository.

To run the tests, simply run the following command:

go test -v ./...

This will run all the tests in the repository and print out the results.

Contributions

Contributions to the GetStream wrapper are welcome! If you find a bug or have an idea for a new feature, feel free to open an issue or submit a pull request.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidKeyOrSecret           = errors.New("invalid key or secret")
	ErrInvalidInstrumentationClient = errors.New("invalid instrumentation client")
	ErrInvalidLogger                = errors.New("invalid logger")
)

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

This is defining a struct type called `Client` which will be used to create instances of the GetStream client. The struct contains fields for the GetStream API key, secret, a pointer to a `stream.Client` instance, a logger, and an instrumentation client.

func New

func New(opts ...Option) (*Client, error)

The function creates a new client with optional configuration options.

func (*Client) AddActivity

func (f *Client) AddActivity(ctx context.Context, feedID *string, activity *stream.Activity) error

This is a method of the `Client` struct that adds an activity to a feed specified by `feedID`. It takes in a `context.Context` object, a pointer to a string `feedID`, and a pointer to a `stream.Activity` object. It returns an error if there is an issue with the input arguments or if there is an error adding the activity to the feed. The method first checks if the input arguments are valid, gets the flat feed from the feed ID, adds the activity to the feed, and logs the creation of the activity.

func (*Client) AddActivityToManyFeeds

func (f *Client) AddActivityToManyFeeds(ctx context.Context, activity *stream.Activity, feeds ...stream.Feed) error

`func (f *Client) AddActivityToManyFeeds(ctx context.Context, activity *stream.Activity, feeds ...stream.Feed) error` is a method of the `Client` struct that adds an activity to multiple feeds specified by `feeds`. It takes in a `context.Context` object, a pointer to a `stream.Activity` object, and a variadic argument of type `stream.Feed`. It returns an error if there is an issue with the input arguments or if there is an error adding the activity to the feeds. The method first checks if the input arguments are valid, and then adds the activity to all the specified feeds using the `AddToMany` method of the `stream.Client` object.

func (*Client) ApplyOptions

func (c *Client) ApplyOptions(opts ...Option)

The function ApplyOptions takes a variadic number of Options and applies them to the Client.

func (*Client) CreateAggregateFeed

func (c *Client) CreateAggregateFeed(feedType FeedType, feedSlug string) (*stream.AggregatedFeed, error)

`func (c *Client) CreateAggregateFeed(feedType, feedSlug string) (*stream.AggregatedFeed, error)` is a method of the `Client` struct that creates a new `AggregatedFeed` object in the GetStream API based on the given feed type and feed slug. It takes the feed type and feed slug as input arguments and returns a pointer to the newly created `AggregatedFeed` object and any error that occurred during the API call. The method first checks if the input arguments are valid, and then calls the `AggregatedFeed` method of the `stream.Client` instance stored in the `Client` struct, passing in the feed type and feed slug as arguments.

func (*Client) CreateFlatFeed

func (c *Client) CreateFlatFeed(feedType FeedType, feedSlug string) (*stream.FlatFeed, error)

`func (c *Client) CreateFlatFeed(feedType, feedSlug string) (*stream.FlatFeed, error)` is a method of the `Client` struct that creates a new `FlatFeed` object in the GetStream API based on the given feed type and feed slug. It takes the feed type and feed slug as input arguments and returns a pointer to the newly created `FlatFeed` object and any error that occurred during the API call. The method first checks if the input arguments are valid, and then calls the `FlatFeed` method of the `stream.Client` instance stored in the `Client` struct, passing in the feed type and feed slug as arguments.

func (*Client) CreateNotificationFeed

func (c *Client) CreateNotificationFeed(feedType FeedType, feedSlug string) (*stream.NotificationFeed, error)

`func (c *Client) CreateNotificationFeed(feedType, feedSlug string) (*stream.NotificationFeed, error)` is a method of the `Client` struct that creates a new `NotificationFeed` object in the GetStream API based on the given feed type and feed slug. It takes the feed type and feed slug as input arguments and returns a pointer to the newly created `NotificationFeed` object and any error that occurred during the API call. The method first checks if the input arguments are valid, and then calls the `NotificationFeed` method of the `stream.Client` instance stored in the `Client` struct, passing in the feed type and feed slug as arguments.

func (*Client) DeleteActivity

func (f *Client) DeleteActivity(ctx context.Context, feedID *string, activityForeignID *string) error

The `DeleteActivity` function is a method of the `Client` struct that deletes an activity from a feed specified by `feedID` and `activityForeignID`. It takes in a `context.Context` object, a pointer to a string `feedID`, and a pointer to a string `activityForeignID`. It returns an error if there is an issue with the input arguments or if there is an error deleting the activity from the feed. The method first checks if the input arguments are valid, gets the flat feed from the feed ID, removes the activity from the feed using the foreign ID, and logs the removal of the activity.

func (*Client) FollowFeed

func (f *Client) FollowFeed(ctx context.Context, sourceFeedID, targetFeedID string, opts []stream.FollowFeedOption) error

This is a method defined on a struct type `Client`. The method is called `FollowFeed` and it takes in four arguments: a context, two strings `sourceFeedID` and `targetFeedID`, and a slice of `stream.FollowFeedOption` options. The method returns an error.

func (*Client) GetFlatFeedFromFeedID

func (f *Client) GetFlatFeedFromFeedID(feedID *string) (*stream.FlatFeed, error)

`func (f *Client) GetFlatFeedFromFeedID(feedID *string) (*stream.FlatFeed, error)` is a method of the `Client` struct that takes a pointer to a string as input and returns a pointer to a `stream.FlatFeed` object and an error. It is used to retrieve a `FlatFeed` object from the GetStream API based on a given feed ID. The method first validates the feed ID using the `validateFeedID` method, and then splits the feed ID into its constituent parts (feed type and feed slug) using the `strings.Split` function. Finally, it calls the `FlatFeed` method of the `stream.Client` instance stored in the `Client` struct, passing in the feed type and feed slug as arguments, and returns the resulting `FlatFeed` object and any error that occurred during the API call.

func (*Client) GetNotificationFeedFromFeedID

func (f *Client) GetNotificationFeedFromFeedID(feedID *string) (*stream.NotificationFeed, error)

`func (f *Client) GetNotificationFeedFromFeedID(feedID *string) (*stream.NotificationFeed, error)` is a method of the `Client` struct that takes a pointer to a string as input and returns a pointer to a `stream.NotificationFeed` object and an error. It is used to retrieve a `NotificationFeed` object from the GetStream API based on a given feed ID. The method first validates the feed ID using the `validateFeedID` method, and then splits the feed ID into its constituent parts (feed type and feed slug) using the `strings.Split` function. Finally, it calls the `NotificationFeed` method of the `stream.Client` instance stored in the `Client` struct, passing in the feed type and feed slug as arguments, and returns the resulting `NotificationFeed` object and any error that occurred during the API call.

func (*Client) GetNotificationTimeline

func (f *Client) GetNotificationTimeline(ctx context.Context, feedID *string) ([]stream.NotificationFeedResult, error)

`func (f *Client) GetNotificationTimeline(ctx context.Context, feedID *string) ([]stream.NotificationFeedResult, error)` is a method defined on the `Client` struct that retrieves a timeline of notification activities from a notification feed identified by the `feedID` parameter. It returns a slice of `stream.NotificationFeedResult` objects and an error if there was a problem retrieving the activities. The method takes a `context.Context` object as the first parameter to allow for cancellation or timeout of the request.

func (*Client) GetTimeline

func (f *Client) GetTimeline(ctx context.Context, feedID *string) ([]stream.Activity, error)

This is a method defined on the `Client` struct that retrieves a timeline of activities from a flat feed identified by the `feedID` parameter. It returns a slice of `stream.Activity` objects and an error if there was a problem retrieving the activities. The method takes a `context.Context` object as the first parameter to allow for cancellation or timeout of the request.

func (*Client) SendFollowRequestNotification

func (f *Client) SendFollowRequestNotification(ctx context.Context, notificationFeedID string, params *FollowRequestActivity) error

This is a method defined on a struct type `Client`. The method is named `SendFollowRequestNotification` and it takes three parameters: a context object `ctx`, a string `notificationFeedID`, and a pointer to a `FollowRequestActivity` struct `params`. The method returns an error.

func (*Client) Validate

func (c *Client) Validate() error

The function WithClient takes a pointer to a stream.Client and returns an Option.

type FeedType

type FeedType string
const (
	PersonalFeed     FeedType = "personal"
	TimelineFeed     FeedType = "timeline"
	NotificationFeed FeedType = "notification"
)

func (FeedType) String

func (f FeedType) String() string

type FollowRequestActivity

type FollowRequestActivity struct {
	SourceActor           string
	ActionName            string
	FollowRequestRecordID string
	Time                  time.Time
	ActivityForeignID     string
}

type Option

type Option func(*Client)

func WithInstrumentationClient

func WithInstrumentationClient(instrumentationClient *instrumentation.Client) Option

The function WithInstrumentationClient takes a pointer to a instrumentation.Client and returns an Option.

func WithKey

func WithKey(key string) Option

The function WithKey takes a string and returns an Option.

func WithLogger

func WithLogger(logger *zap.Logger) Option

The function WithLogger takes a pointer to a zap.Logger and returns an Option.

func WithSecret

func WithSecret(secret string) Option

The function WithSecret takes a string and returns an Option.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL