notion_ruby_mapping 0.7.7 → 0.8.0

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: 03a125f454d083e662faf00778b9181e386846628e3d0bf6fa068e2cbd05a513
4
- data.tar.gz: f536e72b18ea0b701a2f4e7bad4fbde352e59eabc8f848b72c438226b562c58a
3
+ metadata.gz: d5001d647004eef3101bd45070294fc461cb257e20a6f2eaf61cbc271491b9cd
4
+ data.tar.gz: da78628f7e1ab2c11e176cfa1ec14fa0f5fb1dcdbfdbf37d73ff960bba6b85ab
5
5
  SHA512:
6
- metadata.gz: ebdf167f99b33960ffd125f59f6b5008d7cbbad548bbb044499408dbbdc81ed989c5358733ea126202e40f6142a21265cde46e511e50718caeb204af1221778c
7
- data.tar.gz: cc069fabc9bdfbd92f0ac1b086ebde7742974d692616798ceed29b89f8388bbbd3bf487e3ecb58d28819e3fcc657bbdc8d3c4dce8be315c432c4fa6d00a7bd3e
6
+ metadata.gz: 3e9ae34abd9f5f59f4920bec6f007ae897d291391a2e8c1148af6d53e206a00cfdb035118e3dae0525bdac3b7140c8b9818312e947b857ff6750a9cad749721c
7
+ data.tar.gz: 43b808260694cfa5dd542901e839794309e20a39926aee9328a3976e605affec47170984a79e04bd4965c7d27c671205135ed767c2f956cbc5ff387d6218cd3f
data/README.md CHANGED
@@ -127,6 +127,7 @@ NotionRubyMapping.configuration { |c| c.notion_token = ENV["NOTION_API_TOKEN"] }
127
127
 
128
128
  ## 3. ChangeLog
129
129
 
130
+ - 2023/6/4 [v0.8.0] add unique_id properties, filter_properties
130
131
  - 2023/4/14 [v0.7.7] add token= method for Notion API book typo
131
132
  - 2023/4/1 [v0.7.6] bug fix Ignore last ? option for page_id
132
133
  - 2023/3/8 [v0.7.5] add notionTimeRecorder.rb
@@ -135,7 +135,7 @@ module NotionRubyMapping
135
135
  # @param [String] database_id (with or without "-")
136
136
  # @param [NotionRubyMapping::Query] query query object
137
137
  def database_query_request(database_id, query)
138
- request :post, "v1/databases/#{database_id}/query", query.query_json
138
+ request :post, "v1/databases/#{database_id}/query#{query.database_query_string}", query.query_json
139
139
  end
140
140
 
141
141
  # @param [String] database_id
@@ -3,14 +3,15 @@
3
3
  module NotionRubyMapping
4
4
  # Query object
5
5
  class Query
6
- def initialize(filter: {}, sort: [], page_size: 100, start_cursor: nil)
6
+ def initialize(filter: {}, sort: [], page_size: 100, start_cursor: nil, filter_properties: [])
7
7
  @filter = filter
8
8
  @sort = sort
9
9
  @page_size = page_size
10
10
  @start_cursor = start_cursor
11
+ @filter_properties = Array(filter_properties)
11
12
  end
12
13
  attr_reader :filter, :sort, :page_size
13
- attr_accessor :start_cursor
14
+ attr_accessor :start_cursor, :filter_properties
14
15
 
15
16
  # @param [Query] another_query other query
16
17
  # @return [NotionRubyMapping::Query] updated self (Query object)
@@ -67,5 +68,10 @@ module NotionRubyMapping
67
68
  ans << "start_cursor=#{@start_cursor}" if @start_cursor
68
69
  ans.empty? ? "" : "?#{ans.join("&")}"
69
70
  end
71
+
72
+ def database_query_string
73
+ ans = Array(@filter_properties).map { |p| "filter_properties=#{p.property_id}" }
74
+ ans.empty? ? "" : "?#{ans.join("&")}"
75
+ end
70
76
  end
71
77
  end
@@ -75,24 +75,24 @@ module NotionRubyMapping
75
75
  new name, property_id: input_json["id"], base_type: base_type, property_cache: property_cache, query: query
76
76
  elsif type == "property_item"
77
77
  tmp = new name, property_id: input_json["property_item"]["id"], base_type: base_type,
78
- property_cache: property_cache, query: query
78
+ property_cache: property_cache, query: query
79
79
  objects = List.new(json: input_json, type: :property, value: tmp, query: query).to_a
80
80
  case input_json["property_item"]["type"]
81
81
  when "people"
82
82
  PeopleProperty.new name, people: objects, base_type: base_type,
83
- property_cache: property_cache, query: query
83
+ property_cache: property_cache, query: query
84
84
  when "relation"
85
85
  RelationProperty.new name, relation: objects, base_type: base_type,
86
- property_cache: property_cache, query: query
86
+ property_cache: property_cache, query: query
87
87
  when "rich_text"
88
88
  RichTextProperty.new name, text_objects: objects, base_type: base_type,
89
- property_cache: property_cache, query: query
89
+ property_cache: property_cache, query: query
90
90
  when "rollup"
91
91
  RollupProperty.new name, json: objects, base_type: base_type,
92
- property_cache: property_cache, query: query
92
+ property_cache: property_cache, query: query
93
93
  when "title"
94
94
  TitleProperty.new name, text_objects: objects, base_type: base_type,
95
- property_cache: property_cache, query: query
95
+ property_cache: property_cache, query: query
96
96
  end
97
97
  else
98
98
  klass = {
@@ -115,12 +115,15 @@ module NotionRubyMapping
115
115
  "status" => StatusProperty,
116
116
  "title" => TitleProperty,
117
117
  "rich_text" => RichTextProperty,
118
+ "unique_id" => UniqueIdProperty,
118
119
  "url" => UrlProperty,
119
120
  }[type]
120
121
  raise StandardError, "Irregular property type: #{type}" unless klass
121
122
 
122
- klass.new name, property_id: input_json["id"], json: input_json[type], base_type: base_type,
123
- property_cache: property_cache
123
+ answer = klass.new name, property_id: input_json["id"], json: input_json[type], base_type: base_type,
124
+ property_cache: property_cache
125
+ answer = answer.retrieve_page_property if answer.is_a?(RelationProperty) && input_json["has_more"] == true
126
+ answer
124
127
  end
125
128
  end
126
129
 
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+
3
+ module NotionRubyMapping
4
+ # Number property
5
+ class UniqueIdProperty < Property
6
+ include EqualsDoesNotEqual
7
+ include GreaterThanLessThan
8
+ include IsEmptyIsNotEmpty
9
+ TYPE = "unique_id"
10
+
11
+ ### Public announced methods
12
+
13
+ ## Common methods
14
+
15
+ # @return [Hash, nil]
16
+ def unique_id
17
+ @json
18
+ end
19
+
20
+ ## Database property only methods
21
+
22
+ ## Page property only methods
23
+
24
+ ### Not public announced methods
25
+
26
+ ## Common methods
27
+
28
+ # @param [String] name Property name
29
+ # @param [Float, Integer, Hash] json Number value or format Hash
30
+ def initialize(name, will_update: false, base_type: :page, json: nil, property_id: nil, property_cache: nil)
31
+ super name, will_update: will_update, base_type: base_type, property_id: property_id, property_cache: property_cache
32
+ @json = json
33
+ @json ||= {} if database?
34
+ end
35
+
36
+ # @param [Hash] json
37
+ # @return [NotionRubyMapping::NumberProperty]
38
+ def update_from_json(json)
39
+ @will_update = false
40
+ @json = json["unique_id"]
41
+ self
42
+ end
43
+
44
+ ## Database property only methods
45
+
46
+ ## Page property only methods
47
+
48
+ # @return [Hash]
49
+ def property_values_json
50
+ assert_page_property __method__
51
+ {@name => {"unique_id" => @json, "type" => "unique_id"}}
52
+ end
53
+
54
+ ## Database property only methods
55
+ end
56
+ end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module NotionRubyMapping
4
- VERSION = "0.7.7"
4
+ VERSION = "0.8.0"
5
5
  NOTION_VERSION = "2022-06-28"
6
6
  end
@@ -20,7 +20,7 @@ require_relative "notion_ruby_mapping/version"
20
20
  date_property email_property files_property formula_property last_edited_by_property
21
21
  last_edited_time_property multi_select_property number_property people_property phone_number_property
22
22
  relation_property text_property rich_text_property rollup_property select_property status_property
23
- title_property url_property],
23
+ title_property unique_id_property url_property],
24
24
  }.each do |key, values|
25
25
  values.each do |klass|
26
26
  require_relative "notion_ruby_mapping/#{key}/#{klass}"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: notion_ruby_mapping
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.7
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hiroyuki KOBAYASHI
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-04-14 00:00:00.000000000 Z
11
+ date: 2023-06-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -254,6 +254,7 @@ files:
254
254
  - lib/notion_ruby_mapping/properties/status_property.rb
255
255
  - lib/notion_ruby_mapping/properties/text_property.rb
256
256
  - lib/notion_ruby_mapping/properties/title_property.rb
257
+ - lib/notion_ruby_mapping/properties/unique_id_property.rb
257
258
  - lib/notion_ruby_mapping/properties/url_property.rb
258
259
  - lib/notion_ruby_mapping/version.rb
259
260
  - notion_ruby_mapping.gemspec
@@ -278,7 +279,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
278
279
  - !ruby/object:Gem::Version
279
280
  version: '0'
280
281
  requirements: []
281
- rubygems_version: 3.4.6
282
+ rubygems_version: 3.4.13
282
283
  signing_key:
283
284
  specification_version: 4
284
285
  summary: Notion Ruby mapping tool