Skip to content

Commit

Permalink
wip Zulip
Browse files Browse the repository at this point in the history
  • Loading branch information
guanguans committed Feb 4, 2024
1 parent 9c7f63d commit 34a848a
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 81 deletions.
18 changes: 17 additions & 1 deletion src/Zulip/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,20 @@

namespace Guanguans\Notify\Zulip;

class Client extends \Guanguans\Notify\Foundation\Client {}
use Guanguans\Notify\Foundation\Contracts\Credential;

/**
* @see https://chat.zulip.org/accounts/login
* @see https://zulip.com/api/send-message
*/
class Client extends \Guanguans\Notify\Foundation\Client
{
public function __construct(?Credential $credential = null)
{
parent::__construct($credential);

$this->setHttpOptions([
'base_uri' => 'https://chat.zulip.org',
]);
}
}
4 changes: 2 additions & 2 deletions src/Zulip/Credential.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

class Credential extends BasicAuthCredential
{
public function __construct(string $email, string $token)
public function __construct(string $botEmail, string $botApiKey)
{
parent::__construct($email, $token);
parent::__construct($botEmail, $botApiKey);
}
}
49 changes: 49 additions & 0 deletions src/Zulip/Messages/DirectMessage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

declare(strict_types=1);

/**
* This file is part of the guanguans/notify.
*
* (c) guanguans <[email protected]>
*
* This source file is subject to the MIT license that is bundled.
*/

namespace Guanguans\Notify\Zulip\Messages;

/**
* @method \Guanguans\Notify\Zulip\Messages\DirectMessage type($type)
* @method \Guanguans\Notify\Zulip\Messages\DirectMessage to($to)
* @method \Guanguans\Notify\Zulip\Messages\DirectMessage content($content)
*/
class DirectMessage extends Message
{
protected array $defined = [
'type',
'to',
'content',
];

protected array $required = [
'type',
'to',
'content',
];

protected array $defaults = [
'type' => 'direct',
];

protected array $allowedTypes = [
'to' => ['string', 'int', 'array'],
];

protected array $allowedValues = [
'type' => ['direct'],
];

protected array $options = [
'type' => 'direct',
];
}
8 changes: 4 additions & 4 deletions src/Zulip/Messages/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@

namespace Guanguans\Notify\Zulip\Messages;

use Guanguans\Notify\Foundation\Concerns\AsJson;
use Guanguans\Notify\Foundation\Concerns\AsFormParams;
use Guanguans\Notify\Foundation\Concerns\AsPost;

class Message extends \Guanguans\Notify\Foundation\Message
{
use AsJson;
use AsFormParams;
use AsPost;

public function toHttpUri()
public function toHttpUri(): string
{
return '%s/api/v1/messages';
return 'api/v1/messages';
}
}
61 changes: 0 additions & 61 deletions src/Zulip/Messages/PrivateMessage.php

This file was deleted.

14 changes: 1 addition & 13 deletions src/Zulip/Messages/StreamMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@
*/
class StreamMessage extends Message
{
/**
* @var array<string>
*/
protected array $defined = [
'type',
'to',
Expand All @@ -34,9 +31,6 @@ class StreamMessage extends Message
'local_id',
];

/**
* @var array<string>
*/
protected array $required = [
'type',
'to',
Expand All @@ -45,23 +39,17 @@ class StreamMessage extends Message
];

protected array $allowedTypes = [
'to' => ['string', 'int'],
'to' => ['string', 'int', 'array'],
'content' => 'string',
'topic' => 'string',
'queue_id' => 'string',
'local_id' => 'string',
];

/**
* @var array<string>
*/
protected array $defaults = [
'type' => 'stream',
];

/**
* @var array<array<\string>>
*/
protected array $allowedValues = [
'type' => ['stream'],
];
Expand Down

0 comments on commit 34a848a

Please sign in to comment.