stream-ruby 4.4.0 → 4.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +31 -13
- data/lib/stream/client.rb +53 -17
- data/lib/stream/errors.rb +34 -0
- data/lib/stream/feed.rb +13 -0
- data/lib/stream/url.rb +3 -3
- data/lib/stream/version.rb +1 -1
- metadata +37 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: bdef85497ab7ca002728c569b246ad90a804ea8f40a7bc0596cd22190df551d6
|
|
4
|
+
data.tar.gz: e7a9977ea752848600e057f38ebdeefbe8762da4eb1a6c8d66173efd8d332c24
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f88ce620bb7d599a7b6d557c97c7170240193c1a3ed8541e02fb84f631ab9a986d1e8404f54e8205b2cdb7882516dd1f37b6739d8a05390ae63b858641cb1318
|
|
7
|
+
data.tar.gz: ea8247db45adad7bc0e339ecc0de437089cae55c7272d5e6980e0bd82dacf688af6e31e0aaa03714424288fecdbb4a90fbf7bdc0e0c6751cef882debd3a075a0
|
data/README.md
CHANGED
|
@@ -1,30 +1,47 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Official Ruby SDK for [Stream Feeds](https://getstream.io/activity-feeds/)
|
|
2
2
|
|
|
3
3
|
[](https://github.com/GetStream/stream-ruby/actions) [](http://badge.fury.io/rb/stream-ruby)
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
<p align="center">
|
|
6
|
+
<img src="./assets/logo.svg" width="50%" height="50%">
|
|
7
|
+
</p>
|
|
8
|
+
<p align="center">
|
|
9
|
+
Official Ruby API client for Stream Feeds, a web service for building scalable newsfeeds and activity streams.
|
|
10
|
+
<br />
|
|
11
|
+
<a href="https://getstream.io/activity-feeds/"><strong>Explore the docs »</strong></a>
|
|
12
|
+
<br />
|
|
13
|
+
<br />
|
|
14
|
+
<a href="https://github.com/GetStream/stream-rails">Code Samples</a>
|
|
15
|
+
·
|
|
16
|
+
<a href="https://github.com/GetStream/stream-ruby/issues">Report Bug</a>
|
|
17
|
+
·
|
|
18
|
+
<a href="https://github.com/GetStream/stream-ruby/issues">Request Feature</a>
|
|
19
|
+
</p>
|
|
6
20
|
|
|
7
|
-
|
|
21
|
+
## 📝 About Stream
|
|
8
22
|
|
|
9
|
-
|
|
23
|
+
> 💡 This is a library for the **Feeds** product. The Chat SDKs can be found [here](https://getstream.io/chat/docs/).
|
|
10
24
|
|
|
11
|
-
|
|
25
|
+
You can sign up for a Stream account at our [Get Started](https://getstream.io/get_started/) page.
|
|
12
26
|
|
|
13
|
-
|
|
27
|
+
You can use this library to access Feeds API endpoints server-side.
|
|
14
28
|
|
|
15
|
-
|
|
29
|
+
For the client-side integrations (web and mobile) have a look at the JavaScript, iOS and Android SDK libraries ([docs](https://getstream.io/activity-feeds/)). This API Client project requires Ruby 2.5.x at a minimum.
|
|
16
30
|
|
|
17
|
-
|
|
31
|
+
> 💡 We have a Rails integration available [here](https://github.com/GetStream/stream-rails).
|
|
32
|
+
|
|
33
|
+
## ⚙️ Installation
|
|
18
34
|
|
|
19
35
|
```bash
|
|
20
36
|
gem install 'stream-ruby'
|
|
21
37
|
```
|
|
22
38
|
|
|
23
|
-
|
|
39
|
+
|
|
40
|
+
## 📚 Full documentation
|
|
24
41
|
|
|
25
42
|
Documentation for this Ruby client are available at the [Stream website](https://getstream.io/docs/ruby/?language=ruby).
|
|
26
43
|
|
|
27
|
-
|
|
44
|
+
## ✨ Getting started
|
|
28
45
|
|
|
29
46
|
```ruby
|
|
30
47
|
# Instantiate a new client to connect to us east API endpoint
|
|
@@ -151,11 +168,12 @@ client.add_to_many(activity, feeds)
|
|
|
151
168
|
client.og('https://google.com')
|
|
152
169
|
```
|
|
153
170
|
|
|
154
|
-
|
|
155
|
-
|
|
171
|
+
## ✍️ Contributing
|
|
156
172
|
Project is licensed under the [BSD 3-Clause](LICENSE).
|
|
157
173
|
|
|
158
|
-
|
|
174
|
+
We welcome code changes that improve this library or fix a problem, please make sure to follow all best practices and add tests if applicable before submitting a Pull Request on Github. We are very happy to merge your code in the official repository. Make sure to sign our [Contributor License Agreement (CLA)](https://docs.google.com/forms/d/e/1FAIpQLScFKsKkAJI7mhCr7K9rEIOpqIDThrWxuvxnwUq2XkHyG154vQ/viewform) first. See our [license file](./LICENSE) for more details.
|
|
175
|
+
|
|
176
|
+
## 🧑💻 We are hiring!
|
|
159
177
|
|
|
160
178
|
We've recently closed a [$38 million Series B funding round](https://techcrunch.com/2021/03/04/stream-raises-38m-as-its-chat-and-activity-feed-apis-power-communications-for-1b-users/) and we keep actively growing.
|
|
161
179
|
Our APIs are used by more than a billion end-users, and you'll have a chance to make a huge impact on the product within a team of the strongest engineers all over the world.
|
data/lib/stream/client.rb
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
require 'faraday'
|
|
2
|
+
require 'faraday/net_http_persistent'
|
|
2
3
|
require 'stream/errors'
|
|
3
4
|
require 'stream/feed'
|
|
4
5
|
require 'stream/signer'
|
|
@@ -37,7 +38,7 @@ module Stream
|
|
|
37
38
|
#
|
|
38
39
|
def initialize(api_key = '', api_secret = '', app_id = nil, opts = {})
|
|
39
40
|
if api_key.nil? || api_key.empty?
|
|
40
|
-
env_url = ENV
|
|
41
|
+
env_url = ENV.fetch('STREAM_URL', nil)
|
|
41
42
|
if env_url =~ Stream::STREAM_URL_COM_RE
|
|
42
43
|
re = Stream::STREAM_URL_COM_RE
|
|
43
44
|
elsif env_url =~ Stream::STREAM_URL_IO_RE
|
|
@@ -45,7 +46,7 @@ module Stream
|
|
|
45
46
|
end
|
|
46
47
|
raise ArgumentError, 'empty api_key parameter and missing or invalid STREAM_URL env variable' unless re
|
|
47
48
|
|
|
48
|
-
matches = re.match(ENV
|
|
49
|
+
matches = re.match(ENV.fetch('STREAM_URL', nil))
|
|
49
50
|
api_key = matches['key']
|
|
50
51
|
api_secret = matches['secret']
|
|
51
52
|
app_id = matches['app_id']
|
|
@@ -170,7 +171,10 @@ module Stream
|
|
|
170
171
|
faraday.use RaiseHttpException
|
|
171
172
|
faraday.options[:open_timeout] = @options[:default_timeout]
|
|
172
173
|
faraday.options[:timeout] = @options[:default_timeout]
|
|
173
|
-
faraday.adapter
|
|
174
|
+
faraday.adapter :net_http_persistent, pool_size: 5 do |http|
|
|
175
|
+
# AWS load balancer idle timeout is 60 secs, so let's make it 59
|
|
176
|
+
http.idle_timeout = 59
|
|
177
|
+
end
|
|
174
178
|
end
|
|
175
179
|
@base_path = url_generator.base_path
|
|
176
180
|
@conn.path_prefix = base_path
|
|
@@ -199,17 +203,12 @@ module Stream
|
|
|
199
203
|
class RaiseHttpException < Faraday::Middleware
|
|
200
204
|
def call(env)
|
|
201
205
|
@app.call(env).on_complete do |response|
|
|
202
|
-
|
|
206
|
+
status_code = response[:status].to_i
|
|
207
|
+
case status_code
|
|
203
208
|
when 200..203
|
|
204
209
|
return response
|
|
205
|
-
|
|
206
|
-
|
|
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))
|
|
210
|
+
else
|
|
211
|
+
parse_error(response, status_code: status_code)
|
|
213
212
|
end
|
|
214
213
|
end
|
|
215
214
|
end
|
|
@@ -221,11 +220,48 @@ module Stream
|
|
|
221
220
|
|
|
222
221
|
private
|
|
223
222
|
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
223
|
+
EXCEPTION_CLASS_MAPPING = {
|
|
224
|
+
2 => StreamApiResponseApiKeyException,
|
|
225
|
+
3 => StreamApiResponseSignatureException,
|
|
226
|
+
4 => StreamApiResponseInputException,
|
|
227
|
+
5 => StreamApiResponseCustomFieldException,
|
|
228
|
+
6 => StreamApiResponseFeedConfigException,
|
|
229
|
+
7 => StreamApiResponseSiteSuspendedException,
|
|
230
|
+
8 => StreamApiResponseInvalidPaginationException,
|
|
231
|
+
9 => StreamApiResponseRateLimitReached,
|
|
232
|
+
10 => StreamApiResponseMissingUserException,
|
|
233
|
+
11 => StreamApiResponseRankingException,
|
|
234
|
+
12 => StreamApiResponseMissingRankingException,
|
|
235
|
+
13 => StreamApiResponseOldStorageBackendException,
|
|
236
|
+
14 => StreamApiResponseJinjaRuntimeException,
|
|
237
|
+
15 => StreamApiResponseBestPracticeException,
|
|
238
|
+
16 => StreamApiResponseDoesNotExistException,
|
|
239
|
+
17 => StreamApiResponseNotAllowedException,
|
|
240
|
+
22 => StreamApiResponseConflictException
|
|
241
|
+
}.freeze
|
|
242
|
+
private_constant :EXCEPTION_CLASS_MAPPING
|
|
243
|
+
|
|
244
|
+
def parse_error(response, status_code:)
|
|
245
|
+
body = JSON.parse(response.body)
|
|
246
|
+
code = body['code']
|
|
247
|
+
|
|
248
|
+
exception_class = EXCEPTION_CLASS_MAPPING[code] || StreamApiResponseException
|
|
249
|
+
case status_code
|
|
250
|
+
when 401
|
|
251
|
+
raise exception_class, error_message(response, 'Bad feed')
|
|
252
|
+
when 403
|
|
253
|
+
raise exception_class, error_message(response, 'Bad auth/headers')
|
|
254
|
+
when 404
|
|
255
|
+
raise exception_class, error_message(response, 'url not found')
|
|
256
|
+
when 204...600
|
|
257
|
+
raise exception_class, error_message(response, _build_error_message(body))
|
|
258
|
+
end
|
|
259
|
+
end
|
|
260
|
+
|
|
261
|
+
def _build_error_message(body)
|
|
262
|
+
msg = "#{body['exception']} details: #{body['detail']}"
|
|
263
|
+
if body.key?('exception_fields')
|
|
264
|
+
body['exception_fields'].map do |field, messages|
|
|
229
265
|
msg << "\n#{field}: #{messages}"
|
|
230
266
|
end
|
|
231
267
|
end
|
data/lib/stream/errors.rb
CHANGED
|
@@ -3,5 +3,39 @@ module Stream
|
|
|
3
3
|
|
|
4
4
|
class StreamApiResponseException < Error; end
|
|
5
5
|
|
|
6
|
+
class StreamApiResponseApiKeyException < StreamApiResponseException; end
|
|
7
|
+
|
|
8
|
+
class StreamApiResponseSignatureException < StreamApiResponseException; end
|
|
9
|
+
|
|
10
|
+
class StreamApiResponseInputException < StreamApiResponseException; end
|
|
11
|
+
|
|
12
|
+
class StreamApiResponseCustomFieldException < StreamApiResponseException; end
|
|
13
|
+
|
|
14
|
+
class StreamApiResponseFeedConfigException < StreamApiResponseException; end
|
|
15
|
+
|
|
16
|
+
class StreamApiResponseSiteSuspendedException < StreamApiResponseException; end
|
|
17
|
+
|
|
18
|
+
class StreamApiResponseInvalidPaginationException < StreamApiResponseException; end
|
|
19
|
+
|
|
20
|
+
class StreamApiResponseRateLimitReached < StreamApiResponseException; end
|
|
21
|
+
|
|
22
|
+
class StreamApiResponseMissingRankingException < StreamApiResponseFeedConfigException; end
|
|
23
|
+
|
|
24
|
+
class StreamApiResponseMissingUserException < StreamApiResponseException; end
|
|
25
|
+
|
|
26
|
+
class StreamApiResponseRankingException < StreamApiResponseFeedConfigException; end
|
|
27
|
+
|
|
28
|
+
class StreamApiResponseOldStorageBackendException < StreamApiResponseException; end
|
|
29
|
+
|
|
30
|
+
class StreamApiResponseJinjaRuntimeException < StreamApiResponseException; end
|
|
31
|
+
|
|
32
|
+
class StreamApiResponseBestPracticeException < StreamApiResponseException; end
|
|
33
|
+
|
|
34
|
+
class StreamApiResponseDoesNotExistException < StreamApiResponseException; end
|
|
35
|
+
|
|
36
|
+
class StreamApiResponseNotAllowedException < StreamApiResponseException; end
|
|
37
|
+
|
|
38
|
+
class StreamApiResponseConflictException < StreamApiResponseException; end
|
|
39
|
+
|
|
6
40
|
class StreamInputData < Error; end
|
|
7
41
|
end
|
data/lib/stream/feed.rb
CHANGED
|
@@ -158,6 +158,19 @@ module Stream
|
|
|
158
158
|
@client.make_request(:delete, uri, auth_token, params)
|
|
159
159
|
end
|
|
160
160
|
|
|
161
|
+
def follow_stats(followers_slugs = nil, following_slugs = nil)
|
|
162
|
+
uri = '/stats/follow'
|
|
163
|
+
params = {
|
|
164
|
+
followers: @id,
|
|
165
|
+
following: @id
|
|
166
|
+
}
|
|
167
|
+
params[:followers_slugs] = followers_slugs.join(',') if followers_slugs
|
|
168
|
+
params[:following_slugs] = following_slugs.join(',') if following_slugs
|
|
169
|
+
auth_token = create_jwt_token('*', 'read', '*')
|
|
170
|
+
|
|
171
|
+
@client.make_request(:get, uri, auth_token, params)
|
|
172
|
+
end
|
|
173
|
+
|
|
161
174
|
private
|
|
162
175
|
|
|
163
176
|
def create_jwt_token(resource, action, feed_id = nil, user_id = nil)
|
data/lib/stream/url.rb
CHANGED
|
@@ -12,8 +12,8 @@ module Stream
|
|
|
12
12
|
location = make_location(options[:location])
|
|
13
13
|
location ||= 'api'
|
|
14
14
|
api_version = options[:api_version] || 'v1.0'
|
|
15
|
-
if ENV
|
|
16
|
-
uri = URI.parse(ENV
|
|
15
|
+
if ENV.fetch('STREAM_URL', nil)
|
|
16
|
+
uri = URI.parse(ENV.fetch('STREAM_URL'))
|
|
17
17
|
scheme = uri.scheme
|
|
18
18
|
host = uri.host
|
|
19
19
|
port = uri.port
|
|
@@ -22,7 +22,7 @@ module Stream
|
|
|
22
22
|
host = options[:api_hostname]
|
|
23
23
|
port = 443
|
|
24
24
|
end
|
|
25
|
-
unless ENV
|
|
25
|
+
unless ENV.fetch('STREAM_URL', nil) =~ /localhost/
|
|
26
26
|
host_parts = host.split('.')
|
|
27
27
|
host = host_parts.slice(1..-1).join('.') if host_parts.length == 3
|
|
28
28
|
host = "#{location}.#{host}" if location
|
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.
|
|
4
|
+
version: 4.6.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: 2022-09-21 00:00:00.000000000 Z
|
|
14
14
|
dependencies:
|
|
15
15
|
- !ruby/object:Gem::Dependency
|
|
16
16
|
name: faraday
|
|
@@ -26,6 +26,20 @@ dependencies:
|
|
|
26
26
|
- - ">="
|
|
27
27
|
- !ruby/object:Gem::Version
|
|
28
28
|
version: '0'
|
|
29
|
+
- !ruby/object:Gem::Dependency
|
|
30
|
+
name: faraday-net_http_persistent
|
|
31
|
+
requirement: !ruby/object:Gem::Requirement
|
|
32
|
+
requirements:
|
|
33
|
+
- - ">="
|
|
34
|
+
- !ruby/object:Gem::Version
|
|
35
|
+
version: '0'
|
|
36
|
+
type: :runtime
|
|
37
|
+
prerelease: false
|
|
38
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
39
|
+
requirements:
|
|
40
|
+
- - ">="
|
|
41
|
+
- !ruby/object:Gem::Version
|
|
42
|
+
version: '0'
|
|
29
43
|
- !ruby/object:Gem::Dependency
|
|
30
44
|
name: jwt
|
|
31
45
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -40,6 +54,20 @@ dependencies:
|
|
|
40
54
|
- - ">="
|
|
41
55
|
- !ruby/object:Gem::Version
|
|
42
56
|
version: '0'
|
|
57
|
+
- !ruby/object:Gem::Dependency
|
|
58
|
+
name: net-http-persistent
|
|
59
|
+
requirement: !ruby/object:Gem::Requirement
|
|
60
|
+
requirements:
|
|
61
|
+
- - ">="
|
|
62
|
+
- !ruby/object:Gem::Version
|
|
63
|
+
version: '0'
|
|
64
|
+
type: :runtime
|
|
65
|
+
prerelease: false
|
|
66
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
67
|
+
requirements:
|
|
68
|
+
- - ">="
|
|
69
|
+
- !ruby/object:Gem::Version
|
|
70
|
+
version: '0'
|
|
43
71
|
- !ruby/object:Gem::Dependency
|
|
44
72
|
name: rake
|
|
45
73
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -110,7 +138,13 @@ files:
|
|
|
110
138
|
homepage: http://github.com/GetStream/stream-ruby
|
|
111
139
|
licenses:
|
|
112
140
|
- BSD-3-Clause
|
|
113
|
-
metadata:
|
|
141
|
+
metadata:
|
|
142
|
+
rubygems_mfa_required: 'false'
|
|
143
|
+
homepage_uri: https://getstream.io/activity-feeds/
|
|
144
|
+
bug_tracker_uri: https://github.com/GetStream/stream-ruby/issues
|
|
145
|
+
documentation_uri: https://getstream.io/activity-feeds/docs/ruby/?language=ruby
|
|
146
|
+
changelog_uri: https://github.com/GetStream/stream-ruby/blob/main/CHANGELOG.md
|
|
147
|
+
source_code_uri: https://github.com/GetStream/stream-ruby
|
|
114
148
|
post_install_message:
|
|
115
149
|
rdoc_options: []
|
|
116
150
|
require_paths:
|