work on router
This commit is contained in:
parent
a65792ee49
commit
afbf30f1c0
|
@ -36,7 +36,7 @@ GIT
|
||||||
|
|
||||||
GIT
|
GIT
|
||||||
remote: git://github.com/travis-ci/travis-core.git
|
remote: git://github.com/travis-ci/travis-core.git
|
||||||
revision: 8fa9680a47ab457187ddf3a88461a756a6f4c2a6
|
revision: cbfb6da8a1c6f4cc80c40b260d4d2708e3acec03
|
||||||
specs:
|
specs:
|
||||||
travis-core (0.0.1)
|
travis-core (0.0.1)
|
||||||
actionmailer (~> 3.2.19)
|
actionmailer (~> 3.2.19)
|
||||||
|
@ -74,7 +74,7 @@ GIT
|
||||||
|
|
||||||
GIT
|
GIT
|
||||||
remote: git://github.com/travis-ci/travis-yaml.git
|
remote: git://github.com/travis-ci/travis-yaml.git
|
||||||
revision: f3aa306016a08b66a487f966eb8aa3a60ee9b319
|
revision: 1630d576d221aea2340615e87f402df7889b5176
|
||||||
specs:
|
specs:
|
||||||
travis-yaml (0.2.0)
|
travis-yaml (0.2.0)
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,24 @@
|
||||||
module Travis::API::V3
|
module Travis::API::V3
|
||||||
class Result
|
class Result
|
||||||
attr_accessor :resource
|
attr_accessor :type, :resource
|
||||||
|
|
||||||
def initialize(resource = nil)
|
def initialize(type, resource = [])
|
||||||
@resource = resource
|
@type, @resource = type, resource
|
||||||
|
end
|
||||||
|
|
||||||
|
def respond_to_missing?(method, *)
|
||||||
|
super or method.to_sym == type.to_sym
|
||||||
|
end
|
||||||
|
|
||||||
|
def <<(value)
|
||||||
|
resource << value
|
||||||
|
self
|
||||||
|
end
|
||||||
|
|
||||||
|
def method_missing(method, *args)
|
||||||
|
return super unless method.to_sym == type.to_sym
|
||||||
|
raise ArgumentError, 'wrong number of arguments (1 for 0)'.freeze if args.any?
|
||||||
|
resource
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -13,8 +13,29 @@ module Travis::API::V3
|
||||||
|
|
||||||
def call(env)
|
def call(env)
|
||||||
access_control = AccessControl.new(env)
|
access_control = AccessControl.new(env)
|
||||||
p access_control
|
factory, params = @routes.factory_for(env['REQUEST_METHOD'.freeze], env['PATH_INFO'.freeze])
|
||||||
|
env_params = params(env)
|
||||||
|
if factory
|
||||||
|
service = factory.new(access_control, env_params.merge(params))
|
||||||
|
result = service.run
|
||||||
|
render(result, env_params)
|
||||||
|
else
|
||||||
not_found
|
not_found
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def params(env)
|
||||||
|
request = Rack::Request.new(env)
|
||||||
|
params = request.params
|
||||||
|
media_type = request.media_type
|
||||||
|
|
||||||
|
if media_type == 'application/json'.freeze or media_type == 'text/json'.freeze
|
||||||
|
request.body.rewind
|
||||||
|
json_params = env['travis.input.json'.freeze] ||= JSON.load(request.body)
|
||||||
|
params.merge! json_params if json_params.is_a? Hash
|
||||||
|
end
|
||||||
|
|
||||||
|
params
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -4,6 +4,7 @@ module Travis::API::V3
|
||||||
extend DSL
|
extend DSL
|
||||||
|
|
||||||
resource :repository do
|
resource :repository do
|
||||||
|
route '/repo/:id'
|
||||||
get :find_repository
|
get :find_repository
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,5 +1,38 @@
|
||||||
|
require 'travis/api/v3/routes/resource'
|
||||||
|
require 'mustermann'
|
||||||
|
|
||||||
module Travis::API::V3
|
module Travis::API::V3
|
||||||
module Routes::DSL
|
module Routes::DSL
|
||||||
def resource(*) end
|
def resources
|
||||||
|
@resources ||= []
|
||||||
|
end
|
||||||
|
|
||||||
|
def current_resource
|
||||||
|
@current_resource ||= nil
|
||||||
|
end
|
||||||
|
|
||||||
|
def resource(type, &block)
|
||||||
|
resource = Routes::Resource.new(type)
|
||||||
|
with_resource(resource, &block)
|
||||||
|
resources << resource
|
||||||
|
end
|
||||||
|
|
||||||
|
def with_resource(resource)
|
||||||
|
resource_was, @current_resource = current_resource, resource
|
||||||
|
yield
|
||||||
|
ensure
|
||||||
|
@current_resource = resource_was
|
||||||
|
end
|
||||||
|
|
||||||
|
def route(value)
|
||||||
|
current_resource.route = Mustermann.new(value)
|
||||||
|
end
|
||||||
|
|
||||||
|
def get(*args)
|
||||||
|
current_resource.add_service('GET'.freeze, *args)
|
||||||
|
end
|
||||||
|
|
||||||
|
def factory_for(method, path)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
15
lib/travis/api/v3/routes/resource.rb
Normal file
15
lib/travis/api/v3/routes/resource.rb
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
module Travis::API::V3
|
||||||
|
class Routes::Resource
|
||||||
|
attr_accessor :identifier, :route, :services
|
||||||
|
|
||||||
|
def initialize(identifier)
|
||||||
|
@identifier = identifier
|
||||||
|
@services = {}
|
||||||
|
end
|
||||||
|
|
||||||
|
def add_service(request_method, service, sub_route = '')
|
||||||
|
services[request_method] ||= {}
|
||||||
|
services[request_method][sub_route] = service
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -4,7 +4,7 @@ module Travis::API::V3
|
||||||
|
|
||||||
def run
|
def run
|
||||||
raise NotFound unless repository and access_control.visible? repository
|
raise NotFound unless repository and access_control.visible? repository
|
||||||
Result.new(repository)
|
Result.new(:repository, repository)
|
||||||
end
|
end
|
||||||
|
|
||||||
def repository
|
def repository
|
||||||
|
|
|
@ -12,15 +12,16 @@ Gem::Specification.new do |s|
|
||||||
"Piotr Sarnacki",
|
"Piotr Sarnacki",
|
||||||
"Konstantin Haase",
|
"Konstantin Haase",
|
||||||
"Sven Fuchs",
|
"Sven Fuchs",
|
||||||
"Hiro Asari",
|
|
||||||
"Mathias Meyer",
|
"Mathias Meyer",
|
||||||
|
"Hiro Asari",
|
||||||
"Josh Kalderimis",
|
"Josh Kalderimis",
|
||||||
"Henrik Hodne",
|
"Henrik Hodne",
|
||||||
"Andre Arko",
|
"Andre Arko",
|
||||||
"Erik Michaels-Ober",
|
|
||||||
"Dan Buch",
|
"Dan Buch",
|
||||||
|
"Erik Michaels-Ober",
|
||||||
"Steve Richert",
|
"Steve Richert",
|
||||||
"Brian Ford",
|
"Brian Ford",
|
||||||
|
"Patrick Williams",
|
||||||
"Bryan Goldstein",
|
"Bryan Goldstein",
|
||||||
"Puneeth Chaganti",
|
"Puneeth Chaganti",
|
||||||
"Thais Camilo and Konstantin Haase",
|
"Thais Camilo and Konstantin Haase",
|
||||||
|
@ -29,37 +30,37 @@ Gem::Specification.new do |s|
|
||||||
"James Dennes",
|
"James Dennes",
|
||||||
"rainsun",
|
"rainsun",
|
||||||
"Dan Rice",
|
"Dan Rice",
|
||||||
"Nick Schonning",
|
"Nick Schonning"
|
||||||
"Patrick Williams"
|
|
||||||
]
|
]
|
||||||
|
|
||||||
s.email = [
|
s.email = [
|
||||||
"drogus@gmail.com",
|
"drogus@gmail.com",
|
||||||
"konstantin.mailinglists@googlemail.com",
|
"konstantin.mailinglists@googlemail.com",
|
||||||
"me@svenfuchs.com",
|
"me@svenfuchs.com",
|
||||||
"asari.ruby@gmail.com",
|
|
||||||
"meyer@paperplanes.de",
|
"meyer@paperplanes.de",
|
||||||
|
"asari.ruby@gmail.com",
|
||||||
"josh.kalderimis@gmail.com",
|
"josh.kalderimis@gmail.com",
|
||||||
"me@henrikhodne.com",
|
"me@henrikhodne.com",
|
||||||
"henrik@hodne.io",
|
"henrik@hodne.io",
|
||||||
"konstantin.haase@gmail.com",
|
"konstantin.haase@gmail.com",
|
||||||
"andre@arko.net",
|
"andre@arko.net",
|
||||||
"svenfuchs@artweb-design.de",
|
"svenfuchs@artweb-design.de",
|
||||||
"sferik@gmail.com",
|
|
||||||
"dan@travis-ci.org",
|
"dan@travis-ci.org",
|
||||||
|
"sferik@gmail.com",
|
||||||
"steve.richert@gmail.com",
|
"steve.richert@gmail.com",
|
||||||
"bford@engineyard.com",
|
"bford@engineyard.com",
|
||||||
"henrik@travis-ci.com",
|
"henrik@travis-ci.com",
|
||||||
"punchagan@muse-amuse.in",
|
"brysgo@gmail.com",
|
||||||
|
"jdennes@gmail.com",
|
||||||
"rainsuner@gmail.com",
|
"rainsuner@gmail.com",
|
||||||
"dev+narwen+rkh@rkh.im",
|
"dev+narwen+rkh@rkh.im",
|
||||||
"tim@spork.in",
|
"tim@spork.in",
|
||||||
"e@zzak.io",
|
"e@zzak.io",
|
||||||
"jdennes@gmail.com",
|
"punchagan@muse-amuse.in",
|
||||||
"dan@zoombody.com",
|
"dan@zoombody.com",
|
||||||
|
"dan@meatballhat.com",
|
||||||
"nschonni@gmail.com",
|
"nschonni@gmail.com",
|
||||||
"patrick@bittorrent.com",
|
"patrick@bittorrent.com"
|
||||||
"brysgo@gmail.com"
|
|
||||||
]
|
]
|
||||||
|
|
||||||
s.files = [
|
s.files = [
|
||||||
|
@ -154,6 +155,23 @@ Gem::Specification.new do |s|
|
||||||
"lib/travis/api/v2/http/ssl_key.rb",
|
"lib/travis/api/v2/http/ssl_key.rb",
|
||||||
"lib/travis/api/v2/http/user.rb",
|
"lib/travis/api/v2/http/user.rb",
|
||||||
"lib/travis/api/v2/http/validation_error.rb",
|
"lib/travis/api/v2/http/validation_error.rb",
|
||||||
|
"lib/travis/api/v3.rb",
|
||||||
|
"lib/travis/api/v3/access_control.rb",
|
||||||
|
"lib/travis/api/v3/access_control/anonymous.rb",
|
||||||
|
"lib/travis/api/v3/access_control/application.rb",
|
||||||
|
"lib/travis/api/v3/access_control/generic.rb",
|
||||||
|
"lib/travis/api/v3/access_control/legacy_token.rb",
|
||||||
|
"lib/travis/api/v3/access_control/scoped.rb",
|
||||||
|
"lib/travis/api/v3/access_control/signature.rb",
|
||||||
|
"lib/travis/api/v3/access_control/user.rb",
|
||||||
|
"lib/travis/api/v3/opt_in.rb",
|
||||||
|
"lib/travis/api/v3/result.rb",
|
||||||
|
"lib/travis/api/v3/router.rb",
|
||||||
|
"lib/travis/api/v3/routes.rb",
|
||||||
|
"lib/travis/api/v3/routes/dsl.rb",
|
||||||
|
"lib/travis/api/v3/service.rb",
|
||||||
|
"lib/travis/api/v3/services.rb",
|
||||||
|
"lib/travis/api/v3/services/find_repository.rb",
|
||||||
"lib/travis/private_key.rb",
|
"lib/travis/private_key.rb",
|
||||||
"public/favicon.ico",
|
"public/favicon.ico",
|
||||||
"public/images/result/canceled.png",
|
"public/images/result/canceled.png",
|
||||||
|
|
Loading…
Reference in New Issue
Block a user