Skip to content

Commit 2dfa440

Browse files
committed
Add contracts to Request and Response
1 parent b317393 commit 2dfa440

File tree

4 files changed

+72
-2
lines changed

4 files changed

+72
-2
lines changed

src/Contracts/Request.php

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
4+
namespace Ivan770\HttpClient\Contracts;
5+
6+
use Ivan770\HttpClient\Response;
7+
8+
interface Request
9+
{
10+
/**
11+
* Attach builder properties. HttpClient instance is passed into Closure
12+
*
13+
* @param \Closure $callback
14+
* @return Request
15+
*/
16+
public function attach($callback);
17+
18+
/**
19+
* Run request
20+
*
21+
* @return Response
22+
*/
23+
public function execute();
24+
25+
/**
26+
* Run request, and retrieve response contents
27+
*
28+
* @return \Illuminate\Support\Collection|string
29+
*/
30+
public function get();
31+
}

src/Contracts/Response.php

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
namespace Ivan770\HttpClient\Contracts;
4+
5+
use Illuminate\Pipeline\Pipeline;
6+
7+
interface Response
8+
{
9+
/**
10+
* Create collection from response
11+
*
12+
* @return \Illuminate\Support\Collection
13+
*/
14+
public function toCollection();
15+
16+
/**
17+
* Get body of response, or collection, if response is JSON-compatible
18+
*
19+
* @param bool $throw
20+
* @return \Illuminate\Support\Collection|string
21+
*/
22+
public function getContent($throw = true);
23+
24+
/**
25+
* Pass response content to function
26+
*
27+
* @param \Closure $function Function to call
28+
*/
29+
public function then($function);
30+
31+
/**
32+
* Pass response content to pipeline
33+
*
34+
* @return Pipeline
35+
*/
36+
public function pipeline();
37+
}

src/Request.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33

44
namespace Ivan770\HttpClient;
55

6+
use Ivan770\HttpClient\Contracts\Request as RequestContract;
67

7-
abstract class Request
8+
abstract class Request implements RequestContract
89
{
910
/**
1011
* HttpClient instance

src/Response.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@
77
use Illuminate\Container\Container;
88
use Illuminate\Contracts\Pipeline\Pipeline as PipelineContract;
99
use Illuminate\Pipeline\Pipeline;
10+
use Ivan770\HttpClient\Contracts\Response as ResponseContract;
1011

1112
/**
1213
* @method int getStatusCode() Get response status code
1314
* @method array getHeaders(bool $throw = true) Get response headers
1415
* @method array toArray(bool $throw = true) Get array from response
1516
* @method array|mixed|null getInfo(string $type = null) Get info from transport layer
1617
*/
17-
class Response
18+
class Response implements ResponseContract
1819
{
1920
protected $baseResponse;
2021

0 commit comments

Comments
 (0)