Class: Lucid::Shopify::ParseLinkHeader

Inherits:
Object
  • Object
show all
Defined in:
lib/lucid/shopify/parse_link_header.rb

Instance Method Summary collapse

Instance Method Details

#call(link_header) ⇒ Hash

Parse a Link header into query params for each pagination link (e.g. :next, :previous).



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/lucid/shopify/parse_link_header.rb', line 14

def call(link_header)
  return {} if link_header.nil?

  link_header.split(',').map do |link|
    url, rel = link.split(';') # rel should be the first param
    url = url[/<(.*)>/, 1]
    rel = rel[/rel="?(\w+)"?/, 1]

    [rel.to_sym, query_params(url)]
  end.to_h
end