Skip to content

dunyakirkali/notion.ex

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Notion

Code Quality Continuous Integration Coverage Status Hex.pm version Hex.pm downloads

A Notion client in Elixir.

Documentation

Installation

If available in Hex, the package can be installed by adding notion to your list of dependencies in mix.exs:

def deps do
  [
    {:notion, "~> 0.1.0"}
  ]
end

Documentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/notion.

Configuration

You will need to set the following configuration variables in your config/config.exs file:

use Mix.Config

config :notion, api_key: {:system, "NOTION_API_KEY"}

Usage

Example

sort = %Sort{
  property: "Session",
  direction: Sort.Direction.Ascending.value()
}

filter = %Filter{
  and: [
    %PropertyFilter{
      property: "Owner",
      people: %PeopleFilter{
        contains: "9441a930-2a79-40c9-9c00-bd5ad030fd2f"
      }
    },
    %PropertyFilter{
      property: "Status",
      select: %SelectFilter{
        equals: "ToDo"
      }
    }
  ]
}
 
query = %Query{
  filter: filter,
  sorts: [sort]
}

with {:ok, json_string} <- Jason.encode(query),
     {:ok, payload} <- Jason.decode(json_string),
     {:ok, %Tesla.Env{} = env} <- Notion.query_database(db_id, payload) do
  results = env.body.results 

  db = struct(Database, Enum.at(results, 0))
  
  IO.inspect(db.properties[:Task][:title])
end

TODO

  • Implement all date fields

About

An Elixir client for the Notion API

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages