Ejemplo n.º 1
0
 public function __invoke($par)
 {
     $config = $this->getController()->getServiceLocator()->get('config');
     $lang = $this->getController()->getEvent()->getRouteMatch()->getParam('lang', 'en');
     if (empty($config['geocoder_photon_url'])) {
         throw new \InvalidArgumentException('Now Service-Adress for Geo-Service available');
     }
     $client = new \Zend\Http\Client($config['geocoder_photon_url']);
     $client->setMethod('GET');
     $osmTags = ['tourism', 'aeroway', 'railway', 'amenity', 'historic', 'tunnel', 'mountain_pass', 'leisure', 'natural', 'bridge', 'waterway'];
     $osmTags = array_map(function ($i) {
         return urlencode('!' . $i);
     }, $osmTags);
     $uri = sprintf('%s?q=%s&lang=%s&osm_tag=%s', $config['geocoder_photon_url'], urlencode($par), $lang, implode('&osm_tag=', $osmTags));
     $client->setUri($uri);
     $response = $client->send();
     $result = $response->getBody();
     $result = json_decode($result);
     $result = $result->features;
     foreach ($result as $key => $val) {
         $row = ['name' => property_exists($val->properties, 'name') ? $val->properties->name : '', 'postcode' => property_exists($val->properties, 'postcode') ? $val->properties->postcode : '', 'city' => property_exists($val->properties, 'city') ? $val->properties->city : '', 'street' => property_exists($val->properties, 'street') ? $val->properties->street : '', 'state' => property_exists($val->properties, 'state') ? $val->properties->state : '', 'country' => property_exists($val->properties, 'country') ? $val->properties->country : '', 'coordinates' => implode(":", $val->geometry->coordinates), 'osm_key' => property_exists($val->properties, 'osm_key') ? $val->properties->osm_key : '', 'osm_value' => property_exists($val->properties, 'osm_value') ? $val->properties->osm_value : '', 'osm_id' => property_exists($val->properties, 'osm_id') ? $val->properties->osm_id : '', 'data' => json_encode($val)];
         $r[] = $row;
     }
     return $r;
 }
Ejemplo n.º 2
0
 public static function send()
 {
     $me = new self("global");
     $sent = array();
     $pastlink = new FutureLink_PastUI();
     $feed = $pastlink->feed();
     $items = array();
     //we send something only if we have something to send
     if (empty($feed->feed->entry) == false) {
         foreach ($feed->feed->entry as &$item) {
             if (empty($item->futurelink->href) || isset($sent[$item->futurelink->hash])) {
                 continue;
             }
             $sent[$item->futurelink->hash] = true;
             $client = new Zend\Http\Client($item->futurelink->href, array('timeout' => 60));
             if (!empty($feed->feed->entry)) {
                 $client->setParameterPost(array('protocol' => 'futurelink', 'metadata' => json_encode($feed)));
                 try {
                     $client->setMethod(Zend\Http\Request::METHOD_POST);
                     $response = $client->send();
                     $request = $client->getLastResponse();
                     $result = $response->getBody();
                     $resultJson = json_decode($response->getBody());
                     //Here we add the date last updated so that we don't have to send it if not needed, saving load time.
                     if (!empty($resultJson->feed) && $resultJson->feed == "success") {
                         $me->addItem(array('dateLastUpdated' => $item->pastlink->dateLastUpdated, 'pastlinklinkHash' => $item->pastlink->hash, 'futurelinkHash' => $item->futurelink->hash));
                     }
                     $items[$item->pastlink->text] = $result;
                 } catch (Exception $e) {
                 }
             }
         }
         return $items;
     }
 }
 {
     return in_array(strtolower($needle), array_map('strtolower', $haystack));
 }
 /**
  Please send me: array( 'uri'=> '', 'method'=>''[, 'curloptions'=> array( ... ) ])
  I will throw an Exception if something goes wrong so no need to validate
  But you can decide whether you wnat me to do it or not
  */
 public static function sendRequest($arrayParms, $throwEx = true)
 {
     Utils::arrayKeyExists(array('url', 'method'), $arrayParms);
     $client = new \Zend\Http\Client($arrayParms['url']);
     $client->setMethod($arrayParms['method']);
     switch ($arrayParms['method']) {
         case POST:
             Utils::arrayKeyExists('payload', $arrayParms);
             $client->setParameterPost($arrayParms['payload']);
             break;
         case GET:
             Utils::arrayKeyExists('payload', $arrayParms);
             $client->setParameterGet($arrayParms['payload']);
             break;
     }
     $adapter = new \Zend\Http\Client\Adapter\Curl();
     $curloptions = array(CURLOPT_POST => 1, CURLOPT_HTTPAUTH => CURLAUTH_BASIC, CURLOPT_RETURNTRANSFER => 1, CURLOPT_SSL_VERIFYPEER => FALSE, CURLOPT_SSL_VERIFYHOST => FALSE);
     if (array_key_exists('curloptions', $arrayParms)) {
         $curloptions = array_merge($curloptions, $arrayParms['curloptions']);
     }
     $adapter->setOptions(array('curloptions' => $curloptions));
     $client->setAdapter($adapter);
     $response = $client->send();
     if ($response->isSuccess()) {
Ejemplo n.º 4
0
 /**
  * Sends a request and returns a response
  *
  * @param CartRecover_Request $request
  * @return Cart_Recover_Response
  */
 public function sendRequest(CartRecover_Request $request)
 {
     $this->client->setUri($request->getUri());
     $this->client->setParameterGet($request->getParams());
     $this->client->setMethod($request->getMethod());
     $this->client->setHeaders(array('Accept' => 'application/json'));
     $this->response = $this->client->send();
     if ($this->response->getHeaders()->get('Content-Type')->getFieldValue() != 'application/json') {
         throw new CartRecover_Exception_UnexpectedValueException("Unknown response format.");
     }
     $body = json_decode($this->response->getContent(), true);
     $response = new CartRecover_Response();
     $response->setRawResponse($this->response->toString());
     $response->setBody($body);
     $response->setHeaders($this->response->getHeaders()->toArray());
     $response->setStatus($this->response->getReasonPhrase(), $this->response->getStatusCode());
     return $response;
 }
Ejemplo n.º 5
0
 /**
  * @param string $par Query Parameter
  * @param string $geoCoderUrl Url of the geo location service
  * @param string $land language
  *
  * @return array|mixed|string
  */
 public function __invoke($par, $geoCoderUrl, $land)
 {
     $client = new \Zend\Http\Client($geoCoderUrl);
     $client->setMethod('GET');
     // more countries 'country' => 'DE,CH,AT'
     // with countryCode 'zoom' => 2
     $plz = 0 < (int) $par ? 1 : 0;
     $client->setParameterGet(array('q' => $par, 'country' => 'DE', 'plz' => $plz, 'zoom' => 1));
     $response = $client->send();
     $result = $response->getBody();
     $result = json_decode($result);
     $result = (array) $result->result;
     return $result;
 }
 public function getCausas()
 {
     $cliente = new \Zend\Http\Client('http://civil.poderjudicial.cl', array('maxredirects' => 100, 'timeout' => 600, 'keepalive' => true));
     $headers = $cliente->getRequest()->getHeaders();
     $cookies = new Zend\Http\Cookies($headers);
     $cliente->setMethod('GET');
     $response = $cliente->send();
     $cliente->setUri('http://civil.poderjudicial.cl/CIVILPORWEB/AtPublicoViewAccion.do?tipoMenuATP=1');
     $cookies->addCookiesFromResponse($response, $cliente->getUri());
     $response = $cliente->send();
     echo '<pre>';
     print_r($response);
     echo '</pre>';
 }
Ejemplo n.º 7
0
 public function __invoke($par)
 {
     $config = $this->getController()->getServiceLocator()->get('config');
     if (empty($config['geocoder_cross_url'])) {
         throw new \InvalidArgumentException('Now Service-Adress for Geo-Service available');
     }
     $client = new \Zend\Http\Client($config['geocoder_photon_url']);
     $client->setMethod('GET');
     // more countries 'country' => 'DE,CH,AT'
     // with countryCode 'zoom' => 2
     $plz = 0 < (int) $par ? 1 : 0;
     $client->setParameterGet(array('q' => $par, 'country' => 'DE', 'plz' => $plz, 'zoom' => 1));
     $response = $client->send();
     $result = $response->getBody();
     $result = json_decode($result);
     $result = (array) $result->result;
     return $result;
 }
Ejemplo n.º 8
0
 /**
  * Performs HTTP request to given $url using given HTTP $method.
  * Send additinal query specified by variable/value array,
  * On success returns HTTP response without headers, false on failure.
  *
  * @param string $url OpenID server url
  * @param string $method HTTP request method 'GET' or 'POST'
  * @param array $params additional qwery parameters to be passed with
  * @param int &$staus HTTP status code
  *  request
  * @return mixed
  */
 protected function _httpRequest($url, $method = 'GET', array $params = array(), &$status = null)
 {
     $client = $this->_httpClient;
     if ($client === null) {
         $client = new \Zend\Http\Client($url, array('maxredirects' => 4, 'timeout' => 15, 'useragent' => 'Zend_OpenId'));
     } else {
         $client->setUri($url);
     }
     $client->resetParameters();
     if ($method == 'POST') {
         $client->setMethod(\Zend\Http\Client::POST);
         $client->setParameterPost($params);
     } else {
         $client->setMethod(\Zend\Http\Client::GET);
         $client->setParameterGet($params);
     }
     try {
         $response = $client->request();
     } catch (\Exception $e) {
         $this->_setError('HTTP Request failed: ' . $e->getMessage());
         return false;
     }
     $status = $response->getStatus();
     $body = $response->getBody();
     if ($status == 200 || $status == 400 && !empty($body)) {
         return $body;
     } else {
         $this->_setError('Bad HTTP response');
         return false;
     }
 }
Ejemplo n.º 9
0
 /**
  * Return a new HTTP client.
  *
  * @param string $url     Target URL
  * @param string $method  Request method
  * @param float  $timeout Request timeout in seconds
  *
  * @return \Zend\Http\Client
  */
 public function createClient($url = null, $method = \Zend\Http\Request::METHOD_GET, $timeout = null)
 {
     $client = new \Zend\Http\Client();
     $client->setMethod($method);
     if (!empty($this->defaults)) {
         $client->setOptions($this->defaults);
     }
     if (null !== $this->defaultAdapter) {
         $client->setAdapter($this->defaultAdapter);
     }
     if (null !== $url) {
         $client->setUri($url);
     }
     if ($timeout) {
         $client->setOptions(array('timeout' => $timeout));
     }
     $this->proxify($client);
     return $client;
 }
Ejemplo n.º 10
0
 /**
  * Upload inventory data
  *
  * @param string $data Inventory data (XML or zlib-compressed XML)
  * @return \Zend\Http\Response Server response
  */
 public function uploadData($data)
 {
     $client = new \Zend\Http\Client($this->_serverUri, array('adapter' => $this->_adapter, 'strictredirects' => true, 'useragent' => 'Braintacle_local_upload'));
     $client->setMethod('POST')->setHeaders(array('Content-Type' => 'application/x-compress'))->setRawBody($data);
     return $client->send();
 }
Ejemplo n.º 11
0
 /**
  * Fetches and sets data from the remote system via {@link $this->uri}.
  */
 protected function fetchData()
 {
     $uri = $this->getUri();
     if (!$uri) {
         return;
     }
     $client = new \Zend\Http\Client($this->getUri());
     $client->setMethod('GET');
     try {
         $response = $client->send();
     } catch (\Exception $e) {
         return;
     }
     $status = $response->getStatusCode();
     if ($status == 200) {
         $result = $response->getBody();
         $result = (array) json_decode($result);
         if (0 < count($result)) {
             $name = array_pop($result);
             $this->setName($name);
         }
     }
 }
Ejemplo n.º 12
0
 public function testPutRoleResources()
 {
     $client = new \Zend\Http\Client(self::HOST . '/roles/1/resources/ZfeggAdmin\\V1\\Rest\\AdminRole\\Controller::collection');
     $client->setMethod('PUT');
     $client->setHeaders(['Accept' => 'application/hal+json', 'Content-Type' => 'application/json']);
     $client->setRawBody(json_encode(['resource' => 'ZfeggAdmin\\V1\\Rest\\AdminRole\\Controller::collection', 'privileges' => ['GET', 'post', 'Put', 'delete']]));
     $response = $client->send();
     echo Json::prettyPrint($response->getBody());
 }
 protected function getPaypalRequest()
 {
     $config = $this->getServiceLocator()->get('config');
     $paypalConfig = new \SpeckPaypal\Element\Config($config['speck-paypal-api']);
     $adapter = new \Zend\Http\Client\Adapter\Curl();
     $adapter->setOptions(array('curloptions' => array(CURLOPT_SSL_VERIFYPEER => false)));
     $client = new \Zend\Http\Client();
     $client->setMethod('POST');
     $client->setAdapter($adapter);
     $paypalRequest = new \SpeckPaypal\Service\Request();
     $paypalRequest->setClient($client);
     $paypalRequest->setConfig($paypalConfig);
     return $paypalRequest;
 }
Ejemplo n.º 14
0
/**
 * 构造POST和GET组合的请求 返回相应请求
 *
 * @param string $url            
 * @param array $get            
 * @param array $post            
 * @param boolean $returnObj            
 * @return Zend_Http_Response false
 */
function doRequest($url, $get = array(), $post = array(), $returnObj = false)
{
    try {
        $url = trim($url);
        if (!filter_var($url, FILTER_VALIDATE_URL)) {
            throw new Exception('Invalid URL');
            return false;
        }
        $client = new Zend\Http\Client();
        $client->setUri($url);
        if (count($get) > 0 && is_array($get)) {
            $client->setParameterGet($get);
        }
        if (count($post) > 0 && is_array($post)) {
            $client->setParameterPost($post);
        }
        $client->setEncType(Zend\Http\Client::ENC_URLENCODED);
        $client->setOptions(array('maxredirects' => 5, 'strictredirects' => false, 'useragent' => 'Zend\\Http\\Client', 'timeout' => 10, 'adapter' => 'Zend\\Http\\Client\\Adapter\\Socket', 'httpversion' => Request::VERSION_11, 'storeresponse' => true, 'keepalive' => false, 'outputstream' => false, 'encodecookies' => true, 'argseparator' => null, 'rfc3986strict' => false));
        if (!empty($post)) {
            $client->setMethod(Request::METHOD_POST);
        } else {
            $client->setMethod(Request::METHOD_GET);
        }
        $response = $client->send();
        return $returnObj ? $response : $response->getBody();
    } catch (Exception $e) {
        fb(exceptionMsg($e), \FirePHP::LOG);
        return false;
    }
}
// The repository you're getting the changelog for
$milestone = $config['milestone'];
// The milestone ID
$client = new Zend\Http\Client();
$client->setOptions(array('adapter' => 'Zend\\Http\\Client\\Adapter\\Curl'));
$request = $client->getRequest();
$headers = $request->getHeaders();
$headers->addHeaderLine("Authorization", "token {$token}");
$client->setUri("https://api.github.com/repos/{$user}/{$repo}/milestones/{$milestone}");
$milestoneResponseBody = $client->send()->getBody();
$milestonePayload = json_decode($milestoneResponseBody, true);
if (!isset($milestonePayload['title'])) {
    file_put_contents('php://stderr', sprintf("Provided milestone ID [%s] does not exist: %s\n", $milestone, $milestoneResponseBody));
}
$client->setUri('https://api.github.com/search/issues?q=' . urlencode('milestone:' . $milestonePayload['title'] . ' repo:' . $user . '/' . $repo . ' state:closed'));
$client->setMethod('GET');
$issues = array();
$error = false;
do {
    $response = $client->send();
    $json = $response->getBody();
    $payload = json_decode($json, true);
    if (!(is_array($payload) && isset($payload['items']))) {
        file_put_contents('php://stderr', sprintf("Github API returned error message [%s]\n", is_object($payload) ? $payload['message'] : $json));
        exit(1);
    }
    if (isset($payload['incomplete_results']) && !isset($payload['incomplete_results'])) {
        file_put_contents('php://stderr', sprintf("Github API returned incomplete results [%s]\n", $json));
        exit(1);
    }
    $issues = array_merge($issues, $payload['items']);
Ejemplo n.º 16
0
 /**
  * @throws Exception\ReceiversWasNotSpecified
  */
 public function send()
 {
     if (!count($this->getMessages())) {
         throw new Exception\ReceiversWasNotSpecified();
     }
     $client = new \Zend\Http\Client();
     $client->setUri(implode('/', [self::getConfig()['uri'], 'index/send']));
     $client->setHeaders(['x-auth' => self::getToken()]);
     $client->setMethod('POST');
     $messages = [];
     foreach ($this->getMessages() as $message) {
         $messages[] = $message->asArray();
     }
     $client->setParameterPost(['messages' => $messages]);
     return $client->send()->getBody();
 }