Class: NotionOrbit::Notion

Inherits:
Object
  • Object
show all
Defined in:
lib/notion_orbit/notion.rb

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ Notion

Returns a new instance of Notion.



5
6
7
8
9
10
11
# File 'lib/notion_orbit/notion.rb', line 5

def initialize(params = {})
    @orbit_api_key = params.fetch(:orbit_api_key)
    @orbit_workspace = params.fetch(:orbit_workspace)
    @notion_api_key = params.fetch(:notion_api_key)
    @notion_database_id = params.fetch(:notion_database_id)
    @notion_workspace_slug = params.fetch(:notion_workspace_slug)
end

Instance Method Details

#process_notesObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/notion_orbit/notion.rb', line 13

def process_notes
    notion_service = NotionOrbit::Services::Notion.new(notion_api_key: @notion_api_key)
    orbit_service = NotionOrbit::Services::Orbit.new(orbit_workspace: @orbit_workspace, orbit_api_key: @orbit_api_key)
    
    notes = notion_service.notes(database_id: @notion_database_id)
      
    notes.each do |note|
        next if note[:properties][:email].nil? || note[:properties][:email] == ""

        member_slug = orbit_service.member_slug(email: note[:properties][:email]) 
        next if member_slug == "" || member_slug.nil?

        NotionOrbit::Orbit.call(
            type: "note",
            data: {
                note: {
                    email: note[:properties][:email],
                    member_slug: member_slug,
                    page_id: note[:properties][:page_id],
                    content: note[:content]
                }
            },
            orbit_workspace: @orbit_workspace,
            orbit_api_key: @orbit_api_key,
            notion_api_key: @notion_api_key
        )
    end      
end