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
00e990ab
Commit
00e990ab
authored
6 years ago
by
Alexander Olofsson
Browse files
Options
Downloads
Patches
Plain Diff
Starting work on AS protocol extensions
parent
7c0938c7
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
lib/matrix_sdk/api.rb
+5
-1
5 additions, 1 deletion
lib/matrix_sdk/api.rb
lib/matrix_sdk/protocols/as.rb
+3
-1
3 additions, 1 deletion
lib/matrix_sdk/protocols/as.rb
lib/matrix_sdk/protocols/cs.rb
+24
-13
24 additions, 13 deletions
lib/matrix_sdk/protocols/cs.rb
with
32 additions
and
15 deletions
lib/matrix_sdk/api.rb
+
5
−
1
View file @
00e990ab
...
@@ -15,7 +15,7 @@ module MatrixSdk
...
@@ -15,7 +15,7 @@ module MatrixSdk
}.
freeze
}.
freeze
attr_accessor
:access_token
,
:connection_address
,
:connection_port
,
:device_id
,
:autoretry
,
:global_headers
attr_accessor
:access_token
,
:connection_address
,
:connection_port
,
:device_id
,
:autoretry
,
:global_headers
attr_reader
:homeserver
,
:validate_certificate
,
:read_timeout
,
:well_known
attr_reader
:homeserver
,
:validate_certificate
,
:read_timeout
,
:protocols
,
:well_known
ignore_inspect
:access_token
,
:logger
ignore_inspect
:access_token
,
:logger
...
@@ -140,6 +140,10 @@ module MatrixSdk
...
@@ -140,6 +140,10 @@ module MatrixSdk
))
))
end
end
def
protocol?
(
protocol
)
protocols
.
include?
protocol
end
# Gets the logger for the API
# Gets the logger for the API
# @return [Logging::Logger] The API-scope logger
# @return [Logging::Logger] The API-scope logger
def
logger
def
logger
...
...
This diff is collapsed.
Click to expand it.
lib/matrix_sdk/protocols/as.rb
+
3
−
1
View file @
00e990ab
module
MatrixSdk::Protocols::AS
module
MatrixSdk::Protocols::AS
raise
'Not implemented yet'
def
self
.
extended
(
_klass
)
# XXX
end
end
end
This diff is collapsed.
Click to expand it.
lib/matrix_sdk/protocols/cs.rb
+
24
−
13
View file @
00e990ab
...
@@ -42,6 +42,7 @@ module MatrixSdk::Protocols::CS
...
@@ -42,6 +42,7 @@ module MatrixSdk::Protocols::CS
query
[
:timeout
]
=
((
query
[
:timeout
]
||
30
)
*
1000
).
to_i
query
[
:timeout
]
=
((
query
[
:timeout
]
||
30
)
*
1000
).
to_i
query
[
:timeout
]
=
params
.
delete
(
:timeout_ms
).
to_i
if
params
.
key?
:timeout_ms
query
[
:timeout
]
=
params
.
delete
(
:timeout_ms
).
to_i
if
params
.
key?
:timeout_ms
query
[
:user_id
]
=
params
.
delete
(
:user_id
)
if
protocols?
(
:AS
)
&&
params
.
key?
(
:user_id
)
request
(
:get
,
:client_r0
,
'/sync'
,
query:
query
)
request
(
:get
,
:client_r0
,
'/sync'
,
query:
query
)
end
end
...
@@ -63,7 +64,7 @@ module MatrixSdk::Protocols::CS
...
@@ -63,7 +64,7 @@ module MatrixSdk::Protocols::CS
# For options that are permitted in this call
# For options that are permitted in this call
def
register
(
params
=
{})
def
register
(
params
=
{})
kind
=
params
.
delete
(
:kind
)
{
'user'
}
kind
=
params
.
delete
(
:kind
)
{
'user'
}
store_token
=
params
.
delete
(
:store_token
)
{
true
}
store_token
=
params
.
delete
(
:store_token
)
{
!
protocol?
(
:AS
)
}
store_device_id
=
params
.
delete
(
:store_device_id
)
{
store_token
}
store_device_id
=
params
.
delete
(
:store_device_id
)
{
store_token
}
request
(
:post
,
:client_r0
,
'/register'
,
body:
params
,
query:
{
kind:
kind
}).
tap
do
|
resp
|
request
(
:post
,
:client_r0
,
'/register'
,
body:
params
,
query:
{
kind:
kind
}).
tap
do
|
resp
|
...
@@ -159,7 +160,6 @@ module MatrixSdk::Protocols::CS
...
@@ -159,7 +160,6 @@ module MatrixSdk::Protocols::CS
# @param event_type [String] The event type to send
# @param event_type [String] The event type to send
# @param content [Hash] The contents of the state event
# @param content [Hash] The contents of the state event
# @param params [Hash] Options for the request
# @param params [Hash] Options for the request
# @option params [Integer] :timestamp The timestamp when the event was created, only used for AS events
# @option params [String] :state_key The state key of the event, if there is one
# @option params [String] :state_key The state key of the event, if there is one
# @return [Response] A response hash with the parameter :event_id
# @return [Response] A response hash with the parameter :event_id
# @see https://matrix.org/docs/spec/client_server/r0.3.0.html#put-matrix-client-r0-rooms-roomid-state-eventtype-statekey
# @see https://matrix.org/docs/spec/client_server/r0.3.0.html#put-matrix-client-r0-rooms-roomid-state-eventtype-statekey
...
@@ -167,7 +167,7 @@ module MatrixSdk::Protocols::CS
...
@@ -167,7 +167,7 @@ module MatrixSdk::Protocols::CS
# The Matrix Spec, for more information about the call and response
# The Matrix Spec, for more information about the call and response
def
send_state_event
(
room_id
,
event_type
,
content
,
params
=
{})
def
send_state_event
(
room_id
,
event_type
,
content
,
params
=
{})
query
=
{}
query
=
{}
query
[
:
ts
]
=
params
[
:timestamp
].
to_i
if
params
.
key?
:timestamp
query
[
:
user_id
]
=
params
.
delete
(
:user_id
)
if
protocols?
(
:AS
)
&&
params
.
key?
(
:user_id
)
room_id
=
CGI
.
escape
room_id
.
to_s
room_id
=
CGI
.
escape
room_id
.
to_s
event_type
=
CGI
.
escape
event_type
.
to_s
event_type
=
CGI
.
escape
event_type
.
to_s
...
@@ -181,14 +181,13 @@ module MatrixSdk::Protocols::CS
...
@@ -181,14 +181,13 @@ module MatrixSdk::Protocols::CS
# @param event_type [String] The event type of the message
# @param event_type [String] The event type of the message
# @param content [Hash] The contents of the message
# @param content [Hash] The contents of the message
# @param params [Hash] Options for the request
# @param params [Hash] Options for the request
# @option params [Integer] :timestamp The timestamp when the event was created, only used for AS events
# @option params [Integer] :txn_id The ID of the transaction, or automatically generated
# @option params [Integer] :txn_id The ID of the transaction, or automatically generated
# @return [Response] A response hash with the parameter :event_id
# @return [Response] A response hash with the parameter :event_id
# @see https://matrix.org/docs/spec/client_server/r0.3.0.html#put-matrix-client-r0-rooms-roomid-send-eventtype-txnid
# @see https://matrix.org/docs/spec/client_server/r0.3.0.html#put-matrix-client-r0-rooms-roomid-send-eventtype-txnid
# The Matrix Spec, for more information about the call and response
# The Matrix Spec, for more information about the call and response
def
send_message_event
(
room_id
,
event_type
,
content
,
params
=
{})
def
send_message_event
(
room_id
,
event_type
,
content
,
params
=
{})
query
=
{}
query
=
{}
query
[
:
ts
]
=
params
[
:timestamp
].
to_i
if
params
.
key?
:timestamp
query
[
:
user_id
]
=
params
.
delete
(
:user_id
)
if
protocols?
(
:AS
)
&&
params
.
key?
(
:user_id
)
txn_id
=
transaction_id
txn_id
=
transaction_id
txn_id
=
params
.
fetch
(
:txn_id
,
"
#{
txn_id
}#{
Time
.
now
.
to_i
}
"
)
txn_id
=
params
.
fetch
(
:txn_id
,
"
#{
txn_id
}#{
Time
.
now
.
to_i
}
"
)
...
@@ -204,7 +203,6 @@ module MatrixSdk::Protocols::CS
...
@@ -204,7 +203,6 @@ module MatrixSdk::Protocols::CS
# @param room_id [MXID,String] The room ID to send the message event to
# @param room_id [MXID,String] The room ID to send the message event to
# @param event_id [String] The event ID of the event to redact
# @param event_id [String] The event ID of the event to redact
# @param params [Hash] Options for the request
# @param params [Hash] Options for the request
# @option params [Integer] :timestamp The timestamp when the event was created, only used for AS events
# @option params [String] :reason The reason for the redaction
# @option params [String] :reason The reason for the redaction
# @option params [Integer] :txn_id The ID of the transaction, or automatically generated
# @option params [Integer] :txn_id The ID of the transaction, or automatically generated
# @return [Response] A response hash with the parameter :event_id
# @return [Response] A response hash with the parameter :event_id
...
@@ -212,7 +210,7 @@ module MatrixSdk::Protocols::CS
...
@@ -212,7 +210,7 @@ module MatrixSdk::Protocols::CS
# The Matrix Spec, for more information about the call and response
# The Matrix Spec, for more information about the call and response
def
redact_event
(
room_id
,
event_id
,
params
=
{})
def
redact_event
(
room_id
,
event_id
,
params
=
{})
query
=
{}
query
=
{}
query
[
:
ts
]
=
params
[
:timestamp
].
to_i
if
params
.
key?
:timestamp
query
[
:
user_id
]
=
params
.
delete
(
:user_id
)
if
protocols?
(
:AS
)
&&
params
.
key?
(
:user_id
)
content
=
{}
content
=
{}
content
[
:reason
]
=
params
[
:reason
]
if
params
[
:reason
]
content
[
:reason
]
=
params
[
:reason
]
if
params
[
:reason
]
...
@@ -381,6 +379,7 @@ module MatrixSdk::Protocols::CS
...
@@ -381,6 +379,7 @@ module MatrixSdk::Protocols::CS
}
}
query
[
:to
]
=
params
[
:to
]
if
params
.
key?
:to
query
[
:to
]
=
params
[
:to
]
if
params
.
key?
:to
query
[
:filter
]
=
params
.
fetch
(
:filter
)
if
params
.
key?
:filter
query
[
:filter
]
=
params
.
fetch
(
:filter
)
if
params
.
key?
:filter
query
[
:user_id
]
=
params
.
delete
(
:user_id
)
if
protocols?
(
:AS
)
&&
params
.
key?
(
:user_id
)
room_id
=
CGI
.
escape
room_id
.
to_s
room_id
=
CGI
.
escape
room_id
.
to_s
...
@@ -488,20 +487,24 @@ module MatrixSdk::Protocols::CS
...
@@ -488,20 +487,24 @@ module MatrixSdk::Protocols::CS
user_id:
user_id
,
user_id:
user_id
,
reason:
params
[
:reason
]
||
''
reason:
params
[
:reason
]
||
''
}
}
query
=
{}
query
[
:user_id
]
=
params
.
delete
(
:user_id
)
if
protocols?
(
:AS
)
&&
params
.
key?
(
:user_id
)
room_id
=
CGI
.
escape
room_id
.
to_s
room_id
=
CGI
.
escape
room_id
.
to_s
request
(
:post
,
:client_r0
,
"/rooms/
#{
room_id
}
/ban"
,
body:
content
)
request
(
:post
,
:client_r0
,
"/rooms/
#{
room_id
}
/ban"
,
body:
content
,
query:
query
)
end
end
def
unban_user
(
room_id
,
user_id
)
def
unban_user
(
room_id
,
user_id
)
content
=
{
content
=
{
user_id:
user_id
user_id:
user_id
}
}
query
=
{}
query
[
:user_id
]
=
params
.
delete
(
:user_id
)
if
protocols?
(
:AS
)
&&
params
.
key?
(
:user_id
)
room_id
=
CGI
.
escape
room_id
.
to_s
room_id
=
CGI
.
escape
room_id
.
to_s
request
(
:post
,
:client_r0
,
"/rooms/
#{
room_id
}
/unban"
,
body:
content
)
request
(
:post
,
:client_r0
,
"/rooms/
#{
room_id
}
/unban"
,
body:
content
,
query:
query
)
end
end
def
get_user_tags
(
user_id
,
room_id
)
def
get_user_tags
(
user_id
,
room_id
)
...
@@ -633,16 +636,21 @@ module MatrixSdk::Protocols::CS
...
@@ -633,16 +636,21 @@ module MatrixSdk::Protocols::CS
content
=
{
content
=
{
room_id:
room_id
room_id:
room_id
}
}
query
=
{}
query
[
:user_id
]
=
params
.
delete
(
:user_id
)
if
protocols?
(
:AS
)
&&
params
.
key?
(
:user_id
)
room_alias
=
CGI
.
escape
room_alias
.
to_s
room_alias
=
CGI
.
escape
room_alias
.
to_s
request
(
:put
,
:client_r0
,
"/directory/room/
#{
room_alias
}
"
,
body:
content
)
request
(
:put
,
:client_r0
,
"/directory/room/
#{
room_alias
}
"
,
body:
content
,
query:
query
)
end
end
def
remove_room_alias
(
room_alias
)
def
remove_room_alias
(
room_alias
)
query
=
{}
query
[
:user_id
]
=
params
.
delete
(
:user_id
)
if
protocols?
(
:AS
)
&&
params
.
key?
(
:user_id
)
room_alias
=
CGI
.
escape
room_alias
.
to_s
room_alias
=
CGI
.
escape
room_alias
.
to_s
request
(
:delete
,
:client_r0
,
"/directory/room/
#{
room_alias
}
"
)
request
(
:delete
,
:client_r0
,
"/directory/room/
#{
room_alias
}
"
,
query:
query
)
end
end
def
get_room_members
(
room_id
)
def
get_room_members
(
room_id
)
...
@@ -667,7 +675,10 @@ module MatrixSdk::Protocols::CS
...
@@ -667,7 +675,10 @@ module MatrixSdk::Protocols::CS
send_state_event
(
room_id
,
'm.room.guest_access'
,
content
)
send_state_event
(
room_id
,
'm.room.guest_access'
,
content
)
end
end
def
whoami?
def
whoami?
(
params
=
{})
request
(
:get
,
:client_r0
,
'/account/whoami'
)
query
=
{}
query
[
:user_id
]
=
params
.
delete
(
:user_id
)
if
protocols?
(
:AS
)
&&
params
.
key?
(
:user_id
)
request
(
:get
,
:client_r0
,
'/account/whoami'
,
query:
query
)
end
end
end
end
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