Beispiel #1
0
 /**
  * @covers Desk\Client::factory
  */
 public function testFactory()
 {
     $factory = \Mockery::mock('Desk\\Client\\Factory')->shouldReceive('factory')->with(array('foo' => 'bar'))->andReturn('return value')->getMock();
     Client::setFactory($factory);
     $result = Client::factory(array('foo' => 'bar'));
     $this->assertSame('return value', $result);
 }
Beispiel #2
0
 /**
  * Combined getter/setter for API clients.
  *
  * @param int $type The "type" of API client to get or set
  * @param \Desk\Client The new object to use as a client (optional)
  *
  * @return \Desk\Client
  */
 public function client($type, $client = null)
 {
     if (!Client::isValidType($type)) {
         throw new Exception\InvalidArgumentException("Invalid Desk API client type \"{$type}\"");
     }
     if ($client) {
         if ($client instanceof Client) {
             $this->clients[$type] = $client;
         } else {
             throw new Exception\InvalidArgumentException('Desk API client is not an instance of \\Desk\\Client');
         }
     }
     // initialise client if it doesn't exist
     if (empty($this->clients[$type])) {
         $this->clients[$type] = Client::factory($type, $this->transport);
     }
     return $this->clients[$type];
 }
Beispiel #3
0
<?php

require_once 'vendor/autoload.php';
$client = \Desk\Client::factory(array('subdomain' => 'younique', 'username' => '*****@*****.**', 'password' => 'Canada25!'));
//gets paginated list of cases
$args = array();
$cases = $client->getCommand('SearchCases', $args)->execute()->getEmbedded('entries');
$result = new stdClass();
foreach ($cases as $key => $value) {
    $case_links = $value->getResource('message');
    $case_id = $case_links->getLink('case')->get('id');
    $case_id = $value->getResource('message')->getLink('case')->get('id');
    $result->{$case_id} = new stdClass();
    $result->{$case_id}->body = $case_links->get('body');
    $result->{$case_id}->subject = $case_links->get('subject');
    $result->{$case_id}->from = $case_links->get('from');
    $result->{$case_id}->to = $case_links->get('to');
    $result->{$case_id}->direction = $case_links->get('direction');
    $result->{$case_id}->status = $case_links->get('status');
    $result->{$case_id}->created_at = $case_links->get('created_at');
    $result->{$case_id}->updated_at = $case_links->get('updated_at');
    //get replies
    $result->{$case_id}->replies = new stdClass();
    $replies = $client->getCommand('ListCaseReplies')->set('case_id', $case_id)->execute()->getEmbedded('entries');
    foreach ($replies as $key => $value) {
        $reply_id = $value->getLink('self')->get('reply_id');
        $reply = new stdClass();
        $reply->subject = $value->get('subject');
        $reply->body = $value->get('body');
        $reply->from = $value->get('from');
        $reply->to = $value->get('to');
 /**
  * Prepares the relevant type of API client with a mock transport.
  *
  * @return \Desk\Client
  */
 protected final function client()
 {
     $client = Client::factory($this->getType());
     $client->transport(\Mockery::mock('\\Desk\\Transport'));
     return $client;
 }
Beispiel #5
0
 /**
  * @covers Desk\Client\Factory::processConfig
  * @dataProvider dataProcessConfigInvalid
  * @expectedException Guzzle\Common\Exception\InvalidArgumentException
  */
 public function testProcessConfigInvalid($config)
 {
     Client::factory($config);
 }
Beispiel #6
0
 public function getTicketsByEmail($email)
 {
     require_once APPLICATION_PATH . LIBRARY_DIR . '/desk_api/vendor/autoload.php';
     $client = \Desk\Client::factory(array('subdomain' => 'younique', 'username' => '*****@*****.**', 'password' => 'Canada25!'));
     //gets paginated list of cases
     $args = array('email' => $email);
     $cases = $client->getCommand('SearchCases', $args)->execute()->getEmbedded('entries');
     $result = array();
     foreach ($cases as $key => $value) {
         $case_links = $value->getResource('message');
         $case_id = $case_links->getLink('case')->get('id');
         $case = new stdClass();
         $case->id = $case_id;
         $case->body = $case_links->get('body');
         $case->subject = $case_links->get('subject');
         $case->from = $case_links->get('from');
         $case->to = $case_links->get('to');
         $case->direction = $case_links->get('direction');
         $case->status = $value->get('status');
         $case->created_at = $case_links->get('created_at')->format('Y-m-d H:i:s');
         $case->updated_at = $case_links->get('updated_at')->format('Y-m-d H:i:s');
         //get replies
         $case->replies = array();
         $replies = $client->getCommand('ListCaseReplies')->set('case_id', $case_id)->execute()->getEmbedded('entries');
         foreach ($replies as $key => $value) {
             $reply_id = $value->getLink('self')->get('reply_id');
             $reply = new stdClass();
             $reply->id = $reply_id;
             $reply->subject = $value->get('subject');
             $reply->body = $value->get('body');
             $reply->from = $value->get('from');
             $reply->to = $value->get('to');
             $reply->direction = $value->get('direction');
             $reply->status = $value->get('status');
             $reply->created_at = $value->get('created_at')->format('Y-m-d H:i:s');
             $reply->updated_at = $value->get('updated_at')->format('Y-m-d H:i:s');
             $case->replies[] = $reply;
         }
         //get notes
         $case->notes = array();
         $notes = $client->getCommand('ListCaseNotes')->set('case_id', $case_id)->execute()->getEmbedded('entries');
         foreach ($notes as $key => $value) {
             $note_id = $value->getLink('self')->get('note_id');
             $note = new stdClass();
             $note->id = $note_id;
             $note->subject = $value->get('subject');
             $note->body = $value->get('body');
             $note->to = $value->get('to');
             $note->direction = $value->get('direction');
             $note->status = $value->get('status');
             $note->created_at = $value->get('created_at')->format('Y-m-d H:i:s');
             $note->updated_at = $value->get('updated_at')->format('Y-m-d H:i:s');
             //get note user
             $user = $value->getLink('user');
             $user_id = $user->get('id');
             $note->from = $client->getCommand('ShowUser')->set('id', $user_id)->execute()->get('name');
             $case->notes[] = $note;
         }
         $result[] = $case;
     }
     return $result;
 }
Beispiel #7
0
 /**
  * @dataProvider dataCreateClientInvalid
  * @expectedException Guzzle\Common\Exception\InvalidArgumentException
  */
 public function testCreateClientInvalid($config)
 {
     Client::factory($config);
 }