notion_orbit 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +7 -0
  2. data/.env.sample +5 -0
  3. data/.github/CODE_OF_CONDUCT.md +134 -0
  4. data/.github/CONTRIBUTING.md +69 -0
  5. data/.github/workflows/CI.yml +25 -0
  6. data/.gitignore +34 -0
  7. data/Gemfile +11 -0
  8. data/Gemfile.lock +115 -0
  9. data/LICENSE +21 -0
  10. data/README.md +108 -0
  11. data/bin/console +16 -0
  12. data/bin/notion_orbit +28 -0
  13. data/bin/setup +8 -0
  14. data/docs/database-id-location.png +0 -0
  15. data/docs/new-note-screenshot.png +0 -0
  16. data/docs/setup-table-for-orbit.png +0 -0
  17. data/docs/setup.md +17 -0
  18. data/docs/ways-to-use.png +0 -0
  19. data/lib/notion_orbit.rb +12 -0
  20. data/lib/notion_orbit/client.rb +55 -0
  21. data/lib/notion_orbit/interactions/note.rb +37 -0
  22. data/lib/notion_orbit/notion.rb +42 -0
  23. data/lib/notion_orbit/notion_objects/block.rb +60 -0
  24. data/lib/notion_orbit/notion_objects/block_types/bulleted_list_item.rb +15 -0
  25. data/lib/notion_orbit/notion_objects/block_types/heading_1.rb +11 -0
  26. data/lib/notion_orbit/notion_objects/block_types/heading_2.rb +11 -0
  27. data/lib/notion_orbit/notion_objects/block_types/heading_3.rb +11 -0
  28. data/lib/notion_orbit/notion_objects/block_types/numbered_list_item.rb +15 -0
  29. data/lib/notion_orbit/notion_objects/block_types/paragraph.rb +15 -0
  30. data/lib/notion_orbit/notion_objects/block_types/to_do.rb +11 -0
  31. data/lib/notion_orbit/notion_objects/block_types/unsupported.rb +11 -0
  32. data/lib/notion_orbit/notion_objects/blocks.rb +18 -0
  33. data/lib/notion_orbit/notion_objects/rich_text.rb +36 -0
  34. data/lib/notion_orbit/orbit.rb +16 -0
  35. data/lib/notion_orbit/services/notion.rb +57 -0
  36. data/lib/notion_orbit/services/orbit.rb +73 -0
  37. data/lib/notion_orbit/version.rb +5 -0
  38. data/notion_orbit.gemspec +43 -0
  39. data/scripts/check_notes.rb +17 -0
  40. metadata +201 -0
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module NotionOrbit
4
+ class Orbit
5
+ def self.call(type:, data:, orbit_workspace:, orbit_api_key:, notion_api_key:)
6
+ if type == "note"
7
+ NotionOrbit::Interactions::Note.new(
8
+ note: data[:note],
9
+ orbit_workspace: orbit_workspace,
10
+ orbit_api_key: orbit_api_key,
11
+ notion_api_key: notion_api_key
12
+ )
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,57 @@
1
+ module NotionOrbit
2
+ module Services
3
+ class Notion
4
+ attr_reader :client, :token
5
+
6
+ def initialize(params = {})
7
+ @client = ::Notion::Client.new(token: params.fetch(:token))
8
+ end
9
+
10
+ def notes(database_id:)
11
+ pages = @client.database_query(id: database_id).results
12
+
13
+ # only process pages that opt-in to sending the note to Orbit
14
+ pages = pages.filter { |page| page.properties['Send to Orbit'].checkbox }
15
+ puts pages
16
+
17
+ notes = []
18
+ pages.each do |page|
19
+ notes << {
20
+ properties: page_properties(page),
21
+ content: page_content(page)
22
+ }
23
+ end
24
+ notes
25
+ end
26
+
27
+ def mark_note_as_synced(page_id, orbit_note_url)
28
+ properties = {
29
+ 'Orbit Note URL': orbit_note_url,
30
+ 'Orbit Status': [{ text: { content: "OK" }}]
31
+ }
32
+ @client.update_page(id: page_id, properties: properties)
33
+ end
34
+
35
+ private
36
+
37
+ def page_properties(page)
38
+ {
39
+ email: page[:properties]['Member Email'].email,
40
+ page_id: page[:id]
41
+ }
42
+ end
43
+
44
+ def page_content(page)
45
+ raw_blocks = @client.block_children(id: page.id).results
46
+ blocks = NotionOrbit::NotionObjects::Blocks.new(raw_blocks)
47
+ content = blocks.to_markdown
48
+ content += "\\n\\n"
49
+ content += "[Open in Notion](#{page_url(page[:id])})"
50
+ end
51
+
52
+ def page_url(page_id)
53
+ "https://notion.so/#{ENV['NOTION_WORKSPACE_SLUG']}/#{page_id}}"
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,73 @@
1
+ require 'uri'
2
+ require 'net/http'
3
+ require 'openssl'
4
+
5
+ module NotionOrbit
6
+ module Services
7
+ class Orbit
8
+ def initialize(orbit_workspace:, orbit_api_key:)
9
+ @orbit_workspace = orbit_workspace
10
+ @orbit_api_key = orbit_api_key
11
+ end
12
+
13
+ def member_slug(email:)
14
+ url = URI("https://app.orbit.love/api/v1/#{@orbit_workspace}/members/find?source=email&email=#{email}")
15
+
16
+ http = Net::HTTP.new(url.host, url.port)
17
+ http.use_ssl = true
18
+
19
+ request = Net::HTTP::Get.new(url)
20
+ request["Accept"] = 'application/json'
21
+ request["Content-Type"] = "application/json"
22
+ request["Authorization"] = "Bearer #{@orbit_api_key}"
23
+
24
+ response = http.request(request)
25
+ json = JSON.parse(response.read_body)
26
+
27
+ return json["data"]["attributes"]["slug"] if json["data"]
28
+
29
+ create_orbit_member(email)
30
+ end
31
+
32
+ def create_orbit_member(email)
33
+ url = URI("https://app.orbit.love/api/v1/#{@orbit_workspace}/members")
34
+
35
+ http = Net::HTTP.new(url.host, url.port)
36
+ http.use_ssl = true
37
+
38
+ request = Net::HTTP::Post.new(url)
39
+ request["Accept"] = 'application/json'
40
+ request["Content-Type"] = 'application/json'
41
+ request["Authorization"] = "Bearer #{@orbit_api_key}"
42
+ request["Content-Type"] = "application/json"
43
+ request["User-Agent"] = "community-ruby-notion-orbit/#{NotionOrbit::VERSION}",
44
+ request.body = "{\"member\":{\"email\":\"#{email}\"},\"identity\":{\"source\":\"notion\",\"email\":\"#{email}\"}}"
45
+
46
+ response = http.request(request)
47
+
48
+ json = JSON.parse(response.read_body)
49
+
50
+ return json["data"]["id"] if json["data"]
51
+
52
+ nil
53
+ end
54
+
55
+ def send_note(api_key:, member_slug:, content:)
56
+ url = URI("https://app.orbit.love/api/v1/#{@orbit_workspace}/members/#{member_slug}/notes")
57
+
58
+ http = Net::HTTP.new(url.host, url.port)
59
+ http.use_ssl = true
60
+
61
+ request = Net::HTTP::Post.new(url)
62
+ request["Accept"] = 'application/json'
63
+ request["Content-Type"] = 'application/json'
64
+ request["Authorization"] = "Bearer #{api_key}"
65
+ request["Content-Type"] = "application/json"
66
+ request["User-Agent"] = "community-ruby-notion-orbit/#{NotionOrbit::VERSION}"
67
+ request.body = "{\"body\":\"#{content}\"}"
68
+
69
+ response = http.request(request)
70
+ end
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module NotionOrbit
4
+ VERSION = "0.0.1"
5
+ end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/notion_orbit/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "notion_orbit"
7
+ spec.version = NotionOrbit::VERSION
8
+ spec.authors = ["Orbit DevRel", "Nicolas Goutay", "Ben Greenberg"]
9
+ spec.email = ["devrel@orbit.love"]
10
+
11
+ spec.summary = "Integrate Notion meeting notes into your Orbit workspace"
12
+ spec.description = "This gem integrates Notion meeting notes into your Orbit workspace"
13
+ spec.homepage = "https://github.com/orbit-love/community-ruby-notion-orbit"
14
+ spec.license = "MIT"
15
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.7.2")
16
+
17
+ spec.metadata["homepage_uri"] = spec.homepage
18
+ spec.metadata["source_code_uri"] = spec.homepage
19
+ spec.metadata["changelog_uri"] = "https://github.com/orbit-love/community-ruby-notion-orbit/blob/main/CHANGELOG.md"
20
+
21
+ # Specify which files should be added to the gem when it is released.
22
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
23
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
24
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
25
+ end
26
+ spec.bindir = "bin"
27
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+
30
+ # Uncomment to register a new dependency of your gem
31
+ # spec.add_dependency "example-gem", "~> 1.0"
32
+ spec.add_dependency "http", "~> 4.4"
33
+ spec.add_dependency "json", "~> 2.5"
34
+ spec.add_dependency "zeitwerk", "~> 2.4"
35
+ spec.add_dependency "notion-ruby-client"
36
+ spec.add_dependency "thor", "~> 1.1"
37
+ spec.add_dependency "dotenv"
38
+ spec.add_development_dependency "rspec", "~> 3.4"
39
+ spec.add_development_dependency "webmock", "~> 3.12"
40
+
41
+ # For more information and examples about making a new gem, checkout our
42
+ # guide at: https://bundler.io/guides/creating_gem.html
43
+ end
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "notion_orbit"
5
+ require "thor"
6
+
7
+ module NotionOrbit
8
+ module Scripts
9
+ class CheckNotes < Thor
10
+ desc "render", "check for new Notion notes and push them to Orbit"
11
+ def render
12
+ client = NotionOrbit::Client.new
13
+ client.notes
14
+ end
15
+ end
16
+ end
17
+ end
metadata ADDED
@@ -0,0 +1,201 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: notion_orbit
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Orbit DevRel
8
+ - Nicolas Goutay
9
+ - Ben Greenberg
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2021-05-27 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: http
17
+ requirement: !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - "~>"
20
+ - !ruby/object:Gem::Version
21
+ version: '4.4'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - "~>"
27
+ - !ruby/object:Gem::Version
28
+ version: '4.4'
29
+ - !ruby/object:Gem::Dependency
30
+ name: json
31
+ requirement: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - "~>"
34
+ - !ruby/object:Gem::Version
35
+ version: '2.5'
36
+ type: :runtime
37
+ prerelease: false
38
+ version_requirements: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - "~>"
41
+ - !ruby/object:Gem::Version
42
+ version: '2.5'
43
+ - !ruby/object:Gem::Dependency
44
+ name: zeitwerk
45
+ requirement: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: '2.4'
50
+ type: :runtime
51
+ prerelease: false
52
+ version_requirements: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - "~>"
55
+ - !ruby/object:Gem::Version
56
+ version: '2.4'
57
+ - !ruby/object:Gem::Dependency
58
+ name: notion-ruby-client
59
+ requirement: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ type: :runtime
65
+ prerelease: false
66
+ version_requirements: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ - !ruby/object:Gem::Dependency
72
+ name: thor
73
+ requirement: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - "~>"
76
+ - !ruby/object:Gem::Version
77
+ version: '1.1'
78
+ type: :runtime
79
+ prerelease: false
80
+ version_requirements: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - "~>"
83
+ - !ruby/object:Gem::Version
84
+ version: '1.1'
85
+ - !ruby/object:Gem::Dependency
86
+ name: dotenv
87
+ requirement: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ type: :runtime
93
+ prerelease: false
94
+ version_requirements: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ - !ruby/object:Gem::Dependency
100
+ name: rspec
101
+ requirement: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - "~>"
104
+ - !ruby/object:Gem::Version
105
+ version: '3.4'
106
+ type: :development
107
+ prerelease: false
108
+ version_requirements: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - "~>"
111
+ - !ruby/object:Gem::Version
112
+ version: '3.4'
113
+ - !ruby/object:Gem::Dependency
114
+ name: webmock
115
+ requirement: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - "~>"
118
+ - !ruby/object:Gem::Version
119
+ version: '3.12'
120
+ type: :development
121
+ prerelease: false
122
+ version_requirements: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - "~>"
125
+ - !ruby/object:Gem::Version
126
+ version: '3.12'
127
+ description: This gem integrates Notion meeting notes into your Orbit workspace
128
+ email:
129
+ - devrel@orbit.love
130
+ executables:
131
+ - console
132
+ - notion_orbit
133
+ - setup
134
+ extensions: []
135
+ extra_rdoc_files: []
136
+ files:
137
+ - ".env.sample"
138
+ - ".github/CODE_OF_CONDUCT.md"
139
+ - ".github/CONTRIBUTING.md"
140
+ - ".github/workflows/CI.yml"
141
+ - ".gitignore"
142
+ - Gemfile
143
+ - Gemfile.lock
144
+ - LICENSE
145
+ - README.md
146
+ - bin/console
147
+ - bin/notion_orbit
148
+ - bin/setup
149
+ - docs/database-id-location.png
150
+ - docs/new-note-screenshot.png
151
+ - docs/setup-table-for-orbit.png
152
+ - docs/setup.md
153
+ - docs/ways-to-use.png
154
+ - lib/notion_orbit.rb
155
+ - lib/notion_orbit/client.rb
156
+ - lib/notion_orbit/interactions/note.rb
157
+ - lib/notion_orbit/notion.rb
158
+ - lib/notion_orbit/notion_objects/block.rb
159
+ - lib/notion_orbit/notion_objects/block_types/bulleted_list_item.rb
160
+ - lib/notion_orbit/notion_objects/block_types/heading_1.rb
161
+ - lib/notion_orbit/notion_objects/block_types/heading_2.rb
162
+ - lib/notion_orbit/notion_objects/block_types/heading_3.rb
163
+ - lib/notion_orbit/notion_objects/block_types/numbered_list_item.rb
164
+ - lib/notion_orbit/notion_objects/block_types/paragraph.rb
165
+ - lib/notion_orbit/notion_objects/block_types/to_do.rb
166
+ - lib/notion_orbit/notion_objects/block_types/unsupported.rb
167
+ - lib/notion_orbit/notion_objects/blocks.rb
168
+ - lib/notion_orbit/notion_objects/rich_text.rb
169
+ - lib/notion_orbit/orbit.rb
170
+ - lib/notion_orbit/services/notion.rb
171
+ - lib/notion_orbit/services/orbit.rb
172
+ - lib/notion_orbit/version.rb
173
+ - notion_orbit.gemspec
174
+ - scripts/check_notes.rb
175
+ homepage: https://github.com/orbit-love/community-ruby-notion-orbit
176
+ licenses:
177
+ - MIT
178
+ metadata:
179
+ homepage_uri: https://github.com/orbit-love/community-ruby-notion-orbit
180
+ source_code_uri: https://github.com/orbit-love/community-ruby-notion-orbit
181
+ changelog_uri: https://github.com/orbit-love/community-ruby-notion-orbit/blob/main/CHANGELOG.md
182
+ post_install_message:
183
+ rdoc_options: []
184
+ require_paths:
185
+ - lib
186
+ required_ruby_version: !ruby/object:Gem::Requirement
187
+ requirements:
188
+ - - ">="
189
+ - !ruby/object:Gem::Version
190
+ version: 2.7.2
191
+ required_rubygems_version: !ruby/object:Gem::Requirement
192
+ requirements:
193
+ - - ">="
194
+ - !ruby/object:Gem::Version
195
+ version: '0'
196
+ requirements: []
197
+ rubygems_version: 3.2.15
198
+ signing_key:
199
+ specification_version: 4
200
+ summary: Integrate Notion meeting notes into your Orbit workspace
201
+ test_files: []