Skip to content

Commit 2ab3373

Browse files
authored
Merge pull request #51 from GetStream/stream-feed-v0.1.2
v0.1.2
2 parents e5c7675 + bc620c6 commit 2ab3373

File tree

8 files changed

+246
-29
lines changed

8 files changed

+246
-29
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<a href="https://github.com/invertase/melos"><img alt="melos" src="https://img.shields.io/badge/maintained%20with-melos-f700ff.svg?style=flat-square"></a>
1010
</p>
1111
<p align="center">
12-
<img src="./images/flutter_feeds_alpha.png" alt="Stream Feed Activity Feed cover image" />
12+
<img src="./images/flutter_feeds_beta_1.png" alt="Stream Feed Activity Feed cover image" />
1313
</p>
1414

1515
**🔗 Quick Links**
@@ -28,7 +28,7 @@ dependencies:
2828
flutter:
2929
sdk: flutter
3030

31-
stream_feed: ^0.0.1
31+
stream_feed: ^[latest-version]
3232
```
3333
#### Using with Flutter
3434

images/flutter_feeds_beta_1.png

394 KB
Loading

packages/stream_feed/.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,4 @@ build/
7070
!**/ios/**/default.mode2v3
7171
!**/ios/**/default.pbxuser
7272
!**/ios/**/default.perspectivev3
73-
!/packages/flutter_tools/test/data/dart_dependencies_test/**/.packages
73+
!/packages/flutter_tools/test/data/dart_dependencies_test/**/.packages

packages/stream_feed/CHANGELOG.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1-
## 0.0.1 TODO: Add release date.
1+
## 0.1.2: 07/05/2021
2+
3+
- update dependencies
4+
5+
## 0.1.1: 07/05/2021
26

37
- first beta version

packages/stream_feed/README.md

+224-14
Original file line numberDiff line numberDiff line change
@@ -5,36 +5,246 @@
55

66
**🔗 Quick Links**
77

8-
- [Register](https://getstream.io/activity-feeds/trial/) to get an API key for Stream Activity Feeds
8+
- [Register](https://getstream.io/activity-feed/sdk/flutter/tutorial/) to get an API key for Stream Activity Feeds
99
- [Stream Activity Feeds UI Kit](https://getstream.io/activity-feeds/ui-kit/)
1010

11-
### Changelog
11+
## 🛠 Installation
1212

13-
Check out the [changelog on pub.dev](https://pub.dev/packages/stream_feed/changelog) to see the latest changes in the package.
13+
#### Install from pub <a href="https://pub.dartlang.org/packages/stream_feed"><img alt="Pub" src="https://img.shields.io/pub/v/stream_feed.svg"></a>
1414

15-
## Getting started
16-
17-
### Add dependency
18-
Add this to your package's pubspec.yaml file, use the latest version [![Pub](https://img.shields.io/pub/v/stream_feed.svg)](https://pub.dartlang.org/packages/stream_feed)
15+
Next step is to add `stream_feed` to your dependencies, to do that just open pubspec.yaml and add it inside the dependencies section.
1916

2017
```yaml
2118
dependencies:
22-
stream_feed: ^latest-version
19+
flutter:
20+
sdk: flutter
21+
22+
stream_feed: ^[latest-version]
2323
```
24+
#### Using with Flutter
2425
25-
You should then run `flutter packages get`
26+
This package can be integrated into Flutter applications. Remember to not expose the App Secret in your Flutter web apps, mobile apps, or other non-trusted environments like desktop apps.
2627
27-
## 🔮 Example Project
28+
## 🔌 Usage
29+
30+
### API client setup Serverside + Clientside
31+
32+
If you want to use the API client directly on your web/mobile app you need to generate a user token server-side and pass it.
33+
34+
#### Server-side token generation
35+
36+
```dart
37+
38+
// Instantiate a new client (server side)
39+
const apiKey = 'my-API-key';
40+
const secret = 'my-API-secret';
2841

29-
There is a detailed Flutter example project in the `example` folder. You can directly run and play on it.
42+
// Instantiate a new client (server side)
43+
var client = StreamFeedClient.connect(apiKey, secret: secret);
3044

31-
## 🛠 Setup API Client
45+
// Optionally supply the app identifier and an options object specifying the data center to use and timeout for requests (15s)
46+
client = StreamFeedClient.connect(apiKey,
47+
secret: secret,
48+
appId: 'yourappid',
49+
options: StreamHttpClientOptions(
50+
location: Location.usEast, connectTimeout: Duration(seconds: 15)));
51+
52+
// Create a token for user with id "the-user-id"
53+
final userToken = client.frontendToken('the-user-id');
54+
```
3255

33-
First you need to instantiate a feed client. The Feed client will manage API calls. You should only create the client once and re-use it across your application.
56+
> :warning: for security, you must never expose your API secret or generated client side token, and it's highly recommended to use `exp` claim in client side token.
57+
58+
59+
#### Client API init
3460

3561
```dart
36-
final client = StreamFeedClient.connect("stream-feed-api-key",token:userToken);
62+
// Instantiate new client with a user token
63+
var client = StreamFeedClient.connect(apiKey, token: Token('userToken'));
3764
```
65+
66+
### 🔮 Examples
67+
68+
```dart
69+
// Instantiate a feed object server side
70+
var user1 = client.flatFeed('user', '1');
71+
72+
// Get activities from 5 to 10 (slow pagination)
73+
final activities = await user1.getActivities(limit: 5, offset: 5);
74+
// Filter on an id less than a given UUID
75+
final filtered_activities = await user1.getActivities(
76+
limit: 5,
77+
filter: Filter().idLessThan('e561de8f-00f1-11e4-b400-0cc47a024be0')
78+
79+
// All API calls are performed asynchronous and return a Promise object
80+
await user1
81+
.getActivities(
82+
limit: 5,
83+
filter: Filter().idLessThan('e561de8f-00f1-11e4-b400-0cc47a024be0'))
84+
.then((value) => /* on success */
85+
print(value))
86+
.onError((error,
87+
stackTrace) => /* on failure, reason.error contains an explanation */
88+
print(error));
89+
90+
// Create a new activity
91+
final activity = Activity( actor: '1', verb: 'tweet', object: '1', foreignId: 'tweet:1' );
92+
final added_activity = await user1.addActivity(activity);
93+
// Create a bit more complex activity
94+
final complex_activity = Activity(
95+
actor: '1',
96+
verb: 'run',
97+
object: '1',
98+
foreignId: 'run:1',
99+
extraData: {
100+
'course': {'name': 'Golden Gate park', 'distance': 10},
101+
'participants': ['Thierry', 'Tommaso'],
102+
'started_at': DateTime.now().toIso8601String(),
103+
},
104+
);
105+
final added_complex_activity = await user1.addActivity(complex_activity);
106+
107+
// Remove an activity by its id
108+
await user1.removeActivityById('e561de8f-00f1-11e4-b400-0cc47a024be0');
109+
// or remove by the foreign id
110+
await user1.removeActivityByForeignId('tweet:1');
111+
112+
// mark a notification feed as read
113+
await notification1.getActivities(
114+
marker: ActivityMarker().allRead(),
115+
);
116+
117+
118+
// mark a notification feed as seen
119+
await notification1.getActivities(
120+
marker: ActivityMarker().allSeen(),
121+
);
122+
123+
// Follow another feed
124+
await user1.follow(client.flatFeed('flat', '42'));
125+
126+
// Stop following another feed
127+
await user1.unfollow(client.flatFeed('flat', '42'));
128+
129+
// Stop following another feed while keeping previously published activities
130+
// from that feed
131+
await user1.unfollow(client.flatFeed('flat', '42'), keepHistory: true);
132+
133+
// Follow another feed without copying the history
134+
await user1.follow(client.flatFeed('flat', '42'), activityCopyLimit: 0);
135+
136+
// List followers, following
137+
await user1.getFollowers(limit: 10, offset: 10);
138+
await user1.getFollowed(limit: 10, offset: 0);
139+
140+
141+
await user1.follow(client.flatFeed('flat', '42'));
142+
143+
// adding multiple activities
144+
const activities = [
145+
Activity(actor: '1', verb: 'tweet', object: '1'),
146+
Activity(actor: '2', verb: 'tweet', object: '3'),
147+
];
148+
await user1.addActivities(activities);
149+
150+
// specifying additional feeds to push the activity to using the to param
151+
// especially useful for notification style feeds
152+
final to = FeedId.fromIds(['user:2', 'user:3']);
153+
final activityTo = Activity(
154+
to: to,
155+
actor: '1',
156+
verb: 'tweet',
157+
object: '1',
158+
foreignId: 'tweet:1',
159+
);
160+
await user1.addActivity(activityTo);
161+
162+
163+
// adding one activity to multiple feeds
164+
final feeds = FeedId.fromIds(['flat:1', 'flat:2', 'flat:3', 'flat:4']);
165+
final activityTarget = Activity(
166+
actor: 'User:2',
167+
verb: 'pin',
168+
object: 'Place:42',
169+
target: 'Board:1',
170+
);
171+
172+
// ⚠️ server-side only!
173+
await client.batch.addToMany(activityTarget, feeds!);
174+
175+
// Batch create follow relations (let flat:1 follow user:1, user:2 and user:3 feeds in one single request)
176+
const follows = [
177+
Follow('flat:1', 'user:1'),
178+
Follow('flat:1', 'user:2'),
179+
Follow('flat:1', 'user:3'),
180+
];
181+
182+
// ⚠️ server-side only!
183+
await client.batch.followMany(follows);
184+
185+
// Updating parts of an activity
186+
final set = {
187+
'product.price': 19.99,
188+
shares: {
189+
facebook: '...',
190+
twitter: '...',
191+
},
192+
};
193+
final unset = ['daily_likes', 'popularity'];
194+
195+
// ...by ID
196+
final update = ActivityUpdate.withId( '54a60c1e-4ee3-494b-a1e3-50c06acb5ed4', set, unset);
197+
await client.updateActivityById(update);
198+
// ...or by combination of foreign ID and time
199+
const timestamp = DateTime.now();
200+
const foreignID= 'product:123';
201+
final update2 = ActivityUpdate.withForeignId(
202+
foreignID,
203+
timestamp,
204+
set,
205+
unset,
206+
);
207+
await client.updateActivityById(update2);
208+
209+
210+
// update the 'to' fields on an existing activity
211+
// client.flatFeed("user", "ken").function (foreign_id, timestamp, new_targets, added_targets, removed_targets)
212+
// new_targets, added_targets, and removed_targets are all arrays of feed IDs
213+
// either provide only the `new_targets` parameter (will replace all targets on the activity),
214+
// OR provide the added_targets and removed_targets parameters
215+
// NOTE - the updateActivityToTargets method is not intended to be used in a browser environment.
216+
await client.flatFeed('user', 'ken').updateActivityToTargets('foreign_id:1234', timestamp, ['feed:1234']);
217+
await client.flatFeed('user', 'ken').updateActivityToTargets('foreign_id:1234', timestamp, null, ['feed:1234']);
218+
await client.flatFeed('user', 'ken').updateActivityToTargets('foreign_id:1234', timestamp, null, null, ['feed:1234']);
219+
```
220+
221+
### Realtime (Faye)
222+
223+
Stream uses [Faye](http://faye.jcoglan.com) for realtime notifications. Below is quick guide to subscribing to feed changes
224+
225+
```dart
226+
227+
// ⚠️ userToken is generated server-side (see previous section)
228+
final client = StreamFeedClient.connect('YOUR_API_KEY', token: userToken,appId: 'APP_ID');
229+
final user1 = client.flatFeed('user', '1');
230+
231+
// subscribe to the changes
232+
final subscription = await userFeed.subscribe((message) => print(message));
233+
// now whenever something changes to the feed user 1
234+
// the callback will be called
235+
236+
// To cancel a subscription you can call cancel on the
237+
// object returned from a subscribe call.
238+
// This will remove the listener from this channel.
239+
await subscription.cancel();
240+
```
241+
242+
Docs are available on [GetStream.io](http://getstream.io/docs/?language=dart).
243+
244+
## 🔮 Example Project
245+
246+
There is a detailed Flutter example project in the [example](https://github.com/GetStream/stream-feed-flutter/blob/master/packages/stream_feed/example/main.dart) folder. You can directly run and play on it.
247+
38248
## Contributing
39249

40250
### Code conventions

packages/stream_feed/lib/src/core/models/event.dart

-1
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,5 @@ class Content extends Equatable {
284284
factory Content.fromJson(Map<String, dynamic> json) =>
285285
_$ContentFromJson(json);
286286

287-
@override
288287
Map<String, dynamic> toJson() => _$ContentToJson(this);
289288
}

packages/stream_feed/lib/version.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
/// Current package version
22
/// Used in [HttpClient] to build the `x-stream-client` header
3-
const String packageVersion = '0.0.1';
3+
const String packageVersion = '0.1.2';

packages/stream_feed/pubspec.yaml

+13-9
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,29 @@
11
name: stream_feed
22
description: Stream Feed official Dart SDK. Build your own feed experience using Dart and Flutter.
3-
version: 0.0.1
3+
version: 0.1.2
4+
repository: https://github.com/GetStream/stream-feed-flutter
5+
issue_tracker: https://github.com/GetStream/stream-feed-flutter/issues
46
homepage: https://getstream.io/
57
environment:
68
sdk: '>=2.12.0 <3.0.0'
79

810
dependencies:
9-
dio: ^4.0.0-prev2
11+
dio: ^4.0.0
1012
equatable: ^2.0.0
1113
faye_dart: ^0.1.0
12-
jose: ^0.3.0-nullsafety.2
13-
json_annotation: ^4.0.0
14+
http_parser: ^4.0.0
15+
jose: ^0.3.2
16+
json_annotation: ^4.0.1
17+
logging: ^1.0.1
1418
meta: ^1.3.0
1519
mime: ^1.0.0
16-
logging: ^1.0.1
20+
web_socket_channel: ^2.1.0
1721

1822
dev_dependencies:
19-
build_runner: ^1.10.0
20-
json_serializable: ^4.0.2
21-
mocktail: ^0.1.0
22-
test: ^1.16.5
23+
build_runner: ^2.0.2
24+
json_serializable: ^4.1.1
25+
mocktail: ^0.1.2
26+
test: ^1.17.3
2327

2428
# For information on the generic Dart part of this file, see the
2529
# following page: https://dart.dev/tools/pub/pubspec

0 commit comments

Comments
 (0)