diff options
author | Matias Linares <matiaslina@gmail.com> | 2021-01-11 22:48:16 -0300 |
---|---|---|
committer | Matias Linares <matiaslina@gmail.com> | 2021-01-11 22:48:16 -0300 |
commit | f6397392c4fc88d1e9335bbbc4f91d8cb2f29368 (patch) | |
tree | dddb106193d48ca078946d2edb403ef75faca9dd | |
parent | 14551a46b61a78a55cacf282e0534a1938215467 (diff) | |
parent | 289165e26df8830a15b6df1a63321583a2e67499 (diff) | |
download | perl6-matrix-client-f6397392c4fc88d1e9335bbbc4f91d8cb2f29368.tar.gz |
Merge branch 'documentation'
-rw-r--r-- | META6.json | 12 | ||||
-rw-r--r-- | docs/Matrix/Client.rakudoc (renamed from docs/client.pod6) | 0 | ||||
-rw-r--r-- | docs/Matrix/Client/Exception.rakudoc | 52 | ||||
-rw-r--r-- | docs/Matrix/Client/Requester.rakudoc (renamed from docs/requester.pod6) | 3 | ||||
-rw-r--r-- | docs/Matrix/Client/Response.rakudoc (renamed from docs/responses.pod6) | 1 | ||||
-rw-r--r-- | docs/Matrix/Client/Room.rakudoc (renamed from docs/room.pod6) | 0 | ||||
-rw-r--r-- | docs/basics.rakudoc (renamed from docs/basics.pod6) | 0 | ||||
-rw-r--r-- | docs/usage.rakudoc (renamed from docs/usage.pod6) | 0 | ||||
-rw-r--r-- | docs/x-matrix-response.pod6 | 23 | ||||
-rw-r--r-- | lib/Matrix/Client.rakumod (renamed from lib/Matrix/Client.pm6) | 18 | ||||
-rw-r--r-- | lib/Matrix/Client/Common.rakumod (renamed from lib/Matrix/Client/Common.pm6) | 0 | ||||
-rw-r--r-- | lib/Matrix/Client/Exception.rakumod (renamed from lib/Matrix/Client/Exception.pm6) | 9 | ||||
-rw-r--r-- | lib/Matrix/Client/MediaStore.rakumod | 6 | ||||
-rw-r--r-- | lib/Matrix/Client/Requester.rakumod (renamed from lib/Matrix/Client/Requester.pm6) | 0 | ||||
-rw-r--r-- | lib/Matrix/Client/Response.rakumod (renamed from lib/Matrix/Response.pm6) | 60 | ||||
-rw-r--r-- | lib/Matrix/Client/Room.rakumod (renamed from lib/Matrix/Client/Room.pm6) | 16 | ||||
-rw-r--r-- | t/10-use.t | 2 | ||||
-rw-r--r-- | t/20-client.t | 6 | ||||
-rw-r--r-- | t/30-room.t | 9 | ||||
-rw-r--r-- | t/60-media.t | 4 |
20 files changed, 125 insertions, 96 deletions
@@ -14,13 +14,13 @@ "name" : "Matrix::Client", "perl" : "6.c", "provides" : { - "Matrix::Client" : "lib/Matrix/Client.pm6", - "Matrix::Client::Common" : "lib/Matrix/Client/Common.pm6", - "Matrix::Client::Exception" : "lib/Matrix/Client/Exception.pm6", - "Matrix::Client::Requester" : "lib/Matrix/Client/Requester.pm6", + "Matrix::Client" : "lib/Matrix/Client.rakumod", + "Matrix::Client::Common" : "lib/Matrix/Client/Common.rakumod", + "Matrix::Client::Exception" : "lib/Matrix/Client/Exception.rakumod", + "Matrix::Client::Requester" : "lib/Matrix/Client/Requester.rakumod", "Matrix::Client::MediaStore": "lib/Matrix/Client/MediaStore.rakumod", - "Matrix::Client::Room" : "lib/Matrix/Client/Room.pm6", - "Matrix::Response" : "lib/Matrix/Response.pm6" + "Matrix::Client::Room" : "lib/Matrix/Client/Room.rakumod", + "Matrix::Client::Response" : "lib/Matrix/Client/Response.rakumod" }, "resources" : [ ], "source-url" : "https://github.com/matiaslina/perl6-matrix-client.git", diff --git a/docs/client.pod6 b/docs/Matrix/Client.rakudoc index ba1f2e1..ba1f2e1 100644 --- a/docs/client.pod6 +++ b/docs/Matrix/Client.rakudoc diff --git a/docs/Matrix/Client/Exception.rakudoc b/docs/Matrix/Client/Exception.rakudoc new file mode 100644 index 0000000..f814bbc --- /dev/null +++ b/docs/Matrix/Client/Exception.rakudoc @@ -0,0 +1,52 @@ +=begin pod + +=TITLE Matrix::Client::Exception + +=SUBTITLE Module for all exceptions. + +=head1 X::Matrix::Response + +Error querying the matrix server + + + class X::Matrix::Response is Exception + +Error class when the matrix server returns an error code (4XX). + +=head2 METHODS + +=head3 code + +Returns the HTTP error code. + +=head3 error + +Returns a C<Str> with the matrix error. A full list of error codes can be +found in the L<matrix spec|https://matrix.org/docs/spec/client_server/r0.4.0.html#api-standards>. + +=head3 message + + method message(--> Str) + +Returns the exception message. + +=head1 X::Matrix::MXCParse + +Error while parsing a L<Matrix Content (MXC) URI|https://matrix.org/docs/spec/client_server/r0.6.1#matrix-content-mxc-uris>. + + class X::Matrix::MXCParse is Exception + + +=head2 METHODS + +=head3 code + +Returns the URI that failed to parse. + +=head3 message + + method message(--> Str) + +Returns the exception message. + +=end pod diff --git a/docs/requester.pod6 b/docs/Matrix/Client/Requester.rakudoc index 6710948..2c0215d 100644 --- a/docs/requester.pod6 +++ b/docs/Matrix/Client/Requester.rakudoc @@ -4,7 +4,6 @@ =SUBTITLE Role for HTTP requests - role Matrix::Client::Requester { } Role that gives the base API for objects that interacts to the matrix server. The @@ -28,7 +27,7 @@ Prefix to all the paths used in the methods. =head2 get - method get(Str $path, :$media = False, *%data) + method get(Str $path, :$media = False, *%data) Do a GET to C<$path>. diff --git a/docs/responses.pod6 b/docs/Matrix/Client/Response.rakudoc index 7515d39..e0bed14 100644 --- a/docs/responses.pod6 +++ b/docs/Matrix/Client/Response.rakudoc @@ -6,7 +6,6 @@ =head1 Event - class Matrix::Response::Event { } Common contents of a response. diff --git a/docs/room.pod6 b/docs/Matrix/Client/Room.rakudoc index f186583..f186583 100644 --- a/docs/room.pod6 +++ b/docs/Matrix/Client/Room.rakudoc diff --git a/docs/basics.pod6 b/docs/basics.rakudoc index 5770f4f..5770f4f 100644 --- a/docs/basics.pod6 +++ b/docs/basics.rakudoc diff --git a/docs/usage.pod6 b/docs/usage.rakudoc index 03454d1..03454d1 100644 --- a/docs/usage.pod6 +++ b/docs/usage.rakudoc diff --git a/docs/x-matrix-response.pod6 b/docs/x-matrix-response.pod6 deleted file mode 100644 index d93c263..0000000 --- a/docs/x-matrix-response.pod6 +++ /dev/null @@ -1,23 +0,0 @@ -=begin pod - -=TITLE X::Matrix::Response - -=SUBTITLE Error querying the matrix server - - - class X::Matrix::Response is Exception {} - -Error class when the matrix server returns an error code (4XX). - -=head1 METHODS - -=head2 code - -Returns the HTTP error code. - -=head2 error - -Returns a C<Str> with the matrix error. A full list of error codes can be -found in the L<matrix spec|https://matrix.org/docs/spec/client_server/r0.4.0.html#api-standards>. - -=end pod
\ No newline at end of file diff --git a/lib/Matrix/Client.pm6 b/lib/Matrix/Client.rakumod index 2e26ee7..01babe5 100644 --- a/lib/Matrix/Client.pm6 +++ b/lib/Matrix/Client.rakumod @@ -1,7 +1,7 @@ use HTTP::Request::Common; use URI::Encode; use JSON::Fast; -use Matrix::Response; +use Matrix::Client::Response; use Matrix::Client::Common; use Matrix::Client::Room; use Matrix::Client::Requester; @@ -123,14 +123,14 @@ method whoami { method devices(Matrix::Client:D: --> Seq) { my $data = from-json($.get("/devices").content); $data<devices>.map(-> $device-data { - Matrix::Response::Device.new(|$device-data) + Matrix::Client::Response::Device.new(|$device-data) }) } #| GET - /_matrix/client/r0/devices/{deviceId} -method device(Matrix::Client:D: Str $device-id where *.chars > 0 --> Matrix::Response::Device) { +method device(Matrix::Client:D: Str $device-id where *.chars > 0 --> Matrix::Client::Response::Device) { my $device-data = from-json($.get("/devices/$device-id").content); - Matrix::Response::Device.new(|$device-data) + Matrix::Client::Response::Device.new(|$device-data) } #| PUT - /_matrix/client/r0/devices/{deviceId} @@ -143,10 +143,10 @@ method update-device(Matrix::Client:D: ## Presence #| GET - /_matrix/client/r0/presence/{userId}/status -method presence(Matrix::Client:D: $user-id? --> Matrix::Response::Presence) { +method presence(Matrix::Client:D: $user-id? --> Matrix::Client::Response::Presence) { my $id = $user-id // $.whoami; my $data = from-json($.get("/presence/$id/status").content); - Matrix::Response::Presence.new(|$data) + Matrix::Client::Response::Presence.new(|$data) } #| PUT - /_matrix/client/r0/presence/{userId}/status @@ -164,7 +164,7 @@ multi method tags(Str $room-id, Str:D $tag, $order) { #| GET - /_matrix/client/r0/user/{userId}/rooms/{roomId}/tags multi method tags(Str $room-id) { my $id = $.whoami; - Matrix::Response::Tag.new(from-json($.get("/user/$id/rooms/$room-id/tags").content)) + Matrix::Client::Response::Tag.new(from-json($.get("/user/$id/rooms/$room-id/tags").content)) } #| DELETE - /_matrix/client/r0/user/{userId}/rooms/{roomId}/tags/{tag} @@ -188,13 +188,13 @@ multi method sync(Str:D :$sync-filter, Str :$since = "") { :$since ); - Matrix::Response::Sync.new($res.content) + Matrix::Client::Response::Sync.new($res.content) } #| GET - /_matrix/client/r0/sync multi method sync(:$since = "") { my $res = $.get("/sync", timeout => 30000, since => $since); - Matrix::Response::Sync.new($res.content) + Matrix::Client::Response::Sync.new($res.content) } # Rooms diff --git a/lib/Matrix/Client/Common.pm6 b/lib/Matrix/Client/Common.rakumod index 83cf65d..83cf65d 100644 --- a/lib/Matrix/Client/Common.pm6 +++ b/lib/Matrix/Client/Common.rakumod diff --git a/lib/Matrix/Client/Exception.pm6 b/lib/Matrix/Client/Exception.rakumod index e02f572..6fb4c75 100644 --- a/lib/Matrix/Client/Exception.pm6 +++ b/lib/Matrix/Client/Exception.rakumod @@ -1,14 +1,15 @@ -package X::Matrix { - class Response is Exception { +module Matrix::Client::Exception { + + class X::Matrix::Response is Exception { has $.code; has $.error; - method message { + method message(--> Str) { "$!code: $!error" } } - class MXCParse is Exception { + class X::Matrix::MXCParse is Exception { has $.uri; method message { "Cannot parse '$!uri'" } diff --git a/lib/Matrix/Client/MediaStore.rakumod b/lib/Matrix/Client/MediaStore.rakumod index 9779db2..afea9e5 100644 --- a/lib/Matrix/Client/MediaStore.rakumod +++ b/lib/Matrix/Client/MediaStore.rakumod @@ -3,7 +3,7 @@ use URI::Escape; use Matrix::Client::Requester; use Matrix::Client::Exception; -use Matrix::Response; +use Matrix::Client::Response; unit class Matrix::Client::MediaStore does Matrix::Client::Requester; @@ -110,7 +110,7 @@ multi method thumbnail(Str $server-name, Str $media-id, } #| GET - /_matrix/media/r0/config -method config(--> Matrix::Response::MediaStore::Config) { +method config(--> Matrix::Client::Response::MediaStore::Config) { my $response = $.get("/config"); - Matrix::Response::MediaStore::Config.new(from-json($response.content)) + Matrix::Client::Response::MediaStore::Config.new(from-json($response.content)) } diff --git a/lib/Matrix/Client/Requester.pm6 b/lib/Matrix/Client/Requester.rakumod index 36a9f69..36a9f69 100644 --- a/lib/Matrix/Client/Requester.pm6 +++ b/lib/Matrix/Client/Requester.rakumod diff --git a/lib/Matrix/Response.pm6 b/lib/Matrix/Client/Response.rakumod index a0b2896..3836a20 100644 --- a/lib/Matrix/Response.pm6 +++ b/lib/Matrix/Client/Response.rakumod @@ -1,13 +1,13 @@ use JSON::Fast; -unit module Matrix::Response; +unit module Matrix::Client::Response; -class Matrix::Response::Event { +class Event { has %.content; has $.type is required; } -class Matrix::Response::RoomEvent is Matrix::Response::Event { +class RoomEvent is Event { has Str $.sender; has Int $.origin_server_ts; has $.event_id; @@ -18,57 +18,57 @@ class Matrix::Response::RoomEvent is Matrix::Response::Event { method room-id { $.room_id } } -class Matrix::Response::StateEvent is Matrix::Response::RoomEvent { +class StateEvent is RoomEvent { has $.prev_content; has $.state_key; } -class Matrix::Response::MemberEvent is Matrix::Response::StateEvent { +class MemberEvent is StateEvent { has $.type is required where 'm.room.member'; } -class Matrix::Response::Timeline { - has Matrix::Response::Event @.events; +class Timeline { + has Event @.events; has Bool $limited; has Str $prev-batch; } -class Matrix::Response::RoomInfo { +class RoomInfo { has $.room-id is required; - has Matrix::Response::Event @.state; - has Matrix::Response::Timeline $.timeline; + has Event @.state; + has Timeline $.timeline; method gist(--> Str) { - "<Matrix::Response::RoomInfo: $.room-id>" + "<RoomInfo: $.room-id>" } } -class Matrix::Response::InviteInfo { +class InviteInfo { has $.room-id is required; - has Matrix::Response::Event @.events; + has Event @.events; method gist(--> Str) { - "<Matrix::Response::InviteState: $.room-id>" + "<InviteState: $.room-id>" } } sub gather-events($room-id, $from) { gather for $from<events>.List -> $ev { - take Matrix::Response::StateEvent.new(:room_id($room-id), |$ev); + take StateEvent.new(:room_id($room-id), |$ev); } } -class Matrix::Response::Messages { +class Messages { has $.start; has $.end; - has Matrix::Response::RoomEvent @.messages; + has RoomEvent @.messages; } -class Matrix::Response::Sync { +class Sync { has Str $.next-batch; - has Matrix::Response::Event @.presence; - has Matrix::Response::RoomInfo @.joined-rooms; - has Matrix::Response::InviteInfo @.invited-rooms; + has Event @.presence; + has RoomInfo @.joined-rooms; + has InviteInfo @.invited-rooms; multi method new(Str $json) { return self.new(from-json($json)); @@ -76,31 +76,31 @@ class Matrix::Response::Sync { multi method new(Hash $json) { my $next-batch = $json<next_batch>; - my Matrix::Response::Event @presence; - my Matrix::Response::RoomInfo @joined-rooms; - my Matrix::Response::InviteInfo @invited-rooms; + my Event @presence; + my RoomInfo @joined-rooms; + my InviteInfo @invited-rooms; for $json<presence><events>.List -> $ev { - @presence.push(Matrix::Response::Event.new(|$ev)); + @presence.push(Event.new(|$ev)); } for $json<rooms><join>.kv -> $room-id, $data { my @state = gather-events($room-id, $data<state>); - my $timeline = Matrix::Response::Timeline.new( + my $timeline = Timeline.new( limited => $data<timeline><limited>, prev-batch => $data<timeline><prev_batch>, events => gather-events($room-id, $data<timeline>) ); - @joined-rooms.push(Matrix::Response::RoomInfo.new( + @joined-rooms.push(RoomInfo.new( :$room-id, :$timeline, :@state )); } for $json<rooms><invite>.kv -> $room-id, $data { my @events = gather-events($room-id, $data<invite_state>); - @invited-rooms.push(Matrix::Response::InviteInfo.new( + @invited-rooms.push(InviteInfo.new( :$room-id, :@events )); } @@ -133,7 +133,7 @@ class Tag { } } -class Matrix::Response::Device { +class Device { has Str $.device-id; has $.display-name; has $.last-seen-ip; @@ -147,7 +147,7 @@ class Matrix::Response::Device { ) { } } -class Matrix::Response::MediaStore::Config { +class MediaStore::Config { has Int $.upload-size; method new(%config) { diff --git a/lib/Matrix/Client/Room.pm6 b/lib/Matrix/Client/Room.rakumod index 3d6ecaa..1e8c582 100644 --- a/lib/Matrix/Client/Room.pm6 +++ b/lib/Matrix/Client/Room.rakumod @@ -1,7 +1,7 @@ use JSON::Fast; use Matrix::Client::Common; use Matrix::Client::Requester; -use Matrix::Response; +use Matrix::Client::Response; unit class Matrix::Client::Room does Matrix::Client::Requester; @@ -56,9 +56,9 @@ method aliases(--> List) { ## Getting events for a room #| GET - /_matrix/client/r0/rooms/{roomId}/event/{eventId} -method event(Str $event-id --> Matrix::Response::RoomEvent) { +method event(Str $event-id --> Matrix::Client::Response::RoomEvent) { my %data = from-json($.get("/event/$event-id").content); - Matrix::Response::RoomEvent.new(|%data) + Matrix::Client::Response::RoomEvent.new(|%data) } #| GET - /_matrix/client/r0/rooms/{roomId}/state @@ -66,7 +66,7 @@ multi method state(--> Seq) { my $data = from-json($.get('/state').content); gather for $data.List -> $event { - take Matrix::Response::StateEvent.new(:room-id($.id), |$event) + take Matrix::Client::Response::StateEvent.new(:room-id($.id), |$event) } } @@ -86,7 +86,7 @@ method messages( Str:D :$from!, Str :$to, Str :$dir where * eq 'f'|'b' = 'f', Int :$limit = 10, :%filter, - --> Matrix::Response::Messages + --> Matrix::Client::Response::Messages ) { my $res = $.get( "/messages", :$from, :$to, :$dir, :$limit, :%filter @@ -95,10 +95,10 @@ method messages( my @messages = $data<chunk>.map(-> $ev { - Matrix::Response::RoomEvent.new(|$ev) + Matrix::Client::Response::RoomEvent.new(|$ev) }); - Matrix::Response::Messages.new( + Matrix::Client::Response::Messages.new( start => $data<start>, end => $data<end>, messages => @messages @@ -116,7 +116,7 @@ method members(:$at, Str :$membership, Str :$not-membership --> Seq) { my %data = from-json($.get('/members', |%query).content); gather for %data<chunk>.List -> $ev { - take Matrix::Response::MemberEvent.new(|$ev) + take Matrix::Client::Response::MemberEvent.new(|$ev) } } @@ -4,7 +4,7 @@ use Test; use-ok 'Matrix::Client'; use-ok 'Matrix::Client::Room'; use-ok 'Matrix::Client::Requester'; -use-ok 'Matrix::Response'; +use-ok 'Matrix::Client::Response'; use-ok 'Matrix::Client::Exception'; use-ok 'Matrix::Client::MediaStore'; diff --git a/t/20-client.t b/t/20-client.t index 2215a6b..c15d86f 100644 --- a/t/20-client.t +++ b/t/20-client.t @@ -55,12 +55,12 @@ subtest 'User data' => { subtest 'sync' => { plan 3; - isa-ok $client.sync(), Matrix::Response::Sync, + isa-ok $client.sync(), Matrix::Client::Response::Sync, 'sync without params is a Response'; isa-ok $client.sync(:sync-filter('{"room": { "timeline": { "limit": 1 } } }')), - Matrix::Response::Sync, 'sync with Str sync-filter'; + Matrix::Client::Response::Sync, 'sync with Str sync-filter'; isa-ok $client.sync(:sync-filter(room => timeline => limit => 1)), - Matrix::Response::Sync, 'sync wit Hash sync-filter'; + Matrix::Client::Response::Sync, 'sync wit Hash sync-filter'; } subtest 'directory' => { diff --git a/t/30-room.t b/t/30-room.t index 56321a0..9cec207 100644 --- a/t/30-room.t +++ b/t/30-room.t @@ -41,9 +41,10 @@ lives-ok { $main-room.leave; }, 'Can leave room'; -lives-ok { - $main-room.join; -}, 'Can join a room'; +skip 'M_UNKNOWN: No known servers', 1; +#lives-ok { +# $main-room.join; +#}, 'Can join a room'; lives-ok { $client.join-room($public-room-id) @@ -59,7 +60,7 @@ subtest 'states' => { plan 2; isa-ok $main-room.state(), Seq; my @states = $main-room.state(); - isa-ok @states.first(), Matrix::Response::StateEvent; + isa-ok @states.first(), Matrix::Client::Response::StateEvent; }; subtest 'creation' => { diff --git a/t/60-media.t b/t/60-media.t index 2417cb1..618e2c2 100644 --- a/t/60-media.t +++ b/t/60-media.t @@ -60,7 +60,7 @@ subtest 'config', { } } - isa-ok $media.config, Matrix::Response::MediaStore::Config, 'Can load Associative'; + isa-ok $media.config, Matrix::Client::Response::MediaStore::Config, 'Can load Associative'; is $media.config.upload-size, 5000, 'correct upload size'; my $empty-media = Matrix::Client::MediaStore.new(:home-server("1234")) but role { @@ -69,7 +69,7 @@ subtest 'config', { } } - isa-ok $empty-media.config, Matrix::Response::MediaStore::Config, 'Can load empty configuration'; + isa-ok $empty-media.config, Matrix::Client::Response::MediaStore::Config, 'Can load empty configuration'; is $empty-media.config.upload-size, Int, 'Unknown upload-size'; nok $empty-media.config.upload-size.defined, 'upload-size not defined'; |