PHP code example of wendelladriel / laravel-caller

1. Go to this page and download the library: Download wendelladriel/laravel-caller library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

wendelladriel / laravel-caller example snippets




return [
    /*
    |--------------------------------------------------------------------------
    | SERVICES
    |--------------------------------------------------------------------------
    |
    | Here you can configure multiple services that you want to create an HTTP Client for.
    | The auth types supported are: basic, digest and token.
    | For more information on these settings check: https://laravel.com/docs/http-client
    |
    */
    'services' => [
        'default' => [
            'url'            => env('CALLER_DEFAULT_URL', 'https://example.com'),
            'timeout'        => env('CALLER_DEFAULT_TIMEOUT', 30),
            'retries'        => env('CALLER_DEFAULT_RETRIES', 0),
            'retry_after'    => env('CALLER_DEFAULT_RETRY_AFTER', 100),
            'cookies_domain' => env('CALLER_DEFAULT_COOKIES_DOMAIN', 'https://example.com'),

            'auth' => [
                'type'       => env('CALLER_DEFAULT_AUTH_TYPE', 'basic'),
                'user'       => env('CALLER_DEFAULT_AUTH_USER', '[email protected]'),
                'password'   => env('CALLER_DEFAULT_AUTH_PASSWORD', 's3Cr3T'),
                'token'      => env('CALLER_DEFAULT_AUTH_TOKEN'),
                'token_type' => env('CALLER_DEFAULT_AUTH_TOKEN_TYPE', 'Bearer'),
            ],

            'headers' => [
                // ADD HEADERS HERE
                // 'X-First' => 'FOO',
            ],

            'cookies' => [
                // ADD COOKIES HERE
                // 'FOO' => 'BAR',
            ],
        ],
    ],
];



namespace App;

use WendellAdriel\LaravelCaller\Caller;

// YOUR CODE HERE

$twitterClient = new Caller('twitter');
// OR YOU CAN USE THE STATIC METHOD
$twitterClient = Caller::make('twitter');



namespace App;

use WendellAdriel\LaravelCaller\Caller;

// YOUR CODE HERE

$twitterClient = new Caller();
// OR YOU CAN USE THE STATIC METHOD
$twitterClient = Caller::make();



/**
 * @param string $url      - The URL for the request that will be joined with the base URL configured in the service
 * @param array  $params   - The params to be sent to the request
 * @param bool   $asForm   - If the request should be sent as "application/x-www-form-urlencoded"
 * @param bool   $isPublic - If is set to true the auth won't be configured for the request
 * @param array  $headers  - Specific headers for the request that will be merged with the headers configured in the service
 * @param array  $cookies  - Specific cookies for the request that will be merged with the cookies configured in the service
 * @param bool   $debug    - Dumps the outgoing request before it is sent and terminate the script's execution
 * @return Response
 */
public function get(
    string $url,
    array $params,
    bool $asForm = false,
    bool $isPublic = false,
    array $headers = [],
    array $cookies = [],
    bool $debug = false
): Response



namespace App;

use WendellAdriel\LaravelCaller\Caller;

// YOUR CODE HERE

$client = new Caller(); // USES THE DEFAULT SERVICE
$client->setService('twitter'); // CHANGES TO THE TWITTER SERVICE



namespace App;

use WendellAdriel\LaravelCaller\Caller;
use WendellAdriel\LaravelCaller\CallerAttachment;

// YOUR CODE HERE

$client = new Caller();
$client->setAttachment(new CallerAttachment('file', file_get_contents('photo.jpg'), 'photo.jpg'));

// THE ATTACHMENT CAN ALSO USE A STREAM RESOURCE AND CAN BE CREATED IN A STATIC WAY
$file = fopen('photo.jpg', 'r');
$client->setAttachment(CallerAttachment::make('file', $file, 'photo.jpg'));

php artisan vendor:publish --provider="WendellAdriel\LaravelCaller\LaravelCallerServiceProvider" --tag=config