Sha256: 8b5fc211079a1328de5b7fcf1588c38995e85df6c0f133cd6987dfbfc58ea198

Contents?: true

Size: 1.1 KB

Versions: 3

Compression:

Stored size: 1.1 KB

Contents

# frozen_string_literal: true
module Notion
  module Faraday
    module Request
      def get(path, options = {})
        request(:get, path, options)
      end

      def patch(path, options = {})
        request(:patch, path, options)
      end

      def post(path, options = {})
        request(:post, path, options)
      end

      def put(path, options = {})
        request(:put, path, options)
      end

      def delete(path, options = {})
        request(:delete, path, options)
      end

      private

      def request(method, path, options)
        response = connection.send(method) do |request|
          request.headers['Authorization'] = "Bearer #{token}"
          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
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
notion-ruby-client-0.0.5 lib/notion/faraday/request.rb
notion-ruby-client-0.0.4 lib/notion/faraday/request.rb
notion-ruby-client-0.0.3 lib/notion/faraday/request.rb