Esempio n. 1
1
 /**
  * @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;
 }
Esempio n. 2
0
 /**
  * Get Http Adapter
  * @return
  */
 public function getHttpAdapter()
 {
     if (null === $this->httpAdapter) {
         $this->httpAdapter = new Curl();
         $this->httpAdapter->setOptions(array('sslverifypeer' => false));
     }
     return $this->httpAdapter;
 }
Esempio n. 3
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);
 }
Esempio n. 4
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);
 }
Esempio n. 5
0
 /**
  * @group ZF-7040
  */
 public function testGetCurlHandle()
 {
     $adapter = new Adapter\Curl();
     $adapter->setOptions(array('timeout' => 2, 'maxredirects' => 1));
     $adapter->connect("http://framework.zend.com");
     $this->assertTrue(is_resource($adapter->getHandle()));
 }
Esempio n. 6
0
 /**
  * Store or update an entity in the search index
  *
  * @param  array $data
  * @throws Exception\RuntimeException
  * @throws Exception\IndexException
  * @return boolean true if successfull
  */
 protected function index(array $data)
 {
     $adapter = new Http\Client\Adapter\Curl();
     $adapter->setOptions(array('curloptions' => array(CURLOPT_SSL_VERIFYPEER => false)));
     $client = new Http\Client();
     $client->setAdapter($adapter);
     $client->setMethod('POST');
     $client->setUri($this->getDocumentEndpoint());
     $client->setRawBody(Json::encode($data));
     $client->setHeaders(array('Content-Type' => 'application/json'));
     $response = $client->send();
     if (!$response->isSuccess()) {
         if ($this->throwExceptions) {
             throw new Exception\IndexException("Bad response received from CloudSearch.\n" . $response->toString());
         }
         return false;
     }
     $results = Json::decode($response->getContent(), Json::TYPE_ARRAY);
     $count = $results['adds'] + $results['deletes'];
     return $count != count($data) ? 0 : $count;
 }
Esempio n. 7
0
 /**
  * @group 4555
  */
 public function testResponseDoesNotDoubleDecodeGzippedBody()
 {
     $this->client->setUri($this->baseuri . 'testCurlGzipData.php');
     $adapter = new Adapter\Curl();
     $adapter->setOptions(array('curloptions' => array(CURLOPT_ENCODING => '')));
     $this->client->setAdapter($adapter);
     $this->client->setMethod('GET');
     $this->client->send();
     $this->assertEquals('Success', $this->client->getResponse()->getBody());
 }
 /**
  * Creates a HTTP client object.
  * 
  * @param string $useSsl
  * @return Http\Client
  */
 protected function createHttpClient($useSsl = null)
 {
     if (null === $useSsl) {
         $useSsl = $this->useSsl();
     }
     $httpClient = new \Zend\Http\Client(null, array('useragent' => $this->getOption(self::OPT_HTTP_CLIENT_USER_AGENT)));
     if ($useSsl) {
         $adapter = new Http\Client\Adapter\Curl();
         $adapter->setOptions(array('curloptions' => array(CURLOPT_SSL_VERIFYPEER => true, CURLOPT_SSL_VERIFYHOST => 2, CURLOPT_CAINFO => $this->getCaFile())));
         $httpClient->setAdapter($adapter);
     }
     return $httpClient;
 }
 /**
  * Creates a Zend\Http\Client object based on the provided configuration.
  * 
  * @param array $config
  * @throws GeneralException\MissingConfigException
  * @return \Zend\Http\Client
  */
 public function createHttpClient(array $config)
 {
     $zendClientOptions = $this->_defaultZendClientOptions;
     $curlAdapterOptions = $this->_defaultCurlAdapterOptions;
     if (!isset($config[self::OPT_OPTIONS]) || !is_array($config[self::OPT_OPTIONS])) {
         throw new GeneralException\MissingConfigException(self::OPT_OPTIONS);
     }
     $options = $config[self::OPT_OPTIONS];
     if (isset($config[self::OPT_ZEND_CLIENT_OPTIONS]) && is_array($config[self::OPT_ZEND_CLIENT_OPTIONS])) {
         $zendClientOptions = $config[self::OPT_ZEND_CLIENT_OPTIONS] + $zendClientOptions;
     }
     if (isset($config[self::OPT_CURL_ADAPTER_OPTIONS]) && is_array($config[self::OPT_CURL_ADAPTER_OPTIONS])) {
         $curlAdapterOptions = $config[self::OPT_CURL_ADAPTER_OPTIONS] + $curlAdapterOptions;
     }
     if (!isset($options[self::OPT_CAFILE]) && !isset($options[self::OPT_CAPATH])) {
         throw new GeneralException\MissingConfigException(sprintf("%s/%s or %s/%s", self::OPT_OPTIONS, self::OPT_CAFILE, self::OPT_OPTIONS, self::OPT_CAPATH));
     }
     if (isset($options[self::OPT_CAFILE])) {
         $curlAdapterOptions[CURLOPT_CAINFO] = $options[self::OPT_CAFILE];
     }
     if (isset($options[self::OPT_CAPATH])) {
         $curlAdapterOptions[CURLOPT_CAPATH] = $options[self::OPT_CAPATH];
     }
     $client = new Http\Client();
     $client->setOptions($zendClientOptions);
     $adapter = new Http\Client\Adapter\Curl();
     $adapter->setOptions(array('curloptions' => $curlAdapterOptions));
     $client->setAdapter($adapter);
     return $client;
 }
Esempio n. 10
0
 /**
  * Creates a dataProvider object (\Zend\Http\Client)
  *
  * @param  string|null $auth Auth data login:password
  * @return Client
  */
 protected function setDefaultDataProvider()
 {
     $dataProvider = new Client();
     $adapter = new Client\Adapter\Curl();
     $curlOptions = [CURLOPT_FOLLOWLOCATION => 1, CURLOPT_RETURNTRANSFER => 1, CURLOPT_SSL_VERIFYPEER => 0, CURLOPT_SSL_VERIFYHOST => 0];
     $adapter->setOptions(['curloptions' => $curlOptions]);
     $dataProvider->setAdapter($adapter);
     $dataProvider->setOptions(['maxredirects' => 1, 'timeout' => 30, 'useragent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_4)' . ' AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.122 Safari/537.36']);
     return $dataProvider;
 }
Esempio n. 11
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);
 }
Esempio n. 12
0
 /**
  * sendRequest(array $data = null) Send request and get response from internal server
  * @param array [msisdn, message] $data request data
  * @see Aware\ProviderInterface
  * @return json data
  */
 public function sendRequest($uri = null, array $data = null)
 {
     // Compile URL from pattern
     $url = strtr($this->__config['api_url_pattern'], [':username' => $this->__config['username'], ':password' => $this->__config['password'], ':message' => urlencode($data['message']), ':msisdn' => urlencode($data['msisdn'])]);
     // set Client adapter config
     $this->__setAdapterConfig([]);
     // Do the request to server with POST data
     $adapter = new Curl();
     $adapter->setOptions(['curloptions' => $this->getAdapterConfig()]);
     $client = new Client($url);
     $client->setAdapter($adapter);
     $client->setMethod('POST');
     $client->setParameterPost($data);
     $response = $client->send($client->getRequest());
     if ($response->getStatusCode() != 200) {
         throw new Exception\ExceptionStrategy($this->getShortName() . ' connection error. Code: ' . $response->getStatusCode());
     }
     $parseResult = explode('|', trim($response->getContent()));
     if ($parseResult[0] > 0) {
         $result['result']['error'] = $parseResult[1];
     } else {
         $result['result'] = $parseResult[1];
     }
     // Return result
     return $result;
 }
Esempio n. 13
0
 /**
  * sendRequest($uri, array $data) Send request and get response from internal server
  * @param string $uri request URI
  * @param array $data request data
  * @see Aware\ProviderInterface
  * @return json data
  */
 public function sendRequest($uri = null, array $data = null)
 {
     // Compile URL from pattern
     $url = strtr($this->__config['api_url_pattern'] . '?q=WWW', [':lang' => $this->__config['lang'], ':uri' => $uri]);
     // apply API key to request data
     $data['api_key'] = $this->__config['api_key'];
     // set Client adapter config
     $this->__setAdapterConfig([]);
     // Do the request to server with POST data
     $adapter = new Curl();
     $adapter->setOptions(['curloptions' => $this->getAdapterConfig()]);
     $client = new Client($url);
     $client->setAdapter($adapter);
     $client->setMethod('POST');
     $client->setParameterPost($data);
     $response = $client->send($client->getRequest());
     if ($response->getStatusCode() != 200) {
         throw new Exception\ExceptionStrategy($this->getShortName() . ' connection error. Code: ' . $response->getStatusCode());
     }
     // Parse and return result
     $json = json_decode($response->getContent(), TRUE);
     if (!empty($json['error'])) {
         $error = iconv(mb_detect_encoding($json['error']), 'UTF-8//TRANSLIT', $json['error']);
         $json['result']['error'] = $json['code'] . ': ' . $json['error'];
     }
     // Return result
     return $json['result'];
 }