From b0643e39808930d2ea5a04f1a35e9b1e14e06861 Mon Sep 17 00:00:00 2001 From: Matias Linares Date: Sat, 8 Sep 2018 12:46:03 -0300 Subject: Add documentation to run method. --- docs/client.pod6 | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/docs/client.pod6 b/docs/client.pod6 index 6256cde..302e99b 100644 --- a/docs/client.pod6 +++ b/docs/client.pod6 @@ -242,4 +242,34 @@ the servers may choose to implement additional access control for this endpoint. Uploads a file to the server. It returns the MXC URI to the uploaded content. +=head2 run + + method run(Int :$sleep = 10, :$sync-filter? --> Supply) + +Returns a C that emits L with the last +events. The C<$sleep> parameter is to sleep for that amount of seconds before +making a L request again. The C<$sync-filter> is the same parameter that +will be passed to L method to filter out the useful events. + +This can be useful to turn something like: + + my $since; + loop { + $response = $client.sync(:$since); + $since = $response.next-batch; + + for $response.joined-rooms -> $room { + for $room.timeline.event -> $event { + # Do something useful with $event + } + } + } + +into: + + my $sup = $client.run(); + react whenever $sup -> $event { + # Do something useful with $event + } + =end pod -- cgit v1.2.3-54-g00ecf From 2aab03cd0db9854ffc787dc7c2d2c790bc84cc50 Mon Sep 17 00:00:00 2001 From: Matias Linares Date: Sat, 8 Sep 2018 12:47:13 -0300 Subject: Add run example. --- examples/run.p6 | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 examples/run.p6 diff --git a/examples/run.p6 b/examples/run.p6 new file mode 100644 index 0000000..f78df16 --- /dev/null +++ b/examples/run.p6 @@ -0,0 +1,21 @@ +#!/usr/bin/env perl6 +use v6; +use lib ; +use Matrix::Client; + +sub MAIN(Str:D $username, Str:D $password, :$home-server = "https://matrix.deprecated.org") { + my Matrix::Client $client .= new: :$home-server; + $client.login($username, $password); + + my $sup = $client.run(:sleep<5>); + + signal(SIGINT).tap({ + say "Bye"; + $client.logout; + exit 0; + }); + + react whenever $sup -> $ev { + say $ev; + } +} -- cgit v1.2.3-54-g00ecf From 66c31dda1500b54fd284b82478019e9da6a7e9d1 Mon Sep 17 00:00:00 2001 From: Matias Linares Date: Sat, 8 Sep 2018 13:29:04 -0300 Subject: Add documentation for Matrix::Client::Room --- docs/room.pod6 | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 docs/room.pod6 diff --git a/docs/room.pod6 b/docs/room.pod6 new file mode 100644 index 0000000..1df8c84 --- /dev/null +++ b/docs/room.pod6 @@ -0,0 +1,68 @@ +=begin pod + +=TITLE class Matrix::Client::Room + +=SUBTITLE Room requester + + class Matrix::Client::Room does Matrix::Client::Requester {} + +The C is a shortcut to all the C endpoints. It +does the role as L so one can instantiate a Room with +the one's access token and the room id to make requests directly to this room +without the need for a L. + +=head1 Example + + my $room-id = "!pGOClvZafMH:matrix.server.com"; + my $home-server = "https://matrix.server.com"; + my $access-token = "…"; + + my Matrix::Client::Room $room .= new( + :$access-token, + :$home-server, + :id($room-id) + ); + + say $room.name; + +=head1 Methods + +=head2 name + + method name(--> Str) + +Returns the name of the room. If no C was emmited (i.e.: no name +was set for this room), then an empty string is returned. + +=head2 send + + method send(Str $body!, Str :$type? = "m.text") + +Sends a message to the room. It will return the C for this message. + +=head2 state + + multi method state(--> Seq) + multi method state(Str $event-type) + +Get the state events for the current state of a room. it will return a C +for every event on that room. + +If an C<$event-type> is passed, the return value will be the value of that +single event. + +=head2 send-state + + method send-state(Str:D $event-type, :$state-key = "", *%args --> Str) + +Send a state event to the server. The event will be overwritten if the +C<$event-type>, C<$state-key> and the arguments all match with a state in the +server. + +It will return the C for this state change. + +=head2 leave + + method leave() + +Leaves the room. -- cgit v1.2.3-54-g00ecf