Sha256: dc79de526fbb54e7d5bd4a835033605b52ddb669d762efeeecea343510ac46ba

Contents?: true

Size: 1.67 KB

Versions: 4

Compression:

Stored size: 1.67 KB

Contents

# frozen_string_literal: true

module NotionOrbit
    class Notion
        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

        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
    end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
notion_orbit-0.0.6 lib/notion_orbit/notion.rb
notion_orbit-0.0.5 lib/notion_orbit/notion.rb
notion_orbit-0.0.4 lib/notion_orbit/notion.rb
notion_orbit-0.0.3 lib/notion_orbit/notion.rb