Example #1
0
function bitly_expand($short_url, $username, $key)
{
    $bitly_code = str_replace('http://bit.ly/', '', $short_url);
    $bitly_result = json_decode_file("http://api.bit.ly/expand?version=2.0.1&shortUrl={$short_url}&login={$username}&apiKey={$key}");
    if ($bitly_result->statusCode == 'OK') {
        return $bitly_result->results->{$bitly_code}->longUrl;
    } else {
        # If something went wrong, just hand it back
        return $short_url;
    }
}
Example #2
0
/**
 * @param $errors
 *
 * @return string|null
 */
function built_test_composer_json_get_version(&$errors)
{
    $file = 'composer.json';
    $data = json_decode_file($file, true);
    $version = isset($data['version']) ? $data['version'] : null;
    if (!strlen($version)) {
        echo "ERROR: Unable to obtain version from composer.json.\n";
        $errors++;
        return null;
    }
    echo "INFO: composer.json version is {$version}.\n";
    if (!preg_match('~^\\d.\\d.\\d$~', $version)) {
        echo "ERROR: Unable to validate version '{$version}'.\n";
        $errors++;
        return null;
    }
    return $version;
}
Example #3
0
<?php

# Oh well then thank you
require_once 'helpers.php';
# Just holds $credentials, an object with all my private bits.
require_once 'credentials.php';
# Get all our data situated
$filename = 'data.json';
$data = json_decode_file($filename);
$data_updated = false;
# Refresh status and city each hour
foreach (w('status city') as $type) {
    if (time() - $data->{$type}->updated_at > 60 * 60) {
        if ($refreshed_text = refresh_text($type)) {
            $data->{$type}->text = $refreshed_text;
        }
        $data->{$type}->updated_at = time();
        $data_updated = true;
    }
}
# Should be bother rewriting the JSON file?
if ($data_updated) {
    file_put_contents($filename, json_encode($data));
}
# Fetch fresh information
function refresh_text($type)
{
    global $credentials;
    # Get all our API functions
    require_once 'resources.php';
    switch ($type) {