Class: Rack::Auth::Travis::Request

Inherits:
AbstractRequest
  • Object
show all
Defined in:
lib/rack/auth/travis.rb

Constant Summary collapse

JSON_REGEXP =
/^application\/([\w!#\$%&\*`\-\.\^~]*\+)?json$/i

Instance Method Summary collapse

Constructor Details

#initialize(env, authenticators = Travis.default_authenticators) ⇒ Request

Returns a new instance of Request.



96
97
98
99
# File 'lib/rack/auth/travis.rb', line 96

def initialize(env, authenticators = Travis.default_authenticators)
  super(env)
  @authenticators = authenticators || []
end

Instance Method Details

#json?Boolean

Returns:

  • (Boolean)


105
106
107
# File 'lib/rack/auth/travis.rb', line 105

def json?
  request.env['CONTENT_TYPE'] =~ JSON_REGEXP
end

#nameObject



121
122
123
# File 'lib/rack/auth/travis.rb', line 121

def name
  @name ||= repository['name']
end

#owner_nameObject



117
118
119
# File 'lib/rack/auth/travis.rb', line 117

def owner_name
  @owner ||= repository['owner_name']
end

#repo_slugObject



125
126
127
# File 'lib/rack/auth/travis.rb', line 125

def repo_slug
  [owner_name, name].join('/')
end

#tokenObject



129
130
131
# File 'lib/rack/auth/travis.rb', line 129

def token
  @token ||= parts.first.to_s
end

#travis?Boolean

Returns:

  • (Boolean)


101
102
103
# File 'lib/rack/auth/travis.rb', line 101

def travis?
  token =~ /[\da-f]{64}/i
end

#valid?Boolean

Returns:

  • (Boolean)


109
110
111
112
113
114
115
# 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