Exemplo n.º 1
0
 public function testLinkExists()
 {
     $link = LinkFactory::createLink('http://example.com/ci', true, null, '127.0.0.1', false, true);
     // assert that existent link ending returns true
     $this->assertNotEquals(LinkHelper::linkExists($link->short_url), false);
     // assert that nonexistent link ending returns false
     $this->assertEquals(LinkHelper::linkExists('nonexistent'), false);
 }
Exemplo n.º 2
0
 public function performShorten(Request $request)
 {
     if (env('SETTING_SHORTEN_PERMISSION') && !self::isLoggedIn()) {
         return redirect(route('index'))->with('error', 'You must be logged in to shorten links.');
     }
     $this->request = $request;
     $long_url = $request->input('link-url');
     $custom_ending = $request->input('custom-ending');
     $is_secret = $request->input('options') == "s" ? true : false;
     $creator = session('username');
     $link_ip = $request->ip();
     try {
         $short_url = LinkFactory::createLink($long_url, $is_secret, $custom_ending, $link_ip, $creator);
     } catch (\Exception $e) {
         return self::renderError($e->getMessage());
     }
     return view('shorten_result', ['short_url' => $short_url]);
 }
Exemplo n.º 3
0
 public static function shortenLink(Request $request)
 {
     $response_type = $request->input('response_type');
     $user = self::getApiUserInfo($request);
     /* */
     $long_url = $request->input('url');
     // * required
     $is_secret = $request->input('is_secret') == 'true' ? true : false;
     if (!self::checkRequiredArgs([$long_url])) {
         abort(400, "Missing required arguments.");
     }
     $link_ip = $request->ip();
     $custom_ending = $request->input('custom_ending');
     try {
         $formatted_link = LinkFactory::createLink($long_url, $is_secret, $custom_ending, $link_ip, $user->username);
     } catch (\Exception $e) {
         abort(400, $e->getMessage());
     }
     return self::encodeResponse($formatted_link, 'shorten', $response_type);
 }