-
-
Save gugat/735c11df2d41dffcadd692e49f5d839c to your computer and use it in GitHub Desktop.
Parse link headers from Postman API in Ruby
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rest_client' | |
class parse_link_headers | |
def self.parse_link_header(url, params={}) | |
response = RestClient.get url, params | |
links = Hash.new | |
parts = response.headers[:link].split(',') | |
# Parse each part into a named link | |
parts.each do |part, index| | |
section = part.split(';') | |
url = section[0][/<(.*)>/,1] | |
name = section[1][/rel="(.*)"/,1].to_sym | |
results = section[2][/results="(.*)"/,1].to_sym | |
links[name] = url if results | |
end | |
return links | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment