Пример #1
0
 /**
  * Create a ticket from a tweet
  *
  * @param array $params
  *
  * @throws MissingParametersException
  * @throws ResponseException
  * @throws \Exception
  * @return mixed
  */
 public function createFromTweet(array $params)
 {
     if (!$params['twitter_status_message_id'] || !$params['monitored_twitter_handle_id']) {
         throw new MissingParametersException(__METHOD__, ['twitter_status_message_id', 'monitored_twitter_handle_id']);
     }
     $endPoint = Http::prepare('channels/twitter/tickets.json');
     $response = Http::send($this->client, $endPoint, [self::OBJ_NAME => $params], 'POST');
     $lastResponseCode = $this->client->getDebug()->lastResponseCode;
     if (!is_object($response) || $lastResponseCode != 201) {
         throw new ResponseException(__METHOD__, $lastResponseCode == 422 ? ' (hint: you can\'t create two tickets from the same tweet)' : '');
     }
     return $response;
 }
 public function testPutRequestWithContentType()
 {
     $response = Http::send($this->client, 'tickets.json', ['check' => 1], 'PUT', 'application/x-www-form-urlencoded');
     $data = new \StdClass();
     $data->check = 1;
     $this->assertEquals(is_object($response), true, 'Should return an object');
     $this->assertEquals($response->{CURLOPT_URL}, $this->client->getApiUrl() . Http::prepare('tickets.json'), 'Should be the correct url');
     $this->assertEquals($response->{CURLOPT_CUSTOMREQUEST}, 'PUT', 'Should be a PUT');
     $this->assertEquals($response->{CURLOPT_POSTFIELDS}, $data, 'Should have POST data');
     $this->assertContains('Accept: application/json', $response->{CURLOPT_HTTPHEADER}, 'Should contain a Accept header');
     $this->assertContains('Content-Type: application/x-www-form-urlencoded', $response->{CURLOPT_HTTPHEADER}, 'Should contain a Content-Type header');
 }