Giter Club home page Giter Club logo

telegraph's Introduction

Telegraph API Client for PHP >=8.0

Telegraph is an anonymous blogging platform, a free publishing tool created by Telegram.

Installation

Install latest 3.x version via Composer.

composer require chipslays/telegraph

Usage

Easy Peasy Mode

$client = new Telegraph\Client;

$account = $client->createAccount('johndoe', 'John Doe', 'https://example.com');

$page = $account->createPage('Hello World', 'This is a Hello World example.');

echo $page->getUrl(); // https://telegra.ph/Hello-World-10-21-12

Hard Mode

use Telegraph\Client;
use Telegraph\Element;
use Telegraph\File;
use Telegraph\Types\Account;
use Telegraph\Types\NodeElement;

$client = new Client;

$account = $client->createAccount('johndoe', 'John Doe', 'https://example.com');

$page = $account->createPage(
    'Rich Example',
    [
        Element::text("Line 1\nLine 2\nLine 3\n\n"),
        Element::line(),
        Element::bigHeading("H3 text"),
        Element::smallHeading("H4 text"),
        Element::line(),
        Element::strongText("Strong text\n"),
        Element::italicText("Itaic text\n"),
        Element::underlineText("Underline text\n"),
        Element::strikeText("Strike text\n"),
        Element::emphasizedText("Em text\n"),
        Element::code("Code text\n"),
        Element::link("This is link\n", 'https://github.com/chipslays/telegraph'),
        Element::space(), // add a new line otherwise the previous tags will be in heading
        new NodeElement('h3', [new NodeElement('a', 'This is link in title, wow!', ['href' => '#'])]),
        Element::space(), // add a new line otherwise the previous tags will be in blockquote
        Element::blockquote("Blockquote text\n"),
        Element::line(),
        Element::pre("echo 'Hello Pre Text!';"),
        Element::line(),
        Element::smallHeading("Items List"),
        Element::list(['Item 1', 'Item 2', 'Item 3']),
        Element::smallHeading("Numeric List"),
        Element::list(['Item 1', 'Item 2', 'Item 3'], true),
        Element::line(),
        Element::image('https://images.unsplash.com/photo-1541963463532-d68292c34b19?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxleHBsb3JlLWZlZWR8Mnx8fGVufDB8fHx8&w=1000&q=80', 'Image Caption'),
        // Element::image(File::upload('/path/to/local/image.jpg')),
        Element::line(),
        Element::smallHeading("Embed Blocks"),
        Element::youtube('https://www.youtube.com/watch?v=dQw4w9WgXcQ', 'Youtube Caption'),
        Element::vimeo('https://vimeo.com/340057344', 'Vimeo Caption'),
        Element::twitter('https://twitter.com/elonmusk/status/1354174279894642703', 'GAMESTONK!!1!1'),
        // Element::embed('vendorName', 'https://example.com', 'Universal method for embed.'),
    ],
);

echo $page->getUrl(); // https://telegra.ph/Rich-Example-10-21

Upload files to Telegraph server.

use Telegraph\File;

// Returns string
$imageUrl = File::upload('/path/to/local/image.jpg');

// Can pass url
$imageUrl = File::upload('https://example.com/image.jpg');

// Returns array with preserved keys
// ['my_nudes' => 'https://telegra.ph/*, ....]
$imageUrl = File::upload([
    'my_nudes' => '/path/to/local/image.jpg',
    'home_video_with_my_gf' => '/path/to/local/video.mp4',
]);

Examples

You can found examples here.

Here are really almost all popular use cases Telegraph API.

Documentation

Not found.

So, code well documencated, Client class supports all methods of Telegraph API, just start typing e.g. $client->createAccount(...) and your IDE helps you.

Use the Element helper class to create rich content or use raw NodeElement for more flexible stuff.

Element class uses NodeElement under the hood.

See how it work here.

Good luck stanger.

License

The MIT License (MIT). Please see License File for more information.

telegraph's People

Contributors

chipslays avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

lahirunirmalx

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.