add owner/github_id/:id endpoint

This commit is contained in:
carlad 2015-10-28 13:13:02 +01:00
parent bce9ea5b46
commit 245edc5f55
5 changed files with 7 additions and 3 deletions

View File

@ -1,9 +1,10 @@
module Travis::API::V3
class Queries::Organization < Query
params :id, :login
params :id, :login, :github_id
def find
return Models::Organization.find_by_id(id) if id
return Models::Organization.find_by_github_id(github_id) if github_id
return Models::Organization.where('lower(login) = ?'.freeze, login.downcase).first if login
raise WrongParams, 'missing organization.id or organization.login'.freeze
end

View File

@ -9,6 +9,7 @@ module Travis::API::V3
def query(type, main_type: self.main_type, params: self.params)
main_type = type if main_type == :owner
params = params.merge("#{type}.login" => params["owner.login".freeze]) if params["owner.login".freeze]
params = params.merge("#{type}.github_id" => params["owner.github_id".freeze]) if params["owner.github_id".freeze]
Queries[type].new(params, main_type, service: @service)
end

View File

@ -1,9 +1,10 @@
module Travis::API::V3
class Queries::User < Query
params :id, :login, :email
params :id, :login, :email, :github_id
def find
return Models::User.find_by_id(id) if id
return Models::User.find_by_github_id(github_id) if github_id
return Models::User.where('lower(login) = ?'.freeze, login.downcase).first if login
return find_by_email(email) if email
raise WrongParams, 'missing user.id or user.login'.freeze

View File

@ -12,6 +12,7 @@ module Travis::API::V3
return service_index(env) if env['PATH_INFO'.freeze] == ?/.freeze
access_control = AccessControl.new(env)
factory, params = routes.factory_for(env['REQUEST_METHOD'.freeze], env['PATH_INFO'.freeze])
p factory
env_params = params(env)
raise NotFound unless factory

View File

@ -48,7 +48,7 @@ module Travis::API::V3
end
resource :owner do
route '/owner/({owner.login}|{user.login}|{organization.login})'
route '/owner/({owner.login}|{user.login}|{organization.login}|github_id/{owner.github_id})'
get :find
get :repositories, '/repos'
end