Class: Synotion::Syncer
- Inherits:
-
Object
- Object
- Synotion::Syncer
- Defined in:
- lib/synotion/syncer.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Syncer
constructor
A new instance of Syncer.
- #sync(markdown_file_path, options = {}) ⇒ Object
- #sync_content(markdown_content, identifier, options = {}) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Syncer
Returns a new instance of Syncer.
7 8 9 10 11 |
# File 'lib/synotion/syncer.rb', line 7 def initialize( = {}) @config = build_config() @config.validate! @client = Client.new(@config.notion_api_key) end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
5 6 7 |
# File 'lib/synotion/syncer.rb', line 5 def client @client end |
#config ⇒ Object (readonly)
Returns the value of attribute config.
5 6 7 |
# File 'lib/synotion/syncer.rb', line 5 def config @config end |
Instance Method Details
#sync(markdown_file_path, options = {}) ⇒ Object
13 14 15 16 17 18 19 20 |
# File 'lib/synotion/syncer.rb', line 13 def sync(markdown_file_path, = {}) raise ArgumentError, "File not found: #{markdown_file_path}" unless File.exist?(markdown_file_path) markdown_content = File.read(markdown_file_path) identifier = [:unique_value] || markdown_file_path sync_content(markdown_content, identifier, .merge(filename: markdown_file_path)) end |
#sync_content(markdown_content, identifier, options = {}) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/synotion/syncer.rb', line 22 def sync_content(markdown_content, identifier, = {}) mode = [:mode] || config.update_mode database_id = [:database_id] || config.database_id page_id = [:page_id] || config.page_id converter = MarkdownConverter.new(markdown_content) blocks = converter.to_notion_blocks title = [:title] || extract_title(converter, [:filename]) if page_id sync_to_page(page_id, blocks, mode, title) elsif database_id unique_property = [:unique_property] || config.unique_property sync_to_database(database_id, identifier, blocks, mode, title, unique_property, ) else raise ConfigurationError, 'Either page_id or database_id must be specified' end end |