{"action":"created","comment":{"url":"https://api.github.com/repos/redco/redcode-currency-rate/pulls/comments/42545797","id":42545797,"diff_hunk":"@@ -0,0 +1,158 @@\n+<?php\n+\n+namespace RedCode\\Currency\\Rate\\Provider;\n+\n+use RedCode\\Currency\\ICurrency;\n+use RedCode\\Currency\\ICurrencyManager;\n+use RedCode\\Currency\\Rate\\ICurrencyRate;\n+use RedCode\\Currency\\Rate\\ICurrencyRateManager;\n+\n+class YahooCurrencyRateProvider implements ICurrencyRateProvider\n+{\n+    const PROVIDER_NAME = 'yahoo';\n+\n+    public function __construct(ICurrencyRateManager $currencyRateManager, ICurrencyManager $currencyManager)\n+    {\n+        $this->currencyRateManager  = $currencyRateManager;\n+        $this->currencyManager      = $currencyManager;\n+    }\n+\n+    /**\n+     * Load rates by date\n+     *\n+     * @param ICurrency[] $currencies\n+     * @param \\DateTime|null $date\n+     *\n+     * @return ICurrencyRate[]\n+     */\n+    public function getRates($currencies, \\DateTime $date = null)\n+    {\n+        $currencyCodes = [];\n+\n+        foreach ($currencies as $currency) {\n+            $currencyCodes[] = $currency->getCode();\n+        }\n+\n+        if (null === $date) {\n+            $date = new \\DateTime();\n+            $results = $this->_processActualRequest($currencyCodes);\n+        } else {\n+            $results = $this->_processHistoricalRequest($currencyCodes, $date);\n+        }\n+\n+        $rates = [];\n+        foreach ($results as $code => $rate) {\n+            $rates[$code] = $this->currencyRateManager->getNewInstance(\n+                $this->currencyManager->getCurrency($code),\n+                $this,\n+                $date,\n+                $rate,\n+                1\n+            );\n+        }\n+\n+        return $rates;\n+    }\n+\n+    /**\n+     * @param $currencyCodes\n+     *\n+     * @return array\n+     */\n+    private function _processActualRequest($currencyCodes)\n+    {\n+        $baseUrl =  'http://query.yahooapis.com';\n+        $requestString = '/v1/public/yql?q=';\n+        $query = 'select * from yahoo.finance.xchange where pair in (\"'.implode('\",\"', $currencyCodes).'\")';\n+        $query .= '&env=store://datatables.org/alltableswithkeys';\n+        $query = str_replace(' ', '%20', $query);\n+\n+        $curl = curl_init();\n+        curl_setopt($curl, CURLOPT_URL, $baseUrl . $requestString . $query);\n+        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);\n+        curl_setopt($curl, CURLOPT_HEADER, false);\n+        $response = curl_exec($curl);\n+        curl_close($curl);\n+\n+        $ratesXml = new \\SimpleXMLElement($response);\n+\n+        $currencies = [];\n+\n+        /** @var \\SimpleXMLElement $rate */\n+        foreach ($ratesXml->results->rate as $rate) {\n+            $id = (string)$rate->attributes()['id'];\n+            $id = str_replace('=X', '', $id);\n+\n+            $currencies[$id] = (string)$rate->Rate;\n+        }\n+\n+        return $currencies;\n+    }\n+\n+    /**\n+     * @param $currencyCodes\n+     * @param \\DateTime $date\n+     *\n+     * @return array\n+     */\n+    private function _processHistoricalRequest($currencyCodes, \\DateTime $date)\n+    {\n+        $url = 'http://finance.yahoo.com/connection/currency-converter-cache';","path":"src/RedCode/Currency/Rate/Provider/YahooCurrencyRateProvider.php","position":100,"original_position":100,"commit_id":"165b7037a4bb96140039ed406ba1a44e009f225b","original_commit_id":"165b7037a4bb96140039ed406ba1a44e009f225b","user":{"login":"maZahaca","id":1290067,"avatar_url":"https://avatars.githubusercontent.com/u/1290067?v=3","gravatar_id":"","url":"https://api.github.com/users/maZahaca","html_url":"https://github.com/maZahaca","followers_url":"https://api.github.com/users/maZahaca/followers","following_url":"https://api.github.com/users/maZahaca/following{/other_user}","gists_url":"https://api.github.com/users/maZahaca/gists{/gist_id}","starred_url":"https://api.github.com/users/maZahaca/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/maZahaca/subscriptions","organizations_url":"https://api.github.com/users/maZahaca/orgs","repos_url":"https://api.github.com/users/maZahaca/repos","events_url":"https://api.github.com/users/maZahaca/events{/privacy}","received_events_url":"https://api.github.com/users/maZahaca/received_events","type":"User","site_admin":false},"body":"Ok, let's stay on the variant of usage yahoo.finance.historicaldata with dates, when it's possible. \r\nWhen it's NOT throw an exception NoRatesAvailableForDateException [date, provider]. Check [this file](https://github.com/redco/redcode-currency-rate/blob/master/src/RedCode/Currency/Rate/Exception/RateNotFoundException.php) for get an example.\r\n\r\nIt would be great if you can also change \\Exception -> NoRatesAvailableForDateException\r\nin [the file](https://github.com/redco/redcode-currency-rate/blob/master/src/RedCode/Currency/Rate/Provider/EcbCurrencyRateProvider.php#L48)","created_at":"2015-10-20T20:01:22Z","updated_at":"2015-10-20T20:01:22Z","html_url":"https://github.com/redco/redcode-currency-rate/pull/12#discussion_r42545797","pull_request_url":"https://api.github.com/repos/redco/redcode-currency-rate/pulls/12","_links":{"self":{"href":"https://api.github.com/repos/redco/redcode-currency-rate/pulls/comments/42545797"},"html":{"href":"https://github.com/redco/redcode-currency-rate/pull/12#discussion_r42545797"},"pull_request":{"href":"https://api.github.com/repos/redco/redcode-currency-rate/pulls/12"}}},"pull_request":{"url":"https://api.github.com/repos/redco/redcode-currency-rate/pulls/12","id":47996667,"html_url":"https://github.com/redco/redcode-currency-rate/pull/12","diff_url":"https://github.com/redco/redcode-currency-rate/pull/12.diff","patch_url":"https://github.com/redco/redcode-currency-rate/pull/12.patch","issue_url":"https://api.github.com/repos/redco/redcode-currency-rate/issues/12","number":12,"state":"open","locked":false,"title":"add Yahoo currency provider","user":{"login":"remedge","id":285520,"avatar_url":"https://avatars.githubusercontent.com/u/285520?v=3","gravatar_id":"","url":"https://api.github.com/users/remedge","html_url":"https://github.com/remedge","followers_url":"https://api.github.com/users/remedge/followers","following_url":"https://api.github.com/users/remedge/following{/other_user}","gists_url":"https://api.github.com/users/remedge/gists{/gist_id}","starred_url":"https://api.github.com/users/remedge/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/remedge/subscriptions","organizations_url":"https://api.github.com/users/remedge/orgs","repos_url":"https://api.github.com/users/remedge/repos","events_url":"https://api.github.com/users/remedge/events{/privacy}","received_events_url":"https://api.github.com/users/remedge/received_events","type":"User","site_admin":false},"body":"- add YahooCurrencyRateProvider;\n- add test for new provider;\n- add guzzle dependency to composer.json","created_at":"2015-10-17T22:18:44Z","updated_at":"2015-10-20T20:01:22Z","closed_at":null,"merged_at":null,"merge_commit_sha":"6edf1c6684656e95447265fbeda1f8a5f9554fbd","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/redco/redcode-currency-rate/pulls/12/commits","review_comments_url":"https://api.github.com/repos/redco/redcode-currency-rate/pulls/12/comments","review_comment_url":"https://api.github.com/repos/redco/redcode-currency-rate/pulls/comments{/number}","comments_url":"https://api.github.com/repos/redco/redcode-currency-rate/issues/12/comments","statuses_url":"https://api.github.com/repos/redco/redcode-currency-rate/statuses/165b7037a4bb96140039ed406ba1a44e009f225b","head":{"label":"remedge:add-yahoo-provider","ref":"add-yahoo-provider","sha":"165b7037a4bb96140039ed406ba1a44e009f225b","user":{"login":"remedge","id":285520,"avatar_url":"https://avatars.githubusercontent.com/u/285520?v=3","gravatar_id":"","url":"https://api.github.com/users/remedge","html_url":"https://github.com/remedge","followers_url":"https://api.github.com/users/remedge/followers","following_url":"https://api.github.com/users/remedge/following{/other_user}","gists_url":"https://api.github.com/users/remedge/gists{/gist_id}","starred_url":"https://api.github.com/users/remedge/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/remedge/subscriptions","organizations_url":"https://api.github.com/users/remedge/orgs","repos_url":"https://api.github.com/users/remedge/repos","events_url":"https://api.github.com/users/remedge/events{/privacy}","received_events_url":"https://api.github.com/users/remedge/received_events","type":"User","site_admin":false},"repo":{"id":44456339,"name":"redcode-currency-rate","full_name":"remedge/redcode-currency-rate","owner":{"login":"remedge","id":285520,"avatar_url":"https://avatars.githubusercontent.com/u/285520?v=3","gravatar_id":"","url":"https://api.github.com/users/remedge","html_url":"https://github.com/remedge","followers_url":"https://api.github.com/users/remedge/followers","following_url":"https://api.github.com/users/remedge/following{/other_user}","gists_url":"https://api.github.com/users/remedge/gists{/gist_id}","starred_url":"https://api.github.com/users/remedge/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/remedge/subscriptions","organizations_url":"https://api.github.com/users/remedge/orgs","repos_url":"https://api.github.com/users/remedge/repos","events_url":"https://api.github.com/users/remedge/events{/privacy}","received_events_url":"https://api.github.com/users/remedge/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/remedge/redcode-currency-rate","description":"Lib for loading currency rates","fork":true,"url":"https://api.github.com/repos/remedge/redcode-currency-rate","forks_url":"https://api.github.com/repos/remedge/redcode-currency-rate/forks","keys_url":"https://api.github.com/repos/remedge/redcode-currency-rate/keys{/key_id}","collaborators_url":"https://api.github.com/repos/remedge/redcode-currency-rate/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/remedge/redcode-currency-rate/teams","hooks_url":"https://api.github.com/repos/remedge/redcode-currency-rate/hooks","issue_events_url":"https://api.github.com/repos/remedge/redcode-currency-rate/issues/events{/number}","events_url":"https://api.github.com/repos/remedge/redcode-currency-rate/events","assignees_url":"https://api.github.com/repos/remedge/redcode-currency-rate/assignees{/user}","branches_url":"https://api.github.com/repos/remedge/redcode-currency-rate/branches{/branch}","tags_url":"https://api.github.com/repos/remedge/redcode-currency-rate/tags","blobs_url":"https://api.github.com/repos/remedge/redcode-currency-rate/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/remedge/redcode-currency-rate/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/remedge/redcode-currency-rate/git/refs{/sha}","trees_url":"https://api.github.com/repos/remedge/redcode-currency-rate/git/trees{/sha}","statuses_url":"https://api.github.com/repos/remedge/redcode-currency-rate/statuses/{sha}","languages_url":"https://api.github.com/repos/remedge/redcode-currency-rate/languages","stargazers_url":"https://api.github.com/repos/remedge/redcode-currency-rate/stargazers","contributors_url":"https://api.github.com/repos/remedge/redcode-currency-rate/contributors","subscribers_url":"https://api.github.com/repos/remedge/redcode-currency-rate/subscribers","subscription_url":"https://api.github.com/repos/remedge/redcode-currency-rate/subscription","commits_url":"https://api.github.com/repos/remedge/redcode-currency-rate/commits{/sha}","git_commits_url":"https://api.github.com/repos/remedge/redcode-currency-rate/git/commits{/sha}","comments_url":"https://api.github.com/repos/remedge/redcode-currency-rate/comments{/number}","issue_comment_url":"https://api.github.com/repos/remedge/redcode-currency-rate/issues/comments{/number}","contents_url":"https://api.github.com/repos/remedge/redcode-currency-rate/contents/{+path}","compare_url":"https://api.github.com/repos/remedge/redcode-currency-rate/compare/{base}...{head}","merges_url":"https://api.github.com/repos/remedge/redcode-currency-rate/merges","archive_url":"https://api.github.com/repos/remedge/redcode-currency-rate/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/remedge/redcode-currency-rate/downloads","issues_url":"https://api.github.com/repos/remedge/redcode-currency-rate/issues{/number}","pulls_url":"https://api.github.com/repos/remedge/redcode-currency-rate/pulls{/number}","milestones_url":"https://api.github.com/repos/remedge/redcode-currency-rate/milestones{/number}","notifications_url":"https://api.github.com/repos/remedge/redcode-currency-rate/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/remedge/redcode-currency-rate/labels{/name}","releases_url":"https://api.github.com/repos/remedge/redcode-currency-rate/releases{/id}","created_at":"2015-10-17T22:06:19Z","updated_at":"2015-10-17T22:06:21Z","pushed_at":"2015-10-17T22:39:45Z","git_url":"git://github.com/remedge/redcode-currency-rate.git","ssh_url":"git@github.com:remedge/redcode-currency-rate.git","clone_url":"https://github.com/remedge/redcode-currency-rate.git","svn_url":"https://github.com/remedge/redcode-currency-rate","homepage":null,"size":113,"stargazers_count":0,"watchers_count":0,"language":"PHP","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"redco:master","ref":"master","sha":"b0e7faf5ec93f11f57d8ee03c083285c56db58f5","user":{"login":"redco","id":6990183,"avatar_url":"https://avatars.githubusercontent.com/u/6990183?v=3","gravatar_id":"","url":"https://api.github.com/users/redco","html_url":"https://github.com/redco","followers_url":"https://api.github.com/users/redco/followers","following_url":"https://api.github.com/users/redco/following{/other_user}","gists_url":"https://api.github.com/users/redco/gists{/gist_id}","starred_url":"https://api.github.com/users/redco/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/redco/subscriptions","organizations_url":"https://api.github.com/users/redco/orgs","repos_url":"https://api.github.com/users/redco/repos","events_url":"https://api.github.com/users/redco/events{/privacy}","received_events_url":"https://api.github.com/users/redco/received_events","type":"Organization","site_admin":false},"repo":{"id":9728121,"name":"redcode-currency-rate","full_name":"redco/redcode-currency-rate","owner":{"login":"redco","id":6990183,"avatar_url":"https://avatars.githubusercontent.com/u/6990183?v=3","gravatar_id":"","url":"https://api.github.com/users/redco","html_url":"https://github.com/redco","followers_url":"https://api.github.com/users/redco/followers","following_url":"https://api.github.com/users/redco/following{/other_user}","gists_url":"https://api.github.com/users/redco/gists{/gist_id}","starred_url":"https://api.github.com/users/redco/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/redco/subscriptions","organizations_url":"https://api.github.com/users/redco/orgs","repos_url":"https://api.github.com/users/redco/repos","events_url":"https://api.github.com/users/redco/events{/privacy}","received_events_url":"https://api.github.com/users/redco/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/redco/redcode-currency-rate","description":"Lib for loading currency rates","fork":false,"url":"https://api.github.com/repos/redco/redcode-currency-rate","forks_url":"https://api.github.com/repos/redco/redcode-currency-rate/forks","keys_url":"https://api.github.com/repos/redco/redcode-currency-rate/keys{/key_id}","collaborators_url":"https://api.github.com/repos/redco/redcode-currency-rate/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/redco/redcode-currency-rate/teams","hooks_url":"https://api.github.com/repos/redco/redcode-currency-rate/hooks","issue_events_url":"https://api.github.com/repos/redco/redcode-currency-rate/issues/events{/number}","events_url":"https://api.github.com/repos/redco/redcode-currency-rate/events","assignees_url":"https://api.github.com/repos/redco/redcode-currency-rate/assignees{/user}","branches_url":"https://api.github.com/repos/redco/redcode-currency-rate/branches{/branch}","tags_url":"https://api.github.com/repos/redco/redcode-currency-rate/tags","blobs_url":"https://api.github.com/repos/redco/redcode-currency-rate/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/redco/redcode-currency-rate/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/redco/redcode-currency-rate/git/refs{/sha}","trees_url":"https://api.github.com/repos/redco/redcode-currency-rate/git/trees{/sha}","statuses_url":"https://api.github.com/repos/redco/redcode-currency-rate/statuses/{sha}","languages_url":"https://api.github.com/repos/redco/redcode-currency-rate/languages","stargazers_url":"https://api.github.com/repos/redco/redcode-currency-rate/stargazers","contributors_url":"https://api.github.com/repos/redco/redcode-currency-rate/contributors","subscribers_url":"https://api.github.com/repos/redco/redcode-currency-rate/subscribers","subscription_url":"https://api.github.com/repos/redco/redcode-currency-rate/subscription","commits_url":"https://api.github.com/repos/redco/redcode-currency-rate/commits{/sha}","git_commits_url":"https://api.github.com/repos/redco/redcode-currency-rate/git/commits{/sha}","comments_url":"https://api.github.com/repos/redco/redcode-currency-rate/comments{/number}","issue_comment_url":"https://api.github.com/repos/redco/redcode-currency-rate/issues/comments{/number}","contents_url":"https://api.github.com/repos/redco/redcode-currency-rate/contents/{+path}","compare_url":"https://api.github.com/repos/redco/redcode-currency-rate/compare/{base}...{head}","merges_url":"https://api.github.com/repos/redco/redcode-currency-rate/merges","archive_url":"https://api.github.com/repos/redco/redcode-currency-rate/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/redco/redcode-currency-rate/downloads","issues_url":"https://api.github.com/repos/redco/redcode-currency-rate/issues{/number}","pulls_url":"https://api.github.com/repos/redco/redcode-currency-rate/pulls{/number}","milestones_url":"https://api.github.com/repos/redco/redcode-currency-rate/milestones{/number}","notifications_url":"https://api.github.com/repos/redco/redcode-currency-rate/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/redco/redcode-currency-rate/labels{/name}","releases_url":"https://api.github.com/repos/redco/redcode-currency-rate/releases{/id}","created_at":"2013-04-28T09:26:42Z","updated_at":"2015-03-16T10:16:23Z","pushed_at":"2015-10-17T22:39:45Z","git_url":"git://github.com/redco/redcode-currency-rate.git","ssh_url":"git@github.com:redco/redcode-currency-rate.git","clone_url":"https://github.com/redco/redcode-currency-rate.git","svn_url":"https://github.com/redco/redcode-currency-rate","homepage":null,"size":297,"stargazers_count":2,"watchers_count":2,"language":"PHP","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2,"mirror_url":null,"open_issues_count":3,"forks":2,"open_issues":3,"watchers":2,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/redco/redcode-currency-rate/pulls/12"},"html":{"href":"https://github.com/redco/redcode-currency-rate/pull/12"},"issue":{"href":"https://api.github.com/repos/redco/redcode-currency-rate/issues/12"},"comments":{"href":"https://api.github.com/repos/redco/redcode-currency-rate/issues/12/comments"},"review_comments":{"href":"https://api.github.com/repos/redco/redcode-currency-rate/pulls/12/comments"},"review_comment":{"href":"https://api.github.com/repos/redco/redcode-currency-rate/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/redco/redcode-currency-rate/pulls/12/commits"},"statuses":{"href":"https://api.github.com/repos/redco/redcode-currency-rate/statuses/165b7037a4bb96140039ed406ba1a44e009f225b"}}}}