コード例 #1
0
ファイル: SaveTweetTest.php プロジェクト: Hiroto-K/SaveTweet
 /**
  * Test isRegistered()
  *
  * @return void
  */
 public function testIsRegistered()
 {
     $ids = [];
     foreach ($ids as $id) {
         $bool = $this->SaveTweet->isRegistered($id);
         $this->assertFalse($bool);
     }
 }
コード例 #2
0
ファイル: new.php プロジェクト: Hiroto-K/SaveTweet
        if ($parse["host"] !== "twitter.com") {
            throw new RuntimeException("Host is not twitter.com.", 400);
        }
        if (!isset($parse["path"])) {
            throw new RuntimeException("Path is empty.", 400);
        }
        preg_match("#/[a-zA-Z0-9_]{1,15}/status/([0-9]+)#", $parse["path"], $matches);
        if (!isset($matches[1])) {
            throw new RuntimeException("Please send in the 'https://twitter.com/{sn}/status/{id}' format.", 400);
        }
        $id = $matches[1];
    }
    $conf = config("twitter");
    $TwistOAuth = new TwistOAuth($conf["ck"], $conf["cs"], $conf["ot"], $conf["os"]);
    $SaveTweet = new SaveTweet(config("db"), $TwistOAuth);
    if ($SaveTweet->isRegistered($id)) {
        throw new RuntimeException("This ID is already registered.", 400);
    }
    $result = $SaveTweet->add($id);
    $json = ["status" => "OK.", "id" => $result["id"], "user" => $result["user"], "user_id" => $result["user_id"], "tweet_id" => $result["tweet_id"], "body" => $result["body"]];
} catch (PDOException $e) {
    http_response_code(500);
    $json = ["error" => ["message" => config("debug") ? $e->getMessage() : "DataBase Error.", "code" => 500]];
} catch (TwistException $e) {
    http_response_code(500);
    $json = ["error" => ["message" => config("debug") ? $e->getMessage() : "Twitter API Error.", "code" => 500]];
} catch (RuntimeException $e) {
    $json = ["error" => ["message" => $e->getMessage(), "code" => $e->getCode() === 0 ? 500 : $e->getCode()]];
    if ($e->getCode() !== 0) {
        http_response_code($e->getCode());
    }