Class: Notionar::Client
- Inherits:
-
Object
- Object
- Notionar::Client
- Defined in:
- lib/notionar/client.rb
Instance Method Summary collapse
- #database(database_id) ⇒ Object
-
#initialize(token) ⇒ Client
constructor
A new instance of Client.
- #page(page_id) ⇒ Object
- #query_database(database_id, property_name, query) ⇒ Object
- #search(query) ⇒ Object
- #user(user_id) ⇒ Object
- #users ⇒ Object
Constructor Details
#initialize(token) ⇒ Client
Returns a new instance of Client.
3 4 5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/notionar/client.rb', line 3 def initialize(token) endpoint = "https://api.notion.com/" @version = "v1" url = URI.parse(endpoint) @http = Net::HTTP.new(url.host, url.port) @http.use_ssl = true @headers = { "Authorization" => "Bearer #{token}", "Content-Type" => "application/json", "Notion-Version" => "2021-05-13", } end |
Instance Method Details
#database(database_id) ⇒ Object
41 42 43 44 |
# File 'lib/notionar/client.rb', line 41 def database(database_id) @path = "/#{@version}/databases/#{database_id}" request(:get) end |
#page(page_id) ⇒ Object
27 28 29 30 |
# File 'lib/notionar/client.rb', line 27 def page(page_id) @path = "/#{@version}/pages/#{page_id}" request(:get) end |
#query_database(database_id, property_name, query) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/notionar/client.rb', line 46 def query_database(database_id, property_name, query) @path = "/#{@version}/databases/#{database_id}/query" @params = { filter: { property: property_name, select: { equals: query } } } request(:post) end |
#search(query) ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'lib/notionar/client.rb', line 32 def search(query) @path = "/#{@version}/search" @params = { query: query, } request(:post) end |
#user(user_id) ⇒ Object
22 23 24 25 |
# File 'lib/notionar/client.rb', line 22 def user(user_id) @path = "/#{@version}/users/#{user_id}" request(:get) end |
#users ⇒ Object
17 18 19 20 |
# File 'lib/notionar/client.rb', line 17 def users @path = "/#{@version}/users" request(:get) end |