Example #1
0
 public static function send($url, $method, $data = array())
 {
     // create a new Guzzle\Http\Client
     $browser = new Browser();
     $browser->setUserAgent(self::userAgent());
     $options = array();
     $options['allow_redirects'] = @$data['allow_redirects'] ?: false;
     $options['json'] = @$data['json'] ?: false;
     if (@$data['body']) {
         $options['body'] = $data['body'];
         if (\Terminus::get_config("debug")) {
             \Terminus\Loggers\Regular::debug($data['body']);
         }
     }
     $options['verify'] = false;
     $request = $browser->createRequest($method, $url, null, null, $options);
     if (!empty($data['postdata'])) {
         foreach ($data['postdata'] as $k => $v) {
             $request->setPostField($k, $v);
         }
     }
     if (!empty($data['cookies'])) {
         foreach ($data['cookies'] as $k => $v) {
             $request->addCookie($k, $v);
         }
     }
     if (!empty($data['headers'])) {
         foreach ($data['headers'] as $k => $v) {
             $request->setHeader($k, $v);
         }
     }
     if (\Terminus::get_config("debug")) {
         $debug = "#### REQUEST ####" . PHP_EOL;
         $debug .= $request->getRawHeaders();
         \Terminus\Loggers\Regular::debug($debug);
         if (isset($data['body'])) {
             \Terminus\Loggers\Regular::debug($data['body']);
         }
     }
     if (getenv("BUILD_FIXTURES")) {
         Fixtures::put("request_headers", $request->getRawHeaders());
     }
     $response = $request->send();
     if (getenv("BUILD_FIXTURES")) {
         Fixtures::put(array($url, $method, $data), $response);
     }
     return $response;
 }
Example #2
0
 function testPutAndGet()
 {
     // this takes the place of the global argv
     $test = array('sites/test/one', 'POST');
     $data = new stdClass();
     $data->file = __FILE__;
     $data->msg = "success";
     Fixtures::put($test, $data);
     // test manually
     $filename = dirname(dirname(__FILE__)) . '/tests/fixtures/POSTsites-test-one';
     $this->assertFileExists($filename);
     $content = unserialize(file_get_contents($filename));
     $this->assertInstanceOf(get_class($content), $content);
     $this->assertEquals("success", $content->msg);
     // now test the get method
     $content = Fixtures::get($test);
     $this->assertInstanceOf('stdClass', $content);
     $this->assertEquals("success", $content->msg);
 }
Example #3
0
 public static function send($url, $method, $data = array())
 {
     return Fixtures::get(array($url, $method, $data));
 }