public function setUp()
 {
     parent::setUp();
     $this->config = $this->app['config']['self-update']['repository_types']['github'];
     $this->releasesAsJson = fopen('tests/Data/releases.json', 'r');
     $response = new Response(200, ['Content-Type' => 'application/json'], \GuzzleHttp\Psr7\stream_for($this->releasesAsJson));
     $mock = new MockHandler([$response, $response, $response, $response]);
     $handler = HandlerStack::create($mock);
     $this->client = new Client(['handler' => $handler]);
     $this->client->request('GET', self::GITHUB_API_URL . '/repos/' . $this->config['repository_vendor'] . '/' . $this->config['repository_name'] . '/tags');
 }
示例#2
0
文件: Api.php 项目: experts3d/sdk-php
 /**
  * @param $url
  * @param $data
  * @param bool $isjson
  * @return \GuzzleHttp\Message\ResponseInterface
  */
 private function _post($url, $data, $isjson = true)
 {
     if ($isjson) {
         return $this->client->post($url, array('headers' => array('Content-type' => 'application/json'), 'body' => $data));
     } else {
         //x-www-formurlencoded this is deprecated
         $request = $this->client->createRequest('POST', $url);
         $postBody = $request->getBody();
         if (is_array($data)) {
             foreach ($data as $name => $value) {
                 $postBody->setField($name, $value);
             }
         }
         //Make the request to add a model.
         return $this->client->send($request);
     }
 }
示例#3
0
 public function copyOne($from, $to, array $source = [], $parent = null)
 {
     $pathFrom = $from instanceof DocumentPath ? $from : new DocumentPath($from);
     $pathTo = $to instanceof DocumentPath ? $to : new DocumentPath($to);
     if (!$pathFrom->isValid() || !$pathTo->isValid()) {
         throw new InvalidArgumentException('FROM or TO path is not valid');
     }
     // Get source
     if (!$source) {
         $params = ['index' => $pathFrom->getIndex(), 'type' => $pathFrom->getType(), 'id' => $pathFrom->getId(), 'ignore' => 404];
         if ($parent) {
             $params['parent'] = $parent;
         }
         $response = $this->clientFrom->get($params);
         if (!is_array($response)) {
             throw new InvalidArgumentException(sprintf('Failed to find %s', $pathFrom->getPath()));
         }
         $source = $response['_source'];
     }
     // Create
     $params = ['index' => $pathTo->getIndex(), 'type' => $pathTo->getType(), 'id' => $pathTo->getId(), 'body' => $source];
     if ($parent) {
         $params['parent'] = $parent;
     }
     $created = false;
     try {
         $response = $this->clientTo->index($params);
         $created = is_array($response) && ($response['created'] || $response['_version'] > 0);
     } catch (BadRequest400Exception $e) {
         // Tag may contain "/" in id and it's not good, because we can't index this document
         // $created = true;
     }
     if (!$created) {
         throw new Exception(sprintf('Failed to create %s', $pathTo->getPath()));
     }
     return $created;
 }