/** * Returns gravatar profile information for a given email address * * Valid Formats include: json, xml, php, vcf, qr * If a format is not specified, the profile will be returned in hCard format * * Due to the way the gravatar api's work, json and qr formats return a url * string for use in img and script tags * * @param String $email * @param String $format * @return Array|String */ public function getProfile($email, $format = null, $secure = null) { $hash = $this->getHash($email); $extension = ''; if (null !== $format) { $extension = strtolower($format); } if (null === $secure) { $secure = $this->settings['secure']; } $url = ($secure ? 'https://secure' : 'http://www') . '.gravatar.com/' . $hash . '.' . $extension; if ($format === 'qr' || $format === 'json') { return $url; } $browser = new \Buzz\Browser(); if ($format !== 'php') { $response = $browser->get($url, $this->headers[$format]); } else { $response = $browser->get($url); } if ($response->isOk()) { if ($format === 'php') { return unserialize($response->getContent()); } else { return $response->getContent(); } } elseif ($response->isNotFound()) { throw new GravatarException($response->getStatusCode() . ' Error: There is no profile associated with this email address.'); } else { throw new GravatarException($response->getStatusCode() . ' Error: There was an error trying to fetch this profile.'); } return; }
public function index() { $browser = new Buzz\Browser(); $response = $browser->get('http://www.google.com'); echo $browser->getLastRequest() . "\n"; echo $response; }
function downloadJson($url, $file) { $browser = new Buzz\Browser(); // send request $response = $browser->get($url); $content = $response->getContent(); $filename = __DIR__ . '/fixtures/' . $file; file_put_contents($filename, $content); }
public function fetch(Url $url) { if ($url->isImage()) { return new Resource($url, '', '', $url, null, 'image'); } $browser = new \Buzz\Browser(new \Buzz\Client\Curl()); $response = $browser->get((string) $url); $parsedData = (new Parser())->parse($response->getContent(), $url); return new Resource($url, $parsedData->title, $parsedData->description, null !== $parsedData->imageUrl ? new Url($parsedData->imageUrl) : null, null !== $parsedData->videoUrl ? new Url($parsedData->videoUrl) : null, $parsedData->type); }
/** * Make an authenticated api request to twitter. * * @access public * @param mixed $url * @param mixed $expand_urls (Should we auto expand shortened URLs? default: false) * @return string JSON response */ public function request($url) { if (is_null($this->token)) { try { $this->token = $this->getToken(); } catch (Exception $e) { return json_encode(array('success' => false, 'error' => $e->getMessage())); } } $browser = new \Buzz\Browser(new \Buzz\Client\Curl()); $headers = array(); $headers['Authorization'] = 'Bearer ' . $this->token; $headers['User-Agent'] = 'joshmoody\\Twitter\\Consumer: PHP ' . phpversion(); $response = $browser->get('https://api.twitter.com/1.1/' . $url, $headers); if (!$response->isOk()) { throw new \Exception($response->getReasonPhrase()); } else { return new \joshmoody\Twitter\Response($response->getContent()); } }
/** * @Route("/admin/plugins/getPackagesFromPackagist") */ public function searchOnPackagistAction(Request $request) { $response = new JsonResponse(); $query = $request->get('q', ''); $client = new \Buzz\Client\Curl(); $client->setTimeout(3600); $browser = new \Buzz\Browser($client); $packagistResponse = $browser->get('https://packagist.org/search.json?type=newscoop-plugin&q=' . $query); $packages = json_decode($packagistResponse->getContent(), true); $results = $packages['results']; $this->aasort($results, 'downloads'); // hide already installed plugins $cleanResults = array(); $pluginService = $this->container->get('newscoop.plugins.service'); foreach ($results as $resultKey => $package) { $installed = false; foreach ($pluginService->getAllAvailablePlugins() as $key => $plugin) { if ($package['name'] == $plugin->getName()) { $installed = true; $packages['total'] = $packages['total'] - 1; } } if (!$installed) { $cleanResults[] = $package; } } $packages['results'] = $cleanResults; return $response->setData($packages); }
<?php require_once 'vendor/autoload.php'; require_once 'jira_markdown.php'; $dotenv = new Dotenv\Dotenv(__DIR__); $dotenv->load(); $githubHeaders = ['User-Agent: Doctrine Jira Migration', 'Authorization: token ' . $_SERVER['GITHUB_TOKEN']]; $client = new \Buzz\Browser(); $response = $client->get('https://api.github.com/rate_limit', $githubHeaders); var_dump(json_decode($response->getContent(), true));
if (isset($argv[2])) { $files = [$argv[2] . ".json"]; } $count = 0; foreach ($files as $file) { if ($file === "." || $file === "..") { continue; } $issueKey = str_replace('.json', '', $file); $issue = json_decode(file_get_contents('data/' . $project . '/' . $file), true); printf("Preparing %s... ", $issueKey); if (isset($ticketStatus[$issueKey])) { if ($ticketStatus[$issueKey]['status'] === 'pending') { printf("pending, skipped\n"); continue; $response = $client->get($ticketStatus[$issueKey]['url'], $githubHeaders); if ($response->getStatusCode() == 200) { $ticketStatus[$issueKey] = json_decode($response->getContent(), true); file_put_contents("data/" . $project . ".status.json", json_encode($ticketStatus, JSON_PRETTY_PRINT)); printf("updated status... "); } } if ($ticketStatus[$issueKey]['status'] === 'pending') { printf("pending, skipped\n"); continue; } if ($ticketStatus[$issueKey]['status'] === 'imported') { printf("imported, skipped\n"); continue; } if ($ticketStatus[$issueKey]['status'] === 'failed') {
<?php include_once 'vendor/autoload.php'; use Symfony\Component\Stopwatch\Stopwatch; $stopwatch = new Stopwatch(); $stopwatch->start('eventName'); include_once 'vendor/autoload.php'; $url = 'http://api.openweathermap.org/data/2.5/weather?q=London&APPID=96cdeb166e66f9c035e9e7f8ce665ec8'; $browser = new Buzz\Browser(); $response = $browser->get($url); $content = $response->getContent(); $weatherObject = json_decode($content); // var_dump($weatherObject->main->temp); $a = $weatherObject->main->temp; $b = $a - 273; $c = round($b); echo 'Temperatura w ' . $weatherObject->name . ' wynosi: ' . "\n" . $c . '.' . ' st. Celcjusza' . "\n"; $event = $stopwatch->stop('eventName'); echo 'Wyswietlono w: ' . $event->getDuration() . 'ms' . "\n";
private function getDocument($uri) { // Create a CURL client $cURL = new \Buzz\Client\Curl(); $cURL->setVerifyPeer(false); $cURL->setTimeout(30); // Get discovery document $browser = new \Buzz\Browser($cURL); $response = $browser->get(\URL::to($uri)); // Document content return $response->getContent(); }
<?php require_once 'vendor/autoload.php'; require_once 'jira_markdown.php'; $dotenv = new Dotenv\Dotenv(__DIR__); $dotenv->load(); if (!isset($argv[1])) { printf("Missing argument: Project Key\n"); exit(1); } $project = $argv[1]; $projects = (require 'projects.php'); if (!isset($projects[$project])) { printf("Unknown project: {$project}\n"); exit(2); } $jiraHeaders = ['Authorization: Basic ' . base64_encode(sprintf('%s:%s', $_SERVER['JIRA_USER'], $_SERVER['JIRA_PASSWORD']))]; $client = new \Buzz\Browser(); $response = $client->get($_SERVER['JIRA_URL'] . "/rest/api/2/issue/" . $argv[2], $jiraHeaders); var_dump(json_decode($response->getContent(), true));
if (!isset($argv[1])) { printf("Missing argument: Project Key\n"); exit(1); } $project = $argv[1]; $projects = (require 'projects.php'); if (!isset($projects[$project])) { printf("Unknown project: {$project}\n"); exit(2); } $startAt = isset($argv[2]) ? (int) $argv[2] : 0; $githubRepository = $projects[$project]; $githubHeaders = ['User-Agent: Doctrine Jira Migration', 'Authorization: token ' . $_SERVER['GITHUB_TOKEN']]; $jiraHeaders = ['Authorization: Basic ' . base64_encode(sprintf('%s:%s', $_SERVER['JIRA_USER'], $_SERVER['JIRA_PASSWORD']))]; $client = new \Buzz\Browser(); $response = $client->get('https://api.github.com/repos/doctrine/' . $githubRepository . '/milestones?state=all&per_page=100', $githubHeaders); if ($response->getStatusCode() !== 200) { printf("Could not fetch existing Github Milestones\n"); var_dump($response->getContent()); exit(3); } $existingMilestones = []; foreach (json_decode($response->getContent(), true) as $existingMilestone) { $existingMilestones[$existingMilestone['title']] = $existingMilestone['number']; } $count = 0; @mkdir("data/" . $project, 0777); $knownIssueTypes = ['Bug', 'New Feature', 'Improvement']; $knownAssigneesMap = ['beberlei' => 'beberlei', 'guilhermeblanco' => 'guilhermeblanco', 'jwage' => 'jwage', 'asm89' => 'asm89', 'ocramius' => 'ocramius', 'deeky666' => 'deeky666', 'fabio.bat.silva' => 'FabioBatSilva', 'hobodave' => 'hobodave', 'jmikola' => 'jmikola', 'kimhemsoe' => 'kimhemsoe', 'lsmith' => 'lsmith77', 'wschalle' => 'zeroedin-bill', 'doctrinebot' => 'doctrinebot']; while (true) { $response = $client->get($_SERVER['JIRA_URL'] . "/rest/api/2/search?jql=" . urlencode("project = {$project} ORDER BY created ASC") . "&fields=" . urlencode("*all") . "&startAt=" . $startAt, $jiraHeaders);
require_once 'jira_markdown.php'; $dotenv = new Dotenv\Dotenv(__DIR__); $dotenv->load(); if (!isset($argv[1])) { printf("Missing argument: Project Key\n"); exit(1); } $project = $argv[1]; $projects = (require 'projects.php'); $client = new \Buzz\Browser(); if (!isset($projects[$project])) { printf("Unknown project: {$project}\n"); exit(2); } $githubRepository = $projects[$project]; $githubHeaders = ['User-Agent: Doctrine Jira Migration', 'Authorization: token ' . $_SERVER['GITHUB_TOKEN'], 'Accept: application/vnd.github.golden-comet-preview+json']; $jiraHeaders = ['Authorization: Basic ' . base64_encode(sprintf('%s:%s', $_SERVER['JIRA_USER'], $_SERVER['JIRA_PASSWORD']))]; $ticketStatus = []; if (file_exists('data/' . $project . '.status.json')) { $ticketStatus = json_decode(file_get_contents('data/' . $project . '.status.json'), true); } if (isset($ticketStatus[$argv[2]])) { $response = $client->get($ticketStatus[$argv[2]]['url'], $githubHeaders); if ($response->getStatusCode() >= 400) { var_dump($response->getContent()); exit(2); } $issue = json_decode(file_get_contents('data/' . $project . '/' . $argv[2] . '.json'), true); var_dump($issue); var_dump(json_decode($response->getcontent(), true)); }
/** * Execute the console command. * * @return mixed */ public function fire() { // How many alerts to request from mongo $count = Config::get('kuu.cron_batch_size'); // KUU Email Settings $email_from_address = Config::get('kuu.email_from_address'); $email_from_name = Config::get('kuu.email_from_name'); $email_bcc = Config::get('kuu.email_bcc'); // time in seconds, how often to notify $alert_interval_24hrs = Config::get('kuu.alert_interval_24hrs'); // 20 mins $alert_interval_over_24hrs = Config::get('kuu.alert_interval_over_24hrs'); // a day $http_error_descriptions = Config::get('kuu.http_error_descriptions'); $url = Config::get('kuu.apiurl') . '/rest/popalerts?api_key=' . Config::get('kuu.apikey') . '&count=' . $count; $browser = new Buzz\Browser(); $response = $browser->get($url); $response_array = json_decode($response->getContent()); //$checkAlertEmail = new CheckAlertEmail(); if (isset($response_array->Result) && $response_array->Result == 'OK') { $mail_counter = 0; foreach ($response_array->Records as $record_id => $record) { $record->time_formatted = date("m/d H:i:s T", $record->timestamp - $record->downtime); $record->title = 'Site is ' . Str::title($record->type); // $this->info('Record '.print_r($record, TRUE)); $alert_emails = CheckAlertEmail::getAlertEmailsByMongoId($record->check_id); // $alert_emails = CheckAlertEmail::getAlertEmailsByMongoId('5357d420685fabd7490000a4'); // $this->info('Alert Emails '.print_r($alert_emails, TRUE)); //DB::select('SELECT * FROM checks LEFT JOIN checks_alert_email USING (check_id) // LEFT JOIN users ON checks_alert_email.user_id=users.id WHERE mongo_id = ?', // array('5322c33f3cdffe9926000099')); // array($record->check_id)); foreach ($alert_emails as $id => $email) { // $this->info('Alert email '.print_r($alert_emails, TRUE)); $since_last_time = time() - strtotime($email->last_sent . " GMT"); $times_sent = $email->times_sent; // $this->info('since_last_time '.$since_last_time.' '.$times_sent.' '.$alert_interval_24hrs.' '.$alert_interval_over_24hrs); // $this->info('down since '.$record->downtime.' '. (24*60*60) .'seconds in a day ' . $email_from_address.' '.$email_from_name); $isDown = $record->type == 'down'; $trigger_send = false; // if total downtime less than a day, use $alert_interval_24hrs, otherwise use if ($record->downtime < 24 * 60 * 60 && $since_last_time >= $alert_interval_24hrs) { $trigger_send = true; } elseif ($record->downtime >= 24 * 60 * 60 && $since_last_time >= $alert_interval_over_24hrs) { $trigger_send = true; } if ($trigger_send || !$isDown) { //$this->info($email->alert_email.' '.$email->first_name.' '.$email->last_name); $record->alert_email = $email; $record->protocol = $email->type; $record->http_error_descriptions = $http_error_descriptions; $email->subject = $record->title . " - " . $email->url . " - " . $email->type; $email->from_address = $email_from_address; $email->from_name = $email_from_name; $email->bcc_admin = $email_bcc; Mail::send('emails.cronalert', (array) $record, function ($message) use($email) { $message->from($email->from_address, $email->from_name); // Remove To email name, you can set alerts to go to 3rd parties, name won't be valid // $message->to($email->alert_email, $email->first_name.' '.$email->last_name) $message->to($email->alert_email)->subject($email->subject); foreach ($email->bcc_admin as $e) { $message->bcc($e); } //$message->to('*****@*****.**', 'Andrei Tsygankov')->subject('Alerts'); }); $mail_counter++; //$this->info($email->alert_id.' '.$record->type.' '.$email->last_name); if ($isDown) { CheckAlertEmail::where('alert_id', $email->alert_id)->update(array('last_sent' => gmdate("Y-m-d H:i:s"), 'times_sent' => $times_sent + 1)); } else { CheckAlertEmail::where('alert_id', $email->alert_id)->update(array('last_sent' => '0000-00-00 00:00:00', 'times_sent' => 0)); } } } // just send to admin /* if(!count($alert_emails)) { Mail::send('emails.cronalert', (array)$record, function($message) { $message->from('*****@*****.**', 'KeepUsUp'); $message->to('*****@*****.**', 'Admin') ->subject('Alerts') //->cc('*****@*****.**') ; }); $mail_counter++; } */ } $this->info('Successfully sent ' . $mail_counter . ' emails'); } else { if (isset($response_array->Result)) { $this->info('Failed with result=' . $response_array->Result); } else { $this->info('Failed with to fetch REST API data'); } } }
printf("Missing argument: Project Key\n"); exit(1); } $project = $argv[1]; $projects = (require 'projects.php'); $client = new \Buzz\Browser(); if (!isset($projects[$project])) { printf("Unknown project: {$project}\n"); exit(2); } $githubRepository = $projects[$project]; $githubHeaders = ['User-Agent: Doctrine Jira Migration', 'Authorization: token ' . $_SERVER['GITHUB_TOKEN'], 'Accept: application/vnd.github.golden-comet-preview+json']; $page = 1; $numbers = []; while (true) { $response = $client->get('https://api.github.com/repos/doctrine/' . $githubRepository . '/issues?state=all&page=' . $page, $githubHeaders); if ($response->getStatusCode() != 200) { exit; } $issues = json_decode($response->getContent(), true); if (count($issues) === 0) { file_put_contents("data/" . $project . ".issues.json", json_encode($numbers, JSON_PRETTY_PRINT)); exit; } foreach ($issues as $issue) { if ($issue['user']['login'] != $_SERVER['GITHUB_USERNAME']) { continue; } list($key, $title) = explode(':', $issue['title'], 2); $numbers[$key] = $issue['number']; }
<?php require_once 'vendor/autoload.php'; $dotenv = new Dotenv\Dotenv(__DIR__); $dotenv->load(); $client = new \Buzz\Browser(); $githubHeaders = ['User-Agent: Doctrine Jira Migration', 'Authorization: token ' . $_SERVER['GITHUB_TOKEN']]; $githubRepository = "dbal"; $response = $client->get('https://api.github.com/repos/doctrine/' . $githubRepository . '/milestones?state=all&per_page=100', $githubHeaders); if ($response->getStatusCode() !== 200) { printf("Could not fetch existing Github Milestones\n"); var_dump($response->getContent()); exit(3); } foreach (json_decode($response->getContent(), true) as $existingMilestone) { if ($existingMilestone['title'] == '2.5') { continue; } $response = $client->delete('https://api.github.com/repos/doctrine/' . $githubRepository . '/milestones/' . $existingMilestone['number'], $githubHeaders); echo $response->getContent() . "\n"; }
$dotenv = new Dotenv\Dotenv(__DIR__); $dotenv->load(); if (!isset($argv[1])) { printf("Missing argument: Project Key\n"); exit(1); } $project = $argv[1]; $projects = (require 'projects.php'); if (!isset($projects[$project])) { printf("Unknown project: {$project}\n"); exit(2); } $githubRepository = $projects[$project]; $githubHeaders = ['User-Agent: Doctrine Jira Migration', 'Authorization: token ' . $_SERVER['GITHUB_TOKEN']]; $client = new \Buzz\Browser(); $response = $client->get($_SERVER['JIRA_URL'] . "/rest/api/2/project/{$project}/versions"); if ($response->getStatusCode() !== 200) { printf("Could not fetch versions of project '{$project}'\n"); printf($response->getStatusCode()); exit(2); } $versions = json_decode($response->getContent(), true); $skipVersions = ['Git Master']; $milestones = []; foreach ($versions as $version) { $version['name'] = preg_replace('(^v)', '', $version['name']); if (in_array($version['name'], $skipVersions)) { continue; } $milestone = ['title' => $version['name'], 'state' => $version['released'] ? 'closed' : 'open']; if (isset($version['releaseDate']) && $version['releaseDate']) {