notion 1.0.0 → 1.0.1

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: b3ebde6eb43b792a313801584c8043c579e9fd356427df080a14c265e28cf2db
4
- data.tar.gz: 9bf0242abe3ad4c15cebbb9a1cdd65ae64b6ec76a1d8e872836a90b5c2ec9404
3
+ metadata.gz: a5a96adb5d26c56e00d6f8a370b5c272bb69ecd33c57b4db37a483c8ddb70dca
4
+ data.tar.gz: ba367e26e35f4632a3fd25a2c9636b65eb14f602a06311715b4c80ec1a5154bf
5
5
  SHA512:
6
- metadata.gz: 2f0b872d9f1eb4f88f05e4d8e41959291dc4b86bdb0be46582d196de095f174907b78c165c35140c7bc68b41b4cd6b7b7098ae23a3502d8adecc488e9185c03a
7
- data.tar.gz: 8c69f7a02a7374a69590b4b1cdb92767557efaf7f56e5fa7fe3f8450f78c19e4fa9e37b5db8c46e9aef6661dda8dfc56692baeff57912769f052e831af9ae594
6
+ metadata.gz: 3d3f9703c7192ab1654b70b308973da70a9501a8b1d9500bbe310719b863aeade15afcf02acb041f701db657c59c41545ea1df0bff27798c6fca5860aff9fb8f
7
+ data.tar.gz: 13df40b25461a064419604046677f15e14aad820c7064be1d41ca0590f527198f4708156bbf3e9c16149ec61f1e20c65f1c8f2ddc9d9fc175e0ef959a7537ea3
data/README.md CHANGED
@@ -2,7 +2,16 @@
2
2
  [![Build Status](https://travis-ci.com/danmurphy1217/notion-ruby.svg?branch=master)](https://travis-ci.com/danmurphy1217/notion-ruby) [![Ruby Style Guide](https://img.shields.io/badge/code_style-rubocop-brightgreen.svg)](https://github.com/rubocop-hq/rubocop)
3
3
 
4
4
  ## Getting Started
5
- To get started using package, you'll first need to retrieve your token_v2 credentials by signing into Notion online, navigating to the developer tools, inspecting the cookies, and finding the value associated with the **token_v2** key.
5
+ ### Installation
6
+ to install the gem:
7
+ ```ruby
8
+ gem install notion
9
+ ```
10
+ Then, place this at the top of your file:
11
+ ```ruby
12
+ require 'notion_api'
13
+ ```
14
+ To get started using the gem, you'll first need to retrieve your token_v2 credentials by signing into Notion online, navigating to the developer tools, inspecting the cookies, and finding the value associated with the **token_v2** key.
6
15
 
7
16
  From here, you can instantiate the Notion Client with the following code:
8
17
  ```ruby
@@ -322,11 +322,9 @@ module NotionAPI
322
322
 
323
323
  # build and set operations to send to Notion
324
324
  title_hash = Utils::BlockComponents.title(@id, new_title)
325
- last_edited_time_parent_hash = Utils::BlockComponents.last_edited_time(@parent_id)
326
325
  last_edited_time_child_hash = Utils::BlockComponents.last_edited_time(@id)
327
326
  operations = [
328
327
  title_hash,
329
- last_edited_time_parent_hash,
330
328
  last_edited_time_child_hash
331
329
  ]
332
330
 
@@ -516,13 +514,14 @@ module NotionAPI
516
514
  CollectionView.new(clean_id, block_title, block_parent_id, block_collection_id, block_view_id)
517
515
  end
518
516
 
519
- def create_collection(_collection_type, collection_title, data)
517
+ def create_collection(collection_type, collection_title, data)
520
518
  # ! create a Notion Collection View and return its instantiated class object.
521
519
  # ! _collection_type -> the type of collection to create : ``str``
522
520
  # ! collection_title -> the title of the collection view : ``str``
523
521
  # ! data -> JSON data to add to the table : ``str``
524
522
 
525
- unless %w[table].include?(_collection_type) ; raise ArgumentError, "That collection type is not yet supported. Try: \"table\"."; end
523
+ valid_types = %w[table board list timeline calendar gallery]
524
+ unless valid_types.include?(collection_type) ; raise ArgumentError, "That collection type is not yet supported. Try: #{valid_types.join}."; end
526
525
  cookies = Core.options['cookies']
527
526
  headers = Core.options['headers']
528
527
 
@@ -550,8 +549,12 @@ module NotionAPI
550
549
  }
551
550
 
552
551
  create_collection_view = Utils::CollectionViewComponents.create_collection_view(new_block_id, collection_id, view_id)
553
- configure_view = Utils::CollectionViewComponents.set_view_config(new_block_id, view_id, children)
554
- configure_columns = Utils::CollectionViewComponents.set_collection_columns(collection_id, new_block_id, data)
552
+ configure_view = Utils::CollectionViewComponents.set_view_config(collection_type, new_block_id, view_id, children)
553
+
554
+ # returns the JSON and some useful column mappings...
555
+ column_data = Utils::CollectionViewComponents.set_collection_columns(collection_id, new_block_id, data)
556
+ configure_columns_hash = column_data[0]
557
+ column_mappings = column_data[1]
555
558
  set_parent_alive_hash = Utils::BlockComponents.set_parent_to_alive(@id, new_block_id)
556
559
  add_block_hash = Utils::BlockComponents.block_location_add(@id, @id, new_block_id, nil, 'listAfter')
557
560
  new_block_edited_time = Utils::BlockComponents.last_edited_time(new_block_id)
@@ -560,7 +563,7 @@ module NotionAPI
560
563
  operations = [
561
564
  create_collection_view,
562
565
  configure_view,
563
- configure_columns,
566
+ configure_columns_hash,
564
567
  set_parent_alive_hash,
565
568
  add_block_hash,
566
569
  new_block_edited_time,
@@ -571,7 +574,7 @@ module NotionAPI
571
574
  data.each_with_index do |row, i|
572
575
  child = children[i]
573
576
  row.keys.each_with_index do |col_name, j|
574
- child_component = Utils::CollectionViewComponents.insert_data(child, j.zero? ? 'title' : col_name, row[col_name])
577
+ child_component = Utils::CollectionViewComponents.insert_data(child, j.zero? ? 'title' : col_name, row[col_name], column_mappings[j])
575
578
  all_ops.push(child_component)
576
579
  end
577
580
  end
@@ -806,7 +809,7 @@ module NotionAPI
806
809
  ]
807
810
 
808
811
  data.keys.each_with_index do |col_name, j|
809
- child_component = Utils::CollectionViewComponents.insert_data(new_block_id, j.zero? ? 'title' : col_map[col_name], data[col_name])
812
+ child_component = Utils::CollectionViewComponents.insert_data(new_block_id, j.zero? ? 'title' : col_map[col_name], data[col_name], j.zero? ? schema['title']["type"] : schema[col_map[col_name]]['type'])
810
813
  operations.push(child_component)
811
814
  end
812
815
 
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative 'core'
4
+ require_relative 'blocks'
4
5
 
5
6
  module NotionAPI
6
7
  # acts as the 'main interface' to the methods of this package.
@@ -150,7 +150,7 @@ module NotionAPI
150
150
  # titles for images are called source, while titles for text-based blocks are called title, so lets dynamically grab it
151
151
  # https://stackoverflow.com/questions/23765996/get-all-keys-from-ruby-hash/23766007
152
152
  title_value = filter_nil_blocks[clean_id]['value']['properties'].keys[0]
153
- Core.type_whitelist.include?(filter_nil_blocks[clean_id]['value']['type']) ? nil : jsonified_record_response['block'][clean_id]['value']['properties'][title_value].flatten[0]
153
+ Core.type_whitelist.include?(filter_nil_blocks[clean_id]['value']['type']) ? nil : jsonified_record_response['block'][clean_id]['value']['properties'][title_value].flatten[0]
154
154
 
155
155
  end
156
156
  end
@@ -160,7 +160,7 @@ module NotionAPI
160
160
  # ! clean_id -> the cleaned block ID: ``str``
161
161
  # ! collection_id -> the collection ID: ``str``
162
162
  # ! jsonified_record_response -> parsed JSON representation of a notion response object : ``Json``
163
- jsonified_record_response['collection'][collection_id]['value']['name'].flatten.join if jsonified_record_response['collection']
163
+ jsonified_record_response['collection'][collection_id]['value']['name'].flatten.join if jsonified_record_response['collection'] and jsonified_record_response['collection'][collection_id]['value']['name']
164
164
  end
165
165
 
166
166
  def extract_type(clean_id, jsonified_record_response)
@@ -3,9 +3,9 @@
3
3
  module Utils
4
4
  # ! defines utility functions and static variables for this application.
5
5
  URLS = {
6
- GET_BLOCK: 'https://www.notion.so/api/v3/loadPageChunk',
7
- UPDATE_BLOCK: 'https://www.notion.so/api/v3/saveTransactions',
8
- GET_COLLECTION: 'https://www.notion.so/api/v3/queryCollection'
6
+ GET_BLOCK: "https://www.notion.so/api/v3/loadPageChunk",
7
+ UPDATE_BLOCK: "https://www.notion.so/api/v3/saveTransactions",
8
+ GET_COLLECTION: "https://www.notion.so/api/v3/queryCollection",
9
9
  }.freeze
10
10
 
11
11
  class BlockComponents
@@ -15,10 +15,10 @@ module Utils
15
15
  # ! payload for creating a block.
16
16
  # ! block_id -> id of the new block : ``str``
17
17
  # ! block_type -> type of block to create : ``cls``
18
- table = 'block'
18
+ table = "block"
19
19
  path = []
20
- command = 'update'
21
- timestamp = DateTime.now.strftime('%Q')
20
+ command = "update"
21
+ timestamp = DateTime.now.strftime("%Q")
22
22
  {
23
23
  id: block_id,
24
24
  table: table,
@@ -29,41 +29,41 @@ module Utils
29
29
  type: block_type,
30
30
  properties: {},
31
31
  created_time: timestamp,
32
- last_edited_time: timestamp
33
- }
32
+ last_edited_time: timestamp,
33
+ },
34
34
  }
35
35
  end
36
36
 
37
37
  def self.title(id, title)
38
38
  # ! payload for updating the title of a block
39
39
  # ! id -> the ID to update the title of : ``str``
40
- table = 'block'
40
+ table = "block"
41
41
  path = %w[properties title]
42
- command = 'set'
42
+ command = "set"
43
43
 
44
44
  {
45
45
  id: id,
46
46
  table: table,
47
47
  path: path,
48
48
  command: command,
49
- args: [[title]]
49
+ args: [[title]],
50
50
  }
51
51
  end
52
52
 
53
53
  def self.last_edited_time(id)
54
54
  # ! payload for updating the last edited time
55
55
  # ! id -> either the block ID or parent ID : ``str``
56
- timestamp = DateTime.now.strftime('%Q')
57
- table = 'block'
58
- path = ['last_edited_time']
59
- command = 'set'
56
+ timestamp = DateTime.now.strftime("%Q")
57
+ table = "block"
58
+ path = ["last_edited_time"]
59
+ command = "set"
60
60
 
61
61
  {
62
62
  table: table,
63
63
  id: id,
64
64
  path: path,
65
65
  command: command,
66
- args: timestamp
66
+ args: timestamp,
67
67
  }
68
68
  end
69
69
 
@@ -71,9 +71,9 @@ module Utils
71
71
  # ! payload for converting a block to a different type.
72
72
  # ! id -> id of the block to convert : ``str``
73
73
  # ! block_class_to_convert_to -> type to convert to block to: ``NotionAPI::<Block_Type>``
74
- table = 'block'
74
+ table = "block"
75
75
  path = []
76
- command = 'update'
76
+ command = "update"
77
77
 
78
78
  {
79
79
  id: id,
@@ -81,8 +81,8 @@ module Utils
81
81
  path: path,
82
82
  command: command,
83
83
  args: {
84
- type: block_class_to_convert_to.notion_type
85
- }
84
+ type: block_class_to_convert_to.notion_type,
85
+ },
86
86
  }
87
87
  end
88
88
 
@@ -90,10 +90,10 @@ module Utils
90
90
  # ! payload for setting a blocks parent ID to 'alive'
91
91
  # ! block_parent_id -> the blocks parent ID : ``str``
92
92
  # ! new_block_id -> the new block ID, who is a child of the parent : ``str``
93
- table = 'block'
93
+ table = "block"
94
94
  path = []
95
- command = 'update'
96
- parent_table = 'block'
95
+ command = "update"
96
+ parent_table = "block"
97
97
  alive = true
98
98
  {
99
99
  id: new_block_id,
@@ -103,17 +103,17 @@ module Utils
103
103
  args: {
104
104
  parent_id: block_parent_id,
105
105
  parent_table: parent_table,
106
- alive: alive
107
- }
106
+ alive: alive,
107
+ },
108
108
  }
109
109
  end
110
110
 
111
111
  def self.set_block_to_dead(block_id)
112
112
  # ! payload for setting a block to dead (alive == true)
113
113
  # ! block_id -> the block ID to 'kill' : ``str``
114
- table = 'block'
114
+ table = "block"
115
115
  path = []
116
- command = 'update'
116
+ command = "update"
117
117
  alive = false
118
118
 
119
119
  {
@@ -122,8 +122,8 @@ module Utils
122
122
  path: path,
123
123
  command: command,
124
124
  args: {
125
- alive: alive
126
- }
125
+ alive: alive,
126
+ },
127
127
  }
128
128
  end
129
129
 
@@ -136,10 +136,10 @@ module Utils
136
136
  # ! new_block_id -> id of new block : ``str``
137
137
  # ! user_notion_id -> ID of notion user : ``str``
138
138
  # ! contents -> The children of the block
139
- timestamp = DateTime.now.strftime('%Q')
140
- table = 'block'
139
+ timestamp = DateTime.now.strftime("%Q")
140
+ table = "block"
141
141
  path = []
142
- command = 'update'
142
+ command = "update"
143
143
 
144
144
  {
145
145
  id: new_block_id,
@@ -151,17 +151,17 @@ module Utils
151
151
  version: 10,
152
152
  type: block_type,
153
153
  properties: {
154
- title: [[block_title]]
154
+ title: [[block_title]],
155
155
  },
156
156
  content: contents, # root-level blocks
157
157
  created_time: timestamp,
158
158
  last_edited_time: timestamp,
159
- created_by_table: 'notion_user',
159
+ created_by_table: "notion_user",
160
160
  created_by_id: user_notion_id,
161
- last_edited_by_table: 'notion_user',
161
+ last_edited_by_table: "notion_user",
162
162
  last_edited_by_id: user_notion_id,
163
- copied_from: block_id
164
- }
163
+ copied_from: block_id,
164
+ },
165
165
  }
166
166
  end
167
167
 
@@ -169,10 +169,10 @@ module Utils
169
169
  # ! payload for adding a parent
170
170
  # ! block_parent_id -> the parent id of the block : ``str``
171
171
  # ! block_id -> the id of the block : ``str``
172
- table = 'block'
172
+ table = "block"
173
173
  path = []
174
- command = 'update'
175
- parent_table = 'block'
174
+ command = "update"
175
+ parent_table = "block"
176
176
  alive = true
177
177
 
178
178
  {
@@ -183,8 +183,8 @@ module Utils
183
183
  args: {
184
184
  parent_id: block_parent_id,
185
185
  parent_table: parent_table,
186
- alive: alive
187
- }
186
+ alive: alive,
187
+ },
188
188
  }
189
189
  end
190
190
 
@@ -196,27 +196,27 @@ module Utils
196
196
  # ! new_block_id -> id of the new block: ``str``
197
197
  # ! target -> the ID of the target block : ``str``
198
198
  # ! command -> the position of the block, before or after, in relation to the target : ``str``
199
- table = 'block'
200
- path = ['content']
199
+ table = "block"
200
+ path = ["content"]
201
201
 
202
- args = if command == 'listAfter'
203
- {
202
+ args = if command == "listAfter"
203
+ {
204
204
  after: target || block_id,
205
- id: new_block_id || block_id
205
+ id: new_block_id || block_id,
206
206
  }
207
- else
208
- {
207
+ else
208
+ {
209
209
  before: target || block_id,
210
- id: new_block_id || block_id
210
+ id: new_block_id || block_id,
211
211
  }
212
- end
212
+ end
213
213
 
214
214
  {
215
215
  table: table,
216
216
  id: block_parent_id, # ID of the parent for the new block. It should be the block that the method is invoked on.
217
217
  path: path,
218
218
  command: command,
219
- args: args
219
+ args: args,
220
220
  }
221
221
  end
222
222
 
@@ -224,17 +224,17 @@ module Utils
224
224
  # ! removes a notion block
225
225
  # ! block_parent_id -> the parent ID of the block to remove : ``str``
226
226
  # ! block_id -> the ID of the block to remove : ``str``
227
- table = 'block'
228
- path = ['content']
229
- command = 'listRemove'
227
+ table = "block"
228
+ path = ["content"]
229
+ command = "listRemove"
230
230
  {
231
231
  table: table,
232
232
  id: block_parent_id, # ID of the parent for the new block. It should be the block that the method is invoked on.
233
233
  path: path,
234
234
  command: command,
235
235
  args: {
236
- id: block_id
237
- }
236
+ id: block_id,
237
+ },
238
238
  }
239
239
  end
240
240
 
@@ -242,17 +242,17 @@ module Utils
242
242
  # ! payload for setting a "checked" value for TodoBlock.
243
243
  # ! block_id -> the ID of the block to remove : ``str``
244
244
  # ! standardized_check_val -> tyes/no value, determines the checked property of the block : ``str``
245
- table = 'block'
246
- path = ['properties']
247
- command = 'update'
245
+ table = "block"
246
+ path = ["properties"]
247
+ command = "update"
248
248
  {
249
249
  id: block_id,
250
250
  table: table,
251
251
  path: path,
252
252
  command: command,
253
253
  args: {
254
- checked: [[standardized_check_val]]
255
- }
254
+ checked: [[standardized_check_val]],
255
+ },
256
256
  }
257
257
  end
258
258
 
@@ -260,9 +260,9 @@ module Utils
260
260
  # ! update the language for a codeblock
261
261
  # ! block_id -> id of the code block
262
262
  # ! coding_language -> language to change the block to.
263
- table = 'block'
264
- path = ['properties']
265
- command = 'update'
263
+ table = "block"
264
+ path = ["properties"]
265
+ command = "update"
266
266
 
267
267
  {
268
268
  id: block_id,
@@ -270,8 +270,8 @@ module Utils
270
270
  path: path,
271
271
  command: command,
272
272
  args: {
273
- language: [[coding_language]]
274
- }
273
+ language: [[coding_language]],
274
+ },
275
275
  }
276
276
  end
277
277
  end
@@ -282,12 +282,12 @@ module Utils
282
282
  # ! new_block_id -> id of the new block
283
283
  # ! collection_id -> ID of the collection.
284
284
  # ! view_ids -> id of the view
285
- table = 'block'
286
- command = 'update'
285
+ table = "block"
286
+ command = "update"
287
287
  path = []
288
- type = 'collection_view'
288
+ type = "collection_view"
289
289
  properties = {}
290
- timestamp = DateTime.now.strftime('%Q')
290
+ timestamp = DateTime.now.strftime("%Q")
291
291
 
292
292
  {
293
293
  id: new_block_id,
@@ -299,12 +299,12 @@ module Utils
299
299
  type: type,
300
300
  collection_id: collection_id,
301
301
  view_ids: [
302
- view_ids
302
+ view_ids,
303
303
  ],
304
304
  properties: properties,
305
305
  created_time: timestamp,
306
- last_edited_time: timestamp
307
- }
306
+ last_edited_time: timestamp,
307
+ },
308
308
  }
309
309
  end
310
310
 
@@ -312,14 +312,14 @@ module Utils
312
312
  # ! payload for setting the collection blocks to alive.
313
313
  # ! new_block_id -> id of the new block
314
314
  # ! collection_id -> ID of the collection.
315
- table = 'block'
315
+ table = "block"
316
316
  path = []
317
- command = 'update'
318
- parent_table = 'collection'
317
+ command = "update"
318
+ parent_table = "collection"
319
319
  alive = true
320
- type = 'page'
320
+ type = "page"
321
321
  properties = {}
322
- timestamp = DateTime.now.strftime('%Q')
322
+ timestamp = DateTime.now.strftime("%Q")
323
323
 
324
324
  {
325
325
  id: new_block_id,
@@ -334,23 +334,22 @@ module Utils
334
334
  alive: alive,
335
335
  properties: properties,
336
336
  created_time: timestamp,
337
- last_edited_time: timestamp
338
- }
337
+ last_edited_time: timestamp,
338
+ },
339
339
  }
340
340
  end
341
341
 
342
- def self.set_view_config(new_block_id, view_id, children_ids)
342
+ def self.set_view_config(collection_type, new_block_id, view_id, children_ids)
343
343
  # ! payload for setting the configurations of the view.
344
344
  # ! new_block_id -> id of the new block
345
345
  # ! view_id -> id of the view
346
346
  # ! children_ids -> IDs for the children of the collection.
347
- table = 'collection_view'
347
+ table = "collection_view"
348
348
  path = []
349
- command = 'update'
349
+ command = "update"
350
350
  version = 0
351
- type = 'table'
352
- name = 'Default View'
353
- parent_table = 'block'
351
+ name = "Default View"
352
+ parent_table = "block"
354
353
  alive = true
355
354
 
356
355
  {
@@ -361,13 +360,13 @@ module Utils
361
360
  args: {
362
361
  id: view_id,
363
362
  version: version,
364
- type: type,
363
+ type: collection_type,
365
364
  name: name,
366
365
  page_sort: children_ids,
367
366
  parent_id: new_block_id,
368
367
  parent_table: parent_table,
369
- alive: alive
370
- }
368
+ alive: alive,
369
+ },
371
370
  }
372
371
  end
373
372
 
@@ -377,75 +376,86 @@ module Utils
377
376
  # ! new_block_id -> id of the new block
378
377
  # ! data -> json data to insert into table.
379
378
  col_names = data[0].keys
379
+ data_mappings = {Integer => "number", String => "text", Array => "text", Float => "number", Date => "date"}
380
+ exceptions = [ArgumentError, TypeError]
381
+ data_types = col_names.map do |name|
382
+ # TODO: this is a little hacky... should probably think about a better way or add a requirement for user input to match a certain criteria.
383
+ begin
384
+ DateTime.parse(data[0][name]) ? data_mappings[Date] : nil
385
+ rescue *exceptions
386
+ data_mappings[data[0][name].class]
387
+ end
388
+ end
380
389
 
381
390
  schema_conf = {}
382
391
  col_names.each_with_index do |_name, i|
383
392
  if i.zero?
384
- schema_conf[:title] = { name: col_names[i], type: 'title' }
393
+ schema_conf[:title] = { name: col_names[i], type: "title" }
385
394
  else
386
- schema_conf[col_names[i]] = { name: col_names[i], type: 'text' }
395
+ schema_conf[col_names[i]] = { name: col_names[i], type: data_types[i] }
387
396
  end
388
397
  end
389
- {
398
+ return {
390
399
  id: collection_id,
391
- table: 'collection',
400
+ table: "collection",
392
401
  path: [],
393
- command: 'update',
402
+ command: "update",
394
403
  args: {
395
404
  id: collection_id,
396
405
  schema: schema_conf,
397
406
  parent_id: new_block_id,
398
- parent_table: 'block',
399
- alive: true
400
- }
401
- }
407
+ parent_table: "block",
408
+ alive: true,
409
+ },
410
+ }, data_types
402
411
  end
403
412
 
404
413
  def self.set_collection_title(collection_title, collection_id)
405
414
  # ! payload for setting the title of the collection.
406
415
  # ! collection_title -> title of the collection.
407
416
  # ! collection_id -> ID of the collection.
408
- table = 'collection'
409
- path = ['name']
410
- command = 'set'
417
+ table = "collection"
418
+ path = ["name"]
419
+ command = "set"
411
420
 
412
421
  {
413
422
  id: collection_id,
414
423
  table: table,
415
424
  path: path,
416
425
  command: command,
417
- args: [[collection_title]]
426
+ args: [[collection_title]],
418
427
  }
419
428
  end
420
429
 
421
- def self.insert_data(block_id, column, value)
430
+ def self.insert_data(block_id, column, value, mapping)
422
431
  # ! payload for inserting data into the table.
423
432
  # ! block_id -> the ID of the block : ``str``
424
433
  # ! column -> the name of the column to insert data into.
425
434
  # ! value -> the value to insert into the column.
426
- table = 'block'
435
+ # ! mapping -> the column data type.
436
+ table = "block"
427
437
  path = [
428
- 'properties',
429
- column
438
+ "properties",
439
+ column,
430
440
  ]
431
- command = 'set'
441
+ command = "set"
432
442
 
433
443
  {
434
444
  id: block_id,
435
445
  table: table,
436
446
  path: path,
437
447
  command: command,
438
- args: [[value]]
448
+ args: mapping == "date" ? [["‣",[["d",{"type": "date","start_date": value}]]]] : [[value]],
439
449
  }
440
450
  end
441
451
 
442
452
  def self.add_new_row(new_block_id)
443
453
  # ! payload for adding a new row to the table.
444
454
  # ! new_block_id -> the ID of the new row : ``str``
445
- table = 'block'
455
+ table = "block"
446
456
  path = []
447
- command = 'set'
448
- type = 'page'
457
+ command = "set"
458
+ type = "page"
449
459
 
450
460
  {
451
461
  id: new_block_id,
@@ -455,29 +465,29 @@ module Utils
455
465
  args: {
456
466
  type: type,
457
467
  id: new_block_id,
458
- version: 1
459
- }
468
+ version: 1,
469
+ },
460
470
  }
461
471
  end
462
472
 
463
- def self.query_collection(collection_id, view_id, search_query = '')
473
+ def self.query_collection(collection_id, view_id, search_query = "")
464
474
  # ! payload for querying the table for data.
465
475
  # ! collection_id -> the collection ID : ``str``
466
476
  # ! view_id -> the view ID : ``str``
467
477
  # ! search_query -> the query for searching the table : ``str``
468
478
  query = {}
469
479
  loader = {
470
- type: 'table',
480
+ type: "table",
471
481
  limit: 100,
472
482
  searchQuery: search_query,
473
- loadContentCover: true
483
+ loadContentCover: true,
474
484
  }
475
485
 
476
486
  {
477
487
  collectionId: collection_id,
478
488
  collectionViewId: view_id,
479
489
  query: query,
480
- loader: loader
490
+ loader: loader,
481
491
  }
482
492
  end
483
493
 
@@ -485,12 +495,56 @@ module Utils
485
495
  # ! payload for adding a column to the table.
486
496
  # ! collection_id -> the collection ID : ``str``
487
497
  # ! args -> the definition of the column : ``str``
498
+ args["format"] = {
499
+ "table_properties" => [
500
+ {
501
+ "property" => "title",
502
+ "visible" => true,
503
+ "width" => 280,
504
+ },
505
+ {
506
+ "property" => "aliases",
507
+ "visible" => true,
508
+ "width" => 200,
509
+ },
510
+ {
511
+ "property" => "category",
512
+ "visible" => true,
513
+ "width" => 200,
514
+ },
515
+ {
516
+ "property" => "description",
517
+ "visible" => true,
518
+ "width" => 200,
519
+ },
520
+ {
521
+ "property" => "ios_version",
522
+ "visible" => true,
523
+ "width" => 200,
524
+ },
525
+ {
526
+ "property" => "tags",
527
+ "visible" => true,
528
+ "width" => 200,
529
+ },
530
+ {
531
+ "property" => "phone",
532
+ "visible" => true,
533
+ "width" => 200,
534
+ },
535
+ {
536
+ "property" => "unicode_version",
537
+ "visible" => true,
538
+ "width" => 200,
539
+ }
540
+ ],
541
+ }
488
542
  {
489
543
  id: collection_id,
490
- table: 'collection',
544
+ table: "collection",
491
545
  path: [],
492
- command: 'update',
493
- args: args
546
+ command: "update",
547
+ args: args,
494
548
  }
495
549
  end
496
550
  end
@@ -509,9 +563,9 @@ module Utils
509
563
  id: transaction_id,
510
564
  shardId: 955_090,
511
565
  spaceId: space_id,
512
- operations: operations
513
- }
514
- ]
566
+ operations: operations,
567
+ },
568
+ ],
515
569
  }
516
570
  payload
517
571
  end
@@ -1,3 +1,3 @@
1
1
  module NotionAPI
2
- VERSION = '1.0.0'
2
+ VERSION = '1.0.1'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: notion
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dan Murphy
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-11-26 00:00:00.000000000 Z
11
+ date: 2020-11-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty