Sha256: 5ad9d7984b4cb134bd4b1fc2add1d0cde477cb64d1e6ffda813ede285101c9c4

Contents?: true

Size: 1.1 KB

Versions: 1

Compression:

Stored size: 1.1 KB

Contents

module Notion
  class RequestClient
    include HTTParty

    base_uri "https://api.notion.com"
    headers "Content-Type": "application/json"

    def self.active_client
      RequestClient.new(Notion.config)
    end

    def initialize(config)
      self.class.headers Authorization: "Bearer #{config.api_token}"
    end

    def get(*args, &block)
      response = self.class.get(*args, &block)
      raise_on_failure(response)
    end

    def post(*args, &block)
      response = self.class.post(*args, &block)
      raise_on_failure(response)
    end

    def patch(*args, &block)
      response = self.class.patch(*args, &block)
      raise_on_failure(response)
    end

    def put(*args, &block)
      response = self.class.put(*args, &block)
      raise_on_failure(response)
    end

    def delete(*args, &block)
      response = self.class.delete(*args, &block)
      raise_on_failure(response)
    end

    def raise_on_failure(response)
      if response.success?
        response
      else
        raise ErrorFactory.create(response)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
notion-sdk-ruby-0.3.0 lib/notion-sdk-ruby/request_client.rb