/**
  * @coversNothing
  */
 public function testLintServiceDescription()
 {
     if (!$this->canServiceDescriptionBeLoaded()) {
         $json = file_get_contents(Client::getDescriptionFilename());
         $parser = new JsonParser();
         $result = $parser->lint($json);
         if ($result) {
             $this->fail($result->getMessage());
         }
     }
     $this->assertTrue(true);
 }
Example #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];
 }
Example #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');
Example #4
0
 /**
  * Adds a relationship plugin to the client
  *
  * @param Desk\Client $client The client to add the Plugin to
  */
 public function addRelationshipPlugin(Client &$client)
 {
     $client->addSubscriber(new RelationshipPlugin());
 }
 /**
  * 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;
 }
Example #6
0
 /**
  * @covers Desk\Client\Factory::processConfig
  * @dataProvider dataProcessConfigInvalid
  * @expectedException Guzzle\Common\Exception\InvalidArgumentException
  */
 public function testProcessConfigInvalid($config)
 {
     Client::factory($config);
 }
Example #7
0
 /**
  * Adds the correct ResourceIteratorFactory to the client
  *
  * @param \Desk\Client $client The client to configure
  */
 public function addResourceIteratorFactory(Client &$client)
 {
     $client->setResourceIteratorFactory(new DeskIteratorFactory());
 }
Example #8
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;
 }
Example #9
0
 /**
  * @covers Desk\Client::getDescriptionFilename
  */
 public function testGetDescriptionFilename()
 {
     $result = Client::getDescriptionFilename();
     $this->assertInternalType('string', $result);
     $this->assertTrue(file_exists($result));
 }
Example #10
0
 /**
  * @dataProvider dataCreateClientInvalid
  * @expectedException Guzzle\Common\Exception\InvalidArgumentException
  */
 public function testCreateClientInvalid($config)
 {
     Client::factory($config);
 }
Example #11
0
 /**
  * Determines whether the desk.json service description is valid
  *
  * @return boolean
  */
 protected function canServiceDescriptionBeLoaded()
 {
     if (self::$serviceDescriptionCanBeLoaded === null) {
         self::$serviceDescriptionCanBeLoaded = false;
         $filename = DeskClient::getDescriptionFilename();
         $loader = new ServiceDescriptionLoader();
         // try {
         $description = $loader->load($filename);
         self::$serviceDescriptionCanBeLoaded = true;
         // } catch (RuntimeException $e) {
         //     // leave it as false
         // }
     }
     return self::$serviceDescriptionCanBeLoaded;
 }