[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class PhabricatorBotFlowdockProtocolAdapter 4 extends PhabricatorBotBaseStreamingProtocolAdapter { 5 6 public function getServiceType() { 7 return 'Flowdock'; 8 } 9 10 protected function buildStreamingUrl($channel) { 11 $organization = $this->getConfig('flowdock.organization'); 12 if (empty($organization)) { 13 $this->getConfig('organization'); 14 } 15 if (empty($organization)) { 16 throw new Exception( 17 '"flowdock.organization" configuration variable not set'); 18 } 19 20 21 $ssl = $this->getConfig('ssl'); 22 23 $url = ($ssl) ? 'https://' : 'http://'; 24 $url .= "{$this->authtoken}@stream.flowdock.com"; 25 $url .= "/flows/{$organization}/{$channel}"; 26 return $url; 27 } 28 29 protected function processMessage($m_obj) { 30 $command = null; 31 switch ($m_obj['event']) { 32 case 'message': 33 $command = 'MESSAGE'; 34 break; 35 default: 36 // For now, ignore anything which we don't otherwise know about. 37 break; 38 } 39 40 if ($command === null) { 41 return false; 42 } 43 44 // TODO: These should be usernames, not user IDs. 45 $sender = id(new PhabricatorBotUser()) 46 ->setName($m_obj['user']); 47 48 $target = id(new PhabricatorBotChannel()) 49 ->setName($m_obj['flow']); 50 51 return id(new PhabricatorBotMessage()) 52 ->setCommand($command) 53 ->setSender($sender) 54 ->setTarget($target) 55 ->setBody($m_obj['content']); 56 } 57 58 public function writeMessage(PhabricatorBotMessage $message) { 59 switch ($message->getCommand()) { 60 case 'MESSAGE': 61 $this->speak( 62 $message->getBody(), 63 $message->getTarget()); 64 break; 65 } 66 } 67 68 private function speak( 69 $body, 70 PhabricatorBotTarget $flow) { 71 // The $flow->getName() returns the flow's UUID, 72 // as such, the Flowdock API does not require the organization 73 // to be specified in the URI 74 $this->performPost( 75 '/messages', 76 array( 77 'flow' => $flow->getName(), 78 'event' => 'message', 79 'content' => $body, 80 )); 81 } 82 83 public function __destruct() { 84 if ($this->readHandles) { 85 foreach ($this->readHandles as $read_handle) { 86 curl_multi_remove_handle($this->multiHandle, $read_handle); 87 curl_close($read_handle); 88 } 89 } 90 91 curl_multi_close($this->multiHandle); 92 } 93 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Nov 30 09:20:46 2014 | Cross-referenced by PHPXref 0.7.1 |