class Github::Response
Contains methods and attributes that act on the response returned from the request
Constants
- CONTENT_TYPE
Attributes
parser[RW]
Public Class Methods
define_parser(&block)
click to toggle source
# File lib/github_api/response.rb, line 14 def self.define_parser(&block) @parser = block end
new(app, options = {})
click to toggle source
Calls superclass method
# File lib/github_api/response.rb, line 18 def initialize(app, options = {}) super(app) @content_types = Array(options[:content_type]) end
Public Instance Methods
parse_body?(env)
click to toggle source
# File lib/github_api/response.rb, line 27 def parse_body?(env) parse_response_type?(response_type(env)) and parse_response?(env) end
parse_response?(env)
click to toggle source
# File lib/github_api/response.rb, line 43 def parse_response?(env) env[:body].respond_to?(:to_str) end
parse_response_type?(type)
click to toggle source
# File lib/github_api/response.rb, line 37 def parse_response_type?(type) @content_types.empty? || @content_types.any? { |pattern| pattern.is_a?(Regexp) ? type =~ pattern : type == pattern } end
process_body(env)
click to toggle source
# File lib/github_api/response.rb, line 23 def process_body(env) env[:body] = parse(env[:body]) end
response_type(env)
click to toggle source
# File lib/github_api/response.rb, line 31 def response_type(env) type = env[:response_headers][CONTENT_TYPE].to_s type = type.split(';', 2).first if type.index(';') type end