Proxy function for both edit requests types

@param   string      $type
@param   string      $url
@param   array       $params
@param   array       $options
@param   array       $headers
@return  mixed
@throws  \Exception
501352
protected function update($type, $url, $params, $options = [], $headers = []) {
        return $this->makeCall($type, $url, $params, $options, $headers);
    }
554037
function proxy(options) {
  var proxy = null
    , isSSL = false
    ;

  if (options.protocol === 'https:') {
    isSSL = true;
  }

  // Test the proxy parameter first for priority
  if (proxyOptions) {
    proxy = proxyOptions;
  } else {
    // Test proxy by env
    if (proxyHttpEnv) {
      proxy = proxyHttpEnv;
    } else if (proxyHttpsEnv) {
      proxy = proxyHttpsEnv;
    }
  }

  if (!proxy) {
    return;
  }

  if (isSSL) {
    options.agent = new HttpsProxyAgent(proxy);
  } else {
    options.agent = new HttpProxyAgent(proxy);
  }
}
261912
public static function urlHandler($hook, $type, $url, $params) {

		$entity = elgg_extract('entity', $params);
		/* @var ElggEntity $entity */

		if ($entity instanceof Comment) {
			$container = $entity->getContainerEntity();
			if ($container instanceof Comment) {
				return $container->getURL();
			}
			return elgg_normalize_url(implode('/', array(
						'stream',
						'comments',
						$entity->container_guid,
						$entity->guid,
					))) . "#elgg-object-$entity->guid";
		} else if ($entity instanceof RiverObject) {
			return elgg_normalize_url(implode('/', array(
				'stream',
				'view',
				$entity->guid
			)));
		}

		return $url;
	}
1339382
public function request($url, array $options = array()) {
    // Initialize a curl
    $curl = curl_init($url);
    // If there's options
    if ($options) {
      // Set options
      curl_setopt_array($curl, $options);
    }
    // Execute
    $response = curl_exec($curl);
    // Get header size
    $headerSize = curl_getinfo($curl, CURLINFO_HEADER_SIZE);
    // Get body
    $body = substr($response, $headerSize);
    // Get status
    $status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
    // Parse header
    $headers = $this->parseHeaders(substr($response, 0, $headerSize));
    // Close curl
    curl_close($curl);
    // Return response
    return new Response($body, $status, $headers);
  }
8680
public function post($url, array $params = null, array $options = array())
	{
		return $this->request($url, 'POST', $params, $options);
	}
122721
public function request($method, $url, $params = null, $headers = [])
    {
        $headers = array_merge(self::defaultHeaders(), $headers);
        $absUrl = $this->apiBase . $url;
        return $this->httpClient()->request($method, $absUrl, $params, $headers);
    }
1101044
function (options) {
        // Nothing to do
        if (!options) { return; }

        // The existing url is updated.
        _.has(options, 'url') && this.url.update(options.url);

        // The existing list of headers must be cleared before adding the given headers to it.
        options.header && this.headers.repopulate(options.header);

        // Only update the method if one is provided.
        _.has(options, 'method') && (this.method = _.isNil(options.method) ?
            DEFAULT_REQ_METHOD : String(options.method).toUpperCase());

        // The rest of the properties are not assumed to exist so we merge in the defined ones.
        _.mergeDefined(this, /** @lends Request.prototype */ {
            /**
             * @type {RequestBody|undefined}
             */
            body: _.createDefined(options, 'body', RequestBody),

            // auth is a special case, empty RequestAuth should not be created for falsy values
            // to allow inheritance from parent
            /**
             * @type {RequestAuth}
             */
            auth: options.auth ? new RequestAuth(options.auth) : undefined,

            /**
             * @type {ProxyConfig}
             */
            proxy: options.proxy && new ProxyConfig(options.proxy),

            /**
             * @type {Certificate|undefined}
             */
            certificate: options.certificate && new Certificate(options.certificate)
        });
    }
761350
public function post($url, $params, $options = [], $headers = []) {
        return $this->makeCall('post', $url, $params, $options, $headers);
    }
1371751
public function delete($url, array $headers = [], array $params = [])
    {
        return $this->instance->createHttpClient()->delete($url, $headers, $params);
    }
363815
public function addLogHandler($type, $options)
    {
        // Throw exception if no handler configuration has been set. FirePHPHandler is the exception, it doesn't
        // have any config options.
        if ($options == []) {
            throw new \Exception('Missing handler configuration!', 1);
        }

        // Set the log level if one wasn't given.
        if (!array_key_exists('log_level', $options)) {
            $options['log_level'] = $this->defaultLogLevel;
        }

        // Allow messages to "bubble-up" the stack to other handlers
        if (!array_key_exists('bubble', $options)) {
            $options['bubble'] = true;
        }

        // Add the requested handler
        switch ($type) {
            case 'file':
                $this->pushHandler(new StreamHandler($options['log_location'],
                                                     $this->loggerLevel($options['log_level']),
                                                     $options['bubble']
                                                    )
                );
                break;

            case 'firebug':
                $this->pushHandler(new FirePHPHandler($this->loggerLevel($options['log_level']), $options['bubble']));
                break;

            case 'syslog':
                $syslog = new SyslogHandler($options['facility'], $options['syslogLevel'], $options['bubble']);
                $formatter = new LineFormatter('%channel%.%level_name%: %message% %context% %extra%');
                $syslog->setFormatter($formatter);
                $this->pushHandler($syslog);
                break;

            case 'mail':
                // Create the Swift_mail transport
                $transport = Swift_SmtpTransport::newInstance(
                    $options['host'],
                    $options['port'], 'ssl')
                        ->setUsername(
                            $options['username'])
                        ->setPassword(
                            $options['password']);

                // Create the Mailer using your created Transport
                $mailer = Swift_Mailer::newInstance($transport);

                // Create a message
                $message = Swift_Message::newInstance($options['subject'])
                    ->setFrom($options['from'])
                    ->setTo($options['to'])
                    ->setBody('', 'text/html');

                $htmlFormatter = new HtmlFormatter();

                $mailStream = new SwiftMailerHandler($mailer,
                                                     $message,
                                                     $this->loggerLevel($options['log_level']),
                                                     $options['bubble']
                );
                $mailStream->setFormatter($htmlFormatter);
                $this->pushHandler($mailStream);
                break;

            case 'sms':
                $twilio = new TwilioHandler($options['account_sid'],
                                            $options['auth_token'],
                                            $options['from_numbers'],
                                            $options['to_numbers'],
                                            $options['log_level'],
                                            $options['bubble']
                );

                $formatter = new LineFormatter('%channel%.%level_name%: %message% %context%');
                $twilio->setFormatter($formatter);

                $this->pushHandler($twilio);
                break;

            default:
                throw new \Exception('Unknown Log Handler', 1);
                break;
        }
    }
626080
public function get($url, $params = array(), $options = array())
    {
        return $this->request($url, self::GET, $params, $options);
    }
56378
protected function _customRequest($url, $data, $type)
    {
        $response = $this->curl->init($this->url ?? $url)
                        ->option('returntransfer', true)
                        ->option('customrequest', strtoupper($type))
                        ->option('ssl_verifypeer', $this->sslVerifyPeer)
                        ->option('postfields', $data)
                        ->exec();

        return $this->_result($response);
    }
1361333
public static function request($type = 'GET', $uri = '', $params = null)
    {
        $settings = MailchimpLists::$plugin->getSettings();

        // Get datacenter from end of api key
        $explode = explode('-', $settings->apiKey);
        $dc = end($explode);

        $client = new \GuzzleHttp\Client([
          'base_uri' => 'https://'.$dc.'.api.mailchimp.com/3.0/',
          'http_errors' => false,
          'timeout' => 10,
          'auth' => ['plugin', $settings->apiKey]
        ]);

        try {

          $response = $client->request($type, $uri, [
            'json' => $params
          ]);

          return [
            'success' => true,
            'statusCode' => $response->getStatuscode(),
            'reason' => $response->getReasonPhrase(),
            'body' => json_decode($response->getBody(), true)
          ];

        } catch (\Exception $e) {

          return [
            'success' => false,
            'reason' => $e->getMessage()
          ];

        }
    }
733139
protected function runResponseHandler(Result $result, $type, $url, $params) {
        // Check if a status specific handler isset or else fallback to the default
        if (isset($this->responseHandlers[$result->getStatus()])) {
            $handler = $this->responseHandlers[$result->getStatus()];
        } else {
            $handler = $this->responseHandlers['default'];
        }

        // If the handler is a callable run the handler and return the result
        if (is_callable($handler)) {
            return $handler($result, $type, $url, $params);
        }
        // If the handler does not exists, throw exception
        else if (!method_exists($this, $handler)) {
            throw new ResponseHandlerNotFoundException('Response handler not found: ' . $handler);
        }

        // Run the handler and return the result
        return $this->$handler($result, $type, $url, $params);
    }
1045338
protected function call( $type, $params ) {
		if ( !isset( $this->callbacks[$type] ) ) {
			return;
		}
		foreach ( $this->callbacks[$type] as $callback ) {
			if ( is_callable( $callback ) ) {
				call_user_func_array( $callback, $params );
			}
		}
	}
436849
protected function createRequest($type, $url, $token)
    {
        return $this->client->createRequest($type, $url, $this->getDefaultHeaders($token));
    }
965389
public function get($url, array $params = null, array $options = array())
	{
		return $this->request($url, 'GET', $params, $options);
	}