stream-ruby 3.1.0 → 4.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +46 -48
- data/lib/stream/activities.rb +5 -6
- data/lib/stream/batch.rb +3 -5
- data/lib/stream/client.rb +23 -19
- data/lib/stream/collections.rb +8 -10
- data/lib/stream/feed.rb +29 -49
- data/lib/stream/reactions.rb +22 -26
- data/lib/stream/signer.rb +3 -3
- data/lib/stream/url.rb +4 -2
- data/lib/stream/users.rb +6 -8
- data/lib/stream/version.rb +1 -1
- metadata +14 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 31aab2710cc563a2d15372a93ef3c7247525e3579a0fc3208f08986cbdab50ba
|
4
|
+
data.tar.gz: 6d6c543c663e877798aad76d4af12c8b6c6db23bdbaa3fda050418bf460ff191
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5ee20ef5160fa068b869c4eace00310bcae8d7fc15e2730c01312015060b533deb68be4d944ada943042d7a2d84e3c83564599df76b2edb5f954db124bd81ca6
|
7
|
+
data.tar.gz: 814193cfdcd06a7376303fea24ce59c8881d914893e4fd336a85b093f757de642fd268c146112ff2cedd65185aef3e389757a9a10aec9a83493ea4f1c3f32ca6
|
data/README.md
CHANGED
@@ -1,5 +1,4 @@
|
|
1
|
-
stream-ruby
|
2
|
-
===========
|
1
|
+
# stream-ruby
|
3
2
|
|
4
3
|
[![Build Status](https://travis-ci.org/GetStream/stream-ruby.svg?branch=master)](https://travis-ci.org/GetStream/stream-ruby) [![Gem Version](https://badge.fury.io/rb/stream-ruby.svg)](http://badge.fury.io/rb/stream-ruby)
|
5
4
|
|
@@ -11,18 +10,14 @@ You can sign up for a Stream account at https://getstream.io/get_started.
|
|
11
10
|
|
12
11
|
#### Ruby version requirements and support
|
13
12
|
|
14
|
-
This API Client project requires Ruby 2.
|
15
|
-
- 2.2.10
|
16
|
-
- 2.3.8
|
17
|
-
- 2.4.5
|
18
|
-
- 2.5.3
|
13
|
+
This API Client project requires Ruby 2.5.x at a minimum.
|
19
14
|
|
20
15
|
See the [Travis configuration](.travis.yml) for details of how it is built and tested.
|
21
16
|
|
22
17
|
### Installation
|
23
18
|
|
24
19
|
```bash
|
25
|
-
gem install
|
20
|
+
gem install 'stream-ruby'
|
26
21
|
```
|
27
22
|
|
28
23
|
### Full documentation
|
@@ -34,30 +29,43 @@ Documentation for this Ruby client are available at the [Stream website](https:/
|
|
34
29
|
```ruby
|
35
30
|
# Instantiate a new client to connect to us east API endpoint
|
36
31
|
require 'stream'
|
37
|
-
client = Stream::Client.new('YOUR_API_KEY', 'API_KEY_SECRET', 'APP_ID', :
|
32
|
+
client = Stream::Client.new('YOUR_API_KEY', 'API_KEY_SECRET', 'APP_ID', location: 'us-east')
|
33
|
+
|
38
34
|
# Find your API keys here https://getstream.io/dashboard/
|
39
35
|
|
40
36
|
# Instantiate a feed object
|
41
37
|
user_feed_1 = client.feed('user', '1')
|
42
38
|
|
43
39
|
# Get activities from 5 to 10 (slow pagination)
|
44
|
-
result = user_feed_1.get(:
|
40
|
+
result = user_feed_1.get(limit: 5, offset: 5)
|
45
41
|
# (Recommended & faster) Filter on an id less than the given UUID
|
46
|
-
result =
|
42
|
+
result =
|
43
|
+
user_feed_1.get(limit: 5, id_lt: 'e561de8f-00f1-11e4-b400-0cc47a024be0')
|
47
44
|
|
48
45
|
# Create a new activity
|
49
|
-
activity_data = {:
|
46
|
+
activity_data = { actor: 1, verb: 'tweet', object: 1, foreign_id: 'tweet:1' }
|
50
47
|
activity_response = user_feed_1.add_activity(activity_data)
|
51
48
|
# Create a bit more complex activity
|
52
|
-
activity_data = {
|
53
|
-
|
54
|
-
|
55
|
-
|
49
|
+
activity_data = {
|
50
|
+
actor: 1,
|
51
|
+
verb: 'tweet',
|
52
|
+
object: 1,
|
53
|
+
foreign_id: 'tweet:1',
|
54
|
+
course: { name: 'Golden Gate park', distance: 10 },
|
55
|
+
participants: %w[Thierry Tommaso],
|
56
|
+
started_at: DateTime.now
|
56
57
|
}
|
57
58
|
activity_response = user_feed_1.add_activity(activity_data)
|
58
59
|
|
59
60
|
# Update an existing activity (requires both :foreign_id and :time fields)
|
60
|
-
activity_data = {
|
61
|
+
activity_data = {
|
62
|
+
actor: 1,
|
63
|
+
verb: 'tweet',
|
64
|
+
object: 1,
|
65
|
+
foreign_id: 'tweet:1',
|
66
|
+
popularity: 100,
|
67
|
+
time: '2016-05-13T16:12:30'
|
68
|
+
}
|
61
69
|
client.update_activity(activity_data)
|
62
70
|
|
63
71
|
# Update activities
|
@@ -67,7 +75,7 @@ client.update_activities([activity_data])
|
|
67
75
|
user_feed_1.remove_activity('e561de8f-00f1-11e4-b400-0cc47a024be0')
|
68
76
|
|
69
77
|
# Remove activities by their foreign_id
|
70
|
-
user_feed_1.remove_activity('tweet:1', foreign_id
|
78
|
+
user_feed_1.remove_activity('tweet:1', foreign_id: true)
|
71
79
|
|
72
80
|
# Follow another feed
|
73
81
|
user_feed_1.follow('flat', '42')
|
@@ -77,60 +85,45 @@ user_feed_1.unfollow('flat', '42')
|
|
77
85
|
|
78
86
|
# Batch adding activities
|
79
87
|
activities = [
|
80
|
-
|
81
|
-
|
88
|
+
[actor: '1', verb: 'tweet', object: '1'],
|
89
|
+
[actor: '2', verb: 'like', object: '3']
|
82
90
|
]
|
83
91
|
user_feed_1.add_activities(activities)
|
84
92
|
|
85
93
|
# Batch following many feeds (requires ruby 2.1 or later)
|
86
94
|
follows = [
|
87
|
-
{:
|
88
|
-
{:
|
89
|
-
{:
|
95
|
+
{ source: 'flat:1', target: 'user:1' },
|
96
|
+
{ source: 'flat:1', target: 'user:2' },
|
97
|
+
{ source: 'flat:1', target: 'user:3' }
|
90
98
|
]
|
91
99
|
client.follow_many(follows)
|
92
100
|
|
93
101
|
# Add an activity and push it to other feeds too using the `to` field
|
94
|
-
data = [
|
95
|
-
:actor_id => '1',
|
96
|
-
:verb => 'like',
|
97
|
-
:object_id => '3',
|
98
|
-
:to => %w(user:44 user:45)
|
99
|
-
]
|
102
|
+
data = [actor_id: '1', verb: 'like', object_id: '3', to: %w[user:44 user:45]]
|
100
103
|
user_feed_1.add_activity(data)
|
101
104
|
|
102
|
-
|
103
105
|
# Updating parts of an activity
|
104
106
|
set = {
|
105
|
-
'product.price': 19.99,
|
106
|
-
'shares': {
|
107
|
-
'facebook': '...',
|
108
|
-
'twitter': '...'
|
109
|
-
},
|
107
|
+
'product.price': 19.99, 'shares': { 'facebook': '...', 'twitter': '...' }
|
110
108
|
}
|
111
|
-
unset = [
|
112
|
-
'daily_likes',
|
113
|
-
'popularity'
|
114
|
-
]
|
109
|
+
unset = %w[daily_likes popularity]
|
115
110
|
# ...by ID
|
116
111
|
client.activity_partial_update(
|
117
|
-
id: '54a60c1e-4ee3-494b-a1e3-50c06acb5ed4',
|
118
|
-
set: set,
|
119
|
-
unset: unset,
|
112
|
+
id: '54a60c1e-4ee3-494b-a1e3-50c06acb5ed4', set: set, unset: unset
|
120
113
|
)
|
121
114
|
# ...or by combination of foreign ID and time
|
122
115
|
client.activity_partial_update(
|
123
116
|
foreign_id: 'product:123',
|
124
117
|
time: '2016-11-10T13:20:00.000000',
|
125
118
|
set: set,
|
126
|
-
unset: unset
|
119
|
+
unset: unset
|
127
120
|
)
|
128
121
|
|
129
122
|
# Generating tokens for client side usage
|
130
123
|
token = user_feed_1.readonly_token
|
131
124
|
|
132
125
|
# Javascript client side feed initialization
|
133
|
-
user1 = client.feed('user', '1', '{{ token }}')
|
126
|
+
user1 = client.feed('user', '1', '{{ token }}')
|
134
127
|
|
135
128
|
# Retrieve first 10 followers of a feed
|
136
129
|
user_feed_1.followers(0, 10)
|
@@ -145,16 +138,21 @@ user_feed_1.following(10)
|
|
145
138
|
user_feed_1.following(10, 10)
|
146
139
|
|
147
140
|
# Check if user_feed_1 follows specific feeds
|
148
|
-
user_feed_1.following(0, 2, filter=[
|
141
|
+
user_feed_1.following(0, 2, filter = %w[user:42 user:43])
|
149
142
|
|
150
143
|
# Add one activity to many feeds in one request
|
151
|
-
feeds = %w
|
152
|
-
activity = {
|
144
|
+
feeds = %w[flat:1 flat:2 flat:3 flat:4]
|
145
|
+
activity = {
|
146
|
+
actor: 'User:2', verb: 'pin', object: 'Place:42', target: 'Board:1'
|
147
|
+
}
|
153
148
|
client.add_to_many(activity, feeds)
|
149
|
+
|
150
|
+
# Retrive open graph information
|
151
|
+
client.og('https://google.com')
|
154
152
|
```
|
155
153
|
|
156
154
|
### Copyright and License Information
|
157
155
|
|
158
|
-
Copyright (c) 2014-
|
156
|
+
Copyright (c) 2014-2020 Stream.io Inc, and individual contributors. All rights reserved.
|
159
157
|
|
160
158
|
See the file "LICENSE" for information on the history of this software, terms & conditions for usage, and a DISCLAIMER OF ALL WARRANTIES.
|
data/lib/stream/activities.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
module Stream
|
2
2
|
module Activities
|
3
|
-
|
4
3
|
#
|
5
4
|
# Get activities directly, via ID or Foreign ID + timestamp
|
6
5
|
#
|
@@ -28,13 +27,13 @@ module Stream
|
|
28
27
|
if params[:foreign_id_times]
|
29
28
|
foreign_ids = []
|
30
29
|
timestamps = []
|
31
|
-
params[:foreign_id_times].each
|
30
|
+
params[:foreign_id_times].each do |e|
|
32
31
|
foreign_ids << e[:foreign_id]
|
33
32
|
timestamps << e[:time]
|
34
|
-
|
33
|
+
end
|
35
34
|
params = {
|
36
35
|
foreign_ids: foreign_ids,
|
37
|
-
timestamps: timestamps
|
36
|
+
timestamps: timestamps
|
38
37
|
}
|
39
38
|
end
|
40
39
|
signature = Stream::Signer.create_jwt_token('activities', '*', @api_secret, '*')
|
@@ -142,8 +141,8 @@ module Stream
|
|
142
141
|
# ])
|
143
142
|
#
|
144
143
|
def batch_activity_partial_update(changes = [])
|
145
|
-
|
146
|
-
|
144
|
+
signature = Stream::Signer.create_jwt_token('activities', '*', @api_secret, '*')
|
145
|
+
make_request(:post, '/activity/', signature, {}, { changes: changes })
|
147
146
|
end
|
148
147
|
end
|
149
148
|
end
|
data/lib/stream/batch.rb
CHANGED
@@ -16,9 +16,7 @@ module Stream
|
|
16
16
|
#
|
17
17
|
def follow_many(follows, activity_copy_limit = nil)
|
18
18
|
query_params = {}
|
19
|
-
unless activity_copy_limit.nil?
|
20
|
-
query_params['activity_copy_limit'] = activity_copy_limit
|
21
|
-
end
|
19
|
+
query_params['activity_copy_limit'] = activity_copy_limit unless activity_copy_limit.nil?
|
22
20
|
signature = Stream::Signer.create_jwt_token('follower', '*', @api_secret, '*')
|
23
21
|
make_request(:post, '/follow_many/', signature, query_params, follows)
|
24
22
|
end
|
@@ -52,8 +50,8 @@ module Stream
|
|
52
50
|
#
|
53
51
|
def add_to_many(activity_data, feeds)
|
54
52
|
data = {
|
55
|
-
:
|
56
|
-
:
|
53
|
+
feeds: feeds,
|
54
|
+
activity: activity_data
|
57
55
|
}
|
58
56
|
signature = Stream::Signer.create_jwt_token('feed', '*', @api_secret, '*')
|
59
57
|
make_request(:post, '/feed/add_to_many/', signature, {}, data)
|
data/lib/stream/client.rb
CHANGED
@@ -5,8 +5,8 @@ require 'stream/signer'
|
|
5
5
|
require 'stream/url'
|
6
6
|
|
7
7
|
module Stream
|
8
|
-
STREAM_URL_COM_RE = %r{https
|
9
|
-
STREAM_URL_IO_RE = %r{https
|
8
|
+
STREAM_URL_COM_RE = %r{https://(?<key>\w+):(?<secret>\w+)@((api\.)|((?<location>[-\w]+)\.))?(?<api_hostname>stream-io-api\.com)/[\w=-?%&]+app_id=(?<app_id>\d+)}i.freeze
|
9
|
+
STREAM_URL_IO_RE = %r{https://(?<key>\w+):(?<secret>\w+)@((api\.)|((?<location>[-\w]+)\.))?(?<api_hostname>getstream\.io)/[\w=-?%&]+app_id=(?<app_id>\d+)}i.freeze
|
10
10
|
|
11
11
|
class Client
|
12
12
|
attr_reader :api_key
|
@@ -36,7 +36,6 @@ module Stream
|
|
36
36
|
# Stream::Client.new('my_key', 'my_secret', 'my_app_id', :location => 'us-east')
|
37
37
|
#
|
38
38
|
def initialize(api_key = '', api_secret = '', app_id = nil, opts = {})
|
39
|
-
|
40
39
|
if api_key.nil? || api_key.empty?
|
41
40
|
env_url = ENV['STREAM_URL']
|
42
41
|
if env_url =~ Stream::STREAM_URL_COM_RE
|
@@ -100,7 +99,7 @@ module Stream
|
|
100
99
|
# @return [string]
|
101
100
|
#
|
102
101
|
def create_user_token(user_id, extra_data = {})
|
103
|
-
|
102
|
+
Stream::Signer.create_user_token(user_id, extra_data, api_secret)
|
104
103
|
end
|
105
104
|
|
106
105
|
def personalization
|
@@ -128,16 +127,21 @@ module Stream
|
|
128
127
|
make_request(:post, '/activities/', auth_token, {}, 'activities' => activities)
|
129
128
|
end
|
130
129
|
|
130
|
+
def og(uri)
|
131
|
+
auth_token = Stream::Signer.create_jwt_token('*', '*', @api_secret, '*')
|
132
|
+
make_request(:get, '/og', auth_token, { url: uri })
|
133
|
+
end
|
134
|
+
|
131
135
|
def get_default_params
|
132
|
-
{:
|
136
|
+
{ api_key: @api_key }
|
133
137
|
end
|
134
138
|
|
135
139
|
def get_http_client
|
136
|
-
@
|
140
|
+
@get_http_client ||= StreamHTTPClient.new(url_generator)
|
137
141
|
end
|
138
142
|
|
139
143
|
def make_query_params(params)
|
140
|
-
Hash[get_default_params.merge(params).sort_by {|k,
|
144
|
+
Hash[get_default_params.merge(params).sort_by { |k, _v| k.to_s }]
|
141
145
|
end
|
142
146
|
|
143
147
|
def make_request(method, relative_url, signature, params = {}, data = {}, headers = {})
|
@@ -187,7 +191,7 @@ module Stream
|
|
187
191
|
|
188
192
|
case response[:status].to_i
|
189
193
|
when 200..203
|
190
|
-
|
194
|
+
::JSON.parse(response[:body])
|
191
195
|
end
|
192
196
|
end
|
193
197
|
end
|
@@ -196,16 +200,16 @@ module Stream
|
|
196
200
|
def call(env)
|
197
201
|
@app.call(env).on_complete do |response|
|
198
202
|
case response[:status].to_i
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
203
|
+
when 200..203
|
204
|
+
return response
|
205
|
+
when 401
|
206
|
+
raise StreamApiResponseException, error_message(response, 'Bad feed')
|
207
|
+
when 403
|
208
|
+
raise StreamApiResponseException, error_message(response, 'Bad auth/headers')
|
209
|
+
when 404
|
210
|
+
raise StreamApiResponseException, error_message(response, 'url not found')
|
211
|
+
when 204...600
|
212
|
+
raise StreamApiResponseException, error_message(response, _build_error_message(response.body))
|
209
213
|
end
|
210
214
|
end
|
211
215
|
end
|
@@ -229,7 +233,7 @@ module Stream
|
|
229
233
|
end
|
230
234
|
|
231
235
|
def error_message(response, body = nil)
|
232
|
-
"#{response[:method].to_s.upcase} #{response[:url]}: #{[response[:status]
|
236
|
+
"#{response[:method].to_s.upcase} #{response[:url]}: #{["#{response[:status]}:", body].compact.join(' ')}"
|
233
237
|
end
|
234
238
|
end
|
235
239
|
end
|
data/lib/stream/collections.rb
CHANGED
@@ -4,15 +4,15 @@ module Stream
|
|
4
4
|
data = {
|
5
5
|
id: id,
|
6
6
|
user_id: user_id,
|
7
|
-
data: collection_data
|
7
|
+
data: collection_data
|
8
8
|
}
|
9
9
|
uri = "/collections/#{collection_name}/"
|
10
|
-
make_collection_request(:post, {}, data, :
|
10
|
+
make_collection_request(:post, {}, data, endpoint: uri)
|
11
11
|
end
|
12
12
|
|
13
13
|
def get(collection_name, id)
|
14
14
|
uri = "collections/#{collection_name}/#{id}/"
|
15
|
-
make_collection_request(:get, {}, {}, :
|
15
|
+
make_collection_request(:get, {}, {}, endpoint: uri)
|
16
16
|
end
|
17
17
|
|
18
18
|
def update(collection_name, id, data: nil)
|
@@ -20,12 +20,12 @@ module Stream
|
|
20
20
|
data: data
|
21
21
|
}
|
22
22
|
uri = "collections/#{collection_name}/#{id}/"
|
23
|
-
make_collection_request(:put, {}, data, :
|
23
|
+
make_collection_request(:put, {}, data, endpoint: uri)
|
24
24
|
end
|
25
25
|
|
26
26
|
def delete(collection_name, id)
|
27
27
|
uri = "collections/#{collection_name}/#{id}/"
|
28
|
-
make_collection_request(:delete, {}, {}, :
|
28
|
+
make_collection_request(:delete, {}, {}, endpoint: uri)
|
29
29
|
end
|
30
30
|
|
31
31
|
def upsert(collection, objects = [])
|
@@ -53,11 +53,9 @@ module Stream
|
|
53
53
|
end
|
54
54
|
|
55
55
|
def create_reference(collection, id)
|
56
|
-
|
57
|
-
if id.respond_to?(:keys)
|
58
|
-
|
59
|
-
end
|
60
|
-
"SO:#{collection}:#{_id}"
|
56
|
+
k = id
|
57
|
+
k = id['id'] if id.respond_to?(:keys) && !id['id'].nil?
|
58
|
+
"SO:#{collection}:#{k}"
|
61
59
|
end
|
62
60
|
|
63
61
|
private
|
data/lib/stream/feed.rb
CHANGED
@@ -8,13 +8,9 @@ module Stream
|
|
8
8
|
attr_reader :user_id
|
9
9
|
|
10
10
|
def initialize(client, feed_slug, user_id)
|
11
|
-
unless valid_feed_slug feed_slug
|
12
|
-
raise StreamInputData, 'feed_slug can only contain alphanumeric characters plus underscores'
|
13
|
-
end
|
11
|
+
raise StreamInputData, 'feed_slug can only contain alphanumeric characters plus underscores' unless valid_feed_slug feed_slug
|
14
12
|
|
15
|
-
unless valid_user_id user_id
|
16
|
-
raise StreamInputData, 'user_id can only contain alphanumeric characters plus underscores and dashes'
|
17
|
-
end
|
13
|
+
raise StreamInputData, 'user_id can only contain alphanumeric characters plus underscores and dashes' unless valid_user_id user_id
|
18
14
|
|
19
15
|
@id = "#{feed_slug}:#{user_id}"
|
20
16
|
@client = client
|
@@ -37,29 +33,19 @@ module Stream
|
|
37
33
|
end
|
38
34
|
|
39
35
|
def get(params = {})
|
40
|
-
if params[:enrich]
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
end
|
48
|
-
if params[:mark_seen] && params[:mark_seen].is_a?(Array)
|
49
|
-
params[:mark_seen] = params[:mark_seen].join(',')
|
50
|
-
end
|
36
|
+
uri = if params[:enrich] || params[:reactions]
|
37
|
+
"/enrich/feed/#{@feed_url}/"
|
38
|
+
else
|
39
|
+
"/feed/#{@feed_url}/"
|
40
|
+
end
|
41
|
+
params[:mark_read] = params[:mark_read].join(',') if params[:mark_read]&.is_a?(Array)
|
42
|
+
params[:mark_seen] = params[:mark_seen].join(',') if params[:mark_seen]&.is_a?(Array)
|
51
43
|
if params[:reactions].respond_to?(:keys)
|
52
|
-
if params[:reactions][:own]
|
53
|
-
|
54
|
-
|
55
|
-
if params[:reactions][:recent]
|
56
|
-
params[:withRecentReactions] = true
|
57
|
-
end
|
58
|
-
if params[:reactions][:counts]
|
59
|
-
params[:withReactionCounts] = true
|
60
|
-
end
|
44
|
+
params[:withOwnReactions] = true if params[:reactions][:own]
|
45
|
+
params[:withRecentReactions] = true if params[:reactions][:recent]
|
46
|
+
params[:withReactionCounts] = true if params[:reactions][:counts]
|
61
47
|
end
|
62
|
-
[
|
48
|
+
%i[enrich reactions].each { |k| params.delete(k) }
|
63
49
|
|
64
50
|
auth_token = create_jwt_token('feed', 'read')
|
65
51
|
@client.make_request(:get, uri, auth_token, params)
|
@@ -75,20 +61,20 @@ module Stream
|
|
75
61
|
|
76
62
|
def add_activities(activities)
|
77
63
|
uri = "/feed/#{@feed_url}/"
|
78
|
-
data = {:activities
|
64
|
+
data = { activities: activities }
|
79
65
|
auth_token = create_jwt_token('feed', 'write')
|
80
66
|
|
81
67
|
@client.make_request(:post, uri, auth_token, {}, data)
|
82
68
|
end
|
83
69
|
|
84
|
-
def remove(activity_id, foreign_id
|
70
|
+
def remove(activity_id, foreign_id: false)
|
85
71
|
remove_activity(activity_id, foreign_id)
|
86
72
|
end
|
87
73
|
|
88
|
-
def remove_activity(activity_id, foreign_id
|
74
|
+
def remove_activity(activity_id, foreign_id: false)
|
89
75
|
uri = "/feed/#{@feed_url}/#{activity_id}/"
|
90
76
|
params = {}
|
91
|
-
params = {foreign_id: 1} if foreign_id
|
77
|
+
params = { foreign_id: 1 } if foreign_id
|
92
78
|
auth_token = create_jwt_token('feed', 'delete')
|
93
79
|
|
94
80
|
@client.make_request(:delete, uri, auth_token, params)
|
@@ -111,15 +97,9 @@ module Stream
|
|
111
97
|
'time': time
|
112
98
|
}
|
113
99
|
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
if !added_targets.nil?
|
118
|
-
data['added_targets'] = added_targets
|
119
|
-
end
|
120
|
-
if !removed_targets.nil?
|
121
|
-
data['removed_targets'] = removed_targets
|
122
|
-
end
|
100
|
+
data['new_targets'] = new_targets unless new_targets.nil?
|
101
|
+
data['added_targets'] = added_targets unless added_targets.nil?
|
102
|
+
data['removed_targets'] = removed_targets unless removed_targets.nil?
|
123
103
|
auth_token = create_jwt_token('feed_targets', 'write')
|
124
104
|
|
125
105
|
@client.make_request(:post, uri, auth_token, {}, data)
|
@@ -127,12 +107,12 @@ module Stream
|
|
127
107
|
|
128
108
|
def follow(target_feed_slug, target_user_id, activity_copy_limit = 300)
|
129
109
|
uri = "/feed/#{@feed_url}/follows/"
|
130
|
-
activity_copy_limit = 0 if activity_copy_limit
|
110
|
+
activity_copy_limit = 0 if activity_copy_limit.negative?
|
131
111
|
activity_copy_limit = 1000 if activity_copy_limit > 1000
|
132
112
|
|
133
113
|
follow_data = {
|
134
|
-
|
135
|
-
|
114
|
+
target: "#{target_feed_slug}:#{target_user_id}",
|
115
|
+
activity_copy_limit: activity_copy_limit
|
136
116
|
}
|
137
117
|
auth_token = create_jwt_token('follower', 'write')
|
138
118
|
|
@@ -142,8 +122,8 @@ module Stream
|
|
142
122
|
def followers(offset = 0, limit = 25)
|
143
123
|
uri = "/feed/#{@feed_url}/followers/"
|
144
124
|
params = {
|
145
|
-
|
146
|
-
|
125
|
+
offset: offset,
|
126
|
+
limit: limit
|
147
127
|
}
|
148
128
|
auth_token = create_jwt_token('follower', 'read')
|
149
129
|
|
@@ -153,16 +133,16 @@ module Stream
|
|
153
133
|
def following(offset = 0, limit = 25, filter = [])
|
154
134
|
uri = "/feed/#{@feed_url}/follows/"
|
155
135
|
params = {
|
156
|
-
|
157
|
-
|
158
|
-
|
136
|
+
offset: offset,
|
137
|
+
limit: limit,
|
138
|
+
filter: filter.join(',')
|
159
139
|
}
|
160
140
|
auth_token = create_jwt_token('follower', 'read')
|
161
141
|
|
162
142
|
@client.make_request(:get, uri, auth_token, params)
|
163
143
|
end
|
164
144
|
|
165
|
-
def unfollow(target_feed_slug, target_user_id, keep_history
|
145
|
+
def unfollow(target_feed_slug, target_user_id, keep_history: false)
|
166
146
|
uri = "/feed/#{@feed_url}/follows/#{target_feed_slug}:#{target_user_id}/"
|
167
147
|
auth_token = create_jwt_token('follower', 'delete')
|
168
148
|
params = {}
|
data/lib/stream/reactions.rb
CHANGED
@@ -13,7 +13,7 @@ module Stream
|
|
13
13
|
|
14
14
|
def get(reaction_id)
|
15
15
|
uri = "/reaction/#{reaction_id}/"
|
16
|
-
make_reaction_request(:get, {}, {}, :
|
16
|
+
make_reaction_request(:get, {}, {}, endpoint: uri)
|
17
17
|
end
|
18
18
|
|
19
19
|
def update(reaction_id, data: nil, target_feeds: nil)
|
@@ -22,12 +22,12 @@ module Stream
|
|
22
22
|
target_feeds: target_feeds
|
23
23
|
}
|
24
24
|
uri = "/reaction/#{reaction_id}/"
|
25
|
-
make_reaction_request(:put, {}, data, :
|
25
|
+
make_reaction_request(:put, {}, data, endpoint: uri)
|
26
26
|
end
|
27
27
|
|
28
28
|
def delete(reaction_id)
|
29
29
|
uri = "/reaction/#{reaction_id}/"
|
30
|
-
make_reaction_request(:delete, {}, {}, :
|
30
|
+
make_reaction_request(:delete, {}, {}, endpoint: uri)
|
31
31
|
end
|
32
32
|
|
33
33
|
def add_child(kind, parent_id, user_id, data: nil, target_feeds: nil)
|
@@ -42,36 +42,32 @@ module Stream
|
|
42
42
|
end
|
43
43
|
|
44
44
|
def filter(params = {})
|
45
|
-
|
46
|
-
|
47
|
-
kind = params.fetch(:kind,
|
45
|
+
field = ''
|
46
|
+
value = ''
|
47
|
+
kind = params.fetch(:kind, '')
|
48
48
|
if params[:reaction_id]
|
49
|
-
|
50
|
-
|
49
|
+
field = 'reaction_id'
|
50
|
+
value = params[:reaction_id]
|
51
51
|
elsif params[:activity_id]
|
52
|
-
|
53
|
-
|
52
|
+
field = 'activity_id'
|
53
|
+
value = params[:activity_id]
|
54
54
|
elsif params[:user_id]
|
55
|
-
|
56
|
-
|
55
|
+
field = 'user_id'
|
56
|
+
value = params[:user_id]
|
57
57
|
end
|
58
|
-
unless
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
end
|
66
|
-
make_reaction_request(:get, params, {}, :endpoint => uri)
|
58
|
+
params.delete(field.to_sym) unless field.empty?
|
59
|
+
uri = if kind.nil? || kind.empty?
|
60
|
+
"/reaction/#{field}/#{value}/"
|
61
|
+
else
|
62
|
+
"/reaction/#{field}/#{value}/#{kind}/"
|
63
|
+
end
|
64
|
+
make_reaction_request(:get, params, {}, endpoint: uri)
|
67
65
|
end
|
68
66
|
|
69
67
|
def create_reference(id)
|
70
|
-
|
71
|
-
if id.respond_to?(:keys)
|
72
|
-
|
73
|
-
end
|
74
|
-
"SR:#{_id}"
|
68
|
+
k = id
|
69
|
+
k = id['id'] if id.respond_to?(:keys) && !id['id'].nil?
|
70
|
+
"SR:#{k}"
|
75
71
|
end
|
76
72
|
|
77
73
|
private
|
data/lib/stream/signer.rb
CHANGED
@@ -11,13 +11,13 @@ module Stream
|
|
11
11
|
|
12
12
|
def self.create_user_token(user_id, payload = {}, api_secret)
|
13
13
|
payload['user_id'] = user_id
|
14
|
-
|
14
|
+
JWT.encode(payload, api_secret, 'HS256')
|
15
15
|
end
|
16
16
|
|
17
17
|
def self.create_jwt_token(resource, action, api_secret, feed_id = nil, user_id = nil)
|
18
18
|
payload = {
|
19
|
-
|
20
|
-
|
19
|
+
resource: resource,
|
20
|
+
action: action
|
21
21
|
}
|
22
22
|
payload['feed_id'] = feed_id if feed_id
|
23
23
|
payload['user_id'] = user_id if user_id
|
data/lib/stream/url.rb
CHANGED
@@ -7,10 +7,11 @@ module Stream
|
|
7
7
|
|
8
8
|
class APIURLGenerator < URLGenerator
|
9
9
|
def initialize(options)
|
10
|
+
super()
|
10
11
|
@options = options
|
11
12
|
location = make_location(options[:location])
|
12
|
-
location ||=
|
13
|
-
api_version = options[:api_version]
|
13
|
+
location ||= 'api'
|
14
|
+
api_version = options[:api_version] || 'v1.0'
|
14
15
|
if ENV['STREAM_URL']
|
15
16
|
uri = URI.parse(ENV['STREAM_URL'])
|
16
17
|
scheme = uri.scheme
|
@@ -48,6 +49,7 @@ module Stream
|
|
48
49
|
|
49
50
|
class PersonalizationURLGenerator < URLGenerator
|
50
51
|
def initialize(options)
|
52
|
+
super()
|
51
53
|
@options = options
|
52
54
|
host = 'personalization.stream-io-api.com'
|
53
55
|
@base_path = '/personalization/v1.0'
|
data/lib/stream/users.rb
CHANGED
@@ -13,7 +13,7 @@ module Stream
|
|
13
13
|
|
14
14
|
def get(user_id)
|
15
15
|
uri = "/user/#{user_id}/"
|
16
|
-
make_user_request(:get, {}, {}, :
|
16
|
+
make_user_request(:get, {}, {}, endpoint: uri)
|
17
17
|
end
|
18
18
|
|
19
19
|
def update(user_id, data: nil)
|
@@ -21,20 +21,18 @@ module Stream
|
|
21
21
|
data: data
|
22
22
|
}
|
23
23
|
uri = "/user/#{user_id}/"
|
24
|
-
make_user_request(:put, {}, data, :
|
24
|
+
make_user_request(:put, {}, data, endpoint: uri)
|
25
25
|
end
|
26
26
|
|
27
27
|
def delete(user_id)
|
28
28
|
uri = "/user/#{user_id}/"
|
29
|
-
make_user_request(:delete, {}, {}, :
|
29
|
+
make_user_request(:delete, {}, {}, endpoint: uri)
|
30
30
|
end
|
31
31
|
|
32
32
|
def create_reference(id)
|
33
|
-
|
34
|
-
if id.respond_to?(:keys)
|
35
|
-
|
36
|
-
end
|
37
|
-
"SU:#{_id}"
|
33
|
+
k = id
|
34
|
+
k = id['id'] if id.respond_to?(:keys) && !id['id'].nil?
|
35
|
+
"SU:#{k}"
|
38
36
|
end
|
39
37
|
|
40
38
|
private
|
data/lib/stream/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stream-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 4.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tommaso Barbugli
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2020-11-19 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: faraday
|
@@ -56,44 +56,44 @@ dependencies:
|
|
56
56
|
name: rake
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - "
|
59
|
+
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - "
|
66
|
+
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rspec
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- - "
|
73
|
+
- - ">="
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '
|
75
|
+
version: '0'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- - "
|
80
|
+
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: '
|
82
|
+
version: '0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: simplecov
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- - "
|
87
|
+
- - ">="
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: '0
|
89
|
+
version: '0'
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
|
-
- - "
|
94
|
+
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: '0
|
96
|
+
version: '0'
|
97
97
|
description: Ruby client for getstream.io service
|
98
98
|
email: support@getstream.io
|
99
99
|
executables: []
|
@@ -131,15 +131,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
131
131
|
requirements:
|
132
132
|
- - ">="
|
133
133
|
- !ruby/object:Gem::Version
|
134
|
-
version:
|
134
|
+
version: 2.5.0
|
135
135
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
136
136
|
requirements:
|
137
137
|
- - ">="
|
138
138
|
- !ruby/object:Gem::Version
|
139
139
|
version: '0'
|
140
140
|
requirements: []
|
141
|
-
|
142
|
-
rubygems_version: 2.7.8
|
141
|
+
rubygems_version: 3.1.2
|
143
142
|
signing_key:
|
144
143
|
specification_version: 4
|
145
144
|
summary: A gem that provides a client interface for getstream.io
|