1 | <?php |
||
9 | class LeadService implements ServiceInterface |
||
10 | { |
||
11 | /** |
||
12 | * @var RequestHandler |
||
13 | */ |
||
14 | protected $request; |
||
15 | |||
16 | /** |
||
17 | * @var array |
||
18 | */ |
||
19 | protected $fields = []; |
||
20 | |||
21 | /** |
||
22 | * @var |
||
23 | */ |
||
24 | protected $response; |
||
25 | |||
26 | /** |
||
27 | * @var array Lead |
||
28 | */ |
||
29 | protected $lead = []; |
||
30 | |||
31 | /** |
||
32 | * LeadService constructor. |
||
33 | * @param RequestHandler $requestHandler |
||
34 | */ |
||
35 | 3 | public function __construct(RequestHandler $requestHandler) |
|
39 | |||
40 | /** |
||
41 | * @param Lead $lead |
||
42 | */ |
||
43 | 3 | public function add(EntityInterface $lead) |
|
49 | |||
50 | 3 | public function createLead() |
|
51 | { |
||
52 | 3 | $this->composeAddFields(); |
|
53 | 3 | $this->request->performRequest($this->getLink(), $this->fields); |
|
54 | 3 | $this->response = $this->request->getResponse(); |
|
55 | |||
56 | 3 | if ($this->checkResponse()) { |
|
57 | 2 | return $this->getResponse(); |
|
58 | } |
||
59 | |||
60 | 1 | return false; |
|
61 | } |
||
62 | |||
63 | 2 | public function getResponse() |
|
67 | |||
68 | /** |
||
69 | * @return bool |
||
70 | */ |
||
71 | 3 | protected function checkResponse() |
|
72 | { |
||
73 | 3 | if (isset($this->response['_embedded']['items']) && count($this->response['_embedded']['items'])) { |
|
74 | 2 | return true; |
|
75 | } |
||
76 | |||
77 | 1 | return false; |
|
78 | } |
||
79 | |||
80 | /** |
||
81 | * @return string |
||
82 | */ |
||
83 | 3 | protected function getLink() |
|
87 | |||
88 | /** |
||
89 | * Fill fields for response |
||
90 | */ |
||
91 | 3 | protected function composeAddFields() |
|
101 | } |