Skip to content

Commit a3fb48c

Browse files
authored
docs: unify READMEs across backend repos (#84)
1 parent f2fcee5 commit a3fb48c

File tree

4 files changed

+148
-116
lines changed

4 files changed

+148
-116
lines changed

CONTRIBUTING.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
2+
# :recycle: Contributing
3+
4+
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 for more details.
5+
6+
## Getting started
7+
8+
### Install dependencies
9+
10+
```shell
11+
$ bundle install --path vendor/bundle
12+
```
13+
14+
### Run tests
15+
16+
```shell
17+
$ STREAM_KEY=my_api_key STREAM_SECRET=my_api_secret bundle exec rake spec
18+
```
19+
20+
### Linters and type check
21+
22+
We use [Rubocop](https://github.com/rubocop/rubocop) for linting and [Sorbet](https://sorbet.org/) for type checking.
23+
24+
To run them:
25+
```shell
26+
$ bundle exec rake rubocop
27+
$ bundle exec srb tc
28+
```
29+
30+
These linters can be easily integrated into IDEs such as RubyMine or VS Code.
31+
32+
For VS Code, just install the basic Ruby extension which handles Rubocop ([`rebornix.ruby`](https://marketplace.visualstudio.com/items?itemName=rebornix.Ruby)) and the official Sorbet one ([`sorbet.sorbet-vscode-extension`](https://marketplace.visualstudio.com/items?itemName=sorbet.sorbet-vscode-extension)).
33+
34+
Recommended settings:
35+
```json
36+
{
37+
"editor.formatOnSave": true,
38+
"ruby.useBundler": true,
39+
"ruby.lint": {
40+
"rubocop": {
41+
"useBundler": true, // enable rubocop via bundler
42+
}
43+
},
44+
"ruby.format": "rubocop",
45+
"ruby.useLanguageServer": true,
46+
"sorbet.enabled": true
47+
}
48+
```
49+
50+
### Commit message convention
51+
52+
This repository follows a commit message convention in order to automatically generate the [CHANGELOG](./CHANGELOG.md). Make sure you follow the rules of [conventional commits](https://www.conventionalcommits.org/) when opening a pull request.
53+
54+
### Releasing a new version (for Stream developers)
55+
56+
In order to release new version you need to be a maintainer of the library.
57+
58+
- Kick off a job called `initiate_release` ([link](https://github.com/GetStream/stream-chat-ruby/actions/workflows/initiate_release.yml)).
59+
60+
The job creates a pull request with the changelog. Check if it looks good.
61+
62+
- Merge the pull request.
63+
64+
Once the PR is merged, it automatically kicks off another job which will upload the Gem to RubyGems.org and creates a GitHub release.

README.md

Lines changed: 67 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,64 @@
1-
# stream-chat-ruby
1+
# Official Ruby SDK for [Stream Chat](https://getstream.io/chat/)
22

33
[![build](https://github.com/GetStream/stream-chat-ruby/workflows/build/badge.svg)](https://github.com/GetStream/stream-chat-ruby/actions) [![Gem Version](https://badge.fury.io/rb/stream-chat-ruby.svg)](http://badge.fury.io/rb/stream-chat-ruby)
44

5-
stream-chat-ruby is the official Ruby client for [Stream chat](https://getstream.io/chat/) a service for building chat applications.
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 Chat, a service for building chat applications.
10+
<br />
11+
<a href="https://getstream.io/chat/docs/"><strong>Explore the docs »</strong></a>
12+
<br />
13+
<br />
14+
<a href="https://github.com/GetStream/rails-chat-example">Code Samples</a>
15+
·
16+
<a href="https://github.com/GetStream/stream-chat-ruby/issues">Report Bug</a>
17+
·
18+
<a href="https://github.com/GetStream/stream-chat-ruby/issues">Request Feature</a>
19+
</p>
620

7-
You can sign up for a Stream account at https://getstream.io/chat/get_started/.
21+
## 📝 About Stream
822

9-
You can use this library to access chat API endpoints server-side. For the
10-
client-side integrations (web and mobile) have a look at the JavaScript, iOS and
11-
Android SDK libraries (https://getstream.io/chat/).
23+
You can sign up for a Stream account at our [Get Started](https://getstream.io/chat/get_started/) page.
1224

13-
### Installation
25+
You can use this library to access chat API endpoints server-side.
1426

15-
stream-chat-ruby supports:
27+
For the client-side integrations (web and mobile) have a look at the JavaScript, iOS and Android SDK libraries ([docs](https://getstream.io/chat/)).
1628

17-
- Ruby (2.5, 2.6, 2.7, 3.0, 3.1)
29+
## ⚙️ Installation
30+
31+
[`stream-chat-ruby`](https://rubygems.org/gems/stream-chat-ruby) supports:
1832

19-
#### Install
33+
- Ruby (2.5, 2.6, 2.7, 3.0, 3.1)
2034

2135
```bash
22-
gem install stream-chat-ruby
36+
$ gem install stream-chat-ruby
2337
```
2438

25-
### Documentation
26-
27-
[Official API docs](https://getstream.io/chat/docs/)
28-
29-
### Supported features
30-
31-
- Chat channel type, channels and members
32-
- Messages
33-
- User management
34-
- Moderation API
35-
- Push configuration
36-
- User devices
37-
- User search
38-
- Channel search
39-
- Blocklists
40-
- Export channels
41-
42-
### Import
39+
## ✨ Getting started
4340

4441
```ruby
4542
require 'stream-chat'
46-
```
4743

48-
### Initialize client
49-
50-
```ruby
5144
client = StreamChat::Client.new(api_key='STREAM_KEY', api_secret='STREAM_SECRET')
5245
```
5346

54-
### Generate a token for client side use
47+
> 💡 Note: since v2.21.0 we implemented [Sorbet](https://sorbet.org/) type checker. As of v2.x.x we only use it for static type checks and you won't notice any difference, but from v3.0.0 **we will enable runtime checks** 🚨 🚨 🚨.
48+
49+
> What this means, is that you'll receive an error during runtime if you pass an invalid type to our methods. To prepare for that, just make sure whatever you pass in, matches the method signature (`sig { ... }`).
50+
51+
---
52+
53+
> Additionally, in a future major version, we would like to enforce symbol hash keys during runtime to conform to Ruby best practises. It's a good idea to prepare your application for that.
54+
> ```ruby
55+
> # Wrong:
56+
> user = { "user" => { "id" => "bob-1"}}
57+
> # Correct:
58+
> user = { :user => { :id => "bob-1" }}
59+
> ```
60+
61+
### Generate a token for client-side usage:
5562
5663
```ruby
5764
client.create_token('bob-1')
@@ -66,125 +73,90 @@ client.update_user({
6673
:name => 'Robert Tables'
6774
})
6875

69-
# batch update is also supported
70-
jane = ...
71-
june = ...
76+
# Batch update is also supported
77+
jane = {:id => 'jane-1'}
78+
june = {:id => 'june-1'}
7279
client.update_users([jane, june])
7380
```
7481

75-
### Channel types CRUD
82+
### Channel types
7683

7784
```ruby
78-
# Create
7985
client.create_channel_type({
80-
'name' => 'livechat',
81-
'automod' => 'disabled',
82-
'commands' => ['ban'],
83-
'mutes' => true
86+
:name => 'livechat',
87+
:automod => 'disabled',
88+
:commands => ['ban'],
89+
:mutes => true
8490
})
8591

86-
# Update
87-
client.update_channel_type('livechat', 'automod' => 'enabled'})
88-
89-
# Get
90-
client.get_channel_type('livechat')
91-
92-
# List
93-
client.list_channel_types
94-
95-
# Delete
96-
client.delete_channel_type('livechat')
92+
channel_types = client.list_channel_types()
9793
```
9894

9995
### Channels
10096

10197
```ruby
10298
# Create a channel with members from the start
103-
chan = client.channel("messaging", channel_id: "bob-and-jane", data: {'members'=> ['bob-1', 'jane-77']})
99+
chan = client.channel("messaging", channel_id: "bob-and-jane", data: {:members => ['bob-1', 'jane-77']})
104100
chan.create('bob-1')
105101

106102
# Create a channel and then add members
107103
chan = client.channel("messaging", channel_id: "bob-and-jane")
108104
chan.create('bob-1')
109105
chan.add_members(['bob-1', 'jane-77'])
106+
```
110107

111-
# Send messages
112-
m1 = chan.send_message({'text' => 'Hi Jane!'}, 'bob-1')
113-
m2 = chan.send_message({'text' => 'Hi Bob'}, 'jane-77')
114-
115-
# Send replies
116-
r1 = chan.send_message({'text' => 'And a good day!', 'parent_id' => m1['id']}, 'bob-1')
117-
118-
# Send reactions
119-
chan.send_reaction(m1['id'], {'type' => 'like'}, 'bob-1')
108+
### Reactions
109+
```ruby
110+
chan.send_reaction(m1['id'], {:type => 'like'}, 'bob-1')
111+
```
120112

121-
# Add/remove moderators
113+
### Moderation
114+
```ruby
122115
chan.add_moderators(['jane-77'])
123116
chan.demote_moderators(['bob-1'])
124117

125-
# Add a ban with a timeout
126118
chan.ban_user('bob-1', timeout: 30)
127119

128-
# Remove a ban
129120
chan.unban_user('bob-1')
130-
131-
# Query channel state
132-
chan.query({'messages' => { 'limit' => 10, 'id_lte' => m1['id']}})
133-
134-
# Update metadata (overwrite)
135-
chan.update({'motd' => 'one apple a day....'})
136-
137-
# Update partial
138-
# 1. key-value pairs to set
139-
# 2. keys to unset (remove)
140-
chan.update_partial({color: 'blue', age: 30}, ['motd'])
141-
142-
# Query channel members
143-
chan.query_members({name: {'$autocomplete': 'test'}}, sort: {last_created_at: -1}, offset: 5, limit: 5)
144121
```
145122

146123
### Messages
147124

148125
```ruby
149-
# Delete a message from any channel by ID
126+
m1 = chan.send_message({:text => 'Hi Jane!'}, 'bob-1')
127+
150128
deleted_message = client.delete_message(r1['id'])
151129

152130
```
153131

154132
### Devices
155133

156134
```ruby
157-
# Add device
158-
jane_phone = client.add_device({'id' => 'iOS Device Token', 'push_provider' => push_provider.apn, 'user_id' => 'jane-77'})
135+
jane_phone = client.add_device({:id => 'iOS Device Token', :push_provider => push_provider.apn, :user_id => 'jane-77'})
159136

160-
# List devices
161137
client.get_devices('jane-77')
162138

163-
# Remove device
164139
client.remove_device(jane_phone['id'], jane_phone['user_id'])
165140
```
166141

167142
### Blocklists
168143

169144
```ruby
170-
# Create a blocklist
171145
client.create_blocklist('my_blocker', %w[fudge cream sugar])
172146

173-
# Enable it on messaging channel type
147+
# Enable it on 'messaging' channel type
174148
client.update_channel_type('messaging', blocklist: 'my_blocker', blocklist_behavior: 'block')
175149

176-
# Get the details of the blocklist
177150
client.get_blocklist('my_blocker')
178151

179-
# Delete the blocklist
180152
client.delete_blocklist('my_blocker')
181153
```
182154

183155
### Export Channels
184156

185157
```ruby
186158
# Register an export
187-
response = client.export_channels({type: 'messaging', id: 'jane'})
159+
response = client.export_channels({:type => 'messaging', :id => 'jane'})
188160

189161
# Check completion
190162
status_response = client.get_export_channel_status(response['task_id'])
@@ -204,33 +176,13 @@ limits = client.get_rate_limits(server_side: true)
204176
limits = client.get_rate_limits(android: true, ios: true, endpoints: ['QueryChannels', 'SendMessage'])
205177
```
206178

207-
### Example Rails application
208-
209-
See [an example rails application using the Ruby SDK](https://github.com/GetStream/rails-chat-example).
210-
211-
### Contributing
212-
213-
First, make sure you can run the test suite. Tests are run via rspec
214-
215-
```bash
216-
STREAM_KEY=my_api_key STREAM_SECRET=my_api_secret bundle exec rake spec
217-
```
218-
219-
This repository follows a commit message convention in order to automatically generate the [CHANGELOG](./CHANGELOG.md). Make sure you follow the rules of [conventional commits](https://www.conventionalcommits.org/) when opening a pull request.
220-
221-
### Releasing a new version
222-
223-
In order to release new version you need to be a maintainer of the library.
224-
225-
- Kick off a job called `initiate_release` ([link](https://github.com/GetStream/stream-chat-ruby/actions/workflows/initiate_release.yml)).
226-
227-
The job creates a pull request with the changelog. Check if it looks good.
179+
## ✍️ Contributing
228180

229-
- Merge the pull request.
181+
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.
230182

231-
Once the PR is merged, it automatically kicks off another job which will upload the Gem to RubyGems.org and creates a GitHub release.
183+
Head over to [CONTRIBUTING.md](./CONTRIBUTING.md) for some development tips.
232184

233-
## We are hiring!
185+
## 🧑‍💻 We are hiring!
234186

235187
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.
236188
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.

assets/logo.svg

Lines changed: 16 additions & 0 deletions
Loading

stream-chat.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Gem::Specification.new do |gem|
1414
gem.homepage = 'http://github.com/GetStream/stream-chat-ruby'
1515
gem.authors = ['getstream.io']
1616
gem.files = Dir.chdir(File.expand_path(__dir__)) do
17-
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|sorbet|spec|\.github|scripts)/}) }
17+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|sorbet|spec|\.github|scripts|assets)/}) }
1818
end
1919
gem.required_ruby_version = '>=2.5.0'
2020
gem.metadata = {

0 commit comments

Comments
 (0)