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
10 changes: 7 additions & 3 deletions src/AbstractController.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ abstract class AbstractController
/** @var array<string> $post_body */
protected array $post_body = [];

/** @var array $guzzle_config */
protected array $guzzle_config = [];

/**
* Creates object. Requires an array of settings.
* @param array<string> $settings
Expand Down Expand Up @@ -90,7 +93,7 @@ public function performRequest(array $postData = [], $withHeaders = false)

if ($this->auth_mode === 0) { // Bearer Token
// Inject the Bearer token header
$client = new Client(['base_uri' => self::API_BASE_URI]);
$client = new Client(array_merge($this->guzzle_config, ['base_uri' => self::API_BASE_URI]));
$headers['Authorization'] = 'Bearer ' . $this->bearer_token;
} elseif ($this->auth_mode === 1) { // OAuth 1.0a User Context
// Insert Oauth1 middleware
Expand All @@ -102,11 +105,11 @@ public function performRequest(array $postData = [], $withHeaders = false)
'token_secret' => $this->access_token_secret,
]);
$stack->push($middleware);
$client = new Client([
$client = new Client(array_merge($this->guzzle_config, [
'base_uri' => self::API_BASE_URI,
'handler' => $stack,
'auth' => 'oauth'
]);
]));
} else { // OAuth 2.0 Authorization Code Flow
throw new \RuntimeException('OAuth 2.0 Authorization Code Flow had not been implemented & also requires user interaction.');
}
Expand Down Expand Up @@ -205,6 +208,7 @@ private function parseSettings(array $settings): void
$this->access_token = $settings['access_token'];
$this->access_token_secret = $settings['access_token_secret'];
$this->free_mode = $settings['free_mode'] ?? false;
$this->guzzle_config = $settings['guzzle_config'] ?? [];
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Media.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ private function prepareRequest(array $settings = []): void
'token_secret' => $settings['access_token_secret'],
]);
$stack->push($oAuth1);
$this->client = new Client([
$this->client = new Client(array_merge($this->guzzle_config, [
'base_uri' => "https://upload.twitter.com/1.1/",
'handler' => $stack,
'auth' => 'oauth'
]);
]));
}

/**
Expand Down