class NotionRb::Api::Base

Constants

API_BASE_URL
BASE_URL
REDEFINE_EXCEPTION
S3_URL_PREFIX
S3_URL_PREFIX_ENCODED
SIGNED_URL_PREFIX

Public Class Methods

new(params) click to toggle source
# File lib/notion_rb/api/base.rb, line 13
def initialize(params)
  @notion_id = params[:notion_id]
  @token_v2 = NotionRb.config[:token_v2]
  @converter = NotionRb::Utils::Converter.new
end

Public Instance Methods

call() click to toggle source
# File lib/notion_rb/api/base.rb, line 19
def call
  response
end
success?() click to toggle source
# File lib/notion_rb/api/base.rb, line 23
def success?
  response.code == '200'
rescue Mechanize::ResponseCodeError
  false
end

Private Instance Methods

agent() click to toggle source
# File lib/notion_rb/api/base.rb, line 31
def agent
  return @agent if @agent

  @agent = Mechanize.new
  cookie = Mechanize::Cookie.new(domain: 'www.notion.so',
                                 name: 'token_v2',
                                 value: @token_v2,
                                 path: '/',
                                 expires: (Date.today + 1).to_s)
  @agent.tap { |agent| agent.cookie_jar << cookie }
end
params() click to toggle source
# File lib/notion_rb/api/base.rb, line 51
def params
  raise REDEFINE_EXCEPTION
end
response() click to toggle source
# File lib/notion_rb/api/base.rb, line 43
def response
  @response ||= agent.post("#{API_BASE_URL}#{url}", params.to_json, 'Content-Type' => 'application/json')
end
url() click to toggle source
# File lib/notion_rb/api/base.rb, line 47
def url
  raise REDEFINE_EXCEPTION
end