v3: add /org/:id endpoint
This commit is contained in:
parent
32c2d9b0b9
commit
b84a0a492b
|
@ -20,6 +20,10 @@ module Travis::API::V3
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
|
def organization_visible?(organization)
|
||||||
|
unrestricted_api?
|
||||||
|
end
|
||||||
|
|
||||||
def repository_visible?(repository)
|
def repository_visible?(repository)
|
||||||
return true if unrestricted_api? and not repository.private?
|
return true if unrestricted_api? and not repository.private?
|
||||||
private_repository_visible?(repository)
|
private_repository_visible?(repository)
|
||||||
|
|
10
lib/travis/api/v3/queries/organization.rb
Normal file
10
lib/travis/api/v3/queries/organization.rb
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
module Travis::API::V3
|
||||||
|
class Queries::Organization < Query
|
||||||
|
params :id
|
||||||
|
|
||||||
|
def find
|
||||||
|
return ::Organization.find_by_id(id) if id
|
||||||
|
raise WrongParams
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -3,8 +3,12 @@ module Travis::API::V3
|
||||||
DIRECT_ATTRIBUTES = %i[id login name github_id]
|
DIRECT_ATTRIBUTES = %i[id login name github_id]
|
||||||
extend self
|
extend self
|
||||||
|
|
||||||
def render(organization, **)
|
def render(organization, script_name: nil, **)
|
||||||
{ :@type => 'organization'.freeze, **direct_attributes(organization) }
|
{
|
||||||
|
:@type => 'organization'.freeze,
|
||||||
|
:@href => Renderer.href(:organization, id: organization.id, script_name: script_name),
|
||||||
|
**direct_attributes(organization)
|
||||||
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
def direct_attributes(repository)
|
def direct_attributes(repository)
|
||||||
|
|
|
@ -19,6 +19,11 @@ module Travis::API::V3
|
||||||
get :for_current_user
|
get :for_current_user
|
||||||
end
|
end
|
||||||
|
|
||||||
|
resource :organization do
|
||||||
|
route '/org/{organization.id}'
|
||||||
|
get :find
|
||||||
|
end
|
||||||
|
|
||||||
resource :organizations do
|
resource :organizations do
|
||||||
route '/orgs'
|
route '/orgs'
|
||||||
get :for_current_user
|
get :for_current_user
|
||||||
|
|
13
lib/travis/api/v3/service_helpers/organization.rb
Normal file
13
lib/travis/api/v3/service_helpers/organization.rb
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
module Travis::API::V3
|
||||||
|
module ServiceHelpers::Organization
|
||||||
|
def organization
|
||||||
|
@organization ||= find_organization
|
||||||
|
end
|
||||||
|
|
||||||
|
def find_organization
|
||||||
|
not_found(true, :organization) unless org = query(:organization).find
|
||||||
|
not_found(false, :organization) unless access_control.visible? org
|
||||||
|
org
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -2,6 +2,7 @@ module Travis::API::V3
|
||||||
module Services
|
module Services
|
||||||
extend ConstantResolver
|
extend ConstantResolver
|
||||||
|
|
||||||
|
Organization = Module.new { extend Services }
|
||||||
Organizations = Module.new { extend Services }
|
Organizations = Module.new { extend Services }
|
||||||
Repositories = Module.new { extend Services }
|
Repositories = Module.new { extend Services }
|
||||||
Repository = Module.new { extend Services }
|
Repository = Module.new { extend Services }
|
||||||
|
|
9
lib/travis/api/v3/services/organization/find.rb
Normal file
9
lib/travis/api/v3/services/organization/find.rb
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
module Travis::API::V3
|
||||||
|
class Services::Organization::Find < Service
|
||||||
|
helpers :organization
|
||||||
|
|
||||||
|
def run!
|
||||||
|
organization
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -14,6 +14,8 @@ describe Travis::API::V3::ServiceIndex do
|
||||||
"for_current_user" => [{"request-method"=>"GET", "uri-template"=>"#{path}repos"}] },
|
"for_current_user" => [{"request-method"=>"GET", "uri-template"=>"#{path}repos"}] },
|
||||||
"organizations" => {
|
"organizations" => {
|
||||||
"for_current_user" => [{"request-method"=>"GET", "uri-template"=>"#{path}orgs"}] },
|
"for_current_user" => [{"request-method"=>"GET", "uri-template"=>"#{path}orgs"}] },
|
||||||
|
"organization" => {
|
||||||
|
"find" => [{"request-method"=>"GET", "uri-template"=>"#{path}org/{organization.id}"}] },
|
||||||
"requests" => {
|
"requests" => {
|
||||||
"find" => [{"request-method"=>"GET", "uri-template"=>"#{path}repo/{repository.id}/requests"}],
|
"find" => [{"request-method"=>"GET", "uri-template"=>"#{path}repo/{repository.id}/requests"}],
|
||||||
"create" => [{"request-method"=>"POST", "uri-template"=>"#{path}repo/{repository.id}/requests"}]}
|
"create" => [{"request-method"=>"POST", "uri-template"=>"#{path}repo/{repository.id}/requests"}]}
|
||||||
|
|
20
spec/v3/services/organization/find_spec.rb
Normal file
20
spec/v3/services/organization/find_spec.rb
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
require 'spec_helper'
|
||||||
|
|
||||||
|
describe Travis::API::V3::Services::Organization::Find do
|
||||||
|
let(:org) { Organization.new(login: 'example-org') }
|
||||||
|
before { org.save! }
|
||||||
|
after { org.delete }
|
||||||
|
|
||||||
|
describe 'existing org, public api' do
|
||||||
|
before { get("/v3/org/#{org.id}") }
|
||||||
|
example { expect(last_response).to be_ok }
|
||||||
|
example { expect(JSON.load(body)).to be == {
|
||||||
|
"@type" => "organization",
|
||||||
|
"@href" => "/v3/org/#{org.id}",
|
||||||
|
"id" => org.id,
|
||||||
|
"login" => "example-org",
|
||||||
|
"name" => nil,
|
||||||
|
"github_id" => nil
|
||||||
|
}}
|
||||||
|
end
|
||||||
|
end
|
|
@ -18,14 +18,15 @@ describe Travis::API::V3::Services::Organizations::ForCurrentUser do
|
||||||
before { get("/v3/orgs", {}, headers) }
|
before { get("/v3/orgs", {}, headers) }
|
||||||
example { expect(last_response).to be_ok }
|
example { expect(last_response).to be_ok }
|
||||||
example { expect(JSON.load(body)).to be == {
|
example { expect(JSON.load(body)).to be == {
|
||||||
"@type" => "organizations",
|
"@type" => "organizations",
|
||||||
"@href" => "/v3/orgs",
|
"@href" => "/v3/orgs",
|
||||||
"organizations" => [{
|
"organizations" => [{
|
||||||
"@type" => "organization",
|
"@type" => "organization",
|
||||||
"id" => org.id,
|
"@href" => "/v3/org/#{org.id}",
|
||||||
"login" => "example-org",
|
"id" => org.id,
|
||||||
"name" => nil,
|
"login" => "example-org",
|
||||||
"github_id" => nil
|
"name" => nil,
|
||||||
|
"github_id" => nil
|
||||||
}]
|
}]
|
||||||
}}
|
}}
|
||||||
end
|
end
|
Loading…
Reference in New Issue
Block a user