gitlab-org--gitlab-foss/lib/github/response.rb

26 lines
508 B
Ruby
Raw Normal View History

2017-04-11 21:33:54 -04:00
module Github
class Response
2017-04-13 12:59:26 -04:00
attr_reader :raw, :headers, :status
2017-04-11 21:33:54 -04:00
2017-04-13 12:59:26 -04:00
def initialize(response)
@raw = response
@headers = response.headers
@status = response.status
end
def body
Oj.load(raw.body, class_cache: false, mode: :compat)
2017-04-11 21:33:54 -04:00
end
def rels
links = headers['Link'].to_s.split(', ').map do |link|
href, name = link.match(/<(.*?)>; rel="(\w+)"/).captures
[name.to_sym, href]
end
Hash[*links.flatten]
end
end
end