Coder Social home page Coder Social logo

telegraph_rb's Introduction

telegraph_rb

Telegra.ph API Ruby client with built-in HTML converter.

require 'telegraph_rb'

Usage

Setup existing Telegra.ph account like this:

client = Telegraph.setup(secret_token)

Or create a new one:

account = Telegraph.create_account(short_name: 'Writer O.G')

After setup you can use following methods:

Page

.create

https://telegra.ph/api#createPage

page_content = [{:tag=>"h1", :children=>["Article Heading"]}
Page.create(
  title: 'My article'
  author_name: 'Writer'
  author_url: 'http://writer.com'
  content: page_content
)
# => Telegraph::Page(title: 'My article', author_name: 'Writer', author_url: 'http://writer.com')

To easily prepare content for a page you can use Telegraph::HTMLConverter module:

class HtmlToContent
 extend Telegraph::HTMLConverter

  def self.perform(html)
    html_to_content(html)
  end
end

html = "<p>Lorem ipsum dolor sit <b>amet</b>"
content = HtmlToContent.perform(html)
Page.create(title: 'My Article', content: content)

.get

https://telegra.ph/api#getPage

page = Page.get(path: 'my-article-12-15')
page.title
#=> My Article

.get_views

https://telegra.ph/api#getViews

Page.get_views(path: 'my-article-12-15', year: 2019)
#=> 33

.edit

https://telegra.ph/api#editPage

page = Page.edit(path: 'my-article-12-15', title: 'New Article Title', content: content)
page.title
#=> 'New Article Title'

Account

.create

Creates account without setupping the client https://telegra.ph/api#createAccount

account = Account.create(short_name: 'Writer O.G')
account.client
#=> nil

.get

https://telegra.ph/api#getAccountInfo

account = Account.get
account.short_name = 'Short Name'

.edit

https://telegra.ph/api#editAccountInfo

Account.edit(short_name: 'New Short Name')

PageList

.get

https://telegra.ph/api#getPageList

page_list = PageList.get
page_list.pages
#=> [Telegraph::Page, Telegraph::Page]
page_list.total_count
#=> 2

telegraph_rb's People

Contributors

gettingud avatar

Watchers

 avatar  avatar

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.