BigW Consortium Gitlab

response.rb 508 Bytes
Newer Older
1 2
module Github
  class Response
3
    attr_reader :raw, :headers, :status
4

5 6 7 8 9 10 11
    def initialize(response)
      @raw     = response
      @headers = response.headers
      @status  = response.status
    end

    def body
12
      Oj.load(raw.body, class_cache: false, mode: :compat)
13 14 15 16 17 18 19 20 21 22 23 24 25
    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