Ejemplo n.º 1
0
<?php

// Joaquin-V/Chatter - Telegram API for PHP 7.
// License: GNU General Public License <http://www.gnu.org/licenses/>
// Copyright (C) 2016 Joaquín Varela
// This file includes all files and defines some constants.
namespace Chatter;

// Basic project information.
const NAME = 'Chatter';
// Project name.
const SOURCE = 'https://github.com/Joaquin-V/Chatter';
// Project's GitHub page.
const GITHUB = SOURCE;
// Just to make sure nothing breaks.
const AUTHOR = 'Joaquín Varela';
// me irl
const WEBSITE = 'N/A';
// Project site.
const LICENSE = 'GPL v3';
// License.
const COPYRIGHT = "Copyright (C) " . AUTHOR . " 2016";
// Include all the files
define('Chatter\\INSTALL_DIR', __DIR__);
// Include all helpers.
include_once INSTALL_DIR . "/Helpers/stdio.php";
// First include the file that contains the recursive includer.
Helpers\stdio::includeDirectory(INSTALL_DIR . "/Helpers");
require_once INSTALL_DIR . '/Telegram.php';
require_once INSTALL_DIR . '/Parser.php';
Ejemplo n.º 2
0
<?php

// Joaquin-V/Chatter - Telegram API for PHP 7.
// License: GNU General Public License <http://www.gnu.org/licenses/>
// Copyright (C) 2016 Joaquín Varela
namespace Chatter;

// Include the results directory which contains all Telegram result classes.
// Make sure the base class, TelegramResult, is loaded first.
// Include all dirs.
Helpers\stdio::includeDirectory(INSTALL_DIR . '/result');
class Parser
{
    // TelegramParser::parseRaw - Parse the API's output directly.
    // @param $result - Raw output of the server.
    // @param $method - Method used to get this result.
    public static function parseRaw(string $result, string $method)
    {
        $json = json_decode($result, true);
        // If the ok value is false, construct a TelegramError.
        if (!$json['ok']) {
            return new result\Error($json);
        }
        // One by one, start seeing what the output could be.
        switch (strtolower($method)) {
            // getMe
            case 'getme':
                return new result\User($json['result']);
                break;
                // getUpdate
            // getUpdate