Class: NotionOrbit::Services::Notion
- Inherits:
-
Object
- Object
- NotionOrbit::Services::Notion
- Defined in:
- lib/notion_orbit/services/notion.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#notion_api_key ⇒ Object
readonly
Returns the value of attribute notion_api_key.
Instance Method Summary collapse
-
#initialize(params = {}) ⇒ Notion
constructor
A new instance of Notion.
- #mark_note_as_synced(page_id, orbit_note_url) ⇒ Object
- #notes(database_id:) ⇒ Object
Constructor Details
#initialize(params = {}) ⇒ Notion
Returns a new instance of Notion.
6 7 8 |
# File 'lib/notion_orbit/services/notion.rb', line 6 def initialize(params = {}) @client = ::Notion::Client.new(token: params[:notion_api_key]) end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
4 5 6 |
# File 'lib/notion_orbit/services/notion.rb', line 4 def client @client end |
#notion_api_key ⇒ Object (readonly)
Returns the value of attribute notion_api_key.
4 5 6 |
# File 'lib/notion_orbit/services/notion.rb', line 4 def notion_api_key @notion_api_key end |
Instance Method Details
#mark_note_as_synced(page_id, orbit_note_url) ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/notion_orbit/services/notion.rb', line 30 def mark_note_as_synced(page_id, orbit_note_url) properties = { 'Orbit Note URL': orbit_note_url, 'Orbit Status': [{ text: { content: "OK" }}] } @client.update_page(id: page_id, properties: properties) end |
#notes(database_id:) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/notion_orbit/services/notion.rb', line 10 def notes(database_id:) pages = @client.database_query(id: database_id).results # only process pages that opt-in to sending the note to Orbit pages = pages.filter { |page| page.properties['Send to Orbit'].checkbox && page[:properties]['Member Email'].email } pages = pages.filter { |page| page.properties['Orbit Status'].rich_text[0] == nil } puts pages notes = [] pages.each do |page| notes << { properties: page_properties(page), content: page_content(page) } end notes end |