Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Matrix Ruby SDK
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Alexander Olofsson
Matrix Ruby SDK
Commits
67fe2c3d
Commit
67fe2c3d
authored
6 years ago
by
Alexander Olofsson
Browse files
Options
Downloads
Patches
Plain Diff
client: Clean up param handling
parent
edf4bd3e
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Pipeline
#2456
passed
6 years ago
Stage: test
Stage: deploy
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
lib/matrix_sdk/client.rb
+14
-18
14 additions, 18 deletions
lib/matrix_sdk/client.rb
with
14 additions
and
18 deletions
lib/matrix_sdk/client.rb
+
14
−
18
View file @
67fe2c3d
...
@@ -18,12 +18,12 @@ module MatrixSdk
...
@@ -18,12 +18,12 @@ module MatrixSdk
:validate_certificate
,
:validate_certificate
=
:validate_certificate
,
:validate_certificate
=
# @param hs_url [String,URI,Api] The URL to the Matrix homeserver, without the /_matrix/ part, or an existing Api instance
# @param hs_url [String,URI,Api] The URL to the Matrix homeserver, without the /_matrix/ part, or an existing Api instance
# @param client_cache [:all,:some,:none] (:all) How much data should be cached in the client
# @param params [Hash] Additional parameters on creation
# @param params [Hash] Additional parameters on creation
# @option params [String,MXID] :user_id The user ID of the logged-in user
# @option params [String,MXID] :user_id The user ID of the logged-in user
# @option params [:all,:some:non] :client_cache (:all) How much data should be cached in the client
# @option params [Integer] :sync_filter_limit (20) Limit of timeline entries in syncs
# @option params [Integer] :sync_filter_limit (20) Limit of timeline entries in syncs
# @see MatrixSdk::Api.new for additional usable params
# @see MatrixSdk::Api.new for additional usable params
def
initialize
(
hs_url
,
params
=
{}
)
def
initialize
(
hs_url
,
client_cache: :all
,
**
params
)
event_initialize
event_initialize
params
[
:user_id
]
||=
params
[
:mxid
]
if
params
[
:mxid
]
params
[
:user_id
]
||=
params
[
:mxid
]
if
params
[
:mxid
]
...
@@ -39,7 +39,7 @@ module MatrixSdk
...
@@ -39,7 +39,7 @@ module MatrixSdk
@rooms
=
{}
@rooms
=
{}
@users
=
{}
@users
=
{}
@cache
=
params
.
fetch
(
:
client_cache
,
:all
)
@cache
=
client_cache
@sync_token
=
nil
@sync_token
=
nil
@sync_thread
=
nil
@sync_thread
=
nil
...
@@ -101,7 +101,7 @@ module MatrixSdk
...
@@ -101,7 +101,7 @@ module MatrixSdk
post_authentication
(
data
)
post_authentication
(
data
)
end
end
def
login
(
username
,
password
,
params
=
{}
)
def
login
(
username
,
password
,
sync_timeout:
15
,
full_state:
false
,
**
params
)
username
=
username
.
to_s
unless
username
.
is_a?
(
String
)
username
=
username
.
to_s
unless
username
.
is_a?
(
String
)
password
=
password
.
to_s
unless
password
.
is_a?
(
String
)
password
=
password
.
to_s
unless
password
.
is_a?
(
String
)
...
@@ -113,12 +113,12 @@ module MatrixSdk
...
@@ -113,12 +113,12 @@ module MatrixSdk
return
if
params
[
:no_sync
]
return
if
params
[
:no_sync
]
sync
timeout:
params
.
fetch
(
:
sync_timeout
,
15
),
sync
timeout:
sync_timeout
,
full_state:
params
.
fetch
(
:
full_state
,
false
),
full_state:
full_state
,
allow_sync_retry:
params
.
fetch
(
:allow_sync_retry
,
nil
)
allow_sync_retry:
params
.
fetch
(
:allow_sync_retry
,
nil
)
end
end
def
login_with_token
(
username
,
token
,
params
=
{}
)
def
login_with_token
(
username
,
token
,
sync_timeout:
15
,
full_state:
false
,
**
params
)
username
=
username
.
to_s
unless
username
.
is_a?
(
String
)
username
=
username
.
to_s
unless
username
.
is_a?
(
String
)
token
=
token
.
to_s
unless
token
.
is_a?
(
String
)
token
=
token
.
to_s
unless
token
.
is_a?
(
String
)
...
@@ -130,8 +130,8 @@ module MatrixSdk
...
@@ -130,8 +130,8 @@ module MatrixSdk
return
if
params
[
:no_sync
]
return
if
params
[
:no_sync
]
sync
timeout:
params
.
fetch
(
:
sync_timeout
,
15
),
sync
timeout:
sync_timeout
,
full_state:
params
.
fetch
(
:
full_state
,
false
),
full_state:
full_state
,
allow_sync_retry:
params
.
fetch
(
:allow_sync_retry
,
nil
)
allow_sync_retry:
params
.
fetch
(
:allow_sync_retry
,
nil
)
end
end
...
@@ -177,7 +177,7 @@ module MatrixSdk
...
@@ -177,7 +177,7 @@ module MatrixSdk
raise
MatrixUnexpectedResponseError
,
'Upload succeeded, but no media URI returned'
raise
MatrixUnexpectedResponseError
,
'Upload succeeded, but no media URI returned'
end
end
def
listen_for_events
(
timeout
=
30
,
arguments
=
{}
)
def
listen_for_events
(
timeout
:
30
,
**
arguments
)
sync
(
arguments
.
merge
(
timeout:
timeout
))
sync
(
arguments
.
merge
(
timeout:
timeout
))
end
end
...
@@ -198,16 +198,13 @@ module MatrixSdk
...
@@ -198,16 +198,13 @@ module MatrixSdk
private
private
def
listen_forever
(
params
=
{})
def
listen_forever
(
timeout:
30
,
bad_sync_timeout:
5
,
sync_interval:
30
,
**
params
)
timeout
=
params
.
delete
(
:timeout
)
{
30
}
orig_bad_sync_timeout
=
bad_sync_timeout
.
dup
bad_sync_timeout
=
params
.
delete
(
:bad_sync_timeout
)
{
5
}
sync_interval
=
params
.
delete
(
:sync_interval
)
{
30
}
while
@should_listen
while
@should_listen
begin
begin
sync
(
params
.
merge
(
timeout:
timeout
))
sync
(
params
.
merge
(
timeout:
timeout
))
bad_sync_timeout
=
params
[
:
bad_sync_timeout
]
bad_sync_timeout
=
orig_
bad_sync_timeout
sleep
(
sync_interval
)
if
sync_interval
>
0
sleep
(
sync_interval
)
if
sync_interval
>
0
rescue
MatrixRequestError
=>
ex
rescue
MatrixRequestError
=>
ex
logger
.
warn
(
"A
#{
ex
.
class
}
occurred during sync"
)
logger
.
warn
(
"A
#{
ex
.
class
}
occurred during sync"
)
...
@@ -262,12 +259,11 @@ module MatrixSdk
...
@@ -262,12 +259,11 @@ module MatrixSdk
end
end
end
end
def
sync
(
params
=
{}
)
def
sync
(
skip_store_batch:
false
,
**
params
)
extra_params
=
{
extra_params
=
{
filter:
sync_filter
.
to_json
filter:
sync_filter
.
to_json
}
}
extra_params
[
:since
]
=
@next_batch
unless
@next_batch
.
nil?
extra_params
[
:since
]
=
@next_batch
unless
@next_batch
.
nil?
skip_store_batch
=
params
.
delete
(
:skip_store_batch
)
{
false
}
attempts
=
0
attempts
=
0
data
=
loop
do
data
=
loop
do
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment