notion-sdk-ruby 0.1.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5d3e4424acc768faab4126af9bdbb3d90df17c9ed67253f9eb5cba03cb31fe55
4
- data.tar.gz: 9ca3dda6a415c27e979c3cad27b792fa6891f1700a63f6f94190a6975d209b80
3
+ metadata.gz: 4491885de234786385349badac10c8224bd15c576f63ddc6073bf6593566727b
4
+ data.tar.gz: 8b4bd58bf052bf6a5612990a0521442b82ff9e8e400afbb92a10b9dd1c3afcca
5
5
  SHA512:
6
- metadata.gz: a285b1f694a878c799de3a44373e22ae7ff25fab89d66879cf1bf3732778ad3819aa65ee54d606d694350311e7ea4d89a0bfb92ac4303050e4ce8bd866c9a1a8
7
- data.tar.gz: 88c571a79fc993e34ee4a0fccc71786723d7862acaf1a9f391844d97390c052cb50186f767f86f03734841cf0de66a99be0c689a4e333c168f4a64ef111bb2a4
6
+ metadata.gz: b139926f4ee0a376d5507d7025a72c89c528461012dfe8ab03c245080c487fece19ce45754bb907bfd0d53f9503a0b48ff8a02052eaa8917862de01347be8549
7
+ data.tar.gz: e06fed554747d0bbaf0f7d81224474e642ff540151d136ca59fb2916fa33ba492279ddb166cd25c441aedf2cf0c542802f1737a34538a3d2f5cbc2f732c2e442
@@ -0,0 +1,35 @@
1
+ # This workflow uses actions that are not certified by GitHub.
2
+ # They are provided by a third-party and are governed by
3
+ # separate terms of service, privacy policy, and support
4
+ # documentation.
5
+ # This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
6
+ # For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
7
+
8
+ name: Ruby
9
+
10
+ on:
11
+ push:
12
+ branches: [ main ]
13
+ pull_request:
14
+ branches: [ main ]
15
+
16
+ jobs:
17
+ test:
18
+
19
+ runs-on: ubuntu-latest
20
+ strategy:
21
+ matrix:
22
+ ruby-version: ['2.6', '2.7', '3.0']
23
+
24
+ steps:
25
+ - uses: actions/checkout@v2
26
+ - name: Set up Ruby
27
+ # To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
28
+ # change this to (see https://github.com/ruby/setup-ruby#versioning):
29
+ # uses: ruby/setup-ruby@v1
30
+ uses: ruby/setup-ruby@473e4d8fe5dd94ee328fdfca9f8c9c7afc9dae5e
31
+ with:
32
+ ruby-version: ${{ matrix.ruby-version }}
33
+ bundler-cache: true # runs 'bundle install' and caches installed gems automatically
34
+ - name: Run tests
35
+ run: bundle exec rake
data/.gitignore CHANGED
@@ -9,3 +9,5 @@
9
9
 
10
10
  # rspec failure tracking
11
11
  .rspec_status
12
+
13
+ .env
@@ -0,0 +1,4 @@
1
+ {
2
+ "editor.formatOnSave": true,
3
+ "editor.tabSize": 2
4
+ }
data/Gemfile CHANGED
@@ -1,7 +1,15 @@
1
- source "https://rubygems.org"
2
-
3
- # Specify your gem's dependencies in notion-sdk-ruby.gemspec
4
- gemspec
5
-
6
- gem "rake", "~> 12.0"
7
- gem "rspec", "~> 3.0"
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in notion-sdk-ruby.gemspec
4
+ gemspec
5
+
6
+ gem "httparty", "~> 0.18.1"
7
+
8
+ group :development, :test do
9
+ gem "rake", "~> 12.0"
10
+ gem "rspec", "~> 3.0"
11
+ gem "standardrb", "~> 1.0"
12
+ gem "webmock", "~> 3.12"
13
+ gem "pry", "~> 0.14.1"
14
+ gem "dotenv", "~> 2.7"
15
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,91 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ notion-sdk-ruby (0.2.1)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ addressable (2.7.0)
10
+ public_suffix (>= 2.0.2, < 5.0)
11
+ ast (2.4.2)
12
+ coderay (1.1.3)
13
+ crack (0.4.5)
14
+ rexml
15
+ diff-lcs (1.4.4)
16
+ dotenv (2.7.6)
17
+ hashdiff (1.0.1)
18
+ httparty (0.18.1)
19
+ mime-types (~> 3.0)
20
+ multi_xml (>= 0.5.2)
21
+ method_source (1.0.0)
22
+ mime-types (3.3.1)
23
+ mime-types-data (~> 3.2015)
24
+ mime-types-data (3.2021.0225)
25
+ multi_xml (0.6.0)
26
+ parallel (1.20.1)
27
+ parser (3.0.1.1)
28
+ ast (~> 2.4.1)
29
+ pry (0.14.1)
30
+ coderay (~> 1.1)
31
+ method_source (~> 1.0)
32
+ public_suffix (4.0.6)
33
+ rainbow (3.0.0)
34
+ rake (12.3.3)
35
+ regexp_parser (2.1.1)
36
+ rexml (3.2.5)
37
+ rspec (3.10.0)
38
+ rspec-core (~> 3.10.0)
39
+ rspec-expectations (~> 3.10.0)
40
+ rspec-mocks (~> 3.10.0)
41
+ rspec-core (3.10.0)
42
+ rspec-support (~> 3.10.0)
43
+ rspec-expectations (3.10.0)
44
+ diff-lcs (>= 1.2.0, < 2.0)
45
+ rspec-support (~> 3.10.0)
46
+ rspec-mocks (3.10.0)
47
+ diff-lcs (>= 1.2.0, < 2.0)
48
+ rspec-support (~> 3.10.0)
49
+ rspec-support (3.10.0)
50
+ rubocop (1.14.0)
51
+ parallel (~> 1.10)
52
+ parser (>= 3.0.0.0)
53
+ rainbow (>= 2.2.2, < 4.0)
54
+ regexp_parser (>= 1.8, < 3.0)
55
+ rexml
56
+ rubocop-ast (>= 1.5.0, < 2.0)
57
+ ruby-progressbar (~> 1.7)
58
+ unicode-display_width (>= 1.4.0, < 3.0)
59
+ rubocop-ast (1.5.0)
60
+ parser (>= 3.0.1.1)
61
+ rubocop-performance (1.11.2)
62
+ rubocop (>= 1.7.0, < 2.0)
63
+ rubocop-ast (>= 0.4.0)
64
+ ruby-progressbar (1.11.0)
65
+ standard (1.1.1)
66
+ rubocop (= 1.14.0)
67
+ rubocop-performance (= 1.11.2)
68
+ standardrb (1.0.0)
69
+ standard
70
+ unicode-display_width (2.0.0)
71
+ webmock (3.12.2)
72
+ addressable (>= 2.3.6)
73
+ crack (>= 0.3.2)
74
+ hashdiff (>= 0.4.0, < 2.0.0)
75
+
76
+ PLATFORMS
77
+ ruby
78
+ x64-mingw32
79
+
80
+ DEPENDENCIES
81
+ dotenv (~> 2.7)
82
+ httparty (~> 0.18.1)
83
+ notion-sdk-ruby!
84
+ pry (~> 0.14.1)
85
+ rake (~> 12.0)
86
+ rspec (~> 3.0)
87
+ standardrb (~> 1.0)
88
+ webmock (~> 3.12)
89
+
90
+ BUNDLED WITH
91
+ 2.1.4
data/README.md CHANGED
@@ -1,8 +1,4 @@
1
- # Notion::Sdk::Ruby
2
-
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/notion/sdk/ruby`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
1
+ # Notion Ruby SDK
6
2
 
7
3
  ## Installation
8
4
 
@@ -22,7 +18,175 @@ Or install it yourself as:
22
18
 
23
19
  ## Usage
24
20
 
25
- TODO: Write usage instructions here
21
+ ```rb
22
+ cilent = Notion::Client.new(token: ENV["NOTION_API_SECRET"])
23
+ ```
24
+
25
+ ### Databases
26
+
27
+ #### #get_database
28
+
29
+ ```rb
30
+ client.get_database("668d797c-76fa-4934-9b05-ad288df2d136")
31
+ ```
32
+
33
+ #### #get_databases
34
+
35
+ ```rb
36
+ client.get_databases
37
+ ```
38
+
39
+ #### #query_database
40
+
41
+ ```rb
42
+ client.query_database("668d797c-76fa-4934-9b05-ad288df2d136", {
43
+ "filter": {
44
+ "or": [
45
+ {
46
+ "property": "In stock",
47
+ "checkbox": {
48
+ "equals": true
49
+ }
50
+ },
51
+ {
52
+ "property": "Cost of next trip",
53
+ "number": {
54
+ "greater_than_or_equal_to": 2
55
+ }
56
+ }
57
+ ]
58
+ },
59
+ "sorts": [
60
+ {
61
+ "property": "Last ordered",
62
+ "direction": "ascending"
63
+ }
64
+ ]
65
+ })
66
+ ```
67
+
68
+ ### Pages
69
+
70
+ #### #get_page
71
+
72
+ ```rb
73
+ client.get_page("b55c9c91-384d-452b-81db-d1ef79372b75")
74
+ ```
75
+
76
+ #### #create_page
77
+
78
+ ```rb
79
+ client.create_page({
80
+ "parent": { "database_id": "48f8fee9cd794180bc2fec0398253067" },
81
+ "properties": {
82
+ "Name": {
83
+ "title": [
84
+ {
85
+ "text": {
86
+ "content": "Tuscan Kale"
87
+ }
88
+ }
89
+ ]
90
+ },
91
+ "Description": {
92
+ "rich_text": [
93
+ {
94
+ "text": {
95
+ "content": "A dark green leafy vegetable"
96
+ }
97
+ }
98
+ ]
99
+ },
100
+ "Food group": {
101
+ "select": {
102
+ "name": "Vegetable"
103
+ }
104
+ },
105
+ "Price": { "number": 2.5 }
106
+ },
107
+ "children": []
108
+ })
109
+ ```
110
+
111
+ #### #update_page
112
+
113
+ ```rb
114
+ client.update_page("b55c9c91-384d-452b-81db-d1ef79372b75", {
115
+ "properties": {
116
+ "In stock": { "checkbox": true }
117
+ }
118
+ })
119
+ ```
120
+
121
+ ### Blocks
122
+
123
+ #### #get_block_children
124
+
125
+ ```rb
126
+ client.get_block_children("b55c9c91-384d-452b-81db-d1ef79372b75", {
127
+ page_size: 100
128
+ })
129
+ ```
130
+
131
+ #### #append_block_children
132
+
133
+ ```rb
134
+ client.append_block_children("b54c9c91-384d-452b-81db-d1ef79372b75", {
135
+ "children": [
136
+ {
137
+ "object": "block",
138
+ "type": "heading_1",
139
+ "heading_1": {
140
+ "text": [{ "type": "text", "text": { "content": "Lacinato kale" } }]
141
+ }
142
+ },
143
+ {
144
+ "object": "block",
145
+ "type": "paragraph",
146
+ "paragraph": {
147
+ "text": [
148
+ {
149
+ "type": "text",
150
+ "text": {
151
+ "content": "Lacinato kale is a variety of kale with a long tradition in Italian cuisine, especially that of Tuscany. It is also known as Tuscan kale, Italian kale, dinosaur kale, kale, flat back kale, palm tree kale, or black Tuscan palm.",
152
+ "link": { "url": "https://en.wikipedia.org/wiki/Lacinato_kale" }
153
+ }
154
+ }
155
+ ]
156
+ }
157
+ }
158
+ ]
159
+ })
160
+ ```
161
+
162
+ ### Users
163
+
164
+ #### #get_user
165
+
166
+ ```rb
167
+ client.get_user("d40e767c-d7af-4b18-a86d-55c61f1e39a4")
168
+ ```
169
+
170
+ #### #get_users
171
+
172
+ ```rb
173
+ client.get_users
174
+ ```
175
+
176
+ ### Search
177
+
178
+ #### #search
179
+
180
+ ```rb
181
+ client.search({
182
+ "query":"External tasks",
183
+ "sort":{
184
+ "direction":"ascending",
185
+ "timestamp":"last_edited_time"
186
+ }
187
+ }
188
+ )
189
+ ```
26
190
 
27
191
  ## Development
28
192
 
@@ -32,8 +196,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
32
196
 
33
197
  ## Contributing
34
198
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/notion-sdk-ruby.
36
-
199
+ Bug reports and pull requests are welcome on GitHub at https://github.com/mgmarlow/notion-sdk-ruby.
37
200
 
38
201
  ## License
39
202
 
data/Rakefile CHANGED
@@ -1,6 +1,7 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
3
-
4
- RSpec::Core::RakeTask.new(:spec)
5
-
6
- task :default => :spec
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+ require "standard/rake"
4
+
5
+ RSpec::Core::RakeTask.new(:spec)
6
+
7
+ task default: [:spec, :standard]
data/bin/console CHANGED
@@ -1,14 +1,11 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require "bundler/setup"
4
- require "notion/sdk/ruby"
4
+ require "pry"
5
+ require 'dotenv/load'
5
6
 
6
- # You can add fixtures and/or initialization code here to make experimenting
7
- # with your gem easier. You can also use a different console, if you like.
7
+ require "notion"
8
8
 
9
- # (If you use this, don't forget to add pry to your Gemfile!)
10
- # require "pry"
11
- # Pry.start
9
+ $client = Notion::Client.new(token: ENV["API_SECRET"])
12
10
 
13
- require "irb"
14
- IRB.start(__FILE__)
11
+ Pry.start
data/lib/notion.rb ADDED
@@ -0,0 +1,13 @@
1
+ require "httparty"
2
+ require "notion/version"
3
+ require "notion/endpoints/blocks"
4
+ require "notion/endpoints/databases"
5
+ require "notion/endpoints/pages"
6
+ require "notion/endpoints/search"
7
+ require "notion/endpoints/users"
8
+ require "notion/endpoints"
9
+ require "notion/client"
10
+
11
+ module Notion
12
+ class Error < StandardError; end
13
+ end
@@ -0,0 +1,11 @@
1
+ module Notion
2
+ class Client
3
+ include Endpoints
4
+ include HTTParty
5
+ base_uri "https://api.notion.com"
6
+
7
+ def initialize(token:)
8
+ self.class.headers({Authorization: "Bearer #{token}"})
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,9 @@
1
+ module Notion
2
+ module Endpoints
3
+ include Databases
4
+ include Pages
5
+ include Blocks
6
+ include Users
7
+ include Search
8
+ end
9
+ end
@@ -0,0 +1,13 @@
1
+ module Notion
2
+ module Endpoints
3
+ module Blocks
4
+ def get_block_children(id, params: {})
5
+ self.class.get("/v1/blocks/#{id}/children", query: params)
6
+ end
7
+
8
+ def append_block_children(id, body)
9
+ self.class.patch("/v1/blocks/#{id}/children", body: body)
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,17 @@
1
+ module Notion
2
+ module Endpoints
3
+ module Databases
4
+ def get_database(id)
5
+ self.class.get("/v1/databases/#{id}")
6
+ end
7
+
8
+ def get_databases
9
+ self.class.get("/v1/databases")
10
+ end
11
+
12
+ def query_database(id, body)
13
+ self.class.post("/v1/databases/#{id}/query", body: body)
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ module Notion
2
+ module Endpoints
3
+ module Pages
4
+ def get_page(id)
5
+ self.class.get("/v1/pages/#{id}")
6
+ end
7
+
8
+ def create_page(body)
9
+ self.class.post("/v1/pages", body: body)
10
+ end
11
+
12
+ def update_page(id, body)
13
+ self.class.patch("/v1/pages/#{id}", body: body)
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,9 @@
1
+ module Notion
2
+ module Endpoints
3
+ module Search
4
+ def search(body)
5
+ self.class.post("/v1/search", body: body)
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,13 @@
1
+ module Notion
2
+ module Endpoints
3
+ module Users
4
+ def get_users
5
+ self.class.get("/v1/users")
6
+ end
7
+
8
+ def get_user(id)
9
+ self.class.get("/v1/users/#{id}")
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,3 @@
1
+ module Notion
2
+ VERSION = "0.2.1"
3
+ end
@@ -1,26 +1,26 @@
1
- require_relative 'lib/notion/sdk/ruby/version'
2
-
3
- Gem::Specification.new do |spec|
4
- spec.name = "notion-sdk-ruby"
5
- spec.version = Notion::Sdk::Ruby::VERSION
6
- spec.authors = ["Graham Marlow"]
7
- spec.email = ["mgmarlow@hey.com"]
8
-
9
- spec.summary = %q{Notion SDK}
10
- spec.homepage = "https://github.com/mgmarlow/notion-sdk-ruby"
11
- spec.license = "MIT"
12
- spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
13
-
14
- spec.metadata["homepage_uri"] = spec.homepage
15
- spec.metadata["source_code_uri"] = "https://github.com/mgmarlow/notion-sdk-ruby"
16
- spec.metadata["changelog_uri"] = "https://github.com/mgmarlow/notion-sdk-ruby/blob/master/CHANGELOG.md"
17
-
18
- # Specify which files should be added to the gem when it is released.
19
- # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
20
- spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
21
- `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
22
- end
23
- spec.bindir = "exe"
24
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
25
- spec.require_paths = ["lib"]
26
- end
1
+ require_relative "lib/notion/version"
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "notion-sdk-ruby"
5
+ spec.version = Notion::VERSION
6
+ spec.authors = ["Graham Marlow"]
7
+ spec.email = ["mgmarlow@hey.com"]
8
+
9
+ spec.summary = "Notion SDK"
10
+ spec.homepage = "https://github.com/mgmarlow/notion-sdk-ruby"
11
+ spec.license = "MIT"
12
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
13
+
14
+ spec.metadata["homepage_uri"] = spec.homepage
15
+ spec.metadata["source_code_uri"] = "https://github.com/mgmarlow/notion-sdk-ruby"
16
+ spec.metadata["changelog_uri"] = "https://github.com/mgmarlow/notion-sdk-ruby/blob/master/CHANGELOG.md"
17
+
18
+ # Specify which files should be added to the gem when it is released.
19
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
20
+ spec.files = Dir.chdir(File.expand_path("..", __FILE__)) do
21
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
22
+ end
23
+ spec.bindir = "exe"
24
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
25
+ spec.require_paths = ["lib"]
26
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: notion-sdk-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Graham Marlow
@@ -17,17 +17,27 @@ executables: []
17
17
  extensions: []
18
18
  extra_rdoc_files: []
19
19
  files:
20
+ - ".github/workflows/ruby.yml"
20
21
  - ".gitignore"
21
22
  - ".rspec"
22
23
  - ".travis.yml"
24
+ - ".vscode/settings.json"
23
25
  - Gemfile
26
+ - Gemfile.lock
24
27
  - LICENSE.txt
25
28
  - README.md
26
29
  - Rakefile
27
30
  - bin/console
28
31
  - bin/setup
29
- - lib/notion/sdk/ruby.rb
30
- - lib/notion/sdk/ruby/version.rb
32
+ - lib/notion.rb
33
+ - lib/notion/client.rb
34
+ - lib/notion/endpoints.rb
35
+ - lib/notion/endpoints/blocks.rb
36
+ - lib/notion/endpoints/databases.rb
37
+ - lib/notion/endpoints/pages.rb
38
+ - lib/notion/endpoints/search.rb
39
+ - lib/notion/endpoints/users.rb
40
+ - lib/notion/version.rb
31
41
  - notion-sdk-ruby.gemspec
32
42
  homepage: https://github.com/mgmarlow/notion-sdk-ruby
33
43
  licenses:
@@ -1,10 +0,0 @@
1
- require "notion/sdk/ruby/version"
2
-
3
- module Notion
4
- module Sdk
5
- module Ruby
6
- class Error < StandardError; end
7
- # Your code goes here...
8
- end
9
- end
10
- end
@@ -1,7 +0,0 @@
1
- module Notion
2
- module Sdk
3
- module Ruby
4
- VERSION = "0.1.0"
5
- end
6
- end
7
- end