From 2f52eba556e4542f829854c41821f4ac7c97b9c5 Mon Sep 17 00:00:00 2001 From: Aaron Parecki Date: Sat, 29 Apr 2017 09:31:54 -0700 Subject: [PATCH] rename Fetcher class, add stub Parser class --- controllers/Parse.php | 4 ++-- lib/XRay/{Fetch.php => Fetcher.php} | 7 +++++-- lib/XRay/Parser.php | 12 ++++++++++++ 3 files changed, 19 insertions(+), 4 deletions(-) rename lib/XRay/{Fetch.php => Fetcher.php} (95%) create mode 100644 lib/XRay/Parser.php diff --git a/controllers/Parse.php b/controllers/Parse.php index eb35338..485de53 100644 --- a/controllers/Parse.php +++ b/controllers/Parse.php @@ -77,7 +77,7 @@ class Parse { $result['url'] = $url; $result['code'] = null; } else { - $fetch = new p3k\XRay\Fetch($this->http); + $fetcher = new p3k\XRay\Fetcher($this->http); $fields = [ 'twitter_api_key','twitter_api_secret','twitter_access_token','twitter_access_token_secret', @@ -89,7 +89,7 @@ class Parse { $opts[$f] = $v; } - $result = $fetch->fetch($url, $opts); + $result = $fetcher->fetch($url, $opts); if(!empty($result['error'])) { $error_code = isset($result['error_code']) ? $result['error_code'] : 200; diff --git a/lib/XRay/Fetch.php b/lib/XRay/Fetcher.php similarity index 95% rename from lib/XRay/Fetch.php rename to lib/XRay/Fetcher.php index dda839f..ea37f8b 100644 --- a/lib/XRay/Fetch.php +++ b/lib/XRay/Fetcher.php @@ -1,7 +1,7 @@ _fetch_tweet($url, $opts); } + // Transform the HTML GitHub URL into an GitHub API request and fetch the API response if(Formats\GitHub::matches_host($url)) { return $this->_fetch_github($url, $opts); } + // All other URLs are fetched normally + // Special-case appspot.com URLs to not follow redirects. // https://cloud.google.com/appengine/docs/php/urlfetch/ if(!should_follow_redirects($url)) { diff --git a/lib/XRay/Parser.php b/lib/XRay/Parser.php new file mode 100644 index 0000000..d39369c --- /dev/null +++ b/lib/XRay/Parser.php @@ -0,0 +1,12 @@ +