1 | <?php |
||
28 | class NbsBrowser |
||
29 | { |
||
30 | const SOURCE = 'http://www.nbs.rs/kursnaListaModul/naZeljeniDan.faces'; |
||
31 | /** |
||
32 | * @var Client |
||
33 | */ |
||
34 | private $guzzleClient; |
||
35 | |||
36 | /** |
||
37 | * @var CookieJar |
||
38 | */ |
||
39 | private $guzzleCookieJar; |
||
40 | |||
41 | /** |
||
42 | * Get XML document with rates. |
||
43 | * |
||
44 | * @param \DateTime $date |
||
45 | * @param string $rateType |
||
46 | * @return StreamInterface |
||
47 | */ |
||
48 | 3 | public function getXmlDocument(\DateTime $date, $rateType) |
|
72 | |||
73 | /** |
||
74 | * Execute HTTP request and get raw body response. |
||
75 | * |
||
76 | * @param string $method HTTP Method. |
||
77 | * @param array $params Params to send with request. |
||
78 | * @return StreamInterface |
||
79 | */ |
||
80 | 3 | private function request($method, array $query = array(), array $params = array()) |
|
92 | |||
93 | /** |
||
94 | * Get NBS's form CSRF token. |
||
95 | * |
||
96 | * @return string CSRF token. |
||
97 | * |
||
98 | * @throws \RuntimeException When API is changed. |
||
99 | */ |
||
100 | 3 | private function getFormCsrfToken() |
|
101 | { |
||
102 | 3 | $crawler = new Crawler($this->request('GET')->getContents()); |
|
103 | |||
104 | 3 | $hiddens = $crawler->filter('input[type="hidden"]'); |
|
105 | |||
106 | /** |
||
107 | * @var \DOMElement $hidden |
||
108 | */ |
||
109 | 3 | foreach ($hiddens as $hidden) { |
|
110 | |||
111 | 3 | if ($hidden->getAttribute('name') === 'javax.faces.ViewState') { |
|
112 | 3 | return $hidden->getAttribute('value'); |
|
113 | } |
||
114 | } |
||
115 | |||
116 | throw new RuntimeException('FATAL ERROR: National Bank of Serbia changed it\'s API, unable to extract token.'); // @codeCoverageIgnore |
||
117 | } |
||
118 | |||
119 | /** |
||
120 | * Get Guzzle Client. |
||
121 | * |
||
122 | * @return Client |
||
123 | */ |
||
124 | 3 | private function getGuzzleClient() |
|
132 | |||
133 | /** |
||
134 | * Get Guzzle CookieJar. |
||
135 | * |
||
136 | * @return CookieJar |
||
137 | */ |
||
138 | 3 | private function getGuzzleCookieJar() |
|
146 | } |
||
147 |