Parent

Class/Module Index [+]

Quicksearch

Github::Request::Jsonize

Public Instance Methods

call(env) click to toggle source
# File lib/github_api/request/jsonize.rb, line 12
def call(env)
  if request_with_body?(env)
    env[:request_headers][CONTENT_TYPE] ||= MIME_TYPE
    env[:body] = encode_body env unless env[:body].respond_to?(:to_str)
  end
  @app.call env
end
encode_body(env) click to toggle source
# File lib/github_api/request/jsonize.rb, line 20
def encode_body(env)
  if MultiJson.respond_to?(:dump)
    MultiJson.dump env[:body]
  else
    MultiJson.encode env[:body]
  end
end
has_body?(env) click to toggle source

Don't encode bodies in string form

# File lib/github_api/request/jsonize.rb, line 34
def has_body?(env)
  body = env[:body] and !(body.respond_to?(:to_str) and body.empty?)
end
request_type(env) click to toggle source
# File lib/github_api/request/jsonize.rb, line 38
def request_type(env)
  type = env[:request_headers][CONTENT_TYPE].to_s
  type = type.split(';', 2).first if type.index(';')
  type
end
request_with_body?(env) click to toggle source
# File lib/github_api/request/jsonize.rb, line 28
def request_with_body?(env)
  type = request_type(env)
  has_body?(env) and (type.empty? or type == MIME_TYPE)
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.