work on router
This commit is contained in:
parent
a65792ee49
commit
afbf30f1c0
|
@ -36,7 +36,7 @@ GIT
|
|||
|
||||
GIT
|
||||
remote: git://github.com/travis-ci/travis-core.git
|
||||
revision: 8fa9680a47ab457187ddf3a88461a756a6f4c2a6
|
||||
revision: cbfb6da8a1c6f4cc80c40b260d4d2708e3acec03
|
||||
specs:
|
||||
travis-core (0.0.1)
|
||||
actionmailer (~> 3.2.19)
|
||||
|
@ -74,7 +74,7 @@ GIT
|
|||
|
||||
GIT
|
||||
remote: git://github.com/travis-ci/travis-yaml.git
|
||||
revision: f3aa306016a08b66a487f966eb8aa3a60ee9b319
|
||||
revision: 1630d576d221aea2340615e87f402df7889b5176
|
||||
specs:
|
||||
travis-yaml (0.2.0)
|
||||
|
||||
|
|
|
@ -1,9 +1,24 @@
|
|||
module Travis::API::V3
|
||||
class Result
|
||||
attr_accessor :resource
|
||||
attr_accessor :type, :resource
|
||||
|
||||
def initialize(resource = nil)
|
||||
@resource = resource
|
||||
def initialize(type, 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
|
||||
|
|
|
@ -12,9 +12,30 @@ module Travis::API::V3
|
|||
end
|
||||
|
||||
def call(env)
|
||||
access_control = AccessControl.new(env)
|
||||
p access_control
|
||||
not_found
|
||||
access_control = AccessControl.new(env)
|
||||
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
|
||||
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
|
||||
|
|
|
@ -4,6 +4,7 @@ module Travis::API::V3
|
|||
extend DSL
|
||||
|
||||
resource :repository do
|
||||
route '/repo/:id'
|
||||
get :find_repository
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,5 +1,38 @@
|
|||
require 'travis/api/v3/routes/resource'
|
||||
require 'mustermann'
|
||||
|
||||
module Travis::API::V3
|
||||
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
|
||||
|
|
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
|
||||
raise NotFound unless repository and access_control.visible? repository
|
||||
Result.new(repository)
|
||||
Result.new(:repository, repository)
|
||||
end
|
||||
|
||||
def repository
|
||||
|
|
|
@ -12,15 +12,16 @@ Gem::Specification.new do |s|
|
|||
"Piotr Sarnacki",
|
||||
"Konstantin Haase",
|
||||
"Sven Fuchs",
|
||||
"Hiro Asari",
|
||||
"Mathias Meyer",
|
||||
"Hiro Asari",
|
||||
"Josh Kalderimis",
|
||||
"Henrik Hodne",
|
||||
"Andre Arko",
|
||||
"Erik Michaels-Ober",
|
||||
"Dan Buch",
|
||||
"Erik Michaels-Ober",
|
||||
"Steve Richert",
|
||||
"Brian Ford",
|
||||
"Patrick Williams",
|
||||
"Bryan Goldstein",
|
||||
"Puneeth Chaganti",
|
||||
"Thais Camilo and Konstantin Haase",
|
||||
|
@ -29,37 +30,37 @@ Gem::Specification.new do |s|
|
|||
"James Dennes",
|
||||
"rainsun",
|
||||
"Dan Rice",
|
||||
"Nick Schonning",
|
||||
"Patrick Williams"
|
||||
"Nick Schonning"
|
||||
]
|
||||
|
||||
s.email = [
|
||||
"drogus@gmail.com",
|
||||
"konstantin.mailinglists@googlemail.com",
|
||||
"me@svenfuchs.com",
|
||||
"asari.ruby@gmail.com",
|
||||
"meyer@paperplanes.de",
|
||||
"asari.ruby@gmail.com",
|
||||
"josh.kalderimis@gmail.com",
|
||||
"me@henrikhodne.com",
|
||||
"henrik@hodne.io",
|
||||
"konstantin.haase@gmail.com",
|
||||
"andre@arko.net",
|
||||
"svenfuchs@artweb-design.de",
|
||||
"sferik@gmail.com",
|
||||
"dan@travis-ci.org",
|
||||
"sferik@gmail.com",
|
||||
"steve.richert@gmail.com",
|
||||
"bford@engineyard.com",
|
||||
"henrik@travis-ci.com",
|
||||
"punchagan@muse-amuse.in",
|
||||
"brysgo@gmail.com",
|
||||
"jdennes@gmail.com",
|
||||
"rainsuner@gmail.com",
|
||||
"dev+narwen+rkh@rkh.im",
|
||||
"tim@spork.in",
|
||||
"e@zzak.io",
|
||||
"jdennes@gmail.com",
|
||||
"punchagan@muse-amuse.in",
|
||||
"dan@zoombody.com",
|
||||
"dan@meatballhat.com",
|
||||
"nschonni@gmail.com",
|
||||
"patrick@bittorrent.com",
|
||||
"brysgo@gmail.com"
|
||||
"patrick@bittorrent.com"
|
||||
]
|
||||
|
||||
s.files = [
|
||||
|
@ -154,6 +155,23 @@ Gem::Specification.new do |s|
|
|||
"lib/travis/api/v2/http/ssl_key.rb",
|
||||
"lib/travis/api/v2/http/user.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",
|
||||
"public/favicon.ico",
|
||||
"public/images/result/canceled.png",
|
||||
|
|
Loading…
Reference in New Issue
Block a user