sendbird 0.0.3 → 0.0.4

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
- SHA1:
3
- metadata.gz: f9309d8d962f105c291bf02cc4fe16950693ff74
4
- data.tar.gz: 1a96fb5eafcf935d5adff257ab1dcdfc843c6832
2
+ SHA256:
3
+ metadata.gz: bee1eb2534381eecf9283f4c80570797c2074fa653b9de44a6be8684442abac2
4
+ data.tar.gz: 4385f9bb5ec81bf97843b635be5c9624014bfdba2a1505c7b0ae5bd980bac8cd
5
5
  SHA512:
6
- metadata.gz: 5b186e7c854d59b6f588feb7a6ad53efdf822d117c6c665c3269d0bf295a4039151f2e753a74bac4f250cf84e919b22366cd5c97a95904de9deb7339add47650
7
- data.tar.gz: 56557a62ae679e8d2285f3b667ddddd211aebbfb18f9f9b0f610d104fc5775238315488cbdbfaa97b8be73d657674a72a94a169f86708de17c0264419b2970e4
6
+ metadata.gz: 12b030843cee3da667ab677565fe7c1e046ec81b38d9967f575a76f4fbd0e1e6e39c212e28fb33accd68fae81052b728dba8ce223373726fae029f164ff5562c
7
+ data.tar.gz: da18d261cd1cdc12155d28977ad37fa32542044382cc38369659fec904e6eca298cef0274c9429f31527de424fcaf807b7b544c0deb22176466d93815d81f2ab
data/README.md CHANGED
@@ -46,10 +46,10 @@ The Sendbird Api is quite big, to understand how to work with this gem, just rem
46
46
  Example:
47
47
  ```ruby
48
48
  body = {
49
- "user_id" => "string",
50
- "nickname" => "string",
51
- "profile_url" => "string",
52
- "issue_access_token" => "boolean"
49
+ "user_id" => "string",
50
+ "nickname" => "string",
51
+ "profile_url" => "string",
52
+ "issue_access_token" => "boolean"
53
53
  }
54
54
  Sendbird::UserApi.create(body)
55
55
  ```
@@ -60,9 +60,9 @@ Example for event [Message send](https://docs.sendbird.com/platform#messages):
60
60
  ```ruby
61
61
  request_body = {
62
62
  "message_type" => "MESG",
63
- "user_id" => "string",
64
- "message" => "string",
65
- "data" => "string",
63
+ "user_id" => "string",
64
+ "message" => "string",
65
+ "data" => "string",
66
66
  "mark_as_read" => "boolean"
67
67
  }
68
68
  Sendbird::MessageApi.send('group_channels', 'group_channels_url', request_body)
@@ -72,7 +72,7 @@ Example for event [User list](https://docs.sendbird.com/platform#messages):
72
72
  ```ruby
73
73
  request_parameters = {
74
74
  "token" => "string",
75
- "limit" => "int",
75
+ "limit" => "int",
76
76
  "user_ids" => "string"
77
77
  }
78
78
  Sendbird::UserApi.list(request_parameters)
@@ -82,7 +82,7 @@ Example for sending a message to a different app:
82
82
  ```ruby
83
83
  request_parameters = {
84
84
  "token" => "string",
85
- "limit" => "int",
85
+ "limit" => "int",
86
86
  "user_ids" => "string",
87
87
  "app" => 'string' # This app has to be in the configuration
88
88
  }
@@ -97,159 +97,8 @@ All methods return a `Sendbird::Response` with have the next methods:
97
97
  #### error_code
98
98
  Returns the error_code from the request, if their is one
99
99
  #### error_message
100
- Returns the error_message from the request, if their is one
100
+ Returns the error_message from the request, if their is one
101
101
 
102
- ## List of all classes and it's class methods.
103
-
104
- ### Sendbird::UserApi
105
- ```ruby
106
- view(user_id)
107
- create(body)
108
- destroy(user_id)
109
- list(params={})
110
- update(user_id, body)
111
- unread_count(user_id)
112
- activate(user_id, body)
113
- block(user_id, body)
114
- unblock(user_id, unblock_user_id)
115
- block_list(user_id, params={})
116
- mark_as_read_all(user_id)
117
- register_gcm_token(user_id, token)
118
- register_apns_token(user_id, token)
119
- unregister_gcm_token(user_id, token)
120
- unregister_apns_token(user_id, token)
121
- unregister_all_device_token(user_id)
122
- push_preferences(user_id)
123
- update_push_preferences(user_id, body)
124
- delete_push_preferences(user_id)
125
- ```
126
-
127
- ### Sendbird::OpenChannelApi
128
- ```ruby
129
- view(channel_url, params={})
130
- create(body={})
131
- list(params={})
132
- destroy(channel_url)
133
- update(channel_url, body)
134
- participants(channel_url, params)
135
- freeze(channel_url, body)
136
- ban_user(channel_url, body)
137
- ban_list(channel_url, params={})
138
- ban_update(channel_url, user_id, body)
139
- ban_delete(channel_url, user_id)
140
- ban_view(channel_url, user_id)
141
- mute(channel_url, body)
142
- mute_list(channel_url, params={})
143
- mute_delete(channel_url, user_id)
144
- mute_view(channel_url, user_id)
145
- ```
146
-
147
- ### Sendbird::GroupChannelApi
148
- ```ruby
149
- create(body)
150
- list(params={})
151
- update(channel_url, body)
152
- destroy(channel_url)
153
- view(channel_url, params={})
154
- members(channel_url, params={})
155
- is_member?(channel_url, user_id)
156
- invite(channel_url, body)
157
- hide(channel_url, body)
158
- leave(channel_url, body)
159
- ```
160
-
161
- ### Sendbird::MetaCounterApi && Sendbird::MetaDataApi
162
- ```ruby
163
- create(channel_type, channel_url, body)
164
- view(channel_type, channel_url, params={})
165
- view_by_key(channel_type, channel_url, key)
166
- update(channel_type, channel_url, body)
167
- update_by_key(channel_type, channel_url, key, body)
168
- destroy(channel_type, channel_url)
169
- destroy_by_key(channel_type, channel_url, key)
170
- ```
171
-
172
- ### Sendbird::ApplicationApi
173
- ```ruby
174
- create(body)
175
- list(params={})
176
- destroy_all
177
- destroy
178
- profanaty(body={})
179
- ccu
180
- mau(params={})
181
- dau(params={})
182
- daily_message_count(params={})
183
- gcm_push_configuration
184
- apns_push_configuration
185
- ```
186
-
187
- ## Interface
188
-
189
- This is the second type of class inside the gem, acts as interface.
190
-
191
- Currently only supporting `User`, in the future I will add the rest of interfaces.
192
-
193
- There are three ways to interact with the user interface:
194
-
195
- #### Block
196
- ```ruby
197
- Sendbird::User.new('testing_user_interface_1') do |u|
198
- u.nickname('Yolo')
199
- u.profile_url('udbue')
200
- u.timezone('Europe/London')
201
- u.request!
202
- end
203
- ```
204
-
205
- #### Chain Methods
206
- ```ruby
207
- user = Sendbird::User.new('testing_user_interface_1')
208
- user.nickname('Yolo').profile_url('udbue').timezone('Europe/London').request!
209
- ```
210
-
211
- #### Simple methods
212
- ```ruby
213
- user = Sendbird::User.new('testing_user_interface_1')
214
- user.nickname='Yolo'
215
- user.profile_url=('udbue')
216
- user.timezone=('Europe/London')
217
- user.request!
218
- ```
219
-
220
- This interface provide you with multiple methods to work with the Sendbird Api:
221
-
222
- ```ruby
223
- user_information=(user_information={})
224
- nickname=(nickname)
225
- profile_url=(profile_url)
226
- issue_access_token=(issue_access_token)
227
- push_preferences=(push_preferences={})
228
- timezone=(timezone)
229
- start_hour=(start_hour)
230
- end_hour=(end_hour)
231
- start_min=(start_min)
232
- end_min=(end_min)
233
- activate
234
- deactivate
235
- mark_as_read_all
236
- register_gcm_token(token)
237
- register_apns_token(token)
238
- unregister_gcm_token(token)
239
- unregister_apns_token(token)
240
- unregister_all_device_token
241
- ```
242
-
243
- The interface will store all the pending requests called before the `request!`, when triggering the `request!` method will optimize how many request, have to be done, you don't have to worry about that.
244
-
245
- The User interface also provide some attributes: `gcm_tokens` and `apns_tokens`, they will store the different token this user have, so by triggering any of the `register_*` methods will store or remove from this attributes.
246
-
247
- The user interface also provide some getter methods that will execute the request instantly, this methods return the info response body. This methods are:
248
- ```ruby
249
- get_user
250
- get_unread_count
251
- get_push_preferences
252
- ```
253
102
 
254
103
  ## Development
255
104
 
@@ -2,15 +2,11 @@ require "sendbird/client"
2
2
  require "sendbird/configuration"
3
3
  require "sendbird/invalid_request"
4
4
  require "sendbird/response"
5
- require "sendbird/request_handler"
6
5
  require "sendbird/application_api"
7
6
  require "sendbird/user_api"
8
- require "sendbird/user"
9
7
  require "sendbird/open_channel_api"
10
8
  require "sendbird/group_channel_api"
11
- require "sendbird/group_channel"
12
9
  require "sendbird/message_api"
13
- require "sendbird/message"
14
10
  require "sendbird/meta_base"
15
11
  require "sendbird/meta_data_api"
16
12
  require "sendbird/meta_counter_api"
@@ -1,3 +1,3 @@
1
1
  module Sendbird
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -21,7 +21,7 @@ Gem::Specification.new do |spec|
21
21
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
22
  spec.require_paths = ["lib"]
23
23
 
24
- spec.add_development_dependency "bundler", "~> 1.13"
24
+ spec.add_development_dependency "bundler", "~> 2.1.4"
25
25
  spec.add_development_dependency "rake", "~> 10.0"
26
26
  spec.add_development_dependency "rspec", "~> 3.0"
27
27
  spec.add_development_dependency "pry"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sendbird
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - GustavoCaso
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-10-11 00:00:00.000000000 Z
11
+ date: 2020-10-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.13'
19
+ version: 2.1.4
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.13'
26
+ version: 2.1.4
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -117,7 +117,6 @@ extra_rdoc_files: []
117
117
  files:
118
118
  - ".gitignore"
119
119
  - ".rspec"
120
- - ".ruby-gemset"
121
120
  - ".travis.yml"
122
121
  - CODE_OF_CONDUCT.md
123
122
  - Gemfile
@@ -131,20 +130,14 @@ files:
131
130
  - lib/sendbird/application_api.rb
132
131
  - lib/sendbird/client.rb
133
132
  - lib/sendbird/configuration.rb
134
- - lib/sendbird/group_channel.rb
135
133
  - lib/sendbird/group_channel_api.rb
136
134
  - lib/sendbird/invalid_request.rb
137
- - lib/sendbird/message.rb
138
135
  - lib/sendbird/message_api.rb
139
136
  - lib/sendbird/meta_base.rb
140
137
  - lib/sendbird/meta_counter_api.rb
141
138
  - lib/sendbird/meta_data_api.rb
142
139
  - lib/sendbird/open_channel_api.rb
143
- - lib/sendbird/request_handler.rb
144
- - lib/sendbird/request_handler/request.rb
145
- - lib/sendbird/request_handler/request_merger.rb
146
140
  - lib/sendbird/response.rb
147
- - lib/sendbird/user.rb
148
141
  - lib/sendbird/user_api.rb
149
142
  - lib/sendbird/version.rb
150
143
  - sendbird.gemspec
@@ -167,8 +160,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
167
160
  - !ruby/object:Gem::Version
168
161
  version: '0'
169
162
  requirements: []
170
- rubyforge_project:
171
- rubygems_version: 2.5.1
163
+ rubygems_version: 3.1.4
172
164
  signing_key:
173
165
  specification_version: 4
174
166
  summary: Wrapper for the Sendbird Platform API
@@ -1,52 +0,0 @@
1
- module Sendbird
2
- class GroupChannel
3
- class MissingUserId < StandardError; end
4
- include RequestHandler
5
-
6
- api_class GroupChannelApi
7
- default_arg :channel_url
8
-
9
- attr_reader :channel_url, :user_id, :pending_requests
10
- def initialize(channel_url, user_id = :missing_user_id)
11
- @channel_url = channel_url
12
- @user_id = user_id
13
- @pending_requests = {}
14
- yield(self) if block_given?
15
- end
16
-
17
- def name=(name)
18
- merge_arguments(:update, {name: name})
19
- self
20
- end
21
-
22
- def cover_url=(cover_url)
23
- merge_arguments(:update, {cover_url: cover_url})
24
- self
25
- end
26
-
27
- def data=(data)
28
- merge_arguments(:update, {data: data})
29
- self
30
- end
31
-
32
- def is_distinct=(is_distinct)
33
- merge_arguments(:update, {is_distinct: is_distinct})
34
- self
35
- end
36
-
37
- def send_message(type, data)
38
- message.send(type, data)
39
- end
40
-
41
- def message
42
- return @message if defined?(@message)
43
- if user_id == :missing_user_id
44
- raise MissingUserId, 'Please provide an user_id at initialize to been able to use send_message'
45
- end
46
- @message ||= Message.new(user_id, channel_url, 'group_channels')
47
- end
48
-
49
- private
50
- attr_writer :pending_requests
51
- end
52
- end
@@ -1,44 +0,0 @@
1
- module Sendbird
2
- class Message
3
- class InvalidMessageType < StandardError; end
4
- attr_reader :user_id, :channel_url, :channel_type
5
-
6
- def initialize(user_id, channel_url, channel_type)
7
- @user_id = user_id
8
- @channel_url = channel_url
9
- @channel_type = channel_type
10
- end
11
-
12
- def send(type, data)
13
- MessageApi.send(channel_type, channel_url, message_body(type).merge(data))
14
- self
15
- end
16
-
17
- private
18
- def message_type(type)
19
- case type
20
- when :text then 'MESG'
21
- when :file then 'FILE'
22
- when :admin then 'ADMM'
23
- else
24
- raise InvalidMessageType, "Please provide a valid message type, valid types are: [:text, :file, :admin]"
25
- end
26
- end
27
-
28
- def message_body(type)
29
- case type
30
- when :text, :file
31
- {
32
- "message_type": message_type(type),
33
- "user_id": user_id
34
- }
35
- when :admin
36
- {
37
- "message_type": message_type(type),
38
- }
39
- else
40
- raise InvalidMessageType, "Please provide a valid message type, valid types are: [:text, :file, :admin]"
41
- end
42
- end
43
- end
44
- end
@@ -1,41 +0,0 @@
1
- require_relative "./request_handler/request"
2
- require_relative "./request_handler/request_merger"
3
-
4
- module Sendbird
5
- module RequestHandler
6
- def self.included(base)
7
- base.extend ClassMethods
8
- end
9
-
10
- def request!
11
- Request.new(pending_requests, api_class, default_arg).execute
12
- rescue InvalidRequest => e
13
- raise e
14
- ensure
15
- self.pending_requests = {}
16
- self
17
- end
18
-
19
- def merge_arguments(method, args, callback=nil)
20
- self.pending_requests = RequestMerger.call(pending_requests, method, args, callback)
21
- end
22
-
23
- def default_arg
24
- self.send(self.class.instance_variable_get(:@default_arg))
25
- end
26
-
27
- def api_class
28
- self.class.instance_variable_get(:@api_class)
29
- end
30
-
31
- module ClassMethods
32
- def api_class(api_class)
33
- @api_class = api_class
34
- end
35
-
36
- def default_arg(method)
37
- @default_arg = method
38
- end
39
- end
40
- end
41
- end
@@ -1,41 +0,0 @@
1
- module Sendbird
2
- module RequestHandler
3
- class Request
4
- attr_reader :pending_requests, :api_class, :default_argument
5
- def initialize(pending_requests, api_class, default_argument)
6
- @pending_requests = pending_requests
7
- @api_class = api_class
8
- @default_argument = default_argument
9
- end
10
-
11
- def execute
12
- pending_requests.each do |method, params|
13
- response = case params[:args]
14
- when Array
15
- if params[:args].any?
16
- api_class.send(method, default_argument, *params[:args])
17
- else
18
- api_class.send(method, default_argument)
19
- end
20
- when Hash
21
- api_class.send(method, default_argument, params[:args])
22
- end
23
- handle_response_status(response, method, params[:args])
24
- execute_callbacks(params[:callback], response)
25
- end
26
- end
27
-
28
- def handle_response_status(response, method, arguments)
29
- if response.status != 200
30
- raise InvalidRequest, "#{response.error_message} executing #{method} with arguments: #{arguments}"
31
- end
32
- end
33
-
34
- def execute_callbacks(callbacks, response)
35
- callbacks.each do |cb|
36
- cb.call(response)
37
- end
38
- end
39
- end
40
- end
41
- end
@@ -1,44 +0,0 @@
1
- module Sendbird
2
- module RequestHandler
3
- class RequestMerger
4
- def self.call(pending_requests, method, args, callback)
5
- new(pending_requests, method, args, callback).merge
6
- end
7
-
8
- attr_reader :pending_requests, :method, :args, :callback
9
- def initialize(pending_requests, method, args, callback)
10
- @pending_requests = pending_requests
11
- @method = method
12
- @args = args
13
- @callback = callback
14
- end
15
-
16
- def merge
17
- pending_requests[method] ||= {}
18
- case args
19
- when Hash
20
- merge_hash_arguments(args)
21
- else
22
- merge_rest_of_arguments(args)
23
- end
24
- append_callbacks(args)
25
- pending_requests
26
- end
27
-
28
- def merge_hash_arguments(args)
29
- pending_requests[method][:args] ||= {}
30
- pending_requests[method][:args] = pending_requests[method][:args].merge(args)
31
- end
32
-
33
- def merge_rest_of_arguments(args)
34
- pending_requests[method][:args] ||= []
35
- pending_requests[method][:args] = pending_requests[method][:args] << args if args
36
- end
37
-
38
- def append_callbacks(args)
39
- pending_requests[method][:callback] ||= []
40
- pending_requests[method][:callback] = pending_requests[method][:callback] << callback if callback
41
- end
42
- end
43
- end
44
- end
@@ -1,178 +0,0 @@
1
- module Sendbird
2
- class User
3
- include RequestHandler
4
-
5
- api_class UserApi
6
- default_arg :user_id
7
-
8
- attr_reader :user_id, :pending_requests, :gcm_tokens, :apns_tokens
9
- def initialize(user_id)
10
- @user_id = user_id
11
- @gcm_tokens = []
12
- @apns_tokens = []
13
- @pending_requests = {}
14
- yield(self) if block_given?
15
- end
16
-
17
- def in_sync?
18
- pending_requests.empty?
19
- end
20
-
21
- #Getters
22
- def get_user
23
- response = UserApi.view(user_id)
24
- if response.status == 200
25
- response.body
26
- else
27
- raise InvalidRequest.new(
28
- error_message(
29
- response.error_message,
30
- __method__,
31
- user_id
32
- )
33
- )
34
- end
35
- end
36
-
37
- def get_unread_count
38
- response = UserApi.unread_count(user_id)
39
- if response.status == 200
40
- response.body['unread_count']
41
- else
42
- raise InvalidRequest.new(
43
- error_message(
44
- response.error_message,
45
- __method__,
46
- user_id
47
- )
48
- )
49
- end
50
- end
51
-
52
- def get_push_preferences
53
- response = UserApi.push_preferences(user_id)
54
- if response.status == 200
55
- response.body
56
- else
57
- raise InvalidRequest.new(
58
- error_message(
59
- response.error_message,
60
- __method__,
61
- user_id
62
- )
63
- )
64
- end
65
- end
66
-
67
- # Setters
68
- def user_information=(user_information={})
69
- merge_arguments(:update, user_information)
70
- self
71
- end
72
- alias_method :user_information, :user_information=
73
-
74
- def nickname=(nickname)
75
- merge_arguments(:update, {nickname: nickname})
76
- self
77
- end
78
- alias_method :nickname, :nickname=
79
-
80
- def profile_url=(profile_url)
81
- merge_arguments(:update, {profile_url: profile_url})
82
- self
83
- end
84
- alias_method :profile_url, :profile_url=
85
-
86
- def issue_access_token=(issue_access_token)
87
- merge_arguments(:update, {issue_access_token: issue_access_token})
88
- self
89
- end
90
- alias_method :issue_access_token, :issue_access_token=
91
-
92
- def activate
93
- merge_arguments(:activate, { activate: true })
94
- self
95
- end
96
-
97
- def deactivate
98
- merge_arguments(:activate, { activate: false })
99
- self
100
- end
101
-
102
- def push_preferences=(push_preferences={})
103
- merge_arguments(:update_push_preferences, push_preferences)
104
- self
105
- end
106
- alias_method :push_preferences, :push_preferences=
107
-
108
- def timezone=(timezone)
109
- merge_arguments(:update_push_preferences, { timezone: timezone })
110
- self
111
- end
112
- alias_method :timezone, :timezone=
113
-
114
- def start_hour=(start_hour)
115
- merge_arguments(:update_push_preferences, { start_hour: start_hour })
116
- self
117
- end
118
- alias_method :start_hour, :start_hour=
119
-
120
- def end_hour=(end_hour)
121
- merge_arguments(:update_push_preferences, { end_hour: end_hour })
122
- self
123
- end
124
- alias_method :end_hour, :end_hour=
125
-
126
- def start_min=(start_min)
127
- merge_arguments(:update_push_preferences, { start_min: start_min })
128
- self
129
- end
130
- alias_method :start_min, :start_min=
131
-
132
- def end_min=(end_min)
133
- merge_arguments(:update_push_preferences, { end_min: end_min })
134
- self
135
- end
136
- alias_method :end_min, :end_min=
137
-
138
- def register_gcm_token(token)
139
- merge_arguments(:register_gcm_token, token, ->(response){ self.gcm_tokens << response.body['token'] })
140
- self
141
- end
142
-
143
- def register_apns_token(token)
144
- merge_arguments(:register_apns_token, token, ->(response){ self.apns_tokens << response.body['token'] })
145
- self
146
- end
147
-
148
- def unregister_gcm_token(token)
149
- merge_arguments(:unregister_gcm_token, token, ->(response){ self.gcm_tokens.delete(response.body['token'])})
150
- self
151
- end
152
-
153
- def unregister_apns_token(token)
154
- merge_arguments(:unregister_apns_token, token, ->(response){ self.apns_tokens.delete(response.body['token'])})
155
- self
156
- end
157
-
158
- def unregister_all_device_token
159
- merge_arguments(:unregister_all_device_token, nil, ->(response) { self.apns_tokens = []; self.gcm_tokens = []; })
160
- self
161
- end
162
-
163
- def mark_as_read_all
164
- merge_arguments(:mark_as_read_all, {})
165
- self
166
- end
167
-
168
- def group_channel(channel_url)
169
- GroupChannel.new(channel_url, user_id)
170
- end
171
-
172
- private
173
- attr_writer :pending_requests, :apns_tokens, :gcm_tokens
174
- def error_message(error_message, method_name, args)
175
- "Invalid request for User with user_id: #{user_id}, error message: #{error_message} the request method was #{method_name} with args: #{args}"
176
- end
177
- end
178
- end