Module: ActiveProject::Connections::Base
- Included in:
- GraphQl, HttpClient, Rest
- Defined in:
- lib/active_project/connections/base.rb
Overview
Shared helpers used by both REST and GraphQL modules, because every cult needs a doctrine of “Don’t Repeat Yourself.”
Instance Method Summary collapse
-
#parse_link_header(header) ⇒ Hash{String => String}
—————————————————————— RFC 5988 Link header parsing ——————————————————————.
Instance Method Details
#parse_link_header(header) ⇒ Hash{String => String}
RFC 5988 Link header parsing
Parses your classic overengineered pagination headers.
<https://api.example.com/
REST’s way of pretending it’s not just guessing how many pages there are.
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/active_project/connections/base.rb', line 21 def parse_link_header(header) return {} unless header # Always a good first step: check if we’ve been given absolutely nothing. header.split(",").each_with_object({}) do |part, acc| url, rel = part.split(";", 2) next unless url && rel url = url[/<([^>]+)>/, 1] # Pull the sacred URL from its <> temple. rel = rel[/rel="?([^";]+)"?/, 1] # Decode the rel tag, likely “next,” “prev,” or “you tried.” acc[rel] = url if url && rel end end |