stream-chat-ruby 0.1.3 → 1.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -1
- data/.travis.yml +5 -4
- data/CHANGELOG.md +25 -0
- data/README.md +4 -4
- data/lib/stream-chat/channel.rb +28 -0
- data/lib/stream-chat/client.rb +78 -6
- data/lib/stream-chat/errors.rb +2 -4
- data/lib/stream-chat/version.rb +1 -1
- data/stream-chat.gemspec +4 -4
- metadata +7 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '079b1dd49ca55175f23ad66e3237cba1437a3b046db9631b1541ae630d31a996'
|
4
|
+
data.tar.gz: 3728ef3fc6b4da313cdf0eb8c8aa8e76b5d2b2756f5f830a2f68f4e2edd7a76f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a96841c65178ec69d31f3deb9744dd0afaf1173fe149a1be33c8234ae8ef8c8aaf9e337843d8afa01492f1c3aaae8374d7a9d11021dab37688f580d4c08b6616
|
7
|
+
data.tar.gz: 5a7ac658a2757d90f3356824731c436225272951ab261eb19a5c15f6b82ab81076be58808d12fb23c596f22bebf562b31e187b1c8493e2aca79cebc668456b4e
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
## August 3rd, 2020 - 1.1.3
|
2
|
+
- Fixed Argument Error on delete_user
|
3
|
+
|
4
|
+
## April 23th, 2020 - 1.1.2
|
5
|
+
- Fixed ArgumentError when no users was passed
|
6
|
+
|
7
|
+
## March 30th, 2020 - 1.1.1
|
8
|
+
- Fixed few minor issues
|
9
|
+
|
10
|
+
## Oct 27th, 2019 - 1.1.0
|
11
|
+
|
12
|
+
- Mark gems use for testing as development dependencies
|
13
|
+
- Added `send_file`, `send_image`, `delete_file`, `delete_image`
|
14
|
+
- Added `invite_members`
|
15
|
+
|
16
|
+
## Oct 19th, 2019 - 1.0.0
|
17
|
+
|
18
|
+
- Added `channel.hide` and `channel.show`
|
19
|
+
- Added `client.flag_message` and `client.unflag_message`
|
20
|
+
- Added `client.flag_user` and `client.unflag_user`
|
21
|
+
- Added `client.get_message`
|
22
|
+
- Added `client.search`
|
23
|
+
- Added `client.update_users_partial`
|
24
|
+
- Added `client.update_user_partial`
|
25
|
+
- Added `client.reactivate_user`
|
data/README.md
CHANGED
@@ -60,9 +60,9 @@ client.create_token('bob-1')
|
|
60
60
|
|
61
61
|
```ruby
|
62
62
|
client.update_user({
|
63
|
-
|
64
|
-
|
65
|
-
|
63
|
+
:id => 'bob-1',
|
64
|
+
:role => 'admin',
|
65
|
+
:name => 'Robert Tables'
|
66
66
|
})
|
67
67
|
|
68
68
|
# batch update is also supported
|
@@ -161,7 +161,7 @@ See [an example rails application using the Ruby SDK](https://github.com/GetStre
|
|
161
161
|
First, make sure you can run the test suite. Tests are run via rspec
|
162
162
|
|
163
163
|
```bash
|
164
|
-
|
164
|
+
STREAM_CHAT_API_KEY=my_api_key STREAM_CHAT_API_SECRET=my_api_secret bundle exec rake spec
|
165
165
|
```
|
166
166
|
|
167
167
|
### Releasing a new version
|
data/lib/stream-chat/channel.rb
CHANGED
@@ -82,6 +82,10 @@ module StreamChat
|
|
82
82
|
@client.post(url, data: {"add_members": user_ids})
|
83
83
|
end
|
84
84
|
|
85
|
+
def invite_members(user_ids)
|
86
|
+
@client.post(url, data: {"invites": user_ids})
|
87
|
+
end
|
88
|
+
|
85
89
|
def add_moderators(user_ids)
|
86
90
|
@client.post(url, data: {"add_moderators": user_ids})
|
87
91
|
end
|
@@ -115,6 +119,30 @@ module StreamChat
|
|
115
119
|
@client.unban_user(user_id, type: @channel_type, id: @id)
|
116
120
|
end
|
117
121
|
|
122
|
+
def hide(user_id)
|
123
|
+
@client.post("#{url}/hide", data: {user_id: user_id})
|
124
|
+
end
|
125
|
+
|
126
|
+
def show(user_id)
|
127
|
+
@client.post("#{url}/show", data: {user_id: user_id})
|
128
|
+
end
|
129
|
+
|
130
|
+
def send_file(url, user, content_type = nil)
|
131
|
+
@client.send_file("#{self.url}/file", url, user, content_type)
|
132
|
+
end
|
133
|
+
|
134
|
+
def send_image(url, user, content_type = nil)
|
135
|
+
@client.send_file("#{self.url}/image", url, user, content_type)
|
136
|
+
end
|
137
|
+
|
138
|
+
def delete_file(url)
|
139
|
+
@client.delete("#{self.url}/file", params: {"url": url})
|
140
|
+
end
|
141
|
+
|
142
|
+
def delete_image(url)
|
143
|
+
@client.delete("#{self.url}/image", params: {"url": url})
|
144
|
+
end
|
145
|
+
|
118
146
|
private
|
119
147
|
|
120
148
|
def add_user_id(payload, user_id)
|
data/lib/stream-chat/client.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# lib/client.rb
|
2
|
+
require 'open-uri'
|
2
3
|
require 'faraday'
|
3
4
|
require 'jwt'
|
4
5
|
require 'stream-chat/channel'
|
@@ -7,6 +8,7 @@ require 'stream-chat/version'
|
|
7
8
|
|
8
9
|
module StreamChat
|
9
10
|
class Client
|
11
|
+
BASE_URL = 'https://chat-us-east-1.stream-io-api.com'
|
10
12
|
|
11
13
|
attr_reader :api_key
|
12
14
|
attr_reader :api_secret
|
@@ -28,12 +30,13 @@ module StreamChat
|
|
28
30
|
@api_secret = api_secret
|
29
31
|
@timeout = timeout
|
30
32
|
@options = options
|
31
|
-
@base_url = 'https://chat-us-east-1.stream-io-api.com'
|
32
33
|
@auth_token = JWT.encode({server: true}, @api_secret, 'HS256')
|
34
|
+
@base_url = options[:base_url] || BASE_URL
|
33
35
|
@conn = Faraday.new(url: @base_url) do |faraday|
|
34
36
|
faraday.options[:open_timeout] = @timeout
|
35
37
|
faraday.options[:timeout] = @timeout
|
36
|
-
faraday.
|
38
|
+
faraday.request :multipart
|
39
|
+
faraday.adapter :net_http
|
37
40
|
end
|
38
41
|
end
|
39
42
|
|
@@ -53,26 +56,73 @@ module StreamChat
|
|
53
56
|
get('app')
|
54
57
|
end
|
55
58
|
|
59
|
+
def flag_message(id, **options)
|
60
|
+
payload = {'target_message_id': id}.merge(options)
|
61
|
+
post("moderation/flag", data: payload)
|
62
|
+
end
|
63
|
+
|
64
|
+
def unflag_message(id, **options)
|
65
|
+
payload = {'target_message_id': id}.merge(options)
|
66
|
+
post("moderation/unflag", data: payload)
|
67
|
+
end
|
68
|
+
|
69
|
+
def flag_user(id, **options)
|
70
|
+
payload = {'target_user_id': id}.merge(options)
|
71
|
+
post("moderation/flag", data: payload)
|
72
|
+
end
|
73
|
+
|
74
|
+
def unflag_user(id, **options)
|
75
|
+
payload = {'target_user_id': id}.merge(options)
|
76
|
+
post("moderation/unflag", data: payload)
|
77
|
+
end
|
78
|
+
|
79
|
+
def get_message(id)
|
80
|
+
get("messages/#{id}")
|
81
|
+
end
|
82
|
+
|
83
|
+
def search(filter_conditions, query, **options)
|
84
|
+
params = options.merge({
|
85
|
+
"filter_conditions": filter_conditions,
|
86
|
+
"query": query,
|
87
|
+
})
|
88
|
+
|
89
|
+
get("search", params: {"payload": params.to_json})
|
90
|
+
end
|
91
|
+
|
56
92
|
def update_users(users)
|
57
93
|
payload = {}
|
58
94
|
users.each do |user|
|
59
|
-
|
95
|
+
id = user[:id] || user["id"]
|
96
|
+
raise ArgumentError, "user must have an id" unless id
|
97
|
+
payload[id] = user
|
60
98
|
end
|
61
99
|
post('users', data: {'users': payload})
|
62
100
|
end
|
63
101
|
|
64
102
|
def update_user(user)
|
65
|
-
|
103
|
+
update_users([user])
|
104
|
+
end
|
105
|
+
|
106
|
+
def update_users_partial(updates)
|
107
|
+
patch('users', data: {'users': updates})
|
108
|
+
end
|
109
|
+
|
110
|
+
def update_user_partial(update)
|
111
|
+
update_users_partial([update])
|
66
112
|
end
|
67
113
|
|
68
114
|
def delete_user(user_id, **options)
|
69
|
-
delete("users/#{user_id}",
|
115
|
+
delete("users/#{user_id}", params: options)
|
70
116
|
end
|
71
117
|
|
72
118
|
def deactivate_user(user_id, **options)
|
73
119
|
post("users/#{user_id}/deactivate", **options)
|
74
120
|
end
|
75
121
|
|
122
|
+
def reactivate_user(user_id, **options)
|
123
|
+
post("users/#{user_id}/reactivate", **options)
|
124
|
+
end
|
125
|
+
|
76
126
|
def export_user(user_id, **options)
|
77
127
|
get("users/#{user_id}/export", params: options)
|
78
128
|
end
|
@@ -218,6 +268,25 @@ module StreamChat
|
|
218
268
|
make_http_request(:patch, relative_url, params: params, data: data)
|
219
269
|
end
|
220
270
|
|
271
|
+
def send_file(relative_url, file_url, user, content_type = 'application/octet-stream')
|
272
|
+
url = [@base_url, relative_url].join('/')
|
273
|
+
|
274
|
+
file = open(file_url)
|
275
|
+
body = {user: user.to_json}
|
276
|
+
|
277
|
+
body[:file] = Faraday::UploadIO.new(file, content_type)
|
278
|
+
|
279
|
+
response = @conn.post url do |req|
|
280
|
+
req.headers["X-Stream-Client"] = get_user_agent
|
281
|
+
req.headers['Authorization'] = @auth_token
|
282
|
+
req.headers["stream-auth-type"] = "jwt"
|
283
|
+
req.params = get_default_params
|
284
|
+
req.body = body
|
285
|
+
end
|
286
|
+
|
287
|
+
parse_response(response)
|
288
|
+
end
|
289
|
+
|
221
290
|
private
|
222
291
|
|
223
292
|
def get_default_params
|
@@ -255,7 +324,10 @@ module StreamChat
|
|
255
324
|
params = params != nil ? params : {}
|
256
325
|
params = Hash[get_default_params.merge(params).sort_by { |k, v| k.to_s }]
|
257
326
|
url = "#{url}?#{URI.encode_www_form(params)}"
|
258
|
-
|
327
|
+
|
328
|
+
if %w[patch post put].include? method.to_s
|
329
|
+
body = data.to_json
|
330
|
+
end
|
259
331
|
|
260
332
|
response = @conn.run_request(
|
261
333
|
method,
|
data/lib/stream-chat/errors.rb
CHANGED
@@ -9,10 +9,8 @@ module StreamChat
|
|
9
9
|
begin
|
10
10
|
parsed_response = JSON.parse(response.body)
|
11
11
|
@json_response = true
|
12
|
-
@error_code = parsed_response.fetch("
|
13
|
-
|
14
|
-
@error_message = parsed_response.fetch("data", {})
|
15
|
-
.fetch("message", "unknown")
|
12
|
+
@error_code = parsed_response.fetch("code", "unknown")
|
13
|
+
@error_message = parsed_response.fetch("message", "unknown")
|
16
14
|
rescue JSON::ParserError
|
17
15
|
@json_response = false
|
18
16
|
end
|
data/lib/stream-chat/version.rb
CHANGED
data/stream-chat.gemspec
CHANGED
@@ -14,10 +14,10 @@ Gem::Specification.new do |gem|
|
|
14
14
|
gem.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
15
15
|
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
18
|
gem.add_dependency 'faraday'
|
19
19
|
gem.add_dependency 'jwt'
|
20
|
-
gem.
|
21
|
-
gem.
|
22
|
-
gem.
|
20
|
+
gem.add_development_dependency 'rake'
|
21
|
+
gem.add_development_dependency 'rspec'
|
22
|
+
gem.add_development_dependency 'simplecov'
|
23
23
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stream-chat-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mircea Cosbuc
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-08-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -45,7 +45,7 @@ dependencies:
|
|
45
45
|
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0'
|
48
|
-
type: :
|
48
|
+
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
@@ -59,7 +59,7 @@ dependencies:
|
|
59
59
|
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
|
-
type: :
|
62
|
+
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
@@ -73,7 +73,7 @@ dependencies:
|
|
73
73
|
- - ">="
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: '0'
|
76
|
-
type: :
|
76
|
+
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
@@ -88,6 +88,7 @@ extra_rdoc_files: []
|
|
88
88
|
files:
|
89
89
|
- ".gitignore"
|
90
90
|
- ".travis.yml"
|
91
|
+
- CHANGELOG.md
|
91
92
|
- Gemfile
|
92
93
|
- LICENSE
|
93
94
|
- PULL_REQUEST_TEMPLATE.md
|
@@ -117,7 +118,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
117
118
|
- !ruby/object:Gem::Version
|
118
119
|
version: '0'
|
119
120
|
requirements: []
|
120
|
-
rubygems_version: 3.
|
121
|
+
rubygems_version: 3.1.2
|
121
122
|
signing_key:
|
122
123
|
specification_version: 4
|
123
124
|
summary: The low level client for serverside calls for Stream Chat.
|