stream-chat-ruby 0.1.1 → 0.1.2

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: 520b69d498d01a2cf41b857e498d3dc0fc4c7dd6ac328848c2bf4f761862953e
4
- data.tar.gz: '091b5137483ae1ec59a68b26026cad060adbdb19ada735f0f1933a6232c2823d'
3
+ metadata.gz: a991d6254ab0ce129f7828b9f28dc18f90b867ba87ad543d24058ee9742f466b
4
+ data.tar.gz: c08d620794b6ddb9e0be2b540a8b543b27eebdc34ac4b3a9db047933e574b90b
5
5
  SHA512:
6
- metadata.gz: 2415204b5775bb39d620351a1d3b60474a18115c4f818eae55cab17982b1dd832b0458edbac3cb1b44ac926aabde06256cdc4e86b54ec2164f2bb9ca0e644e8e
7
- data.tar.gz: 1535f8eadb39fab2f30a89a4649d6bfbfe013fd5fc77775eceda7c5d59ffcde6b344a7ae2f25c12bce535590ba7db161f6503c836058a75ae4c5d48e7b125a72
6
+ metadata.gz: b5f13aaefd25df7431ae242a41d38e6a1765b1f0419c14623a363baedc3d64eb197c30b8f03e91bb7513d6f8c8c674501abf1fb59680ee4385624f0e79d1dd08
7
+ data.tar.gz: efbfac2fe9675cc8077429c6e6cd71d9a10d6234f8b9dfe904b997be339876b62fe89d140c9521adaec3901731c58e117e1646a7b4b65b711a030fc3563fca8a
@@ -2,6 +2,7 @@ language: ruby
2
2
  before_install:
3
3
  - gem update bundler
4
4
  rvm:
5
+ - 2.3.8
5
6
  - 2.4.6
6
7
  - 2.5.5
7
8
  - 2.6.3
data/README.md CHANGED
@@ -14,7 +14,7 @@ Android SDK libraries (https://getstream.io/chat/).
14
14
 
15
15
  stream-chat-ruby supports:
16
16
 
17
- - Ruby (2.6, 2.5, 2.4)
17
+ - Ruby (2.6, 2.5, 2.4, 2.3)
18
18
 
19
19
  #### Install
20
20
 
@@ -26,10 +26,6 @@ gem install stream-chat-ruby
26
26
 
27
27
  [Official API docs](https://getstream.io/chat/docs/)
28
28
 
29
- ### How to build a chat app with Ruby tutorial
30
-
31
- TODO: add a sample Ruby chat program
32
-
33
29
  ### Supported features
34
30
 
35
31
  - Chat channels
@@ -42,23 +38,124 @@ TODO: add a sample Ruby chat program
42
38
  - User search
43
39
  - Channel search
44
40
 
45
- ### Quickstart
41
+ ### Import
42
+
43
+ ```ruby
44
+ require 'stream-chat'
45
+ ```
46
+
47
+ ### Initialize client
48
+
49
+ ```ruby
50
+ client = StreamChat::Client.new(api_key='STREAM_KEY', api_secret='STREAM_SECRET')
51
+ ```
52
+
53
+ ### Generate a token for client side use
54
+
55
+ ```ruby
56
+ client.create_token('bob-1')
57
+ ```
58
+
59
+ ### Create/Update users
46
60
 
47
61
  ```ruby
48
- chat = StreamChat::Client.new(api_key='STREAM_KEY', api_secret='STREAM_SECRET')
62
+ client.update_user({
63
+ 'id' => 'bob-1',
64
+ 'role' => 'admin',
65
+ 'name' => 'Robert Tables'
66
+ })
67
+
68
+ # batch update is also supported
69
+ jane = ...
70
+ june = ...
71
+ client.update_users([jane, june])
72
+ ```
73
+
74
+ ### Channel types CRUD
49
75
 
50
- # add a user
51
- chat.update_user({'id' => 'chuck', 'name' => 'Chuck'})
76
+ ```ruby
77
+ # Create
78
+ client.create_channel_type({
79
+ 'name' => 'livechat',
80
+ 'automod' => 'disabled',
81
+ 'commands' => ['ban'],
82
+ 'mutes' => true
83
+ })
52
84
 
53
- # create a channel about kung-fu
54
- channel = chat.channel('messaging', 'kung-fu')
55
- channel.create('chuck')
85
+ # Update
86
+ client.update_channel_type('livechat', 'automod' => 'enabled'})
56
87
 
57
- # add a first message to the channel
58
- channel.send_message({'text' => 'AMA about kung-fu'})
88
+ # Get
89
+ client.get_channel_type('livechat')
59
90
 
91
+ # List
92
+ client.list_channel_types
93
+
94
+ # Delete
95
+ client.delete_channel_type('livechat')
60
96
  ```
61
97
 
98
+ ### Channels
99
+
100
+ ```ruby
101
+ # Create a channel with members from the start
102
+ chan = client.channel("messaging", channel_id: "bob-and-jane", data: {'members'=> ['bob-1', 'jane-77']})
103
+ chan.create('bob-1')
104
+
105
+ # Create a channel and then add members
106
+ chan = client.channel("messaging", channel_id: "bob-and-jane")
107
+ chan.create('bob-1')
108
+ chan.add_members(['bob-1', 'jane-77'])
109
+
110
+ # Send messages
111
+ m1 = chan.send_message({'text' => 'Hi Jane!'}, 'bob-1')
112
+ m2 = chan.send_message({'text' => 'Hi Bob'}, 'jane-77')
113
+
114
+ # Send replies
115
+ r1 = chan.send_message({'text' => 'And a good day!', 'parent_id' => m1['id']}, 'bob-1')
116
+
117
+ # Send reactions
118
+ chan.send_reaction(m1['id'], {'type' => 'like'}, 'bob-1')
119
+
120
+ # Add/remove moderators
121
+ chan.add_moderators(['jane-77'])
122
+ chan.demote_moderators(['bob-1'])
123
+
124
+ # Add a ban with a timeout
125
+ chan.ban_user('bob-1', timeout: 30)
126
+
127
+ # Remove a ban
128
+ chan.unban_user('bob-1')
129
+
130
+ # Query channel state
131
+ chan.query({'messages' => { 'limit' => 10, 'id_lte' => m1['id']}})
132
+ ```
133
+
134
+ ### Messages
135
+
136
+ ```ruby
137
+ # Delete a message from any channel by ID
138
+ deleted_message = client.delete_message(r1['id'])
139
+
140
+ ```
141
+
142
+ ### Devices
143
+
144
+ ```ruby
145
+ # Add device
146
+ jane_phone = client.add_device({'id' => 'iOS Device Token', 'push_provider' => push_provider.apn, 'user_id' => 'jane-77'})
147
+
148
+ # List devices
149
+ client.get_devices('jane-77')
150
+
151
+ # Remove device
152
+ client.remove_device(jane_phone['id'], jane_phone['user_id'])
153
+ ```
154
+
155
+ ### Example Rails application
156
+
157
+ See [an example rails application using the Ruby SDK](https://github.com/GetStream/rails-chat-example).
158
+
62
159
  ### Contributing
63
160
 
64
161
  First, make sure you can run the test suite. Tests are run via rspec
@@ -4,7 +4,7 @@ module StreamChat
4
4
  attr_reader :id
5
5
  attr_reader :channel_type
6
6
  attr_reader :custom_data
7
-
7
+
8
8
  def initialize(client, channel_type, channel_id=nil, custom_data=nil)
9
9
  @channel_type = channel_type
10
10
  @id = channel_id
@@ -114,10 +114,10 @@ module StreamChat
114
114
  end
115
115
 
116
116
  private
117
-
117
+
118
118
  def add_user_id(payload, user_id)
119
119
  payload.merge({"user": {"id": user_id}})
120
120
  end
121
-
121
+
122
122
  end
123
123
  end
@@ -3,6 +3,7 @@ require 'faraday'
3
3
  require 'jwt'
4
4
  require 'stream-chat/channel'
5
5
  require 'stream-chat/errors'
6
+ require 'stream-chat/version'
6
7
 
7
8
  module StreamChat
8
9
  class Client
@@ -35,7 +36,7 @@ module StreamChat
35
36
  faraday.adapter Faraday.default_adapter
36
37
  end
37
38
  end
38
-
39
+
39
40
  def create_token(user_id, exp = nil)
40
41
  payload = {user_id: user_id}
41
42
  if exp != nil
@@ -69,7 +70,7 @@ module StreamChat
69
70
  end
70
71
 
71
72
  def deactivate_user(user_id, **options)
72
- post("users/#{user_id}/deactivate", **options)
73
+ post("users/#{user_id}/deactivate", **options)
73
74
  end
74
75
 
75
76
  def export_user(user_id, **options)
@@ -151,13 +152,13 @@ module StreamChat
151
152
  def get_channel_type(channel_type)
152
153
  get("channeltypes/#{channel_type}")
153
154
  end
154
-
155
+
155
156
  def list_channel_types
156
157
  get("channeltypes")
157
158
  end
158
159
 
159
160
  def update_channel_type(channel_type, **options)
160
- put
161
+ put("channeltypes/#{channel_type}", **options)
161
162
  end
162
163
 
163
164
  def delete_channel_type(channel_type)
@@ -171,7 +172,7 @@ module StreamChat
171
172
  # @param [hash] data additional channel data
172
173
  #
173
174
  # @return [StreamChat::Channel]
174
- #
175
+ #
175
176
  def channel(channel_type, channel_id: nil, data: nil)
176
177
  StreamChat::Channel.new(self, channel_type, channel_id, data)
177
178
  end
@@ -222,7 +223,7 @@ module StreamChat
222
223
  def get_default_params
223
224
  {api_key: @api_key}
224
225
  end
225
-
226
+
226
227
  def get_user_agent
227
228
  "stream-ruby-client-#{StreamChat::VERSION}"
228
229
  end
@@ -245,7 +246,7 @@ module StreamChat
245
246
  end
246
247
  return parsed_result
247
248
  end
248
-
249
+
249
250
  def make_http_request(method, relative_url, params: nil, data: nil)
250
251
  headers = get_default_headers
251
252
  headers['Authorization'] = @auth_token
@@ -1,5 +1,5 @@
1
1
  # lib/version.rb
2
2
 
3
3
  module StreamChat
4
- VERSION = "0.1.1".freeze
4
+ VERSION = "0.1.2".freeze
5
5
  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: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mircea Cosbuc
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-05-15 00:00:00.000000000 Z
11
+ date: 2019-06-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday