{"id":23882285,"url":"https://github.com/jenky/transmit","last_synced_at":"2025-02-23T01:23:25.548Z","repository":{"id":56997982,"uuid":"385544509","full_name":"jenky/transmit","owner":"jenky","description":null,"archived":false,"fork":false,"pushed_at":"2023-03-20T09:46:41.000Z","size":72,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-04T02:53:07.831Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jenky.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-07-13T09:12:04.000Z","updated_at":"2022-03-03T05:01:18.000Z","dependencies_parsed_at":"2022-08-21T14:50:23.549Z","dependency_job_id":null,"html_url":"https://github.com/jenky/transmit","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jenky%2Ftransmit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jenky%2Ftransmit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jenky%2Ftransmit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jenky%2Ftransmit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jenky","download_url":"https://codeload.github.com/jenky/transmit/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240255328,"owners_count":19772598,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-01-04T02:53:11.229Z","updated_at":"2025-02-23T01:23:25.530Z","avatar_url":"https://github.com/jenky.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Transmit\n\n[![Latest Version on Packagist][ico-version]][link-packagist]\n[![Test Status][ico-gh-actions]][link-gh-actions]\n[![Codecov][ico-codecov]][link-codecov]\n[![Total Downloads][ico-downloads]][link-downloads]\n[![Software License][ico-license]](LICENSE.md)\n\nThis package allows you to quickly create Http client with pre-defined configurations.\n\n## Install\n\nYou may use Composer to install Transmit into your Laravel project:\n\n``` bash\n$ composer require jenky/transmit\n```\n\nAfter installing Transmit, publish its assets using the `vendor:publish` Artisan command.\n\n``` bash\nphp artisan vendor:publish\n```\n\nor\n\n``` bash\nphp artisan vendor:publish --provider=\"Jenky\\Transmit\\TransmitServiceProvider\"\n```\n\n## Configuration\n\nAfter publishing Transmit's assets, its primary configuration file will be located at `config/transmit.php`. This configuration file allows you to configure your guzzle client options and each configuration option includes a description of its purpose, so be sure to thoroughly explore this file.\n\n### Client configuration\n\nA client is simply a HTTP client instance with its own configuration. This allows you to create a HTTP client on the fly and reuse anytime, anywhere you want.\n\n### Configure the options\n\nSet guzzle request options within the channel. Please visit [Request Options](http://docs.guzzlephp.org/en/stable/request-options.html) for more information.\n\n``` php\n'clients' =\u003e [\n    'github' =\u003e [\n        'options' =\u003e [\n            'base_uri' =\u003e 'https://api.github.com/v3/',\n            'time_out' =\u003e 20,\n        ],\n    ],\n]\n```\n\nThen uses it in your code:\n\n``` php\nuse Illuminate\\Support\\Facades\\Http;\n\nHttp::client('github')-\u003eget('....');\n```\n\n### Customizing the client Pending Request\n\nTo get started, define a `tap` array on the channel's configuration. The `tap` array should contain a list of classes that should have an opportunity to customize (or \"tap\" into) the pending request instance after it is created:\n\n``` php\n'default' =\u003e [\n    'tap' =\u003e [\n        App\\Http\\Client\\CustomizeRequest::class,\n    ],\n],\n```\n\nOnce you have configured the `tap` option on your client, you're ready to define the class that will customize your client factory instance. This class only needs a single method: `__invoke`, which receives an `Illuminate\\Http\\Client\\PendingRequest` instance.\n\n``` php\n\u003c?php\n\nnamespace App\\Http\\Client;\n\nuse Illuminate\\Http\\Client\\PendingRequest;\n\nclass CustomizeRequest\n{\n    /**\n     * Customize the given client pending request instance.\n     *\n     * @param  \\Illuminate\\Http\\Client\\PendingRequest  $request\n     * @return void\n     */\n    public function __invoke(PendingRequest $request)\n    {\n        $request-\u003ewithToken('my_access_token');\n    }\n}\n```\n\n\u003e All of your \"tap\" classes are resolved by the service container, so any constructor dependencies they require will automatically be injected.\n\n#### \"Tap\" class parameters\n\n\"Tap\" class can also receive additional parameters. For example, if your handler needs to log the Guzzle request and response by using a specific Laravel logger channel, you could create a `UseLogger` class that receives a channel name as an additional argument.\n\nAdditional parameters will be passed to the class after the `$request` argument:\n\n``` php\n\u003c?php\n\nnamespace App\\Http\\Client;\n\nuse GuzzleHttp\\MessageFormatter;\nuse GuzzleHttp\\Middleware;\nuse Illuminate\\Http\\Client\\PendingRequest;\nuse Illuminate\\Log\\LogManager;\n\nclass UseLogger\n{\n    /**\n     * The logger manager instance.\n     *\n     * @var \\Illuminate\\Log\\LogManager\n     */\n    protected $logger;\n\n    /**\n     * Create new log middleware instance.\n     *\n     * @param  \\Illuminate\\Log\\LogManager $logger\n     * @return void\n     */\n    public function __construct(LogManager $logger)\n    {\n        $this-\u003elogger = $logger;\n    }\n\n    /**\n     * Customize the given client pending request instance.\n     *\n     * @param  \\Illuminate\\Http\\Client\\PendingRequest  $request\n     * @param  string|null  $channel\n     * @param  string  $level\n     * @return void\n     */\n    public function __invoke(PendingRequest $request, ?string $channel = null, string $level = 'debug')\n    {\n        $request-\u003ewithMiddleware(Middleware::log(\n            $this-\u003elogger-\u003echannel($channel), new MessageFormatter, $level\n        ));\n    }\n}\n```\n\n\"Tap\" class parameters may be specified in `transmit` config by separating the class name and parameters with a `:`. Multiple parameters should be delimited by commas:\n\n``` php\n'my_client' =\u003e [\n    'tap' =\u003e [\n        App\\Http\\Client\\UseLogger::class.':slack,info',\n    ],\n],\n```\n\nYou can also use `closure` if you don't want to use class base method:\n\n``` php\n'my_client' =\u003e [\n    'tap' =\u003e [\n        function (PendingRequest $request) {\n            $request-\u003easForm();\n        },\n    ],\n],\n```\n\n## Caveats\n\n### Inspecting faking requests\n\nAll the `assert*` methods should be called from HTTP client instance instead of the `Http` facade if requests are made from specific client.\n\n```php\nuse Illuminate\\Http\\Client\\Request;\nuse Illuminate\\Support\\Facades\\Http;\n\nHttp::fake();\n\nHttp::client('my_client')-\u003eget('foo');\n\nHttp::client('my_client')-\u003eassertSent(function (Request $request) {\n    //\n});\n\nHttp::client('my_client')-\u003eassertNotSent(function (Request $request) {\n    //\n});\n```\n\n## Change log\n\nPlease see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.\n\n## Testing\n\n``` bash\n$ composer test\n```\n\n## Contributing\n\nPlease see [CONTRIBUTING](CONTRIBUTING.md) and [CODE_OF_CONDUCT](CODE_OF_CONDUCT.md) for details.\n\n## Security\n\nIf you discover any security related issues, please email contact@lynh.me instead of using the issue tracker.\n\n## Credits\n\n- [Lynh][link-author]\n- [All Contributors][link-contributors]\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.\n\n[ico-version]: https://img.shields.io/packagist/v/jenky/transmit.svg?logo=packagist\u0026style=for-the-badge\n[ico-license]: https://img.shields.io/badge/license-MIT-brightgreen.svg?style=for-the-badge\n[ico-travis]: https://img.shields.io/travis/com/jenky/transmit/master.svg?style=for-the-badge\n[ico-scrutinizer]: https://img.shields.io/scrutinizer/coverage/g/jenky/transmit.svg?style=for-the-badge\n[ico-code-quality]: https://img.shields.io/scrutinizer/g/jenky/transmit.svg?style=for-the-badge\n[ico-downloads]: https://img.shields.io/packagist/dt/jenky/transmit.svg?style=for-the-badge\n[ico-gh-actions]: https://img.shields.io/github/workflow/status/jenky/transmit/Tests?label=actions\u0026logo=github\u0026style=for-the-badge\n[ico-codecov]: https://img.shields.io/codecov/c/github/jenky/transmit?logo=codecov\u0026style=for-the-badge\n\n[link-packagist]: https://packagist.org/packages/jenky/transmit\n[link-travis]: https://travis-ci.com/jenky/transmit\n[link-scrutinizer]: https://scrutinizer-ci.com/g/jenky/transmit/code-structure\n[link-code-quality]: https://scrutinizer-ci.com/g/jenky/transmit\n[link-downloads]: https://packagist.org/packages/jenky/transmit\n[link-author]: https://github.com/jenky\n[link-contributors]: ../../contributors\n[link-gh-actions]: https://github.com/jenky/transmit/actions\n[link-codecov]: https://codecov.io/gh/jenky/transmit\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjenky%2Ftransmit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjenky%2Ftransmit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjenky%2Ftransmit/lists"}