stream-ruby 3.1.0 → 4.0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 05ce0c71f39cd30007d6dcd0672a1155c6ac917b5a37d851ee20d50eba9f08c0
4
- data.tar.gz: 509f5e5c59cce2bfd309552defaa39b9ed69b6407c9a0e537f1c6fb1a01fe882
3
+ metadata.gz: 31aab2710cc563a2d15372a93ef3c7247525e3579a0fc3208f08986cbdab50ba
4
+ data.tar.gz: 6d6c543c663e877798aad76d4af12c8b6c6db23bdbaa3fda050418bf460ff191
5
5
  SHA512:
6
- metadata.gz: 0edd4f3150ba8b8f3bb25b62f18bfa55e9a7a90eee73641518a7cb134bc4b14639db033e5f70afb005d93e7dbfa1ad183f2a1676115af279022be0aa764bcaec
7
- data.tar.gz: ef0007cfe4c1017f4e1cdd054b277fb51287cba6fc6a67fa5ec60fa06dfd0fd3c6f40f84ebee6d737a7eb603ae9528995bbcfe81ece28aadcd4becc86f4e339e
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.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-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.
@@ -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{|e|
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
- signature = Stream::Signer.create_jwt_token('activities', '*', @api_secret, '*')
146
- make_request(:post, '/activity/', signature, {}, {:changes => changes})
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
@@ -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
- :feeds => feeds,
56
- :activity => activity_data
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)
@@ -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,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
- {: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
+ 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
- return ::JSON.parse(response[:body])
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
- when 200..203
200
- return response
201
- when 401
202
- raise StreamApiResponseException, error_message(response, 'Bad feed')
203
- when 403
204
- raise StreamApiResponseException, error_message(response, 'Bad auth/headers')
205
- when 404
206
- raise StreamApiResponseException, error_message(response, 'url not found')
207
- when 204...600
208
- 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))
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].to_s + ':', body].compact.join(' ')}"
236
+ "#{response[:method].to_s.upcase} #{response[:url]}: #{["#{response[:status]}:", body].compact.join(' ')}"
233
237
  end
234
238
  end
235
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
@@ -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)
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 = 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)
@@ -111,15 +97,9 @@ module Stream
111
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
@@ -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
@@ -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'
@@ -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.1.0'.freeze
2
+ VERSION = '4.0.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.1.0
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: 2019-01-23 00:00:00.000000000 Z
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: '2.10'
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: '2.10'
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.7'
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.7'
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: '0'
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
- rubyforge_project:
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