Swader / diffbot-php-client

[Deprecated - Maintenance mode - use APIs directly please!] The official Diffbot client library
MIT License
53 stars 20 forks source link

Custom HTTP Headers #25

Open steved1982 opened 8 years ago

steved1982 commented 8 years ago

Diffbot allows Custom HTTP Headers like X-Forward-Cookie.

How can I set these using this system?

My current code is just: $api = $diffbot->createProductAPI($_POST["siteURL"]);

Swader commented 8 years ago

This is currently not implemented directly. However, I believe you can work around this by modifying the HttpClient used by the Diffbot class. It's just a Guzzle5 HTTPClient, so take it out with getHttpClient and change the headers you need, then set it again with setHttpClient. Some helpful docs could be these.

I'll look into this some more during the course of next week - currently, I'm writing the full client docs.

Swader commented 8 years ago

@steved1982 I know it's been a while since this has been dealt with, but the client now implements PSR-7, so you can set custom headers by simply tweaking the client instance you use. Details about what was done and why in the 1.0 update are here.

justinyost commented 6 years ago

@Swader This actually doesn't work because you typehinted to the implementing class and not an interface, so we can't swap out the class on the fly.

I've attempted this using both Guzzle as well as HttpPlug's PluginClient instance. both of which fail.

An example:

1) App\Tests\TestCase\Products\Vendors\DiffbotVendorTest::testVendor
TypeError: Argument 1 passed to Swader\Diffbot\Diffbot::setHttpClient() must be an instance of Http\Client\Common\HttpMethodsClient or null, instance of Http\Client\Common\PluginClient given, called in /home/vagrant/phoenix/app/Products/Vendors/DiffbotVendor.php on line 269

/home/vagrant/phoenix/vendor/swader/diffbot-php-client/src/Diffbot.php:98