/**
  * @return array
  */
 public function getResults($offset, $itemCountPerPage)
 {
     $query = $this->createSearchQuery($offset, $itemCountPerPage);
     $adapter = new Http\Client\Adapter\Curl();
     $adapter->setOptions(array('curloptions' => array(CURLOPT_SSL_VERIFYPEER => false)));
     $client = new Http\Client();
     $client->setAdapter($adapter);
     $client->setMethod('GET');
     $client->setUri($this->getOptions()->getSearchEndpoint() . $query);
     $response = $client->send();
     if (!$response->isSuccess()) {
         throw new Exception\RuntimeException("Invalid response received from CloudSearch.\n" . $response->getContent());
     }
     $results = Json::decode($response->getContent(), Json::TYPE_ARRAY);
     $this->count = $results['hits']['found'];
     if (0 == $this->count) {
         return array();
     }
     if ($this->getOptions()->getReturnIdResults()) {
         $results = $this->extractResultsToIdArray($results);
     }
     foreach ($this->getConverters() as $converter) {
         $results = $converter->convert($results);
     }
     return $results;
 }
Example #2
0
 /**
  * Get the HttpClient instance
  * 
  * @return HttpClient
  */
 public function getHttpClient()
 {
     if (empty($this->httpClient)) {
         $this->httpClient = new HttpClient();
         $this->httpClient->setAdapter('Zend\\Http\\Client\\Adapter\\Curl');
     }
     return $this->httpClient;
 }
Example #3
0
 /**
  *
  * @return Client
  */
 protected function getClient()
 {
     if ($this->client === null) {
         $adapter = new \Zend\Http\Client\Adapter\Curl();
         $adapter->setCurlOption(CURLOPT_RETURNTRANSFER, true)->setCurlOption(CURLOPT_SSL_VERIFYPEER, false);
         $this->client = new Client();
         $this->client->setAdapter($adapter);
     }
     return $this->client;
 }
 /**
  * Constructor.
  *
  * @param AuthService $auth
  * @param string $api_url
  * @param string $key
  */
 public function __construct(\ModelFramework\AuthService\AuthService $auth, $api_url, $key)
 {
     $this->client = new Client();
     $this->api_url = $api_url;
     $timestamp = time();
     $company_id = (string) $auth->getMainUser()->company_id;
     $user_id = $auth->getUser()->_id;
     $login = $auth->getUser()->login;
     $key = $key;
     $hash = md5($login . $company_id . $timestamp . $key);
     $this->auth_param = ['timestamp' => $timestamp, 'login' => $login, 'owner' => $user_id, 'bucket' => $company_id, 'hash' => $hash];
     $adapter = new Curl();
     $this->client->setAdapter($adapter);
 }
Example #5
0
 /**
  * Constructor.
  *
  * @param AuthService $auth
  * @param string $api_url
  * @param string $key
  */
 public function __construct(\ModelFramework\AuthService\AuthService $auth, $key, $api_url)
 {
     $this->client = new Client();
     $this->api_url = $api_url;
     $timestamp = time();
     $company_id = (string) $auth->getMainUser()->company_id;
     $user_id = $auth->getUser()->_id;
     $login = $auth->getUser()->login;
     $key = $key;
     $hash = md5($login . $company_id . $timestamp . $key);
     $this->auth_param = ['timestamp' => $timestamp, 'login' => $login, 'owner' => $user_id, 'bucket' => $company_id, 'hash' => $hash];
     $adapter = new Curl();
     $adapter->setOptions(['curloptions' => [CURLOPT_POST => 1, CURLOPT_HTTPAUTH => CURLAUTH_BASIC, CURLOPT_USERPWD => "username:password", CURLOPT_RETURNTRANSFER => true, CURLOPT_SSL_VERIFYPEER => FALSE, CURLOPT_SSL_VERIFYHOST => FALSE]]);
     $this->client->setAdapter($adapter);
 }
Example #6
0
 /**
  * @param $ipString
  * @return IdentityInformation
  * @throws \Zend\Validator\Exception\InvalidArgumentException
  */
 public function getIpInfo($ipString)
 {
     $ipValidator = new Ip();
     if (!$ipValidator->isValid($ipString)) {
         throw new InvalidArgumentException();
     }
     // creating request object
     $request = new Request();
     $request->setUri($this->endPoint . $ipString . '/json');
     $client = new Client();
     $adapter = new Client\Adapter\Curl();
     $adapter->setCurlOption(CURLOPT_TIMEOUT_MS, 500);
     $client->setAdapter($adapter);
     $response = $client->send($request);
     $data = $response->getBody();
     $dataArray = json_decode($data);
     $identityInformation = new IdentityInformation();
     $identityInformation->setCountry(isset($dataArray->country) ? $dataArray->country : '');
     $identityInformation->setRegion(isset($dataArray->region) ? $dataArray->region : '');
     $identityInformation->setCity(isset($dataArray->city) ? $dataArray->city : '');
     $identityInformation->setLocation(isset($dataArray->loc) ? $dataArray->loc : '');
     $identityInformation->setProvider(isset($dataArray->org) ? $dataArray->org : '');
     $identityInformation->setHostName(isset($dataArray->hostname) ? $dataArray->hostname : '');
     return $identityInformation;
 }
Example #7
0
    /**
     * Constructor
     *
     * @param  array|Traversable $options
     */
    function __construct($options = array())
    {
        if ($options instanceof Traversable) {
            $options = ArrayUtils::iteratorToArray($options);
        }

        if (!is_array($options)) {
            throw new Exception\InvalidArgumentException('Invalid options provided');
        }

        $auth = array(
            'username' => $options[self::USERNAME],
            'password' => $options[self::PASSWORD],
            'appKey'   => $options[self::APP_KEY],
        );
        $nirvanix_options = array();
        if (isset($options[self::HTTP_ADAPTER])) {
            $httpc = new HttpClient();
            $httpc->setAdapter($options[self::HTTP_ADAPTER]);
            $nirvanix_options['httpClient'] = $httpc;
        }
        try {
            $this->_nirvanix = new NirvanixService($auth, $nirvanix_options);
            $this->_remoteDirectory = $options[self::REMOTE_DIRECTORY];
            $this->_imfNs = $this->_nirvanix->getService('IMFS');
            $this->_metadataNs = $this->_nirvanix->getService('Metadata');
        } catch (\Zend\Service\Nirvanix\Exception  $e) {
            throw new Exception\RuntimeException('Error on create: '.$e->getMessage(), $e->getCode(), $e);
        }
    }
 public function pharAction()
 {
     $client = $this->serviceLocator->get('zendServerClient');
     $client = new Client();
     if (defined('PHAR')) {
         // the file from which the application was started is the phar file to replace
         $file = $_SERVER['SCRIPT_FILENAME'];
     } else {
         $file = dirname($_SERVER['SCRIPT_FILENAME']) . '/zs-client.phar';
     }
     $request = new Request();
     $request->setMethod(Request::METHOD_GET);
     $request->setHeaders(Headers::fromString('If-Modified-Since: ' . gmdate('D, d M Y H:i:s T', filemtime($file))));
     $request->setUri('https://github.com/zendtech/ZendServerSDK/raw/master/bin/zs-client.phar');
     //$client->getAdapter()->setOptions(array('sslcapath' => __DIR__.'/../../../certs/'));
     $client->setAdapter(new Curl());
     $response = $client->send($request);
     if ($response->getStatusCode() == 304) {
         return 'Already up-to-date.';
     } else {
         ErrorHandler::start();
         rename($file, $file . '.' . date('YmdHi') . '.backup');
         $handler = fopen($file, 'w');
         fwrite($handler, $response->getBody());
         fclose($handler);
         ErrorHandler::stop(true);
         return 'The phar file was updated successfully.';
     }
 }
Example #9
0
 /**
  * @return Client
  */
 public function getClient()
 {
     $clientOptions = isset($this->options['client']) ? $this->options['client'] : [];
     $client = new Client(null, $clientOptions);
     $client->setAdapter(new Client\Adapter\Curl());
     return $client;
 }
 public static function getLatLng($address)
 {
     $latLng = [];
     try {
         $url = sprintf('http://maps.google.com/maps/api/geocode/json?address=%s&sensor=false', $address);
         $client = new Client($url);
         $client->setAdapter(new Curl());
         $client->setMethod('GET');
         $client->setOptions(['curloptions' => [CURLOPT_HEADER => false]]);
         $response = $client->send();
         $body = $response->getBody();
         $result = Json\Json::decode($body, 1);
         $latLng = ['lat' => $result['results'][0]['geometry']['location']['lat'], 'lng' => $result['results'][0]['geometry']['location']['lng']];
         $isException = false;
     } catch (\Zend\Http\Exception\RuntimeException $e) {
         $isException = true;
     } catch (\Zend\Http\Client\Adapter\Exception\RuntimeException $e) {
         $isException = true;
     } catch (Json\Exception\RuntimeException $e) {
         $isException = true;
     } catch (Json\Exception\RecursionException $e2) {
         $isException = true;
     } catch (Json\Exception\InvalidArgumentException $e3) {
         $isException = true;
     } catch (Json\Exception\BadMethodCallException $e4) {
         $isException = true;
     }
     if ($isException === true) {
         //código em caso de problemas no decode
     }
     return $latLng;
 }
Example #11
0
 public function indexAction()
 {
     $client = new HttpClient();
     $client->setAdapter('Zend\\Http\\Client\\Adapter\\Curl');
     $method = $this->params()->fromQuery('method', 'get');
     $client->setUri('http://api-rest/san-restful');
     switch ($method) {
         case 'get':
             $id = $this->params()->fromQuery('id');
             $client->setMethod('GET');
             $client->setParameterGET(array('id' => $id));
             break;
         case 'get-list':
             $client->setMethod('GET');
             break;
         case 'create':
             $client->setMethod('POST');
             $client->setParameterPOST(array('name' => 'samsonasik'));
             break;
         case 'update':
             $data = array('name' => 'ikhsan');
             $adapter = $client->getAdapter();
             $adapter->connect('localhost', 80);
             $uri = $client->getUri() . '?id=1';
             // send with PUT Method, with $data parameter
             $adapter->write('PUT', new \Zend\Uri\Uri($uri), 1.1, array(), http_build_query($data));
             $responsecurl = $adapter->read();
             list($headers, $content) = explode("\r\n\r\n", $responsecurl, 2);
             $response = $this->getResponse();
             $response->getHeaders()->addHeaderLine('content-type', 'text/html; charset=utf-8');
             $response->setContent($content);
             return $response;
         case 'delete':
             $adapter = $client->getAdapter();
             $adapter->connect('localhost', 80);
             $uri = $client->getUri() . '?id=1';
             //send parameter id = 1
             // send with DELETE Method
             $adapter->write('DELETE', new \Zend\Uri\Uri($uri), 1.1, array());
             $responsecurl = $adapter->read();
             list($headers, $content) = explode("\r\n\r\n", $responsecurl, 2);
             $response = $this->getResponse();
             $response->getHeaders()->addHeaderLine('content-type', 'text/html; charset=utf-8');
             $response->setContent($content);
             return $response;
     }
     //if get/get-list/create
     $response = $client->send();
     if (!$response->isSuccess()) {
         // report failure
         $message = $response->getStatusCode() . ': ' . $response->getReasonPhrase();
         $response = $this->getResponse();
         $response->setContent($message);
         return $response;
     }
     $body = $response->getBody();
     $response = $this->getResponse();
     $response->setContent($body);
     return $response;
 }
Example #12
0
 /**
  * Load the connection adapter
  *
  * @param \Zend\Http\Client\Adapter\AdapterInterface $adapter
  * @return void
  */
 public function setAdapter($adapter)
 {
     if ($adapter == null) {
         $this->adapter = $adapter;
     } else {
         parent::setAdapter($adapter);
     }
 }
 /**
  * {@inheritDoc}
  */
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     $services = $serviceLocator->getServiceLocator();
     $client = new HttpClient();
     $client->setAdapter('Zend\\Http\\Client\\Adapter\\Curl');
     $client->setUri('https://api.github.com/repos/sitrunlab/LearnZF2/contributors');
     return new ConsoleController($services->get('Console'), $services->get('Config'), $client);
 }
Example #14
0
 /**
  * Get Http Client
  *
  * @param  string $path
  * @return HttpClient
  */
 public function getHttpClient()
 {
     if (null === $this->httpClient) {
         $this->httpClient = new HttpClient();
         $this->httpClient->setAdapter($this->getHttpAdapter());
     }
     return $this->httpClient;
 }
Example #15
0
 /**
  * Load HTTP client w/ fixture
  *
  * @param string $fixture Fixture name
  *
  * @return HttpClient
  */
 protected function getClient($fixture)
 {
     $file = realpath(__DIR__ . '/../../../../fixtures/wikipedia/' . $fixture);
     $adapter = new TestAdapter();
     $adapter->setResponse(file_get_contents($file));
     $client = new HttpClient();
     $client->setAdapter($adapter);
     return $client;
 }
function _createHttpClient()
{
    $adapter = new Client\Adapter\Socket();
    $client = new Client();
    $client->setOptions(array('maxredirects' => 2, 'strictredirects' => true));
    $client->setAdapter($adapter);
    $adapter->setStreamContext(array('ssl' => array('capath' => '/etc/ssl/certs')));
    return $client;
}
Example #17
0
 /**
  * Constructor
  *
  * Sets up the EDS API Client
  *
  * @param array           $settings Associative array of setting to use in
  * conjunction with the EDS API
  *    <ul>
  *      <li>debug - boolean to control debug mode</li>
  *      <li>authtoken - Authentication to use for calls to the API. If using IP
  * Authentication, this is not needed.</li>
  *      <li>username -  EBSCO username for account setup for usage with the EDS
  * API. This is only required for institutions using UID Authentication </li>
  *      <li>password - EBSCO password for account setup for usage with the EDS
  * API. This is only required for institutions using UID Authentication </li>
  *      <li>orgid - Organization making calls to the EDS API </li>
  *      <li>sessiontoken - SessionToken this call is associated with, is one
  * exists. If not, the a profile value must be present </li>
  *      <li>profile - EBSCO profile to use for calls to the API. </li>
  *      <li>isguest - is the user a guest. This needs to be present if there
  * is no session token present</li>
  *    </ul>
  * @param Zend2HttpClient $client   Zend2 HTTP client object (optional)
  */
 public function __construct($settings = [], $client = null)
 {
     parent::__construct($settings);
     $this->client = is_object($client) ? $client : new Zend2HttpClient();
     $this->client->setOptions(['timeout' => 120]);
     $adapter = new CurlAdapter();
     $adapter->setOptions(['curloptions' => [CURLOPT_SSL_VERIFYPEER => false, CURLOPT_FOLLOWLOCATION => true]]);
     $this->client->setAdapter($adapter);
 }
Example #18
0
 /**
  * {@inheritDoc}
  */
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     $config = $serviceLocator->get('Config');
     $client = new HttpClient();
     $client->setAdapter($config['slm_mail']['http_adapter']);
     if (isset($config['slm_mail']['http_options'])) {
         $client->getAdapter()->setOptions($config['slm_mail']['http_options']);
     }
     return $client;
 }
Example #19
0
 /**
  * Constructor
  * @param string $api_key Flickr's API key
  * @param \Zend\Http\Client $adapter An instanceof \Zend\Http\Client to provide to ZendFlickr with settings for Flickr's new SSL requirement for their API
  */
 public function __construct($api_key = NULL, Client $HttpClient = NULL)
 {
     if ($HttpClient == NULL) {
         $HttpClient = new Client();
         $adapter = new Curl();
         $adapter->setOptions(array("curloptions" => array(CURLOPT_SSL_VERIFYPEER => false)));
         $HttpClient->setAdapter($adapter);
     }
     parent::__construct($api_key, $HttpClient);
 }
Example #20
0
 /**
  * Send custom parameters to the Http Adapter without overriding the Http Client.
  *
  * @param array $config
  *
  * @throws \InvalidArgumentException
  */
 public function setAdapterParameters(array $config = array())
 {
     if (!is_array($config) || empty($config)) {
         throw new InvalidArgumentException('$config must be an associative array with at least 1 item.');
     }
     if ($this->httpClient === null) {
         $this->httpClient = new HttpClient();
         $this->httpClient->setAdapter(new HttpSocketAdapter());
     }
     $this->httpClient->getAdapter()->setOptions($config);
 }
Example #21
0
 /**
  * Load WorldCatUtils client w/ fixture
  *
  * @param string $fixture Fixture name
  * @param bool   $silent  Use silent mode?
  *
  * @return WorldCatUtils
  */
 protected function getClient($fixture = null, $silent = true)
 {
     $client = new HttpClient();
     if (null !== $fixture) {
         $adapter = new TestAdapter();
         $file = realpath(__DIR__ . '/../../../../fixtures/worldcat/' . $fixture);
         $adapter->setResponse(file_get_contents($file));
         $client->setAdapter($adapter);
     }
     return new WorldCatUtils('dummy', $client, $silent);
 }
Example #22
0
 /**
  * Data is OK, but the response header
  * is HTTP/1.1 404 Not Found
  */
 public function testNot200ResponseCode()
 {
     $client = new Client();
     $adapter = new Test();
     $adapter->setResponse(file_get_contents(__DIR__ . '/../data/ja-response/03.txt'));
     $client->setAdapter($adapter);
     $map = new JaMap($client);
     $result1 = $map->request("Hringbraut 107, 101 Reykjavík");
     $this->assertNull($result1->lat);
     $this->assertNull($result1->lng);
 }
Example #23
0
 /**
  * Result is not HTTP/1.1 200
  */
 public function testHttpError()
 {
     $client = new Client();
     $adapter = new Test();
     $adapter->setResponse(file_get_contents(__DIR__ . '/../data/google-map-response/03.txt'));
     $client->setAdapter($adapter);
     $map = new GoogleMap($client);
     $result = $map->request('My address');
     $this->assertNull($result->lat);
     $this->assertNull($result->lng);
 }
Example #24
0
 /**
  * Set up the test case
  *
  */
 protected function setUp()
 {
     if (defined('TESTS_ZEND_HTTP_CLIENT_BASEURI') && TESTS_ZEND_HTTP_CLIENT_BASEURI != false) {
         $this->baseuri = TESTS_ZEND_HTTP_CLIENT_BASEURI;
         if (substr($this->baseuri, -1) != '/') {
             $this->baseuri .= '/';
         }
         $name = $this->getName();
         if (($pos = strpos($name, ' ')) !== false) {
             $name = substr($name, 0, $pos);
         }
         $uri = $this->baseuri . $name . '.php';
         $this->_adapter = new $this->config['adapter']();
         $this->client = new HTTPClient($uri, $this->config);
         $this->client->setAdapter($this->_adapter);
     } else {
         // Skip tests
         $this->markTestSkipped("Zend_Http_Client dynamic tests are not enabled in TestConfiguration.php");
     }
 }
 /**
  * @covers ::updateAddressFormats
  */
 public function testUpdateAddressFormatsUsesProgresAdapter()
 {
     $testAdapter = new HttpTestAdapter();
     $testAdapter->setResponse([(new HttpResponse())->setContent('empty'), (new HttpResponse())->setContent('{"name": "ZZ"}')]);
     $httpClient = new HttpClient();
     $httpClient->setAdapter($testAdapter);
     $progressAdapter = $this->getMock('Zend\\ProgressBar\\Adapter\\AbstractAdapter');
     $progressAdapter->expects($this->any())->method('notify')->with($this->logicalOr($this->equalTo(0.0), $this->equalTo(1.0)), $this->equalTo(1.0));
     $maintenanceService = new MaintenanceService($this->options, $httpClient);
     $maintenanceService->updateAddressFormats($progressAdapter);
 }
 private function search($query, $geolocate = false, $start = 1)
 {
     $query = urlencode($query);
     $client = new Client();
     $client->setOptions(['timeout' => 60]);
     $client->setAdapter('Zend\\Http\\Client\\Adapter\\Curl');
     $client->setUri('https://www.googleapis.com/customsearch/v1');
     $searchParams = $geolocate ? ['key' => GOOGLE_SEARCH_API_KEY, 'cx' => GOOGLE_SEARCH_CSE_ID, 'q' => $query, 'cr' => 'countryCL', 'gl' => 'cl', 'hl' => 'es', 'googlehost' => 'google.cl', 'start' => $start] : ['key' => GOOGLE_SEARCH_API_KEY, 'cx' => GOOGLE_SEARCH_CSE_ID, 'q' => $query, 'start' => $start];
     $client->setParameterGet($searchParams);
     $response = $client->send();
     return $response->isSuccess() ? json_decode($response->getBody()) : null;
 }
Example #27
0
 /**
  * @return string
  */
 public function renderTemplate()
 {
     $config = $this->getServiceLocator()->get('Config');
     if (!isset($config['wordpress']['template'])) {
         throw new Exception\InvalidServiceException('No wordpress template defined');
     }
     $client = new Client($config['wordpress']['template']);
     $client->setAdapter(new Client\Adapter\Curl());
     $client->setMethod('GET');
     $response = $client->send($client->getRequest());
     return $response->getBody();
 }
Example #28
0
 /**
  * @return \WebArchive\SnapshotCollection
  */
 private function generateSnapshots()
 {
     $uri = 'http://pokap.io/';
     $provider = new MementoProvider();
     $client = new Client($provider->createUrlRequest($uri));
     $response = new Response();
     $response->setContent(implode(gzfile(__DIR__ . '/fixtures/pokap.io-memento.gz')));
     $adapter = new TestAdapter();
     $adapter->setResponse($response);
     $client->setAdapter($adapter);
     return $provider->generateSnapshots($client->send(), $uri);
 }
Example #29
0
 /**
  * @param int $year
  *
  * @return \WebArchive\SnapshotCollection
  */
 private function generateSnapshots($year)
 {
     $uri = 'http://archive.org/';
     $provider = new WayBackProvider($year);
     $client = new Client($provider->createUrlRequest($uri));
     $response = new Response();
     $response->setContent(implode(gzfile(__DIR__ . '/fixtures/archive.org-' . $year . '.html.gz')));
     $adapter = new TestAdapter();
     $adapter->setResponse($response);
     $client->setAdapter($adapter);
     return $provider->generateSnapshots($client->send(), $uri);
 }
Example #30
0
 /**
  * Create the http-client-adapter-service
  *
  * @param \Zend\ServiceManager\ServiceLocatorInterface $serviceLocator
  * @return \Zend\Http\Client
  */
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     // Configure the adapter
     $config = $serviceLocator->get('Configuration');
     $options = array();
     if (isset($config['http']['options'])) {
         $options = $config['http']['options'];
     }
     $result = new Client(null, $options);
     $result->setAdapter($serviceLocator->get('Zend\\Http\\Client\\Adapter\\AdapterInterface'));
     return $result;
 }