1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Mremi\Flowdock library. |
5
|
|
|
* |
6
|
|
|
* (c) Rémi Marseille <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Mremi\Flowdock\Api\Push; |
13
|
|
|
|
14
|
|
|
use GuzzleHttp\Client; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Push class |
18
|
|
|
* |
19
|
|
|
* @author Rémi Marseille <[email protected]> |
20
|
|
|
*/ |
21
|
|
|
class Push implements PushInterface |
22
|
|
|
{ |
23
|
|
|
const BASE_CHAT_URL = 'https://api.flowdock.com/v1/messages/chat'; |
24
|
|
|
const BASE_TEAM_INBOX_URL = 'https://api.flowdock.com/v1/messages/team_inbox'; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var string |
28
|
|
|
*/ |
29
|
|
|
private $flowApiToken; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Constructor |
33
|
|
|
* |
34
|
|
|
* @param string $flowApiToken A flow API token |
35
|
|
|
*/ |
36
|
|
|
public function __construct($flowApiToken) |
37
|
|
|
{ |
38
|
|
|
$this->flowApiToken = $flowApiToken; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* {@inheritdoc} |
43
|
|
|
*/ |
44
|
|
|
public function sendChatMessage(ChatMessageInterface $message, array $options = array()) |
45
|
|
|
{ |
46
|
|
|
return $this->sendMessage($message, self::BASE_CHAT_URL, $options); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* {@inheritdoc} |
51
|
|
|
*/ |
52
|
|
|
public function sendTeamInboxMessage(TeamInboxMessageInterface $message, array $options = array()) |
53
|
|
|
{ |
54
|
|
|
return $this->sendMessage($message, self::BASE_TEAM_INBOX_URL, $options); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Sends a message to a flow |
59
|
|
|
* |
60
|
|
|
* @param BaseMessageInterface $message A message instance to send |
61
|
|
|
* @param string $baseUrl A base URL |
62
|
|
|
* @param array $options An array of options used by request |
63
|
|
|
* |
64
|
|
|
* @return boolean |
65
|
|
|
*/ |
66
|
|
|
protected function sendMessage(BaseMessageInterface $message, $baseUrl, array $options = array()) |
67
|
|
|
{ |
68
|
|
|
$client = $this->createClient(sprintf('%s/%s', $baseUrl, $this->flowApiToken)); |
69
|
|
|
|
70
|
|
|
$response = $client->post(null, array_merge( |
71
|
|
|
$options, [ |
72
|
|
|
'headers' => ['Content-Type' => 'application/json'], |
73
|
|
|
'json' => $message->getData() |
74
|
|
|
] |
75
|
|
|
)); |
76
|
|
|
|
77
|
|
|
$message->setResponse($response); |
78
|
|
|
|
79
|
|
|
return !$message->hasResponseErrors(); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Creates a client to interact with Flowdock API |
84
|
|
|
* |
85
|
|
|
* @param string $url |
86
|
|
|
* |
87
|
|
|
* @return Client |
88
|
|
|
*/ |
89
|
|
|
protected function createClient($url) |
90
|
|
|
{ |
91
|
|
|
return new Client($url); |
|
|
|
|
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: