Class: ShopifyClient::ParseLinkHeader

Inherits:
Object
  • Object
show all
Defined in:
lib/shopify-client/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).

Parameters:

  • link_header (String)

Returns:

  • (Hash)


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

def call(link_header)
  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,
      params(url),
    ]
  end.to_h
end