class Rack::Auth::Travis::Request

Constants

JSON_REGEXP

Public Class Methods

new(env, authenticators = Travis.default_authenticators) click to toggle source
Calls superclass method
# File lib/rack/auth/travis.rb, line 96
def initialize(env, authenticators = Travis.default_authenticators)
  super(env)
  @authenticators = authenticators || []
end

Public Instance Methods

json?() click to toggle source
# File lib/rack/auth/travis.rb, line 105
def json?
  request.env['CONTENT_TYPE'] =~ JSON_REGEXP
end
name() click to toggle source
# File lib/rack/auth/travis.rb, line 121
def name
  @name ||= repository['name']
end
owner_name() click to toggle source
# File lib/rack/auth/travis.rb, line 117
def owner_name
  @owner ||= repository['owner_name']
end
repo_slug() click to toggle source
# File lib/rack/auth/travis.rb, line 125
def repo_slug
  [owner_name, name].join('/')
end
token() click to toggle source
# File lib/rack/auth/travis.rb, line 129
def token
  @token ||= parts.first.to_s
end
travis?() click to toggle source
# File lib/rack/auth/travis.rb, line 101
def travis?
  token =~ /[\da-f]{64}/i
end
valid?() click to toggle source
# File lib/rack/auth/travis.rb, line 109
def valid?
  return false unless provided? && travis? && json?
  @authenticators.each do |authenticator|
    return true if authenticator.valid?(self)
  end
  false
end

Private Instance Methods

repository() click to toggle source
# File lib/rack/auth/travis.rb, line 135
def repository
  @repository ||= ((
    JSON.parse(request_body) || {}
  )['payload'] || {})['repository'] || {}
rescue
  {}
end
request_body() click to toggle source
# File lib/rack/auth/travis.rb, line 143
def request_body
  @request_body ||= begin
                      body = request.env['rack.input'].read
                      request.env['rack.input'].rewind
                      body
                    end
end