notion_rb 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dd6ca73e60cf77166f9f1b24a337d4d482520a83dd4c53fd54d0cf471edcb1db
4
- data.tar.gz: 98ea9b268f7b8a41a80d53fdc0c441569d7f07cc5881b1fdd228c221febd2ee4
3
+ metadata.gz: 1ab0eb041c68351cf2c9a9749b78f01cfe13f7d1aae3b11aa452ba95f468c764
4
+ data.tar.gz: 37ff8830acab646cb9d970846ea6fa2c388d75bacbcdcb684938536ead57a43b
5
5
  SHA512:
6
- metadata.gz: 53c0e655e18713b6da75fdd3da0412db0233e39e1c1a9a10695cf03440476690507a804fa63832227a2323ddca3e6546312682238d4667e4ba9038d738556447
7
- data.tar.gz: b4be7e38a4d7f7ba3d61e077acfd2bc0748ce1164c0de2a430602c41792b2909019fa607898b846911b48e705d268d29a6629365843d383524d46809c7a3718f
6
+ metadata.gz: b2738bba8027e7f7e6b741ae67a5771c67d8c27678e5b3e8460da8d6679128d03109f748fb7e2065b091de213f076ee0fdeb0312e6de2421e491172f457f5002
7
+ data.tar.gz: 36444104173a52ff3877d92288613bc0380f3fd5e281e87c436ab6a17bb97ee7fbd7d2d038a8cf60e94800d26e481f82d2ba5394a97e50de7e10b4377dbe15cc
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- notion_rb (0.1.1)
4
+ notion_rb (0.1.2)
5
5
  mechanize
6
6
 
7
7
  GEM
@@ -41,7 +41,7 @@ GEM
41
41
  nokogiri (~> 1.6)
42
42
  ntlm-http (~> 0.1, >= 0.1.1)
43
43
  webrobots (>= 0.0.9, < 0.2)
44
- mime-types (3.3)
44
+ mime-types (3.3.1)
45
45
  mime-types-data (~> 3.2015)
46
46
  mime-types-data (3.2019.1009)
47
47
  mini_portile2 (2.4.0)
data/README.md CHANGED
@@ -26,7 +26,9 @@ Or install it yourself as:
26
26
 
27
27
  ```ruby
28
28
  # Obtain the `token_v2` value by inspecting your browser cookies on a logged-in session on Notion.so
29
- ENV['TOKEN_V2'] = '<some token>'
29
+ NotionRb.configure do |config|
30
+ config[:token_v2] = '<some token>'
31
+ end
30
32
 
31
33
  # Get the block
32
34
  block = NotionRb::Block.new('https://www.notion.so/some_org/some-title-30d7f6e4c2284cbab860a6f40ed3372e')
@@ -34,8 +34,7 @@ module NotionRb
34
34
  end
35
35
 
36
36
  def metadata
37
- metadata = @block[:metadata].except(:properties)
38
- add_parent_metadata(metadata)
37
+ @block[:metadata].except(:properties)
39
38
  end
40
39
 
41
40
  def parent
@@ -83,15 +82,32 @@ module NotionRb
83
82
  NotionRb::Api::Update.new(notion_id: @uuid, title: @block[:title], block_type: @block[:block_type]).success?
84
83
  end
85
84
 
86
- def add_parent_metadata(metadata)
87
- return metadata unless parent.type == 'collection'
85
+ def method_missing(method, *args, &block)
86
+ if schema_methods.include?(method)
87
+ send_schema_method(method)
88
+ else
89
+ super
90
+ end
91
+ end
92
+
93
+ def respond_to_missing?(method_name, *args)
94
+ schema_methods.include?(method_name) || super
95
+ end
88
96
 
97
+ def schema_methods
98
+ return [] unless parent.type == 'collection'
99
+
100
+ parent.metadata[:schema].values.map { |value| value['name'].tableize.to_sym }
101
+ end
102
+
103
+ def send_schema_method(method)
89
104
  parent_schema = parent.metadata[:schema]
90
105
  @block.dig(:metadata, :properties).each do |key, value|
91
106
  schema = parent_schema[key]
92
- metadata.merge!(schema['name'] => value[0][0])
107
+ next unless schema['name'].tableize.to_sym == method
108
+
109
+ return value[0][0]
93
110
  end
94
- metadata
95
111
  end
96
112
  end
97
113
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module NotionRb
4
- VERSION = '0.1.1'
4
+ VERSION = '0.1.2'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: notion_rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tomas Gunther
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-01-03 00:00:00.000000000 Z
11
+ date: 2020-01-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mechanize