Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/Instagram/Instagram.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ class Instagram {
*/
protected $request = '';

/**
* @var array
*/
protected $proxy;

/**
* @var string $pagingNextLink Instagram next page link.
*/
Expand All @@ -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'] : [];
}

/**
Expand Down Expand Up @@ -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 );
Expand Down
12 changes: 12 additions & 0 deletions src/Instagram/Request/Curl.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
20 changes: 19 additions & 1 deletion src/Instagram/Request/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ class Request {
*/
protected $url;

/**
* @var array
*/
protected $proxy;

/**
* Contructor for instantiating a request..
*
Expand All @@ -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 );

Expand All @@ -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;
}

/**
Expand Down