stream-ruby 3.0.1 → 4.1.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: b1234ef10092da5e7ceade3115fc2036afee959883ab2ac22c96480106157f5b
4
- data.tar.gz: 6f5c5f1a2b91385f4497a9695a1cf018d216a5b737835aecfaddaada0c31dce8
3
+ metadata.gz: 9aef0477b7b269f76432beea87cab0b7d41e5887ffdb69100abd1096421028c5
4
+ data.tar.gz: a0974c2b7e0d8967656f7433ea04b7ece51cfb72253aede20793710e6cb318f8
5
5
  SHA512:
6
- metadata.gz: 53793fe9fd892a88959ab38b62b1096d6f71b521e5ea7087a85354685dbaa857bb4f643863edb8281e7a187b0388810c7a2f972277de6fb4c63123339c06d46c
7
- data.tar.gz: 964cc5bad77573acb2a2c4e1856a910fdf5f2ed6ff12f565b1b7c864cecf64b15c1f00ef8c935a983906abadbe6d709867c1638bdf6ebd8341c253bded1495b3
6
+ metadata.gz: 9838aedac28f96372299682572fc3de5a4c8e946ebe1d60dc5851c5cafe26a2ea9d3c44aca46f8e851d2337021e49da77442306db67cca95c30002b06b9267ad
7
+ data.tar.gz: 76c77e37c537150587dfff557b6b3870276f1ce87054119a5653960b7dc07c6cce9d9bf2e250af937d6fbb0fa674316fbd62127c61facff850b6bb6758391feb
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2014-2017 Stream.io Inc, and individual contributors.
1
+ Copyright (c) 2014-2021 Stream.io Inc, and individual contributors.
2
2
 
3
3
  All rights reserved.
4
4
 
data/README.md CHANGED
@@ -1,7 +1,6 @@
1
- stream-ruby
2
- ===========
1
+ # stream-ruby
3
2
 
4
- [![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)
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)
5
4
 
6
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.
7
6
 
@@ -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.2.10 at a minimum. We will support the following versions:
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 "stream-ruby"
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', :location => 'us-east')
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(:limit=>5, :offset=>5)
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 = user_feed_1.get(:limit=>5, :id_lt=>'e561de8f-00f1-11e4-b400-0cc47a024be0')
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 = {:actor => 1, :verb => 'tweet', :object => 1, :foreign_id => 'tweet:1'}
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 = {:actor => 1, :verb => 'tweet', :object => 1, :foreign_id => 'tweet:1',
53
- :course => {:name => 'Golden Gate park', :distance => 10},
54
- :participants => ['Thierry', 'Tommaso'],
55
- :started_at => DateTime.now()
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 = {:actor => 1, :verb => 'tweet', :object => 1, :foreign_id => 'tweet:1', :popularity => 100, :time => '2016-05-13T16:12:30'}
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=true)
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
- [:actor => '1', :verb => 'tweet', :object => '1'],
81
- [:actor => '2', :verb => 'like', :object => '3']
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
- {:source => 'flat:1', :target => 'user:1'},
88
- {:source => 'flat:1', :target => 'user:2'},
89
- {:source => 'flat:1', :target => 'user:3'},
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=['user:42', 'user:43'])
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(flat:1 flat:2 flat:3 flat:4)
152
- activity = {:actor => "User:2", :verb => "pin", :object => "Place:42", :target => "Board:1"}
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-2018 Stream.io Inc, and individual contributors. All rights reserved.
156
+ Copyright (c) 2014-2021 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.
@@ -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
  #
@@ -8,34 +7,33 @@ module Stream
8
7
  #
9
8
  # @return the found activities, if any.
10
9
  #
11
- # @example
12
- #
10
+ # @example Retrieve by activity IDs
11
+ # @client.get_activities(
12
+ # ids: [
13
+ # '4b39fda2-d6e2-42c9-9abf-5301ef071b12',
14
+ # '89b910d3-1ef5-44f8-914e-e7735d79e817'
15
+ # ]
16
+ # )
13
17
  #
14
- # @client.get_activities(
15
- # ids: [
16
- # '4b39fda2-d6e2-42c9-9abf-5301ef071b12',
17
- # '89b910d3-1ef5-44f8-914e-e7735d79e817'
18
- # ]
19
- # )
20
- #
21
- # @client.get_activities(
22
- # foreign_id_times: [
23
- # { foreign_id: 'post:1000', time: '2016-11-10T13:20:00.000000' },
24
- # { foreign_id: 'like:2000', time: '2018-01-07T09:15:59.123456' }
25
- # ]
26
- # )
18
+ # @example Retrieve by Foreign IDs + timestamps
19
+ # @client.get_activities(
20
+ # foreign_id_times: [
21
+ # { foreign_id: 'post:1000', time: '2016-11-10T13:20:00.000000' },
22
+ # { foreign_id: 'like:2000', time: '2018-01-07T09:15:59.123456' }
23
+ # ]
24
+ # )
27
25
  #
28
26
  def get_activities(params = {})
29
27
  if params[:foreign_id_times]
30
28
  foreign_ids = []
31
29
  timestamps = []
32
- params[:foreign_id_times].each{|e|
30
+ params[:foreign_id_times].each do |e|
33
31
  foreign_ids << e[:foreign_id]
34
32
  timestamps << e[:time]
35
- }
33
+ end
36
34
  params = {
37
35
  foreign_ids: foreign_ids,
38
- timestamps: timestamps,
36
+ timestamps: timestamps
39
37
  }
40
38
  end
41
39
  signature = Stream::Signer.create_jwt_token('activities', '*', @api_secret, '*')
@@ -43,42 +41,108 @@ module Stream
43
41
  end
44
42
 
45
43
  #
46
- # Partial update activity, via foreign ID or Foreign ID + timestamp
44
+ # Partial update activity, via activity ID or Foreign ID + timestamp
47
45
  #
48
46
  # @param [Hash<:id, :foreign_id, :time, :set, :unset>] data the request params (id and foreign_id+timestamp mutually exclusive)
49
47
  #
50
48
  # @return the updated activity.
51
49
  #
52
- # @example
53
- #
54
- # @client.activity_partial_update(
55
- # id: "4b39fda2-d6e2-42c9-9abf-5301ef071b12",
56
- # set: {
57
- # "product.price.eur": 12.99,
58
- # "colors": {
59
- # "blue": "#0000ff",
60
- # "green": "#00ff00",
61
- # }
62
- # },
63
- # unset: [ "popularity", "size.xl" ]
64
- # )
65
- #
66
- # @client.activity_partial_update(
67
- # foreign_id: 'product:123',
68
- # time: '2016-11-10T13:20:00.000000',
69
- # set: {
70
- # "product.price.eur": 12.99,
71
- # "colors": {
72
- # "blue": "#0000ff",
73
- # "green": "#00ff00",
74
- # }
75
- # },
76
- # unset: [ "popularity", "size.xl" ]
77
- # )
50
+ # @example Identify using activity ID
51
+ # @client.activity_partial_update(
52
+ # id: "4b39fda2-d6e2-42c9-9abf-5301ef071b12",
53
+ # set: {
54
+ # "product.price.eur": 12.99,
55
+ # "colors": {
56
+ # "blue": "#0000ff",
57
+ # "green": "#00ff00",
58
+ # }
59
+ # },
60
+ # unset: [ "popularity", "size.xl" ]
61
+ # )
62
+ #
63
+ # @example Identify using Foreign ID + timestamp
64
+ # @client.activity_partial_update(
65
+ # foreign_id: 'product:123',
66
+ # time: '2016-11-10T13:20:00.000000',
67
+ # set: {
68
+ # "product.price.eur": 12.99,
69
+ # "colors": {
70
+ # "blue": "#0000ff",
71
+ # "green": "#00ff00",
72
+ # }
73
+ # },
74
+ # unset: [ "popularity", "size.xl" ]
75
+ # )
76
+ #
78
77
  def activity_partial_update(data = {})
79
78
  signature = Stream::Signer.create_jwt_token('activities', '*', @api_secret, '*')
80
79
  make_request(:post, '/activity/', signature, {}, data)
81
80
  end
82
81
 
82
+ #
83
+ # Batch partial activity update
84
+ #
85
+ # @param [Array< Hash<:id, :foreign_id, :time, :set, :unset> >] changes the list of changes to be applied
86
+ #
87
+ # @return the updated activities
88
+ #
89
+ # @example Identify using activity IDs
90
+ # @client.batch_activity_partial_update([
91
+ # {
92
+ # id: "4b39fda2-d6e2-42c9-9abf-5301ef071b12",
93
+ # set: {
94
+ # "product.price.eur": 12.99,
95
+ # "colors": {
96
+ # "blue": "#0000ff",
97
+ # "green": "#00ff00",
98
+ # }
99
+ # },
100
+ # unset: [ "popularity", "size.x2" ]
101
+ # },
102
+ # {
103
+ # id: "8d2dcad8-1e34-11e9-8b10-9cb6d0925edd",
104
+ # set: {
105
+ # "product.price.eur": 17.99,
106
+ # "colors": {
107
+ # "red": "#ff0000",
108
+ # "green": "#00ff00",
109
+ # }
110
+ # },
111
+ # unset: [ "rating" ]
112
+ # }
113
+ # ])
114
+ #
115
+ # @example Identify using Foreign IDs + timestamps
116
+ # @client.batch_activity_partial_update([
117
+ # {
118
+ # foreign_id: "product:123",
119
+ # time: '2016-11-10T13:20:00.000000',
120
+ # set: {
121
+ # "product.price.eur": 22.99,
122
+ # "colors": {
123
+ # "blue": "#0000ff",
124
+ # "green": "#00ff00",
125
+ # }
126
+ # },
127
+ # unset: [ "popularity", "size.x2" ]
128
+ # },
129
+ # {
130
+ # foreign_id: "product:1234",
131
+ # time: '2017-11-10T13:20:00.000000',
132
+ # set: {
133
+ # "product.price.eur": 37.99,
134
+ # "colors": {
135
+ # "black": "#000000",
136
+ # "white": "#ffffff",
137
+ # }
138
+ # },
139
+ # unset: [ "rating" ]
140
+ # }
141
+ # ])
142
+ #
143
+ def batch_activity_partial_update(changes = [])
144
+ signature = Stream::Signer.create_jwt_token('activities', '*', @api_secret, '*')
145
+ make_request(:post, '/activity/', signature, {}, { changes: changes })
146
+ end
83
147
  end
84
148
  end
data/lib/stream/batch.rb CHANGED
@@ -8,19 +8,15 @@ module Stream
8
8
  # @return [nil]
9
9
  #
10
10
  # @example
11
- #
12
- #
13
- # follows = [
14
- # {:source => 'flat:1', :target => 'user:1'},
15
- # {:source => 'flat:1', :target => 'user:3'}
16
- # ]
17
- # @client.follow_many(follows)
11
+ # follows = [
12
+ # {:source => 'flat:1', :target => 'user:1'},
13
+ # {:source => 'flat:1', :target => 'user:3'}
14
+ # ]
15
+ # @client.follow_many(follows)
18
16
  #
19
17
  def follow_many(follows, activity_copy_limit = nil)
20
18
  query_params = {}
21
- unless activity_copy_limit.nil?
22
- query_params['activity_copy_limit'] = activity_copy_limit
23
- end
19
+ query_params['activity_copy_limit'] = activity_copy_limit unless activity_copy_limit.nil?
24
20
  signature = Stream::Signer.create_jwt_token('follower', '*', @api_secret, '*')
25
21
  make_request(:post, '/follow_many/', signature, query_params, follows)
26
22
  end
@@ -33,13 +29,11 @@ module Stream
33
29
  # return [nil]
34
30
  #
35
31
  # @example
36
- #
37
- #
38
- # unfollows = [
39
- # {source: 'user:1', target: 'timeline:1'},
40
- # {source: 'user:2', target: 'timeline:2', keep_history: false}
41
- # ]
42
- # @client.unfollow_many(unfollows)
32
+ # unfollows = [
33
+ # {source: 'user:1', target: 'timeline:1'},
34
+ # {source: 'user:2', target: 'timeline:2', keep_history: false}
35
+ # ]
36
+ # @client.unfollow_many(unfollows)
43
37
  #
44
38
  def unfollow_many(unfollows)
45
39
  signature = Stream::Signer.create_jwt_token('follower', '*', @api_secret, '*')
@@ -56,8 +50,8 @@ module Stream
56
50
  #
57
51
  def add_to_many(activity_data, feeds)
58
52
  data = {
59
- :feeds => feeds,
60
- :activity => activity_data
53
+ feeds: feeds,
54
+ activity: activity_data
61
55
  }
62
56
  signature = Stream::Signer.create_jwt_token('feed', '*', @api_secret, '*')
63
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\:\/\/(?<key>\w+)\:(?<secret>\w+)@((api\.)|((?<location>[-\w]+)\.))?(?<api_hostname>stream-io-api\.com)\/[\w=-\?%&]+app_id=(?<app_id>\d+)}i
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
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
- return Stream::Signer.create_user_token(user_id, extra_data, api_secret)
102
+ Stream::Signer.create_user_token(user_id, extra_data, api_secret)
104
103
  end
105
104
 
106
105
  def personalization
@@ -128,22 +127,26 @@ 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
- {:api_key => @api_key}
136
+ { api_key: @api_key }
133
137
  end
134
138
 
135
139
  def get_http_client
136
- @http_client ||= StreamHTTPClient.new(url_generator)
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, v| k.to_s}]
144
+ get_default_params.merge(params).sort_by { |k, _v| k.to_s }.to_h
141
145
  end
142
146
 
143
147
  def make_request(method, relative_url, signature, params = {}, data = {}, headers = {})
144
148
  headers['Authorization'] = signature
145
149
  headers['stream-auth-type'] = 'jwt'
146
-
147
150
  get_http_client.make_http_request(method, relative_url, make_query_params(params), data, headers)
148
151
  end
149
152
 
@@ -188,7 +191,7 @@ module Stream
188
191
 
189
192
  case response[:status].to_i
190
193
  when 200..203
191
- return ::JSON.parse(response[:body])
194
+ ::JSON.parse(response[:body])
192
195
  end
193
196
  end
194
197
  end
@@ -197,16 +200,16 @@ module Stream
197
200
  def call(env)
198
201
  @app.call(env).on_complete do |response|
199
202
  case response[:status].to_i
200
- when 200..203
201
- return response
202
- when 401
203
- raise StreamApiResponseException, error_message(response, 'Bad feed')
204
- when 403
205
- raise StreamApiResponseException, error_message(response, 'Bad auth/headers')
206
- when 404
207
- raise StreamApiResponseException, error_message(response, 'url not found')
208
- when 204...600
209
- raise StreamApiResponseException, error_message(response, _build_error_message(response.body))
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))
210
213
  end
211
214
  end
212
215
  end
@@ -230,7 +233,7 @@ module Stream
230
233
  end
231
234
 
232
235
  def error_message(response, body = nil)
233
- "#{response[:method].to_s.upcase} #{response[:url]}: #{[response[:status].to_s + ':', body].compact.join(' ')}"
236
+ "#{response[:method].to_s.upcase} #{response[:url]}: #{["#{response[:status]}:", body].compact.join(' ')}"
234
237
  end
235
238
  end
236
239
  end
@@ -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, :endpoint => uri)
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, {}, {}, :endpoint => uri)
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, :endpoint => uri)
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, {}, {}, :endpoint => uri)
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
- _id = id
57
- if id.respond_to?(:keys) and !id["id"].nil?
58
- _id = id["id"]
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/errors.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  module Stream
2
2
  class Error < StandardError; end
3
+
3
4
  class StreamApiResponseException < Error; end
5
+
4
6
  class StreamInputData < Error; end
5
7
  end
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] or params[:reactions]
41
- uri = "/enrich/feed/#{@feed_url}/"
42
- else
43
- uri = "/feed/#{@feed_url}/"
44
- end
45
- if params[:mark_read] && params[:mark_read].is_a?(Array)
46
- params[:mark_read] = params[:mark_read].join(',')
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
- params[:withOwnReactions] = true
54
- end
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
- [:enrich, :reactions].each { |k| params.delete(k) }
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 => 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 = false)
85
- remove_activity(activity_id, foreign_id)
70
+ def remove(activity_id, foreign_id: false)
71
+ remove_activity(activity_id, foreign_id: foreign_id)
86
72
  end
87
73
 
88
- def remove_activity(activity_id, foreign_id = false)
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)
@@ -107,19 +93,13 @@ module Stream
107
93
  def update_activity_to_targets(foreign_id, time, new_targets: nil, added_targets: nil, removed_targets: nil)
108
94
  uri = "/feed_targets/#{@feed_url}/activity_to_targets/"
109
95
  data = {
110
- 'foreign_id': foreign_id,
111
- 'time': time
96
+ foreign_id: foreign_id,
97
+ time: time
112
98
  }
113
99
 
114
- if !new_targets.nil?
115
- data['new_targets'] = new_targets
116
- end
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 < 0
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
- target: "#{target_feed_slug}:#{target_user_id}",
135
- activity_copy_limit: activity_copy_limit
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
- offset: offset,
146
- limit: limit
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
- offset: offset,
157
- limit: limit,
158
- filter: filter.join(',')
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 = false)
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 = {}
@@ -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, {}, {}, :endpoint => uri)
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, :endpoint => uri)
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, {}, {}, :endpoint => uri)
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
- lookup_field = ""
46
- lookup_value = ""
47
- kind = params.fetch(:kind, "")
45
+ field = ''
46
+ value = ''
47
+ kind = params.fetch(:kind, '')
48
48
  if params[:reaction_id]
49
- lookup_field = "reaction_id"
50
- lookup_value = params[:reaction_id]
49
+ field = 'reaction_id'
50
+ value = params[:reaction_id]
51
51
  elsif params[:activity_id]
52
- lookup_field = "activity_id"
53
- lookup_value = params[:activity_id]
52
+ field = 'activity_id'
53
+ value = params[:activity_id]
54
54
  elsif params[:user_id]
55
- lookup_field = "user_id"
56
- lookup_value = params[:user_id]
55
+ field = 'user_id'
56
+ value = params[:user_id]
57
57
  end
58
- unless lookup_field.empty?
59
- params.delete(lookup_field.to_sym)
60
- end
61
- if kind.nil? || kind.empty?
62
- uri = "/reaction/#{lookup_field}/#{lookup_value}/"
63
- else
64
- uri = "/reaction/#{lookup_field}/#{lookup_value}/#{kind}/"
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
- _id = id
71
- if id.respond_to?(:keys) and !id["id"].nil?
72
- _id = id["id"]
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
- return JWT.encode(payload, api_secret, 'HS256')
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
- resource: resource,
20
- action: action
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 ||= "api"
13
- api_version = options[:api_version] ? options[:api_version] : 'v1.0'
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, {}, {}, :endpoint => uri)
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, :endpoint => uri)
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, {}, {}, :endpoint => uri)
29
+ make_user_request(:delete, {}, {}, endpoint: uri)
30
30
  end
31
31
 
32
32
  def create_reference(id)
33
- _id = id
34
- if id.respond_to?(:keys) and !id["id"].nil?
35
- _id = id["id"]
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
@@ -1,3 +1,3 @@
1
1
  module Stream
2
- VERSION = '3.0.1'.freeze
2
+ VERSION = '4.1.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: 3.0.1
4
+ version: 4.1.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: 2018-12-19 00:00:00.000000000 Z
13
+ date: 2021-03-15 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: faraday
@@ -18,82 +18,70 @@ dependencies:
18
18
  requirements:
19
19
  - - ">="
20
20
  - !ruby/object:Gem::Version
21
- version: 0.10.0
22
- - - "<"
23
- - !ruby/object:Gem::Version
24
- version: '1.0'
21
+ version: '0'
25
22
  type: :runtime
26
23
  prerelease: false
27
24
  version_requirements: !ruby/object:Gem::Requirement
28
25
  requirements:
29
26
  - - ">="
30
27
  - !ruby/object:Gem::Version
31
- version: 0.10.0
32
- - - "<"
33
- - !ruby/object:Gem::Version
34
- version: '1.0'
28
+ version: '0'
35
29
  - !ruby/object:Gem::Dependency
36
30
  name: jwt
37
31
  requirement: !ruby/object:Gem::Requirement
38
32
  requirements:
39
33
  - - ">="
40
34
  - !ruby/object:Gem::Version
41
- version: 2.1.0
42
- - - "~>"
43
- - !ruby/object:Gem::Version
44
- version: '2.1'
35
+ version: '0'
45
36
  type: :runtime
46
37
  prerelease: false
47
38
  version_requirements: !ruby/object:Gem::Requirement
48
39
  requirements:
49
40
  - - ">="
50
41
  - !ruby/object:Gem::Version
51
- version: 2.1.0
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: '2.1'
42
+ version: '0'
55
43
  - !ruby/object:Gem::Dependency
56
44
  name: rake
57
45
  requirement: !ruby/object:Gem::Requirement
58
46
  requirements:
59
- - - "~>"
47
+ - - ">="
60
48
  - !ruby/object:Gem::Version
61
49
  version: '0'
62
50
  type: :development
63
51
  prerelease: false
64
52
  version_requirements: !ruby/object:Gem::Requirement
65
53
  requirements:
66
- - - "~>"
54
+ - - ">="
67
55
  - !ruby/object:Gem::Version
68
56
  version: '0'
69
57
  - !ruby/object:Gem::Dependency
70
58
  name: rspec
71
59
  requirement: !ruby/object:Gem::Requirement
72
60
  requirements:
73
- - - "~>"
61
+ - - ">="
74
62
  - !ruby/object:Gem::Version
75
- version: '2.10'
63
+ version: '0'
76
64
  type: :development
77
65
  prerelease: false
78
66
  version_requirements: !ruby/object:Gem::Requirement
79
67
  requirements:
80
- - - "~>"
68
+ - - ">="
81
69
  - !ruby/object:Gem::Version
82
- version: '2.10'
70
+ version: '0'
83
71
  - !ruby/object:Gem::Dependency
84
72
  name: simplecov
85
73
  requirement: !ruby/object:Gem::Requirement
86
74
  requirements:
87
- - - "~>"
75
+ - - ">="
88
76
  - !ruby/object:Gem::Version
89
- version: '0.7'
77
+ version: '0'
90
78
  type: :development
91
79
  prerelease: false
92
80
  version_requirements: !ruby/object:Gem::Requirement
93
81
  requirements:
94
- - - "~>"
82
+ - - ">="
95
83
  - !ruby/object:Gem::Version
96
- version: '0.7'
84
+ version: '0'
97
85
  description: Ruby client for getstream.io service
98
86
  email: support@getstream.io
99
87
  executables: []
@@ -131,15 +119,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
131
119
  requirements:
132
120
  - - ">="
133
121
  - !ruby/object:Gem::Version
134
- version: '0'
122
+ version: 2.5.0
135
123
  required_rubygems_version: !ruby/object:Gem::Requirement
136
124
  requirements:
137
125
  - - ">="
138
126
  - !ruby/object:Gem::Version
139
127
  version: '0'
140
128
  requirements: []
141
- rubyforge_project:
142
- rubygems_version: 2.7.8
129
+ rubygems_version: 3.1.2
143
130
  signing_key:
144
131
  specification_version: 4
145
132
  summary: A gem that provides a client interface for getstream.io