Skip to content

gettingud/telegraph_rb

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

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

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages