stream-ruby 4.5.0 → 4.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ae1395d26cf2fc594224dfc4fb2acd18d5b9ecacb5c8def51ce8df295e1fead8
4
- data.tar.gz: 4765a2b7e087bc060e22d14eca4ee37875c24d802c21455655eaa0c44b466ada
3
+ metadata.gz: bdef85497ab7ca002728c569b246ad90a804ea8f40a7bc0596cd22190df551d6
4
+ data.tar.gz: e7a9977ea752848600e057f38ebdeefbe8762da4eb1a6c8d66173efd8d332c24
5
5
  SHA512:
6
- metadata.gz: ca9c4dc2e6978ccc1961821c6375607bd4ad10f22ffd3f950bf1493a616d4262b6e027cd26cee507260b6238814854edafe0b6a9b7fbc54732430693422bdbd3
7
- data.tar.gz: 81996ad7e64df4fb2da41487a05570395a185000c2dd5124721b637959f7c6c2782d40089dc8461933d93654f145c3872ae3167b727c8ee8cd8cc1243744e81d
6
+ metadata.gz: f88ce620bb7d599a7b6d557c97c7170240193c1a3ed8541e02fb84f631ab9a986d1e8404f54e8205b2cdb7882516dd1f37b6739d8a05390ae63b858641cb1318
7
+ data.tar.gz: ea8247db45adad7bc0e339ecc0de437089cae55c7272d5e6980e0bd82dacf688af6e31e0aaa03714424288fecdbb4a90fbf7bdc0e0c6751cef882debd3a075a0
data/README.md CHANGED
@@ -1,30 +1,47 @@
1
- # stream-ruby
1
+ # Official Ruby SDK for [Stream Feeds](https://getstream.io/activity-feeds/)
2
2
 
3
3
  [![build](https://github.com/GetStream/stream-ruby/workflows/build/badge.svg)](https://github.com/GetStream/stream-ruby/actions) [![Gem Version](https://badge.fury.io/rb/stream-ruby.svg)](http://badge.fury.io/rb/stream-ruby)
4
4
 
5
- [stream-ruby](https://github.com/GetStream/stream-ruby) is the official Ruby client for [Stream](https://getstream.io/), a web service for building scalable newsfeeds and activity streams.
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
- Note there is also a higher level [Ruby on Rails - Stream integration](https://github.com/getstream/stream-rails) library which hooks into the Ruby on Rails ORM.
21
+ ## 📝 About Stream
8
22
 
9
- You can sign up for a Stream account at https://getstream.io/get_started.
23
+ > 💡 This is a library for the **Feeds** product. The Chat SDKs can be found [here](https://getstream.io/chat/docs/).
10
24
 
11
- #### Ruby version requirements and support
25
+ You can sign up for a Stream account at our [Get Started](https://getstream.io/get_started/) page.
12
26
 
13
- This API Client project requires Ruby 2.5.x at a minimum.
27
+ You can use this library to access Feeds API endpoints server-side.
14
28
 
15
- See the [Travis configuration](.travis.yml) for details of how it is built and tested.
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
- ### Installation
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
- ### Full documentation
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
- ### Usage
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
- ### Copyright and License Information
155
-
171
+ ## ✍️ Contributing
156
172
  Project is licensed under the [BSD 3-Clause](LICENSE).
157
173
 
158
- ## We are hiring!
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
@@ -38,7 +38,7 @@ module Stream
38
38
  #
39
39
  def initialize(api_key = '', api_secret = '', app_id = nil, opts = {})
40
40
  if api_key.nil? || api_key.empty?
41
- env_url = ENV['STREAM_URL']
41
+ env_url = ENV.fetch('STREAM_URL', nil)
42
42
  if env_url =~ Stream::STREAM_URL_COM_RE
43
43
  re = Stream::STREAM_URL_COM_RE
44
44
  elsif env_url =~ Stream::STREAM_URL_IO_RE
@@ -46,7 +46,7 @@ module Stream
46
46
  end
47
47
  raise ArgumentError, 'empty api_key parameter and missing or invalid STREAM_URL env variable' unless re
48
48
 
49
- matches = re.match(ENV['STREAM_URL'])
49
+ matches = re.match(ENV.fetch('STREAM_URL', nil))
50
50
  api_key = matches['key']
51
51
  api_secret = matches['secret']
52
52
  app_id = matches['app_id']
@@ -203,17 +203,12 @@ module Stream
203
203
  class RaiseHttpException < Faraday::Middleware
204
204
  def call(env)
205
205
  @app.call(env).on_complete do |response|
206
- case response[:status].to_i
206
+ status_code = response[:status].to_i
207
+ case status_code
207
208
  when 200..203
208
209
  return response
209
- when 401
210
- raise StreamApiResponseException, error_message(response, 'Bad feed')
211
- when 403
212
- raise StreamApiResponseException, error_message(response, 'Bad auth/headers')
213
- when 404
214
- raise StreamApiResponseException, error_message(response, 'url not found')
215
- when 204...600
216
- raise StreamApiResponseException, error_message(response, _build_error_message(response.body))
210
+ else
211
+ parse_error(response, status_code: status_code)
217
212
  end
218
213
  end
219
214
  end
@@ -225,11 +220,48 @@ module Stream
225
220
 
226
221
  private
227
222
 
228
- def _build_error_message(response)
229
- response = JSON.parse(response)
230
- msg = "#{response['exception']} details: #{response['detail']}"
231
- if response.key?('exception_fields')
232
- response['exception_fields'].map do |field, messages|
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|
233
265
  msg << "\n#{field}: #{messages}"
234
266
  end
235
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['STREAM_URL']
16
- uri = URI.parse(ENV['STREAM_URL'])
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['STREAM_URL'] =~ /localhost/
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
@@ -1,3 +1,3 @@
1
1
  module Stream
2
- VERSION = '4.5.0'.freeze
2
+ VERSION = '4.6.0'.freeze
3
3
  end
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.5.0
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: 2022-01-26 00:00:00.000000000 Z
13
+ date: 2022-09-21 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: faraday
@@ -139,6 +139,7 @@ homepage: http://github.com/GetStream/stream-ruby
139
139
  licenses:
140
140
  - BSD-3-Clause
141
141
  metadata:
142
+ rubygems_mfa_required: 'false'
142
143
  homepage_uri: https://getstream.io/activity-feeds/
143
144
  bug_tracker_uri: https://github.com/GetStream/stream-ruby/issues
144
145
  documentation_uri: https://getstream.io/activity-feeds/docs/ruby/?language=ruby