module Notion::Faraday::Request

Public Instance Methods

delete(path, options = {}) click to toggle source
# File lib/notion/faraday/request.rb, line 21
def delete(path, options = {})
  request(:delete, path, options)
end
get(path, options = {}) click to toggle source
# File lib/notion/faraday/request.rb, line 5
def get(path, options = {})
  request(:get, path, options)
end
patch(path, options = {}) click to toggle source
# File lib/notion/faraday/request.rb, line 9
def patch(path, options = {})
  request(:patch, path, options)
end
post(path, options = {}) click to toggle source
# File lib/notion/faraday/request.rb, line 13
def post(path, options = {})
  request(:post, path, options)
end
put(path, options = {}) click to toggle source
# File lib/notion/faraday/request.rb, line 17
def put(path, options = {})
  request(:put, path, options)
end

Private Instance Methods

request(method, path, options) click to toggle source
# File lib/notion/faraday/request.rb, line 27
def request(method, path, options)
  response = connection.send(method) do |request|
    request.headers['Authorization'] = "Bearer #{token}"
    request.headers['Notion-Version'] = Notion::NOTION_REQUEST_VERSION
    case method
    when :get, :delete
      request.url(path, options)
    when :post, :put, :patch
      request.headers['Content-Type'] = 'application/json'
      request.path = path
      request.body = options.to_json unless options.empty?
    end
    request.options.merge!(options.delete(:request)) if options.key?(:request)
  end
  response.body
end