public function testSetMashapeKey()
 {
     Unirest\Request::setMashapeKey('abcd');
     $response = Unirest\Request::get('http://mockbin.com/request');
     $this->assertEquals(200, $response->code);
     $this->assertTrue(property_exists($response->body->headers, 'x-mashape-key'));
     $this->assertEquals('abcd', $response->body->headers->{'x-mashape-key'});
     // send another request
     $response = Unirest\Request::get('http://mockbin.com/request');
     $this->assertEquals(200, $response->code);
     $this->assertTrue(property_exists($response->body->headers, 'x-mashape-key'));
     $this->assertEquals('abcd', $response->body->headers->{'x-mashape-key'});
     Unirest\Request::clearDefaultHeaders();
     $response = Unirest\Request::get('http://mockbin.com/request');
     $this->assertEquals(200, $response->code);
     $this->assertFalse(property_exists($response->body->headers, 'x-mashape-key'));
 }
Example #2
0
 private function doSkyttleAnalyzation($text, $options)
 {
     $url = "https://sentinelprojects-skyttle20.p.mashape.com/";
     $mashape_key = "xyumIBzeMJmshIB41rhsw7ALq5btp1QopRZjsnfDjm4RnA4pDR";
     $headers = array("X-Mashape-Key" => $mashape_key, "Content-Type" => "application/x-www-form-urlencoded", "Accept" => "application/json");
     $body = array("annotate" => 0, "keywords" => 1, "lang" => "en", "sentiment" => 1, "text" => $text);
     if ($options != '') {
         $body['domain'] = $options;
     }
     // Mashape auth
     Unirest\Request::setMashapeKey($mashape_key);
     $response = Unirest\Request::post($url, $header, $body);
     if ($response->code == "200") {
         //return json_encode(array('status'=>'OK', 'site'=>'doSkyttleAnalyzation_200_OK'));
         return $response->body;
     } else {
         return array('responseCode' => $response->code);
     }
 }