@@ -72,6 +72,35 @@ def children_ids(url_or_id = @id)
72
72
jsonified_record_response [ "block" ] [ clean_id ] [ "value" ] [ "content" ] || [ ]
73
73
end
74
74
75
+ def extract_id ( url_or_id )
76
+ # ! parse and clean the URL or ID object provided.
77
+ # ! url_or_id -> the block ID or URL : ``str``
78
+ http_or_https = url_or_id . match ( /^(http|https)/ ) # true if http or https in url_or_id...
79
+ collection_view_match = url_or_id . match ( /(\? v=)/ )
80
+
81
+ if ( url_or_id . length == 36 ) && ( ( url_or_id . split ( "-" ) . length == 5 ) && !http_or_https )
82
+ # passes if url_or_id is perfectly formatted already...
83
+ url_or_id
84
+ elsif ( http_or_https && ( url_or_id . split ( "-" ) . last . length == 32 ) ) || ( !http_or_https && ( url_or_id . length == 32 ) ) || ( collection_view_match )
85
+ # passes if either:
86
+ # 1. a URL is passed as url_or_id and the ID at the end is 32 characters long or
87
+ # 2. a URL is not passed and the ID length is 32 [aka unformatted]
88
+ pattern = [ 8 , 13 , 18 , 23 ]
89
+ if collection_view_match
90
+ id_without_view = url_or_id . split ( "?" ) [ 0 ]
91
+ clean_id = id_without_view . split ( "/" ) . last
92
+ pattern . each { |index | clean_id . insert ( index , "-" ) }
93
+ clean_id
94
+ else
95
+ id = url_or_id . split ( "-" ) . last
96
+ pattern . each { |index | id . insert ( index , "-" ) }
97
+ id
98
+ end
99
+ else
100
+ raise ArgumentError , "Expected a Notion page URL or a page ID. Please consult the documentation for further information."
101
+ end
102
+ end
103
+
75
104
private
76
105
77
106
def get_notion_id ( body )
@@ -205,34 +234,34 @@ def extract_view_ids(clean_id, jsonified_record_response)
205
234
jsonified_record_response [ "block" ] [ clean_id ] [ "value" ] [ "view_ids" ] || [ ]
206
235
end
207
236
208
- def extract_id ( url_or_id )
209
- # ! parse and clean the URL or ID object provided.
210
- # ! url_or_id -> the block ID or URL : ``str``
211
- http_or_https = url_or_id . match ( /^(http|https)/ ) # true if http or https in url_or_id...
212
- collection_view_match = url_or_id . match ( /(\? v=)/ )
213
-
214
- if ( url_or_id . length == 36 ) && ( ( url_or_id . split ( "-" ) . length == 5 ) && !http_or_https )
215
- # passes if url_or_id is perfectly formatted already...
216
- url_or_id
217
- elsif ( http_or_https && ( url_or_id . split ( "-" ) . last . length == 32 ) ) || ( !http_or_https && ( url_or_id . length == 32 ) ) || ( collection_view_match )
218
- # passes if either:
219
- # 1. a URL is passed as url_or_id and the ID at the end is 32 characters long or
220
- # 2. a URL is not passed and the ID length is 32 [aka unformatted]
221
- pattern = [ 8 , 13 , 18 , 23 ]
222
- if collection_view_match
223
- id_without_view = url_or_id . split ( "?" ) [ 0 ]
224
- clean_id = id_without_view . split ( "/" ) . last
225
- pattern . each { |index | clean_id . insert ( index , "-" ) }
226
- clean_id
227
- else
228
- id = url_or_id . split ( "-" ) . last
229
- pattern . each { |index | id . insert ( index , "-" ) }
230
- id
231
- end
232
- else
233
- raise ArgumentError , "Expected a Notion page URL or a page ID. Please consult the documentation for further information."
234
- end
235
- end
237
+ # def extract_id(url_or_id)
238
+ # # ! parse and clean the URL or ID object provided.
239
+ # # ! url_or_id -> the block ID or URL : ``str``
240
+ # http_or_https = url_or_id.match(/^(http|https)/) # true if http or https in url_or_id...
241
+ # collection_view_match = url_or_id.match(/(\?v=)/)
242
+
243
+ # if (url_or_id.length == 36) && ((url_or_id.split("-").length == 5) && !http_or_https)
244
+ # # passes if url_or_id is perfectly formatted already...
245
+ # url_or_id
246
+ # elsif (http_or_https && (url_or_id.split("-").last.length == 32)) || (!http_or_https && (url_or_id.length == 32)) || (collection_view_match)
247
+ # # passes if either:
248
+ # # 1. a URL is passed as url_or_id and the ID at the end is 32 characters long or
249
+ # # 2. a URL is not passed and the ID length is 32 [aka unformatted]
250
+ # pattern = [8, 13, 18, 23]
251
+ # if collection_view_match
252
+ # id_without_view = url_or_id.split("?")[0]
253
+ # clean_id = id_without_view.split("/").last
254
+ # pattern.each { |index| clean_id.insert(index, "-") }
255
+ # clean_id
256
+ # else
257
+ # id = url_or_id.split("-").last
258
+ # pattern.each { |index| id.insert(index, "-") }
259
+ # id
260
+ # end
261
+ # else
262
+ # raise ArgumentError, "Expected a Notion page URL or a page ID. Please consult the documentation for further information."
263
+ # end
264
+ # end
236
265
237
266
def extract_collection_schema ( collection_id , view_id , response = { } )
238
267
# ! retrieve the collection scehma. Useful for 'building' the backbone for a table.
0 commit comments