notion_ruby_mapping 0.7.7 → 0.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 03a125f454d083e662faf00778b9181e386846628e3d0bf6fa068e2cbd05a513
4
- data.tar.gz: f536e72b18ea0b701a2f4e7bad4fbde352e59eabc8f848b72c438226b562c58a
3
+ metadata.gz: 1d5ecb543438b351d894b9f20d2b9ea0f10ebdacf3dd3b01c20bafae1d07f84d
4
+ data.tar.gz: e1463b904bba8cf73e41113754b9aed7492b45500321dd80b4660ba210cdb722
5
5
  SHA512:
6
- metadata.gz: ebdf167f99b33960ffd125f59f6b5008d7cbbad548bbb044499408dbbdc81ed989c5358733ea126202e40f6142a21265cde46e511e50718caeb204af1221778c
7
- data.tar.gz: cc069fabc9bdfbd92f0ac1b086ebde7742974d692616798ceed29b89f8388bbbd3bf487e3ecb58d28819e3fcc657bbdc8d3c4dce8be315c432c4fa6d00a7bd3e
6
+ metadata.gz: 82a8330b58a7a6edb675a03640f3c8a324fd7e3f58e124f184f4806c80a15c07d9f62fa92adfd31cfd21a7fa5db0ade83cd987baa48950f95076b021259abb2d
7
+ data.tar.gz: 86d1738c9a54021b5122435b77e93faff510294330217db44c748ebfaf8e37e3f821bd7fc18a62869200f6054a9b4d3f3b42f184d4f41724ca28eb8002368cf8
data/README.md CHANGED
@@ -127,6 +127,8 @@ NotionRubyMapping.configuration { |c| c.notion_token = ENV["NOTION_API_TOKEN"] }
127
127
 
128
128
  ## 3. ChangeLog
129
129
 
130
+ - 2023/7/10 [v0.8.1] Automatically change type to external when file object is updated
131
+ - 2023/6/4 [v0.8.0] add unique_id properties, filter_properties
130
132
  - 2023/4/14 [v0.7.7] add token= method for Notion API book typo
131
133
  - 2023/4/1 [v0.7.6] bug fix Ignore last ? option for page_id
132
134
  - 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
@@ -39,9 +39,9 @@ module NotionRubyMapping
39
39
  # @param [String] url
40
40
  # @see https://www.notion.so/hkob/FileObject-6218c354e985423a90904f47a985be33#6b841f75d0234a1aac93fb54348abb96
41
41
  def url=(url)
42
- raise StandardError "internal file url can't change." if @type == "file"
43
-
44
42
  @url = url
43
+ @type = "external"
44
+ @expiry_time = nil
45
45
  @will_update = true
46
46
  end
47
47
 
@@ -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.1"
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.1
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-07-10 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