/**
  * @param $request rest/api/2/ REQUEST COMMAND FROM https://docs.atlassian.com/jira/REST/latest/
  * @return array RETURN RESPONSE ARRAY WHAT CAN BE DECODED IN JSON
  * @throws \Jyggen\Curl\Exception\CurlErrorException
  * @throws \Jyggen\Curl\Exception\ProtectedOptionException
  */
 public function _getResponse($request)
 {
     $request = new \Jyggen\Curl\Request($this->url . $request);
     $request->setOption(CURLOPT_USERPWD, sprintf("%s:%s", $this->login, $this->password));
     $request->execute();
     return $request->getResponse();
 }
 public function getPush()
 {
     list($script, $host) = Session::get('action_data');
     if (!$script) {
         return Redirect::action('GameserverController@index')->with("Really nope");
     }
     $commands = $script->commands;
     //      dd($commands);
     if (!($commands != "")) {
         return Redirect::action('GameserverController@index')->with("Nope");
     }
     if ($host == "") {
         return Redirect::action('GameserverController@index')->with("wat");
     }
     $req = new \Jyggen\Curl\Request('http://' . $host);
     $req->setOption(CURLOPT_CONNECTTIMEOUT, 1);
     $req->setOption(CURLOPT_TIMEOUT, 1);
     $req->setOption(CURLOPT_FOLLOWLOCATION, true);
     $req->setOption(CURLOPT_POST, true);
     $req->setOption(CURLOPT_POSTFIELDS, 'commandline=' . urlencode($commands));
     $req->execute();
     if ($req->isSuccessful()) {
         //         return $req->getRawResponse();
         return Redirect::action('GameserverController@index');
     } else {
         //         throw new \Jyggen\Curl\Exception\CurlErrorException($req->getErrorMessage());
         return Redirect::action('GameserverController@index')->with($req->getErrorMessage());
     }
 }
Exemple #3
0
function recent_posts($limit = 3)
{
    return Cache::remember('reddit-posts', 30, function () use($limit) {
        $user_agent = 'User-Agent: php:ffxivcrafting:v0.0.1 (by /u/tickthokk)';
        $request = new Jyggen\Curl\Request('http://api.reddit.com/user/tickthokk/submitted.json');
        $request->setOption(CURLOPT_HTTPHEADER, [$user_agent]);
        $request->execute();
        if (!$request->isSuccessful()) {
            return [];
        }
        $response = json_decode($request->getResponse()->getContent());
        $posts = [];
        foreach ($response->data->children as $child) {
            if ($child->data->subreddit == 'ffxivcrafting') {
                $posts[] = ['title' => $child->data->title, 'url' => 'http://reddit.com' . $child->data->permalink, 'created' => Carbon\Carbon::createFromTimeStamp($child->data->created)->format('M d, Y')];
            }
            if (count($posts) == $limit) {
                break;
            }
        }
        return $posts;
    });
}
 public function getTracks()
 {
     $request = new Jyggen\Curl\Request("http://api.soundcloud.com/users/108057656/tracks.json?client_id=" . self::CLIENT_ID);
     $request->setOption(CURLOPT_INTERFACE, self::RUWEB_IP);
     $request->execute();
     if ($request->isSuccessful()) {
         return $request->getResponse()->getContent();
     } else {
         throw new Exception($request->getErrorMessage());
     }
 }
 private function get_map($json)
 {
     $map_id = $json->MAPID;
     // Markers:
     // http://xivdb.com/modules/maps/php/get-marker.php
     // Fake POSTs
     // type:FIX
     // mapId:f1f3/00
     // type:MPOINT
     // mapId:f1f3/00
     // type:BPOINT
     // mapId:f1f3/00
     foreach (array('FIX', 'MPOINT', 'BPOINT') as $get) {
         $cached_folder = storage_path() . '/app/osmose/cache/maps/' . $json->MAPID;
         $cached_file = $cached_folder . '/' . $get . '.json';
         if (!is_file($cached_file)) {
             \Log::info($json->MAPID . '|' . $get);
             $request = new \Jyggen\Curl\Request('http://xivdb.com/modules/maps/php/get-marker.php');
             $request->setOption(CURLOPT_HTTPHEADER, ['User-Agent: php:ffxivcrafting:v0.0.1 (by /u/tickthokk)', 'Content-type: application/x-www-form-urlencoded; charset=UTF-8', 'X-Requested-With: XMLHttpRequest']);
             $request->setOption(CURLOPT_FOLLOWLOCATION, true);
             $request->setOption(CURLOPT_POST, true);
             $request->setOption(CURLOPT_POSTFIELDS, ['type' => $get, 'mapId' => $json->MAPID]);
             $request->execute();
             if ($request->isSuccessful()) {
                 $response = $request->getResponse();
             } else {
                 throw new Exception($resquest->getErrorMessage());
             }
             $json->{$get} = json_decode($response->getContent())->message;
             // Create the folder if it doesn't exist
             if (!is_dir($cached_folder)) {
                 exec('mkdir -p ' . $cached_folder);
             }
             file_put_contents($cached_file, $json->{$get});
         } else {
             $json->{$get} = file_get_contents($cached_file);
         }
     }
     // Let's get Images
     // 1st level zoom, don't need that much detail
     // Try to get all images.
     //  At 4th level zoom 15 was highest (starting at 0), so we'll go with that and break out as appropriate
     // http://xivdbimg.zamimg.com/modules/maps/Tiles/f1f3/00/4_0_0.png
     // http://xivdbimg.zamimg.com/modules/maps/Tiles/f1f3/00/4_15_15.png
     $path = 'http://xivdbimg.zamimg.com/modules/maps/Tiles/';
     $map_path = base_path() . '/resources/assets/maps/original/';
     $zoom = '1';
     if (!is_dir($map_path . $json->MAPID)) {
         @mkdir($map_path . explode('/', $json->MAPID)[0]);
         mkdir($map_path . $json->MAPID);
     }
     foreach (range(0, 15) as $i) {
         $had_file = false;
         foreach (range(0, 15) as $j) {
             // i then j gets us up to down
             // j then i gets us left to right
             $filename = $zoom . '_' . $i . '_' . $j . '.png';
             $savename = $zoom . '_' . $j . '_' . $i . '.png';
             // Imagemagick will work better if we swap these numbers around
             $img_path = $path . $json->MAPID . '/' . $filename;
             $save_path = $map_path . $json->MAPID . '/' . $savename;
             if (is_file($save_path)) {
                 $had_file = true;
                 continue;
             }
             // File exists? Check for 404
             // if (substr(get_headers($img_path)[0], 9, 3) == '404')
             // 	break;
             $img = @file_get_contents($img_path);
             if ($img === false) {
                 // Alternative to 404 checking
                 break;
             }
             file_put_contents($save_path, $img);
             $had_file = true;
         }
         if (!$had_file) {
             break;
         }
     }
     return $json;
 }