aboutsummaryrefslogtreecommitdiff
path: root/bridges/StockFilingsBridge.php
diff options
context:
space:
mode:
Diffstat (limited to 'bridges/StockFilingsBridge.php')
-rw-r--r--bridges/StockFilingsBridge.php136
1 files changed, 71 insertions, 65 deletions
diff --git a/bridges/StockFilingsBridge.php b/bridges/StockFilingsBridge.php
index f774244a..2817dd97 100644
--- a/bridges/StockFilingsBridge.php
+++ b/bridges/StockFilingsBridge.php
@@ -1,80 +1,86 @@
<?php
-class StockFilingsBridge extends FeedExpander {
- const MAINTAINER = 'captn3m0';
- const NAME = 'SEC Stock filings';
- const URI = 'https://www.sec.gov/edgar/searchedgar/companysearch.html';
- const CACHE_TIMEOUT = 3600; // 1h
- const DESCRIPTION = 'Tracks SEC Filings for a single company';
- const SEARCH_URL = 'https://www.sec.gov/cgi-bin/browse-edgar?owner=exclude&action=getcompany&CIK=';
- const WEBSITE_ROOT = 'https://www.sec.gov';
+class StockFilingsBridge extends FeedExpander
+{
+ const MAINTAINER = 'captn3m0';
+ const NAME = 'SEC Stock filings';
+ const URI = 'https://www.sec.gov/edgar/searchedgar/companysearch.html';
+ const CACHE_TIMEOUT = 3600; // 1h
+ const DESCRIPTION = 'Tracks SEC Filings for a single company';
+ const SEARCH_URL = 'https://www.sec.gov/cgi-bin/browse-edgar?owner=exclude&action=getcompany&CIK=';
+ const WEBSITE_ROOT = 'https://www.sec.gov';
- const PARAMETERS = array(
- array(
- 'ticker' => array(
- 'name' => 'cik',
- 'required' => true,
- 'exampleValue' => 'AMD',
- // https://stackoverflow.com/a/12827734
- 'pattern' => '[A-Za-z0-9]+',
- ),
- ));
+ const PARAMETERS = [
+ [
+ 'ticker' => [
+ 'name' => 'cik',
+ 'required' => true,
+ 'exampleValue' => 'AMD',
+ // https://stackoverflow.com/a/12827734
+ 'pattern' => '[A-Za-z0-9]+',
+ ],
+ ]];
- public function getIcon() {
- return 'https://www.sec.gov/favicon.ico';
- }
+ public function getIcon()
+ {
+ return 'https://www.sec.gov/favicon.ico';
+ }
- /**
- * Generates search URL
- */
- private function getSearchUrl() {
- return self::SEARCH_URL . $this->getInput('ticker');
- }
+ /**
+ * Generates search URL
+ */
+ private function getSearchUrl()
+ {
+ return self::SEARCH_URL . $this->getInput('ticker');
+ }
- /**
- * Returns the Company Name
- */
- private function getRssFeed($html) {
- $links = $html->find('#contentDiv a');
+ /**
+ * Returns the Company Name
+ */
+ private function getRssFeed($html)
+ {
+ $links = $html->find('#contentDiv a');
- foreach ($links as $link) {
- $href = $link->href;
+ foreach ($links as $link) {
+ $href = $link->href;
- if (substr($href, 0, 4) !== 'http') {
- $href = self::WEBSITE_ROOT . $href;
- }
- parse_str(html_entity_decode(parse_url($href, PHP_URL_QUERY)), $query);
+ if (substr($href, 0, 4) !== 'http') {
+ $href = self::WEBSITE_ROOT . $href;
+ }
+ parse_str(html_entity_decode(parse_url($href, PHP_URL_QUERY)), $query);
- if (isset($query['output']) and ($query['output'] == 'atom')) {
- return $href;
- }
- }
+ if (isset($query['output']) and ($query['output'] == 'atom')) {
+ return $href;
+ }
+ }
- return false;
- }
+ return false;
+ }
- /**
- * Return \simple_html_dom object
- * for the entire html of the product page
- */
- private function getHtml() {
- $uri = $this->getSearchUrl();
+ /**
+ * Return \simple_html_dom object
+ * for the entire html of the product page
+ */
+ private function getHtml()
+ {
+ $uri = $this->getSearchUrl();
- return getSimpleHTMLDOM($uri) ?: returnServerError('Could not request SEC.');
- }
+ return getSimpleHTMLDOM($uri) ?: returnServerError('Could not request SEC.');
+ }
- /**
- * Scrape the SEC Stock Filings RSS Feed URL
- * and redirect there
- */
- public function collectData() {
- $html = $this->getHtml();
- $rssFeedUrl = $this->getRssFeed($html);
+ /**
+ * Scrape the SEC Stock Filings RSS Feed URL
+ * and redirect there
+ */
+ public function collectData()
+ {
+ $html = $this->getHtml();
+ $rssFeedUrl = $this->getRssFeed($html);
- if ($rssFeedUrl) {
- parent::collectExpandableDatas($rssFeedUrl);
- } else {
- returnClientError('Could not find RSS Feed URL. Are you sure you used a valid CIK?');
- }
- }
+ if ($rssFeedUrl) {
+ parent::collectExpandableDatas($rssFeedUrl);
+ } else {
+ returnClientError('Could not find RSS Feed URL. Are you sure you used a valid CIK?');
+ }
+ }
}