class Telegraph::Page

Public Class Methods

create(title:, author_name:, author_url:, content:, return_content: false) click to toggle source
# File lib/telegraph_rb/page.rb, line 17
def create(title:, author_name:, author_url:, content:, return_content: false)
  params = {
    title: title,
    author_name: author_name,
    author_url: author_url,
    content: content,
    return_content: return_content,
    access_token: client.token
  }
  response = client.post('createPage', params)
  new(response)
end
edit(path:, title:, content:, author_name: nil, author_url: nil) click to toggle source
# File lib/telegraph_rb/page.rb, line 53
def edit(path:, title:, content:, author_name: nil, author_url: nil)
  params = {
    path: path,
    title: title,
    content: content,
    author_name: author_name,
    author_url: author_url,
    access_token: client.token
  }
  response = client.post('editPage', params)
  new(response)
end
get(path:, return_content: false) click to toggle source
# File lib/telegraph_rb/page.rb, line 30
def get(path:, return_content: false)
  params = {
    path: path,
    return_content: return_content,
    access_token: client.token
  }
  response = client.get('getPage', params)
  new(response)
end
get_views(path:, year: nil, month: nil, day: nil, hour: nil) click to toggle source
# File lib/telegraph_rb/page.rb, line 40
def get_views(path:, year: nil, month: nil, day: nil, hour: nil)
  params = { path: path }
  time_params = {
    year: year,
    month: month,
    day: day,
    hour: hour
  }
  params.merge(time_params) if time_params.values.compact.any?
  response = client.get('getViews', params)
  response[:views]
end

Private Class Methods

client() click to toggle source
# File lib/telegraph_rb/page.rb, line 68
def client
  @client ||= Telegraph.client
end