v3: rename account to owner (so we can use account for private accounts api)

This commit is contained in:
Konstantin Haase 2015-04-17 12:44:04 +02:00
parent 3680fcf389
commit 344979a2a8
9 changed files with 30 additions and 30 deletions
lib/travis/api/v3
spec/v3

View File

@ -1,5 +1,5 @@
module Travis::API::V3
class Queries::Account < Query
class Queries::Owner < Query
def find
find!(:organization) || find!(:user)
end
@ -7,8 +7,8 @@ module Travis::API::V3
private
def query(type, main_type: self.main_type, params: self.params)
main_type = type if main_type == :account
params = params.merge("#{type}.login" => params["account.login".freeze]) if params["account.login".freeze]
main_type = type if main_type == :owner
params = params.merge("#{type}.login" => params["owner.login".freeze]) if params["owner.login".freeze]
Queries[type].new(params, main_type)
end

View File

@ -1,6 +1,6 @@
require 'travis/api/v3/renderer/model_renderer'
require 'travis/api/v3/renderer/owner'
module Travis::API::V3
class Renderer::Organization < Renderer::Account
class Renderer::Organization < Renderer::Owner
end
end

View File

@ -2,7 +2,7 @@ require 'travis/api/v3/renderer/model_renderer'
require 'travis/api/v3/renderer/avatar_url'
module Travis::API::V3
class Renderer::Account < Renderer::ModelRenderer
class Renderer::Owner < Renderer::ModelRenderer
include Renderer::AvatarURL
representation(:minimal, :id, :login)

View File

@ -1,7 +1,7 @@
require 'travis/api/v3/renderer/model_renderer'
require 'travis/api/v3/renderer/owner'
module Travis::API::V3
class Renderer::User < Renderer::Account
class Renderer::User < Renderer::Owner
representation(:standard, :is_syncing, :synced_at)
end
end

View File

@ -3,8 +3,8 @@ module Travis::API::V3
require 'travis/api/v3/routes/dsl'
extend DSL
resource :account do
route '/account/({account.login}|{user.login}|{organization.login})'
resource :owner do
route '/owner/({owner.login}|{user.login}|{organization.login})'
get :find
end

View File

@ -2,11 +2,11 @@ module Travis::API::V3
module Services
extend ConstantResolver
Account = Module.new { extend Services }
Branch = Module.new { extend Services }
Build = Module.new { extend Services }
Organization = Module.new { extend Services }
Organizations = Module.new { extend Services }
Owner = Module.new { extend Services }
Repositories = Module.new { extend Services }
Repository = Module.new { extend Services }
Requests = Module.new { extend Services }

View File

@ -1,17 +1,17 @@
module Travis::API::V3
class Services::Account::Find < Service
class Services::Owner::Find < Service
def result_type
@result_type ||= super
end
def run!
account = find
@result_type = type_for(account)
account
owner = find
@result_type = type_for(owner)
owner
end
def type_for(account)
case account
def type_for(owner)
case owner
when Models::User then :user
when Models::Organization then :organization
end

View File

@ -90,16 +90,16 @@ describe Travis::API::V3::ServiceIndex do
end
end
describe "account resource" do
let(:resource) { resources.fetch("account") }
specify { expect(resources) .to include("account") }
describe "owner resource" do
let(:resource) { resources.fetch("owner") }
specify { expect(resources) .to include("owner") }
specify { expect(resource["@type"]) .to be == "resource" }
describe "find action" do
let(:action) { resource.fetch("actions").fetch("find") }
specify { expect(action).to include("@type"=>"template", "request_method"=>"GET", "uri_template"=>"#{path}account/{account.login}{?include}") }
specify { expect(action).to include("@type"=>"template", "request_method"=>"GET", "uri_template"=>"#{path}account/{user.login}{?include}") }
specify { expect(action).to include("@type"=>"template", "request_method"=>"GET", "uri_template"=>"#{path}account/{organization.login}{?include}") }
specify { expect(action).to include("@type"=>"template", "request_method"=>"GET", "uri_template"=>"#{path}owner/{owner.login}{?include}") }
specify { expect(action).to include("@type"=>"template", "request_method"=>"GET", "uri_template"=>"#{path}owner/{user.login}{?include}") }
specify { expect(action).to include("@type"=>"template", "request_method"=>"GET", "uri_template"=>"#{path}owner/{organization.login}{?include}") }
end
end

View File

@ -1,13 +1,13 @@
require 'spec_helper'
describe Travis::API::V3::Services::Account::Find do
describe Travis::API::V3::Services::Owner::Find do
describe "organization" do
let(:org) { Organization.new(login: 'example-org') }
before { org.save! }
after { org.delete }
describe 'existing org, public api' do
before { get("/v3/account/example-org") }
before { get("/v3/owner/example-org") }
example { expect(last_response).to be_ok }
example { expect(JSON.load(body)).to be == {
"@type" => "organization",
@ -21,7 +21,7 @@ describe Travis::API::V3::Services::Account::Find do
end
describe 'it is not case sensitive' do
before { get("/v3/account/example-ORG") }
before { get("/v3/owner/example-ORG") }
example { expect(last_response).to be_ok }
example { expect(JSON.load(body)).to be == {
"@type" => "organization",
@ -39,7 +39,7 @@ describe Travis::API::V3::Services::Account::Find do
before { other.save! }
after { other.delete }
before { get("/v3/account/example-org?organization.id=#{other.id}") }
before { get("/v3/owner/example-org?organization.id=#{other.id}") }
example { expect(last_response).to be_ok }
example { expect(JSON.load(body)).to be == {
"@type" => "organization",
@ -59,7 +59,7 @@ describe Travis::API::V3::Services::Account::Find do
after { user.delete }
describe 'existing user, public api' do
before { get("/v3/account/example-user") }
before { get("/v3/owner/example-user") }
example { expect(last_response).to be_ok }
example { expect(JSON.load(body)).to be == {
"@type" => "user",
@ -75,7 +75,7 @@ describe Travis::API::V3::Services::Account::Find do
end
describe 'it is not case sensitive' do
before { get("/v3/account/example-USER") }
before { get("/v3/owner/example-USER") }
example { expect(last_response).to be_ok }
example { expect(JSON.load(body)).to be == {
"@type" => "user",
@ -95,7 +95,7 @@ describe Travis::API::V3::Services::Account::Find do
before { other.save! }
after { other.delete }
before { get("/v3/account/example-user?user.id=#{other.id}") }
before { get("/v3/owner/example-user?user.id=#{other.id}") }
example { expect(last_response).to be_ok }
example { expect(JSON.load(body)).to be == {
"@type" => "user",