@@ -23,7 +23,7 @@ See the [Travis configuration](.travis.yml) for details of how it is built and t
2323### Installation
2424
2525``` bash
26- gem install " stream-ruby"
26+ gem install ' stream-ruby'
2727```
2828
2929### Full documentation
@@ -35,30 +35,43 @@ Documentation for this Ruby client are available at the [Stream website](https:/
3535``` ruby
3636# Instantiate a new client to connect to us east API endpoint
3737require ' stream'
38- client = Stream ::Client .new (' YOUR_API_KEY' , ' API_KEY_SECRET' , ' APP_ID' , :location => ' us-east' )
38+ client = Stream ::Client .new (' YOUR_API_KEY' , ' API_KEY_SECRET' , ' APP_ID' , location: ' us-east' )
39+
3940# Find your API keys here https://getstream.io/dashboard/
4041
4142# Instantiate a feed object
4243user_feed_1 = client.feed(' user' , ' 1' )
4344
4445# Get activities from 5 to 10 (slow pagination)
45- result = user_feed_1.get(: limit=> 5 , : offset=> 5 )
46+ result = user_feed_1.get(limit: 5 , offset: 5 )
4647# (Recommended & faster) Filter on an id less than the given UUID
47- result = user_feed_1.get(:limit =>5 , :id_lt =>' e561de8f-00f1-11e4-b400-0cc47a024be0' )
48+ result =
49+ user_feed_1.get(limit: 5 , id_lt: ' e561de8f-00f1-11e4-b400-0cc47a024be0' )
4850
4951# Create a new activity
50- activity_data = {: actor => 1 , : verb => ' tweet' , : object => 1 , : foreign_id => ' tweet:1' }
52+ activity_data = { actor: 1 , verb: ' tweet' , object: 1 , foreign_id: ' tweet:1' }
5153activity_response = user_feed_1.add_activity(activity_data)
5254# Create a bit more complex activity
53- activity_data = {:actor => 1 , :verb => ' tweet' , :object => 1 , :foreign_id => ' tweet:1' ,
54- :course => {:name => ' Golden Gate park' , :distance => 10 },
55- :participants => [' Thierry' , ' Tommaso' ],
56- :started_at => DateTime .now()
55+ activity_data = {
56+ actor: 1 ,
57+ verb: ' tweet' ,
58+ object: 1 ,
59+ foreign_id: ' tweet:1' ,
60+ course: { name: ' Golden Gate park' , distance: 10 },
61+ participants: %w[Thierry Tommaso] ,
62+ started_at: DateTime .now
5763}
5864activity_response = user_feed_1.add_activity(activity_data)
5965
6066# Update an existing activity (requires both :foreign_id and :time fields)
61- activity_data = {:actor => 1 , :verb => ' tweet' , :object => 1 , :foreign_id => ' tweet:1' , :popularity => 100 , :time => ' 2016-05-13T16:12:30' }
67+ activity_data = {
68+ actor: 1 ,
69+ verb: ' tweet' ,
70+ object: 1 ,
71+ foreign_id: ' tweet:1' ,
72+ popularity: 100 ,
73+ time: ' 2016-05-13T16:12:30'
74+ }
6275client.update_activity(activity_data)
6376
6477# Update activities
@@ -68,7 +81,7 @@ client.update_activities([activity_data])
6881user_feed_1.remove_activity(' e561de8f-00f1-11e4-b400-0cc47a024be0' )
6982
7083# Remove activities by their foreign_id
71- user_feed_1.remove_activity(' tweet:1' , foreign_id= true )
84+ user_feed_1.remove_activity(' tweet:1' , foreign_id = true )
7285
7386# Follow another feed
7487user_feed_1.follow(' flat' , ' 42' )
@@ -78,60 +91,45 @@ user_feed_1.unfollow('flat', '42')
7891
7992# Batch adding activities
8093activities = [
81- [ : actor => ' 1' , : verb => ' tweet' , : object => ' 1' ],
82- [ : actor => ' 2' , : verb => ' like' , : object => ' 3' ]
94+ [ actor: ' 1' , verb: ' tweet' , object: ' 1' ],
95+ [ actor: ' 2' , verb: ' like' , object: ' 3' ]
8396]
8497user_feed_1.add_activities(activities)
8598
8699# Batch following many feeds (requires ruby 2.1 or later)
87100follows = [
88- {: source => ' flat:1' , : target => ' user:1' },
89- {: source => ' flat:1' , : target => ' user:2' },
90- {: source => ' flat:1' , : target => ' user:3' },
101+ { source: ' flat:1' , target: ' user:1' },
102+ { source: ' flat:1' , target: ' user:2' },
103+ { source: ' flat:1' , target: ' user:3' }
91104]
92105client.follow_many(follows)
93106
94107# Add an activity and push it to other feeds too using the `to` field
95- data = [
96- :actor_id => ' 1' ,
97- :verb => ' like' ,
98- :object_id => ' 3' ,
99- :to => %w(user:44 user:45)
100- ]
108+ data = [actor_id: ' 1' , verb: ' like' , object_id: ' 3' , to: %w[user:44 user:45] ]
101109user_feed_1.add_activity(data)
102110
103-
104111# Updating parts of an activity
105112set = {
106- ' product.price' : 19.99 ,
107- ' shares' : {
108- ' facebook' : ' ...' ,
109- ' twitter' : ' ...'
110- },
113+ ' product.price' : 19.99 , ' shares' : { ' facebook' : ' ...' , ' twitter' : ' ...' }
111114}
112- unset = [
113- ' daily_likes' ,
114- ' popularity'
115- ]
115+ unset = %w[daily_likes popularity]
116116# ...by ID
117117client.activity_partial_update(
118- id: ' 54a60c1e-4ee3-494b-a1e3-50c06acb5ed4' ,
119- set: set,
120- unset: unset,
118+ id: ' 54a60c1e-4ee3-494b-a1e3-50c06acb5ed4' , set: set, unset: unset
121119)
122120# ...or by combination of foreign ID and time
123121client.activity_partial_update(
124122 foreign_id: ' product:123' ,
125123 time: ' 2016-11-10T13:20:00.000000' ,
126124 set: set,
127- unset: unset,
125+ unset: unset
128126)
129127
130128# Generating tokens for client side usage
131129token = user_feed_1.readonly_token
132130
133131# Javascript client side feed initialization
134- user1 = client.feed(' user' , ' 1' , ' {{ token }}' );
132+ user1 = client.feed(' user' , ' 1' , ' {{ token }}' )
135133
136134# Retrieve first 10 followers of a feed
137135user_feed_1.followers(0 , 10 )
@@ -146,11 +144,13 @@ user_feed_1.following(10)
146144user_feed_1.following(10 , 10 )
147145
148146# Check if user_feed_1 follows specific feeds
149- user_feed_1.following(0 , 2 , filter= [ ' user:42' , ' user:43' ])
147+ user_feed_1.following(0 , 2 , filter = %w[ user:42 user:43] )
150148
151149# Add one activity to many feeds in one request
152- feeds = %w(flat:1 flat:2 flat:3 flat:4)
153- activity = {:actor => " User:2" , :verb => " pin" , :object => " Place:42" , :target => " Board:1" }
150+ feeds = %w[flat:1 flat:2 flat:3 flat:4]
151+ activity = {
152+ actor: ' User:2' , verb: ' pin' , object: ' Place:42' , target: ' Board:1'
153+ }
154154client.add_to_many(activity, feeds)
155155```
156156
0 commit comments