Module: ATProto::AtUriParser
- Extended by:
- RequestUtils, T::Sig
- Defined in:
- lib/at_protocol/at_uri.rb
Defined Under Namespace
Classes: Rule
Constant Summary collapse
- RuleSets =
[ AtUriParser.create_rule(%r{^#{Regexp.escape("https://")}(bsky\.app)/profile/(.+)/post/([\w]+)$}) do |_, handle, rkey, pds| handle.start_with?("did:") ? did = handle : did = resolve_handle(handle, pds) AtUri.new(repo: did, collection: "app.bsky.feed.post", rkey: rkey) end, AtUriParser.create_rule(%r{^#{Regexp.escape("https://")}(bsky\.app)/profile/(.+)$}) do |_, handle, pds| handle.start_with?("did:") ? did = handle : did = resolve_handle(handle, pds) AtUri.new(repo: did) end, AtUriParser.create_rule(%r{^at://(.+)/(.+)/(\w+)$}) do |handle, collection, rkey, pds| handle.start_with?("did:") ? did = handle : did = resolve_handle(handle, pds) AtUri.new(repo: did, collection: collection, rkey: rkey) end, AtUriParser.create_rule(%r{^at://(.+)/(.+)$}) do |handle, collection, pds| handle.start_with?("did:") ? did = handle : did = resolve_handle(handle, pds) AtUri.new(repo: did, collection: collection) end, AtUriParser.create_rule(%r{^at://(.+)$}) do |handle, pds| handle.start_with?("did:") ? did = handle : did = resolve_handle(handle, pds) AtUri.new(repo: did) end, ]
Class Method Summary collapse
Methods included from RequestUtils
at_uri, create_session_uri, default_authenticated_headers, default_headers, delete_record_uri, delete_session_uri, get_paginated_data, get_post_thread_uri, get_session_uri, mute_actor_uri, query_obj_to_query_params, refresh_session_uri, refresh_token_headers, resolve_handle, upload_blob_uri
Class Method Details
.create_rule(pattern, &block) ⇒ Object
48 49 50 51 52 53 |
# File 'lib/at_protocol/at_uri.rb', line 48 def self.create_rule(pattern, &block) transform = Proc.new do |match_data, pds| block.call(*match_data.captures, pds) end Rule.new(pattern, transform) end |
.parse(url, rulesets, pds: "https://bsky.social") ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/at_protocol/at_uri.rb', line 35 def self.parse(url, rulesets, pds: "https://bsky.social") return url if url.is_a?(AtUri) rulesets.each do |ruleset| match_data = url.match(ruleset.pattern) next unless match_data at_uri = ruleset.transform.call(match_data, pds) return at_uri if at_uri.is_a?(AtUri) end nil end |