getstream

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2017 License: LGPL-3.0 Imports: 16 Imported by: 0

README

stream-go

stream-go is a (beta) Go client for Stream.

You can sign up for a Stream account at https://getstream.io/get_started.

-Master Branch: Build Status

-Dev Branch: Build Status

godoc codecov

This library could not exist without the efforts of several open-source community members, including the awesome folks at MrHenry and HyperWorks. Thank you so much for contributing to our community!

The code provided by the MrHenry team is used with written permission; we are working with them to get a final license in place. Stream will be modifying the codebase together with MrHenry over time, so we especially want to point out how great they have been working with us to release this library.

Full documentation

Documentation for this Go client are available at the Stream website.

Example Usage

Creating a client:

import (
	"fmt"
	"github.com/GetStream/stream-go"
)

// we recommend getting your API credentials using os.Getenv()
client, err := getstream.New(&getstream.Config{
    APIKey:      os.Getenv("STREAM_API_KEY"),
    APISecret:   os.Getenv("STREAM_API_SECRET"),
    AppID:       os.Getenv("STREAM_APP_ID"),
    Location:    os.Getenv("STREAM_REGION"),
})
if err != nil {
    return err
}

// but you can define the variables in code as well, of course
APIKey string = "your-api-key"
APISecret string = "your-api-secret"

// your application ID, found on your GetStream.io dashboard
AppID string = "16013"

// Location is optional; leaving it blank will default the
// hostname to "api.getstream.io"
// but we do have geographic-specific choices:
// "us-east", "us-west" and "eu-west"
Location string = "us-east"

// TimeoutInt is an optional integer parameter to define
// the number of seconds before your connection will hang-up
// during a request; you can set this to any non-negative
// and non-zero whole number, and will default to 3
TimeoutInt: 3

client, err := getstream.New(&getstream.Config{
    APIKey:      APIKey,
    APISecret:   APISecret,
    AppID:       AppID,
    Location:    Location,
    TimeoutInt:  TimeoutInt,
})

Creating a Feed object for a user:

// this code assumes you've created a flat feed named "flat-feed-name" for your app
// and similarly-named feeds for aggregated feeds and notification feeds
// we also recommend using UUID values for users

bobFlatFeed, err := client.FlatFeed("flat-feed-name", "bob-uuid")
if err != nil {
    return err
}

bobAggregatedFeed, err := client.AggregatedFeed("aggregated-feed-name", "bob-uuid")
if err != nil {
    return err
}

bobNotificationFeed, err := client.NotificationFeed("notification-feed-name", "bob-uuid")
if err != nil {
    return err
}

Creating an activity on Bob's flat feed:

import "github.com/pborman/uuid"

activity, err := bobFeed.AddActivity(&Activity{
    Verb:      "post",
    ForeignID: uuid.New(),
    Object:    "flat:eric",
    Actor:     "flat:john",
})
if err != nil {
    return err
}

The library is gradually introducing JWT support. You can generate a client token for a feed using the following example:

// create a client using your API key and secret
client, err := getstream.New(&getstream.Config{
    APIKey:    os.Getenv("STREAM_API_KEY"),
    APISecret: os.Getenv("STREAM_API_SECRET"),
    AppID:     os.Getenv("STREAM_APP_ID"),
    Location:  os.Getenv("STREAM_REGION"),
})

// create a feed
feed, err := client.FlatFeed("flat-feed-name", "bob-uuid")
if err != nil {
    return err
}

// create a JWT token for the feed
token, err := client.Signer.GenerateFeedScopeToken(
    getstream.ScopeContextFeed,
    getstream.ScopeActionRead,
    bobFeed)
if err != nil {
    fmt.Println(err)
}

// create a new client using the token
// note in the struct below that we're not setting "APISecret"
// but setting "Token" instead:
bobFlatFeedJWTClient, err := getstream.NewWithToken(&getstream.Config{
    APIKey:    os.Getenv("STREAM_API_KEY"),
    Token:     token, // not setting APISecret
    AppID:     os.Getenv("STREAM_APP_ID"),
    Location:  os.Getenv("STREAM_REGION"),
})
if err != nil {
  return err
}

JWT support is not yet fully tested on the library, but we'd love to hear any feedback you have as you try it out.

API Support

Flat Feed

  • Add one or more Activities (AddActivity, AddActivities)
  • Remove Activity (RemoveActivity, RemoveActivityByForeignID)
  • Get a list of Activities on the Feed (Activities)
  • Follow another Feed (FollowFeedWithCopyLimit)
  • UnFollow another Feed (Unfollow, UnfollowAggregated, UnfollowNotification, UnfollowKeepingHistory)
  • Get Followers of this Feed (FollowersWithLimitAndSkip)
  • Get list of Feeds this Feed is Following (FollowingWithLimitAndSkip)
  • Follow Many Feeds (FollowManyFeeds)
  • Update one or more Activities (UpdateActivity, UpdateActivities)

Aggregated Feed

  • Add one or more Activities (AddActivity, AddActivities)
  • Remove Activity (RemoveActivity, RemoveActivityByForeignID)
  • Get a list of Activities on the Feed (Activities)
  • Follow another Feed (FollowFeedWithCopyLimit)
  • UnFollow another Feed (Unfollow, UnfollowKeepingHistory)
  • Get Followers of this Feed (FollowersWithLimitAndSkip)
  • Get list of Feeds this Feed is Following (FollowingWithLimitAndSkip)

Notification Feed

  • Add one or more Activities (AddActivity, AddActivities)
  • Remove Activity (RemoveActivity, RemoveActivityByForeignID)
  • Get a list of Activities on the Feed (Activities)
  • Follow another Feed (FollowFeedWithCopyLimit)
  • UnFollow another Feed (Unfollow, UnfollowKeepingHistory)
  • Get list of Feeds this Feed is Following (FollowingWithLimitAndSkip)
  • Mark Read (MarkActivitiesAsRead)
  • Mark Seen (MarkActivitiesAsSeenWithLimit)
  • Get Followers of this Feed (FollowersWithLimitAndSkip)
Activity Payload Structure

Payload building Follows our API standards for all request payloads

  • data : Statically typed payloads as json.RawMessage
  • metadata : Top-level key/value pairs

You can/should use data to send Go structures through the library. This will give you the benefit of Go's static type system. If you are unable to determine a type (or compatible type) for the contents of an Activity, you can use metadata which is a map[string]string; encoding this to JSON will move these values to the top-level, so any keys you define in your metadata which conflict with our standard top-level keys will be overwritten.

The benefit of this metadata structure is that these key/value pairs will be exposed to Stream's internals such as ranking.

Design Choices

Many design choices in the library were inherited from the team at MrHenry, with some choices to refactor some of the test code as its own getstream_test package. This choice meant exposing some attributes that perhaps should be left private, and we expect this re-refactoring will take place over time.

The MrHenry team noted this about the Flat / Aggregated / Notification Feed types:

  • they have separate structures and methods to prevent the impact of future Stream changes
  • if two types of feeds grow farther apart, incorporated future changes in this client should not breaking everything
Credits

Have we mentioned the team at MrHenry yet??

Credits from MrHenry that we wanted to pass along as well:

This pkg started out as a fork from HyperWorks and still borrows snippets (token & errors) from the original. We decided to make this a separate repo entirely because drastic changes were made to the interface and internal workings.

We received great support from Stream while creating this pkg for which we are very grateful, and we also want to thank them for creating Stream in the first place.

Documentation

Index

Constants

View Source
const VERSION = "v0.9.0"

Variables

View Source
var GETSTREAM_TRANSPORT = &http.Transport{
	MaxIdleConns:        5,
	MaxIdleConnsPerHost: 5,
	IdleConnTimeout:     60,
	DisableKeepAlives:   false,
}

Functions

func ConvertUUIDToWord

func ConvertUUIDToWord(uuid string) string

ConvertUUIDToWord replaces - with _ It is used by go-getstream to convert UUID to a string that matches the word regex You can use it to convert UUID's to match go-getstream internals.

func ValidateFeedID

func ValidateFeedID(feedID string) (string, error)

func ValidateFeedSlug

func ValidateFeedSlug(feedSlug string) (string, error)

func ValidateUserID

func ValidateUserID(userID string) (string, error)

Types

type Activity

type Activity struct {
	ID        string
	Actor     string
	Verb      string
	Object    string
	Target    string
	Origin    FeedID
	TimeStamp *time.Time

	ForeignID string
	Data      *json.RawMessage
	MetaData  map[string]string

	To []Feed
}

Activity is a getstream Activity Use it to post activities to Feeds It is also the response from Fetch and List Requests

func (Activity) MarshalJSON

func (a Activity) MarshalJSON() ([]byte, error)

MarshalJSON is the custom marshal function for Activities It will be used by json.Marshal()

func (*Activity) UnmarshalJSON

func (a *Activity) UnmarshalJSON(b []byte) (err error)

UnmarshalJSON is the custom unmarshal function for Activities It will be used by json.Unmarshal()

type AggregatedFeed

type AggregatedFeed struct {
	Client   *Client
	FeedSlug string
	UserID   string
	// contains filtered or unexported fields
}

AggregatedFeed is a getstream AggregatedFeed Use it to for CRUD on AggregatedFeed Groups

func (*AggregatedFeed) Activities

Activities returns a list of Activities for a NotificationFeedGroup

func (*AggregatedFeed) AddActivities

func (f *AggregatedFeed) AddActivities(activities []*Activity) ([]*Activity, error)

AddActivities is used to add multiple Activities to a NotificationFeed

func (*AggregatedFeed) AddActivity

func (f *AggregatedFeed) AddActivity(activity *Activity) (*Activity, error)

AddActivity is used to add an Activity to a AggregatedFeed

func (*AggregatedFeed) FeedID

func (f *AggregatedFeed) FeedID() FeedID

FeedID is the combo if the FeedSlug and UserID : "FeedSlug:UserID"

func (*AggregatedFeed) FeedIDWithoutColon

func (f *AggregatedFeed) FeedIDWithoutColon() string

func (*AggregatedFeed) FollowFeedWithCopyLimit

func (f *AggregatedFeed) FollowFeedWithCopyLimit(target *FlatFeed, copyLimit int) error

FollowFeedWithCopyLimit sets a Feed to follow another target Feed CopyLimit is the maximum number of Activities to Copy from History

func (*AggregatedFeed) FollowersWithLimitAndSkip

func (f *AggregatedFeed) FollowersWithLimitAndSkip(limit int, skip int) ([]*GeneralFeed, error)

FollowersWithLimitAndSkip returns a list of GeneralFeed following the current AggregatedFeed

func (*AggregatedFeed) FollowingWithLimitAndSkip

func (f *AggregatedFeed) FollowingWithLimitAndSkip(limit int, skip int) ([]*GeneralFeed, error)

FollowingWithLimitAndSkip returns a list of GeneralFeed followed by the current FlatFeed

func (*AggregatedFeed) GenerateToken

func (f *AggregatedFeed) GenerateToken(signer *Signer) string

GenerateToken returns a new Token for a Feed without setting it to the Feed

func (*AggregatedFeed) RemoveActivity

func (f *AggregatedFeed) RemoveActivity(input *Activity) error

RemoveActivity removes an Activity from a NotificationFeedGroup

func (*AggregatedFeed) RemoveActivityByForeignID

func (f *AggregatedFeed) RemoveActivityByForeignID(input *Activity) error

RemoveActivityByForeignID removes an Activity from a NotificationFeedGroup by ForeignID

func (*AggregatedFeed) SignFeed

func (f *AggregatedFeed) SignFeed(signer *Signer)

SignFeed sets the token on a Feed

func (*AggregatedFeed) Signature

func (f *AggregatedFeed) Signature() string

Signature is used to sign Requests : "FeedSlugUserID Token"

func (*AggregatedFeed) Token

func (f *AggregatedFeed) Token() string

Token returns the token of a Feed

func (*AggregatedFeed) Unfollow

func (f *AggregatedFeed) Unfollow(target *FlatFeed) error

Unfollow is used to Unfollow a target Feed

func (*AggregatedFeed) UnfollowKeepingHistory

func (f *AggregatedFeed) UnfollowKeepingHistory(target *FlatFeed) error

UnfollowKeepingHistory is used to Unfollow a target Feed while keeping the History this means that Activities already visibile will remain

type Client

type Client struct {
	HTTP    *http.Client
	BaseURL *url.URL // https://api.getstream.io/api/
	Config  *Config
	Signer  *Signer
}

Client is used to connect to getstream.io

func New

func New(cfg *Config) (*Client, error)

*

  • New returns a GetStream client. *
  • Params:
  • cfg, pointer to a Config structure which takes the API credentials, Location, etc
  • Returns:
  • Client struct

func (*Client) AbsoluteURL

func (c *Client) AbsoluteURL(path string) (*url.URL, error)

absoluteUrl create a url.URL instance and sets query params (bad!!!)

func (*Client) AddActivityToMany

func (c *Client) AddActivityToMany(activity Activity, feeds []string) error

func (*Client) AggregatedFeed

func (c *Client) AggregatedFeed(feedSlug string, userID string) (*AggregatedFeed, error)

AggregatedFeed returns a getstream feed Slug is the AggregatedFeed Group name id is the Specific AggregatedFeed inside a AggregatedFeed Group to get the feed for Bob you would pass something like "user" as slug and "bob" as the id

func (*Client) FlatFeed

func (c *Client) FlatFeed(feedSlug string, userID string) (*FlatFeed, error)

FlatFeed returns a getstream feed Slug is the FlatFeed Group name id is the Specific FlatFeed inside a FlatFeed Group to get the feed for Bob you would pass something like "user" as slug and "bob" as the id

func (*Client) NotificationFeed

func (c *Client) NotificationFeed(feedSlug string, userID string) (*NotificationFeed, error)

NotificationFeed returns a getstream feed Slug is the NotificationFeed Group name id is the Specific NotificationFeed inside a NotificationFeed Group to get the feed for Bob you would pass something like "user" as slug and "bob" as the id

func (*Client) PrepFollowAggregatedFeed

func (c *Client) PrepFollowAggregatedFeed(targetFeed *FlatFeed, sourceFeed *AggregatedFeed) *PostFlatFeedFollowingManyInput

func (*Client) PrepFollowFlatFeed

func (c *Client) PrepFollowFlatFeed(targetFeed *FlatFeed, sourceFeed *FlatFeed) *PostFlatFeedFollowingManyInput

* PrepFollowFlatFeed - prepares JSON needed for one feed to follow another

Params: targetFeed, FlatFeed which wants to follow another sourceFeed, FlatFeed which is to be followed

Returns: []byte, array of bytes of JSON suitable for API consumption

func (*Client) PrepFollowNotificationFeed

func (c *Client) PrepFollowNotificationFeed(targetFeed *FlatFeed, sourceFeed *NotificationFeed) *PostFlatFeedFollowingManyInput

type Config

type Config struct {
	APIKey          string
	APISecret       string
	AppID           string
	Location        string
	TimeoutInt      int64
	TimeoutDuration time.Duration
	Version         string
	Token           string
	BaseURL         *url.URL
}

Config structure for configuration data

func (*Config) SetAPIKey

func (c *Config) SetAPIKey(apiKey string) string

SetAPIKey sets the API key for your GetStream.io account You can find/generate this value on GetStream.io when visiting your application's page

func (*Config) SetAPISecret

func (c *Config) SetAPISecret(apiSecret string) string

SetAPISecret sets the API secret for your GetStream.io account You can find/generate this value on GetStream.io when visiting your application's page

func (*Config) SetAppID

func (c *Config) SetAppID(appID string) string

SetAppID sets the app id (aka site id) for your GetStream.io application current site_id/app_id values are integers, but parsing as a string will allow for greater flexibility in the future.

func (*Config) SetBaseURL

func (c *Config) SetBaseURL(baseURL *url.URL) *url.URL

SetBaseURL sets the core url of the GetStream API to use

func (*Config) SetLocation

func (c *Config) SetLocation(location string) string

SetLocation sets the region where your application runs Acceptable values are: "us-east"

func (*Config) SetTimeout

func (c *Config) SetTimeout(timeout int64) time.Duration

SetTimeout sets the timeout, in seconds, for request timers timeout param needs to be a time.Duration, ultimately, but we'll convert it here from an int64.

func (*Config) SetToken

func (c *Config) SetToken(token string) string

SetBaseURL sets the core url of the GetStream API to use

func (*Config) SetVersion

func (c *Config) SetVersion(version string) string

SetVersion sets the version of the GetStream API to use Currently, the only acceptable value is "v1.0"

type Error

type Error struct {
	Code       int `json:"code"`
	StatusCode int `json:"status_code"`

	Detail      string `json:"detail"`
	RawDuration string `json:"duration"`
	Exception   string `json:"exception"`
}

Error is a getstream error

func (*Error) Duration

func (e *Error) Duration() time.Duration

Duration is the time it took for the request to be handled

func (*Error) Error

func (e *Error) Error() string

type Feed

type Feed interface {
	Signature() string
	FeedID() FeedID
	FeedIDWithoutColon() string
	Token() string
	SignFeed(signer *Signer)
	GenerateToken(signer *Signer) string
}

Feed is the interface bundling all Feed Types It exposes methods needed for all Types

type FeedID

type FeedID string

FeedID is a typealias of string to create some value safety

func (FeedID) Value

func (f FeedID) Value() string

Value returns a String Representation of FeedID

type FlatFeed

type FlatFeed struct {
	Client   *Client
	FeedSlug string
	UserID   string
	// contains filtered or unexported fields
}

FlatFeed is a getstream FlatFeed Use it to for CRUD on FlatFeed Groups

func (*FlatFeed) Activities

func (f *FlatFeed) Activities(input *GetFlatFeedInput) (*GetFlatFeedOutput, error)

Activities returns a list of Activities for a FlatFeedGroup

func (*FlatFeed) AddActivities

func (f *FlatFeed) AddActivities(activities []*Activity) ([]*Activity, error)

AddActivities is used to add multiple Activities to a FlatFeed

func (*FlatFeed) AddActivity

func (f *FlatFeed) AddActivity(activity *Activity) (*Activity, error)

AddActivity is used to add an Activity to a FlatFeed

func (*FlatFeed) FeedID

func (f *FlatFeed) FeedID() FeedID

FeedID is the combo if the FeedSlug and UserID : "FeedSlug:UserID"

func (*FlatFeed) FeedIDWithoutColon

func (f *FlatFeed) FeedIDWithoutColon() string

func (*FlatFeed) FollowFeedWithCopyLimit

func (f *FlatFeed) FollowFeedWithCopyLimit(target *FlatFeed, copyLimit int) error

FollowFeedWithCopyLimit sets a Feed to follow another target Feed CopyLimit is the maximum number of Activities to Copy from History

func (*FlatFeed) FollowManyFeeds

func (f *FlatFeed) FollowManyFeeds(sourceFeeds []PostFlatFeedFollowingManyInput, copyLimit int) error
  • FollowFeedsWithCopyLimit sets a Feed to follow one or more other target Feeds This method only exists within FlatFeed because only flat feeds can follow other feeds

    Params: sourceFeeds, a list of feeds this feed can follow copyLimit, optional number of items to copy from history, defaults to 100

    Returns: error, if any

func (*FlatFeed) FollowersWithLimitAndSkip

func (f *FlatFeed) FollowersWithLimitAndSkip(limit int, skip int) ([]*GeneralFeed, error)

FollowersWithLimitAndSkip returns a list of GeneralFeed following the current FlatFeed

func (*FlatFeed) FollowingWithLimitAndSkip

func (f *FlatFeed) FollowingWithLimitAndSkip(limit int, skip int) ([]*GeneralFeed, error)

FollowingWithLimitAndSkip returns a list of GeneralFeed followed by the current FlatFeed TODO: need to support filters

func (*FlatFeed) GenerateToken

func (f *FlatFeed) GenerateToken(signer *Signer) string

GenerateToken returns a new Token for a Feed without setting it to the Feed

func (*FlatFeed) RemoveActivity

func (f *FlatFeed) RemoveActivity(input *Activity) error

RemoveActivity removes an Activity from a FlatFeedGroup

func (*FlatFeed) RemoveActivityByForeignID

func (f *FlatFeed) RemoveActivityByForeignID(input *Activity) error

RemoveActivityByForeignID removes an Activity from a FlatFeedGroup by ForeignID

func (*FlatFeed) SignFeed

func (f *FlatFeed) SignFeed(signer *Signer)

SignFeed sets the token on a Feed

func (*FlatFeed) Signature

func (f *FlatFeed) Signature() string

Signature is used to sign Requests : "FeedSlugUserID Token"

func (*FlatFeed) Token

func (f *FlatFeed) Token() string

Token returns the token of a Feed

func (*FlatFeed) Unfollow

func (f *FlatFeed) Unfollow(target *FlatFeed) error

Unfollow is used to Unfollow a target Feed

func (*FlatFeed) UnfollowKeepingHistory

func (f *FlatFeed) UnfollowKeepingHistory(target *FlatFeed) error

UnfollowKeepingHistory is used to Unfollow a target Feed while keeping the History this means that Activities already visibile will remain

func (*FlatFeed) UpdateActivities

func (f *FlatFeed) UpdateActivities(activities []*Activity) error

func (*FlatFeed) UpdateActivity

func (f *FlatFeed) UpdateActivity(activity *Activity) error

type GeneralFeed

type GeneralFeed struct {
	Client   *Client
	FeedSlug string
	UserID   string
	// contains filtered or unexported fields
}

GeneralFeed is a container for Feeds returned from request The specific Type will be unknown so no Actions are associated with a GeneralFeed

func (*GeneralFeed) FeedID

func (f *GeneralFeed) FeedID() FeedID

FeedID is the combo if the FeedSlug and UserID : "FeedSlug:UserID"

func (*GeneralFeed) FeedIDWithoutColon

func (f *GeneralFeed) FeedIDWithoutColon() string

func (*GeneralFeed) GenerateToken

func (f *GeneralFeed) GenerateToken(signer *Signer) string

GenerateToken returns a new Token for a Feed without setting it to the Feed

func (*GeneralFeed) SignFeed

func (f *GeneralFeed) SignFeed(signer *Signer)

SignFeed sets the token on a Feed

func (*GeneralFeed) Signature

func (f *GeneralFeed) Signature() string

Signature is used to sign Requests : "FeedSlugUserID Token"

func (*GeneralFeed) Token

func (f *GeneralFeed) Token() string

Token returns the token of a Feed

func (*GeneralFeed) Unfollow

func (f *GeneralFeed) Unfollow(client *Client, target *FlatFeed) error

Unfollow is used to Unfollow a target Feed

func (*GeneralFeed) UnfollowAggregated

func (f *GeneralFeed) UnfollowAggregated(client *Client, target *AggregatedFeed) error

UnfollowAggregated is used to Unfollow a target Aggregated Feed

func (*GeneralFeed) UnfollowNotification

func (f *GeneralFeed) UnfollowNotification(client *Client, target *NotificationFeed) error

UnfollowNotification is used to Unfollow a target Notification Feed

type GetAggregatedFeedInput

type GetAggregatedFeedInput struct {
	Limit  int `json:"limit,omitempty"`
	Offset int `json:"offset,omitempty"`

	IDGTE string `json:"id_gte,omitempty"`
	IDGT  string `json:"id_gt,omitempty"`
	IDLTE string `json:"id_lte,omitempty"`
	IDLT  string `json:"id_lt,omitempty"`

	Ranking string `json:"ranking,omitempty"`
}

GetAggregatedFeedInput is used to Get a list of Activities from a AggregatedFeed

type GetAggregatedFeedOutput

type GetAggregatedFeedOutput struct {
	Duration string
	Next     string
	Results  []*struct {
		Activities    []*Activity
		ActivityCount int
		ActorCount    int
		CreatedAt     string
		Group         string
		ID            string
		UpdatedAt     string
		Verb          string
	}
}

GetAggregatedFeedOutput is the response from a AggregatedFeed Activities Get Request

type GetFlatFeedInput

type GetFlatFeedInput struct {
	Limit  int
	Offset int

	IDGTE string
	IDGT  string
	IDLTE string
	IDLT  string

	Ranking string
}

GetFlatFeedInput is used to Get a list of Activities from a FlatFeed

func (*GetFlatFeedInput) Params added in v1.0.2

func (i *GetFlatFeedInput) Params() (params map[string]string)

type GetFlatFeedOutput

type GetFlatFeedOutput struct {
	Duration   string      `json:"duration"`
	Next       string      `json:"next"`
	Activities []*Activity `json:"results"`
}

GetFlatFeedOutput is the response from a FlatFeed Activities Get Request

type GetNotificationFeedInput

type GetNotificationFeedInput struct {
	Limit  int `json:"limit,omitempty"`
	Offset int `json:"offset,omitempty"`

	IDGTE string `json:"id_gte,omitempty"`
	IDGT  string `json:"id_gt,omitempty"`
	IDLTE string `json:"id_lte,omitempty"`
	IDLT  string `json:"id_lt,omitempty"`

	Ranking string `json:"ranking,omitempty"`
}

GetNotificationFeedInput is used to Get a list of Activities from a NotificationFeed

type GetNotificationFeedOutput

type GetNotificationFeedOutput struct {
	Duration string
	Next     string
	Results  []*struct {
		Activities    []*Activity
		ActivityCount int
		ActorCount    int
		CreatedAt     string
		Group         string
		ID            string
		IsRead        bool
		IsSeen        bool
		UpdatedAt     string
		Verb          string
	}
	Unread int
	Unseen int
}

GetNotificationFeedOutput is the response from a NotificationFeed Activities Get Request

type NotificationFeed

type NotificationFeed struct {
	Client   *Client
	FeedSlug string
	UserID   string
	// contains filtered or unexported fields
}

NotificationFeed is a getstream NotificationFeed Use it to for CRUD on NotificationFeed Groups

func (*NotificationFeed) Activities

Activities returns a list of Activities for a NotificationFeedGroup

func (*NotificationFeed) AddActivities

func (f *NotificationFeed) AddActivities(activities []*Activity) ([]*Activity, error)

AddActivities is used to add multiple Activities to a NotificationFeed

func (*NotificationFeed) AddActivity

func (f *NotificationFeed) AddActivity(activity *Activity) (*Activity, error)

AddActivity is used to add an Activity to a NotificationFeed

func (*NotificationFeed) FeedID

func (f *NotificationFeed) FeedID() FeedID

FeedID is the combo if the FeedSlug and UserID : "FeedSlug:UserID"

func (*NotificationFeed) FeedIDWithoutColon

func (f *NotificationFeed) FeedIDWithoutColon() string

func (*NotificationFeed) FollowFeedWithCopyLimit

func (f *NotificationFeed) FollowFeedWithCopyLimit(target *FlatFeed, copyLimit int) error

FollowFeedWithCopyLimit sets a Feed to follow another target Feed CopyLimit is the maximum number of Activities to Copy from History

func (*NotificationFeed) FollowersWithLimitAndSkip

func (f *NotificationFeed) FollowersWithLimitAndSkip(limit int, skip int) ([]*GeneralFeed, error)

FollowersWithLimitAndSkip returns a list of GeneralFeed following the current FlatFeed

func (*NotificationFeed) FollowingWithLimitAndSkip

func (f *NotificationFeed) FollowingWithLimitAndSkip(limit int, skip int) ([]*GeneralFeed, error)

FollowingWithLimitAndSkip returns a list of GeneralFeed followed by the current FlatFeed

func (*NotificationFeed) GenerateToken

func (f *NotificationFeed) GenerateToken(signer *Signer) string

GenerateToken returns a new Token for a Feed without setting it to the Feed

func (*NotificationFeed) MarkActivitiesAsRead

func (f *NotificationFeed) MarkActivitiesAsRead(activities []*Activity) error

MarkActivitiesAsRead marks activities as read for this feed

func (*NotificationFeed) MarkActivitiesAsSeenWithLimit

func (f *NotificationFeed) MarkActivitiesAsSeenWithLimit(limit int) error

MarkActivitiesAsSeenWithLimit marks activities as seen for this feed

func (*NotificationFeed) RemoveActivity

func (f *NotificationFeed) RemoveActivity(input *Activity) error

RemoveActivity removes an Activity from a NotificationFeedGroup

func (*NotificationFeed) RemoveActivityByForeignID

func (f *NotificationFeed) RemoveActivityByForeignID(input *Activity) error

RemoveActivityByForeignID removes an Activity from a NotificationFeedGroup by ForeignID

func (*NotificationFeed) SignFeed

func (f *NotificationFeed) SignFeed(signer *Signer)

SignFeed sets the token on a Feed

func (*NotificationFeed) Signature

func (f *NotificationFeed) Signature() string

Signature is used to sign Requests : "FeedSlugUserID Token"

func (*NotificationFeed) Token

func (f *NotificationFeed) Token() string

Token returns the token of a Feed

func (*NotificationFeed) Unfollow

func (f *NotificationFeed) Unfollow(target *FlatFeed) error

Unfollow is used to Unfollow a target Feed

func (*NotificationFeed) UnfollowKeepingHistory

func (f *NotificationFeed) UnfollowKeepingHistory(target *FlatFeed) error

UnfollowKeepingHistory is used to Unfollow a target Feed while keeping the History this means that Activities already visibile will remain

type PostActivityToManyInput

type PostActivityToManyInput struct {
	Activity Activity `json:"activity"`
	FeedIDs  []string `json:"feeds"`
}

type PostFlatFeedFollowingManyInput

type PostFlatFeedFollowingManyInput struct {
	Source string `json:"source"`
	Target string `json:"target"`
}

type ScopeAction

type ScopeAction uint32

ScopeAction defines the Actions allowed by a scope token

const (
	// ScopeActionRead : GET, OPTIONS, HEAD
	ScopeActionRead ScopeAction = 1
	// ScopeActionWrite : POST, PUT, PATCH
	ScopeActionWrite ScopeAction = 2
	// ScopeActionDelete : DELETE
	ScopeActionDelete ScopeAction = 4
	// ScopeActionAll : The JWT has permission to all HTTP verbs
	ScopeActionAll ScopeAction = 8
)

func (ScopeAction) Value

func (a ScopeAction) Value() string

Value returns a string representation

type ScopeContext

type ScopeContext uint32

ScopeContext defines the resources accessible by a scope token

const (
	// ScopeContextActivities :  Activities Endpoint
	ScopeContextActivities ScopeContext = 1
	// ScopeContextFeed : Feed Endpoint
	ScopeContextFeed ScopeContext = 2
	// ScopeContextFollower : Following + Followers Endpoint
	ScopeContextFollower ScopeContext = 4
	// ScopeContextAll : Allow access to any resource
	ScopeContextAll ScopeContext = 8
)

func (ScopeContext) Value

func (a ScopeContext) Value() string

Value returns a string representation

type Signer

type Signer struct {
	Secret string
}

Signer is responsible for generating Tokens

func (Signer) GenerateFeedScopeToken

func (s Signer) GenerateFeedScopeToken(context ScopeContext, action ScopeAction, feedIDWithoutColon string) (string, error)

GenerateFeedScopeToken returns a jwt

func (Signer) GenerateToken

func (s Signer) GenerateToken(message string) string

generateToken will use the Secret of the signer and the message passed as an argument to generate a Token

func (Signer) GenerateUserScopeToken

func (s Signer) GenerateUserScopeToken(context ScopeContext, action ScopeAction, userID string) (string, error)

GenerateUserScopeToken returns a jwt

func (Signer) SignFeed

func (s Signer) SignFeed(feedID string) string

SignFeed sets the token on a Feed

func (Signer) UrlSafe

func (s Signer) UrlSafe(src string) string

Jump to

Keyboard shortcuts

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