diff --git a/src/Instagram/Instagram.php b/src/Instagram/Instagram.php index af3fb07..9fd8a83 100644 --- a/src/Instagram/Instagram.php +++ b/src/Instagram/Instagram.php @@ -66,6 +66,11 @@ class Instagram { */ protected $request = ''; + /** + * @var array + */ + protected $proxy; + /** * @var string $pagingNextLink Instagram next page link. */ @@ -91,6 +96,8 @@ public function __construct( $config ) { // set graph version $this->graphVersion = isset( $config['graph_version'] ) ? $config['graph_version'] : self::DEFAULT_GRAPH_VERSION; + + $this->proxy = isset($config['proxy']) ? (array) $config['proxy'] : []; } /** @@ -145,7 +152,7 @@ public function delete( $params ) { */ public function sendRequest( $method, $endpoint, $params ) { // create our request - $this->request = new Request( $method, $endpoint, $params, $this->graphVersion, $this->accessToken ); + $this->request = new Request( $method, $endpoint, $params, $this->graphVersion, $this->accessToken, $this->proxy); // send the request to the client for processing $response = $this->client->send( $this->request ); diff --git a/src/Instagram/Request/Curl.php b/src/Instagram/Request/Curl.php index ff42c57..220042d 100644 --- a/src/Instagram/Request/Curl.php +++ b/src/Instagram/Request/Curl.php @@ -69,6 +69,18 @@ public function send( $request ) { CURLOPT_CAINFO => __DIR__ . '/certs/cacert.pem', ); + // remove not allowed params + $proxy = array_intersect_key( + $request->getProxy(), + array_flip([ + CURLOPT_PROXY, + CURLOPT_PROXYUSERPWD, + CURLOPT_PROXYTYPE, + ]) + ); + + $options += $proxy; + if ( $request->getMethod() == Request::METHOD_POST ) { // need to add on post fields $options[CURLOPT_POSTFIELDS] = $request->getUrlBody(); } diff --git a/src/Instagram/Request/Request.php b/src/Instagram/Request/Request.php index a4eb5b1..f6c15b3 100644 --- a/src/Instagram/Request/Request.php +++ b/src/Instagram/Request/Request.php @@ -85,6 +85,11 @@ class Request { */ protected $url; + /** + * @var array + */ + protected $proxy; + /** * Contructor for instantiating a request.. * @@ -93,9 +98,10 @@ class Request { * @param array $params the parameters to be sent along with the request. * @param string $graphVersion the graph version for the request. * @param string $accessToken the access token to go along with the request. + * @param array $proxy curl proxy params. * @return void */ - public function __construct( $method, $endpoint = '', $params = array(), $graphVersion = '', $accessToken = '' ) { + public function __construct( $method, $endpoint = '', $params = array(), $graphVersion = '', $accessToken = '', $proxy = [] ) { // set HTTP method $this->method = strtoupper( $method ); @@ -110,6 +116,18 @@ public function __construct( $method, $endpoint = '', $params = array(), $graphV // set url $this->setUrl( $graphVersion ); + + $this->setProxy($proxy); + } + + public function setProxy(array $proxy) + { + $this->proxy = $proxy; + } + + public function getProxy() + { + return $this->proxy; } /**