Browse Source

rename Fetcher class, add stub Parser class

pull/38/head
Aaron Parecki 7 years ago
parent
commit
2f52eba556
No known key found for this signature in database GPG Key ID: 276C2817346D6056
3 changed files with 19 additions and 4 deletions
  1. +2
    -2
      controllers/Parse.php
  2. +5
    -2
      lib/XRay/Fetcher.php
  3. +12
    -0
      lib/XRay/Parser.php

+ 2
- 2
controllers/Parse.php View File

@ -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;

lib/XRay/Fetch.php → lib/XRay/Fetcher.php View File

@ -1,7 +1,7 @@
<?php
namespace p3k\XRay;
class Fetch {
class Fetcher {
private $http;
public function __construct($http) {
@ -36,15 +36,18 @@ class Fetch {
$url = normalize_url($url);
$host = parse_url($url, PHP_URL_HOST);
// Check if this is a Twitter URL and if they've provided API credentials, use the API
// Check if this is a Twitter URL and use the API
if(Formats\Twitter::matches_host($url)) {
return $this->_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)) {

+ 12
- 0
lib/XRay/Parser.php View File

@ -0,0 +1,12 @@
<?php
namespace p3k\XRay;
class Parser {
public function parse($url, $body) {
}
}

Loading…
Cancel
Save