# Class: StreamClient

## StreamClient

#### new StreamClient()

Client to connect to Stream api

Source:
  - lib/client.js, line 20

### Methods

#### addToMany(activity, feeds, callback) → {Promise}

Add one activity to many feeds

##### Parameters:

Name | Type | Description
--- | --- | ---
`activity` | object | The activity to add
`feeds` | Array | Array of objects describing the feeds to add to
`callback` | requestCallback | Callback called on completion

Since:
  - 2.3.0
Source:
  - lib/batch_operations.js, line 8

##### Returns:

Promise object

Type
  Promise

#### createRedirectUrl(targetUrl, userId, events) → {string}

Creates a redirect url for tracking the given events in the context of an email using Stream's analytics platform. Learn more at getstream.io/personalization

##### Parameters:

Name | Type | Description
--- | --- | ---
`targetUrl` | string | Target url
`userId` | string | User id to track
`events` | array | List of events to track

Source:
  - lib/client.js, line 506

##### Returns:

The redirect url

Type
  string

#### feed(feedSlug, userId, tokenopt, siteIdopt, optionsopt) → {StreamFeed}

Returns a feed object for the given feed id and token

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`feedSlug` | string |  | The feed slug
`userId` | string |  | The user identifier
`token` | string | <optional> | The token
`siteId` | string | <optional> | The site identifier

`options`

object

<optional>

Additional function options

###### Properties

Name | Type | Attributes | Description
--- | --- | --- | ---
`readOnly` | boolean | <optional> | A boolean indicating whether to generate a read only token for this feed

Source:
  - lib/client.js, line 232

##### Returns:

Type
  StreamFeed

##### Example

    client.feed('user', '1', 'token2');

#### followMany(follows, activityCopyLimitopt, callbackopt) → {Promise}

Follow multiple feeds with one API call

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`follows` | Array |  | The follow relations to create
`activityCopyLimit` | number | <optional> | How many activities should be copied from the target feed
`callback` | requestCallback | <optional> | Callback called on completion

Since:
  - 2.3.0
Source:
  - lib/batch_operations.js, line 28

##### Returns:

Promise object

Type
  Promise

#### getReadOnlyToken(feedSlug, userId) → {string}

Returns a token that allows only read operations

##### Parameters:

Name | Type | Description
--- | --- | ---
`feedSlug` | string | The feed slug to get a read only token for
`userId` | string | The user identifier

Source:
  - lib/client.js, line 202

##### Returns:

token

Type
  string

##### Example

    client.getReadOnlyToken('user', '1');

#### getReadOnlyToken(feedSlug, userId) → {string}

Returns a token that allows only read operations

##### Parameters:

Name | Type | Description
--- | --- | ---
`feedSlug` | string | The feed slug to get a read only token for
`userId` | string | The user identifier

Source:
  - lib/feed.js, line 288

##### Returns:

token

Type
  string

##### Example

    client.getReadOnlyToken('user', '1');

#### getReadWriteToken(feedSlug, userId) → {string}

Returns a token that allows read and write operations

##### Parameters:

Name | Type | Description
--- | --- | ---
`feedSlug` | string | The feed slug to get a read only token for
`userId` | string | The user identifier

Source:
  - lib/feed.js, line 304

##### Returns:

token

Type
  string

##### Example

    client.getReadWriteToken('user', '1');

#### getReadWriteToken(feedSlug, userId) → {string}

Returns a token that allows read and write operations

##### Parameters:

Name | Type | Description
--- | --- | ---
`feedSlug` | string | The feed slug to get a read only token for
`userId` | string | The user identifier

Source:
  - lib/client.js, line 217

##### Returns:

token

Type
  string

##### Example

    client.getReadWriteToken('user', '1');

#### intialize(apiKey, apiSecretopt, appIdopt, optionsopt)

Initialize a client

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`apiKey` | string |  | the api key
`apiSecret` | string | <optional> | the api secret
`appId` | string | <optional> | id of the app

`options`

object

<optional>

additional options

###### Properties

Name | Type | Attributes | Default | Description
--- | --- | --- | --- | ---
`location` | string | <optional> |  | which data center to use
`expireTokens` | boolean | <optional> | false | whether to use a JWT timestamp field (i.e. iat)

Source:
  - lib/client.js, line 32

##### Examples

initialize is not directly called by via stream.connect, ie:

    stream.connect(apiKey, apiSecret)

secret is optional and only used in server side mode

    stream.connect(apiKey, null, appId);

#### off(keyopt)

Remove one or more event handlers

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`key` | string | <optional> | Name of the handler

Source:
  - lib/client.js, line 102

##### Example

    client.off() removes all handlers
    client.off(name) removes the specified handler

#### on(event, callback)

Support for global event callbacks This is useful for generic error and loading handling

##### Parameters:

Name | Type | Description
--- | --- | ---
`event` | string | Name of the event
`callback` | function | Function that is called when the event fires

Source:
  - lib/client.js, line 87

##### Example

    client.on('request', callback);
    client.on('response', callback);

#### userAgent() → {string}

Get the current user agent

Source:
  - lib/client.js, line 189

##### Returns:

current user agent

Type
  string