1 | <?php |
||
16 | abstract class Service |
||
17 | { |
||
18 | const HTTP_GET = 'GET'; |
||
19 | const HTTP_POST = 'POST'; |
||
20 | const HTTP_PUT = 'PUT'; |
||
21 | const HTTP_DELETE = 'DELETE'; |
||
22 | const HTTP_PATCH = 'PATCH'; |
||
23 | |||
24 | protected $baseUrl; |
||
25 | protected $userid; |
||
26 | protected $password; |
||
27 | protected $parameters = array(); |
||
28 | protected $headers = array( |
||
29 | 'Accept-language'=> 'en-CA' |
||
30 | ); |
||
31 | |||
32 | 6 | public function __construct($baseUrl, $userid, $password) |
|
33 | { |
||
34 | 6 | $this->baseUrl = $baseUrl; |
|
35 | 6 | $this->userid = $userid; |
|
36 | 6 | $this->password = $password; |
|
37 | 6 | } |
|
38 | |||
39 | 1 | public function setLanguage($value) |
|
40 | { |
||
41 | 1 | $this->setHeader('Accept-language', $value); |
|
42 | 1 | return $this; |
|
43 | } |
||
44 | |||
45 | 5 | public function setHeader($name, $value) |
|
46 | { |
||
47 | 5 | $this->headers[$name] = $value; |
|
48 | 5 | return $this; |
|
49 | } |
||
50 | |||
51 | 5 | public function hasParameter($name) |
|
55 | |||
56 | 5 | public function setParameter($name, $value) |
|
57 | { |
||
58 | 5 | $this->parameters[$name] = $value; |
|
59 | 5 | return $this; |
|
60 | } |
||
61 | |||
62 | 5 | public function getParameter($name, $default=null) |
|
63 | { |
||
64 | 5 | return $this->hasParameter($name) ? |
|
65 | 5 | $this->parameters[$name] : $default; |
|
66 | } |
||
67 | |||
68 | 5 | public function getBaseUrl() |
|
72 | |||
73 | /** |
||
74 | * @return Request |
||
75 | */ |
||
76 | abstract protected function buildRequest(); |
||
77 | |||
78 | /** |
||
79 | * @return Response |
||
80 | */ |
||
81 | 5 | public function send() |
|
82 | { |
||
98 | } |
||
99 |