diff --git a/lib/travis/api/v3/service.rb b/lib/travis/api/v3/service.rb index 78c0eadc..ea54a2c5 100644 --- a/lib/travis/api/v3/service.rb +++ b/lib/travis/api/v3/service.rb @@ -1,9 +1,5 @@ module Travis::API::V3 class Service - def self.helpers(*list) - include(*list.map { |e| ServiceHelpers[e] }) - end - def self.result_type(type = nil) @result_type = type if type @result_type ||= parent.result_type if parent and parent.respond_to? :result_type @@ -23,6 +19,12 @@ module Travis::API::V3 @queries[type] ||= Queries[type].new(params) end + def find(type = self.class.result_type, *args) + not_found(true, type) unless object = query(type).find(*args) + not_found(false, type) unless access_control.visible? object + object + end + def not_found(actually_not_found = false, type = nil) type, actually_not_found = actually_not_found, false if actually_not_found.is_a? Symbol error = actually_not_found ? EntityMissing : NotFound diff --git a/lib/travis/api/v3/service_helpers/organization.rb b/lib/travis/api/v3/service_helpers/organization.rb deleted file mode 100644 index 5ce58f81..00000000 --- a/lib/travis/api/v3/service_helpers/organization.rb +++ /dev/null @@ -1,13 +0,0 @@ -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 diff --git a/lib/travis/api/v3/service_helpers/repository.rb b/lib/travis/api/v3/service_helpers/repository.rb deleted file mode 100644 index 71ba9336..00000000 --- a/lib/travis/api/v3/service_helpers/repository.rb +++ /dev/null @@ -1,13 +0,0 @@ -module Travis::API::V3 - module ServiceHelpers::Repository - def repository - @repository ||= find_repository - end - - def find_repository - not_found(true, :repository) unless repo = query(:repository).find - not_found(false, :repository) unless access_control.visible? repo - repo - end - end -end diff --git a/lib/travis/api/v3/services/organization/find.rb b/lib/travis/api/v3/services/organization/find.rb index 21280be9..20bb8ed5 100644 --- a/lib/travis/api/v3/services/organization/find.rb +++ b/lib/travis/api/v3/services/organization/find.rb @@ -1,9 +1,7 @@ module Travis::API::V3 class Services::Organization::Find < Service - helpers :organization - def run! - organization + find end end end diff --git a/lib/travis/api/v3/services/repository/find.rb b/lib/travis/api/v3/services/repository/find.rb index 29309a38..3efff57b 100644 --- a/lib/travis/api/v3/services/repository/find.rb +++ b/lib/travis/api/v3/services/repository/find.rb @@ -1,9 +1,7 @@ module Travis::API::V3 class Services::Repository::Find < Service - helpers :repository - def run! - repository + find end end end diff --git a/lib/travis/api/v3/services/requests/create.rb b/lib/travis/api/v3/services/requests/create.rb index 0e6729c1..1f734aaf 100644 --- a/lib/travis/api/v3/services/requests/create.rb +++ b/lib/travis/api/v3/services/requests/create.rb @@ -1,10 +1,8 @@ module Travis::API::V3 class Services::Requests::Create < Service - helpers :repository - def run not_implemented - query.schedule_for(repository) + query.schedule_for(find(:repository)) accepted end end diff --git a/lib/travis/api/v3/services/requests/find.rb b/lib/travis/api/v3/services/requests/find.rb index 573d5201..80383bbe 100644 --- a/lib/travis/api/v3/services/requests/find.rb +++ b/lib/travis/api/v3/services/requests/find.rb @@ -1,5 +1,4 @@ module Travis::API::V3 class Services::Requests::Find < Service - helpers :repository end end