Class: NotionRuby::Connection

Inherits:
Faraday::Connection
  • Object
show all
Defined in:
lib/notion_ruby/connection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash = {}) ⇒ Connection

Returns a new instance of Connection.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/notion_ruby/connection.rb', line 17

def initialize(hash = {})
  @hash = hash

  super(hash[:api_url] || "https://api.notion.com") do |builder|
    yield builder if block_given?
    builder.use Faraday::Response::RaiseNotionRubyError
    builder.use FaradayMiddleware::EncodeJson
    builder.use FaradayMiddleware::ParseJson, content_type: /\bjson$/
    builder.adapter Faraday.default_adapter
  end

  headers["Authorization"] = "Bearer #{hash[:access_token]}" if hash.key?(:access_token)
  headers["Notion-Version"] = NOTION_VERSION
end

Instance Attribute Details

#hashObject (readonly)

Returns the value of attribute hash.



9
10
11
# File 'lib/notion_ruby/connection.rb', line 9

def hash
  @hash
end

Instance Method Details

#parallel_connection(adapter = :typhoeus) ⇒ Object



11
12
13
14
15
# File 'lib/notion_ruby/connection.rb', line 11

def parallel_connection(adapter = :typhoeus)
  conn = self.class.new @hash
  conn.adapter adapter
  conn
end