diff --git a/lib/bitbucket_rest_api.rb b/lib/bitbucket_rest_api.rb
index de13095..80f59f7 100644
--- a/lib/bitbucket_rest_api.rb
+++ b/lib/bitbucket_rest_api.rb
@@ -58,30 +58,31 @@ def lookup_constant(const_name)
extend AutoloadHelper
autoload_all 'bitbucket_rest_api',
- :API => 'api',
- :ApiFactory => 'api_factory',
- :Authorization => 'authorization',
- :Authorizations => 'authorizations',
- :Validations => 'validations',
- :ParameterFilter => 'parameter_filter',
- :Normalizer => 'normalizer',
- :Client => 'client',
- :CoreExt => 'core_ext',
- :Request => 'request',
- :Response => 'response',
- :Result => 'result',
-
- :Repos => 'repos',
- #:Error => 'error',
- :Issues => 'issues',
- :User => 'user',
- :Users => 'users',
- :Invitations => 'invitations',
- :Teams => 'teams'
+
+ :API => 'api',
+ :ApiFactory => 'api_factory',
+ :Authorization => 'authorization',
+ :Authorizations => 'authorizations',
+ :Validations => 'validations',
+ :ParameterFilter => 'parameter_filter',
+ :Normalizer => 'normalizer',
+ :Client => 'client',
+ :CoreExt => 'core_ext',
+ :Request => 'request',
+ :Response => 'response',
+ :Result => 'result',
+
+ :Repos => 'repos',
+ #:Error => 'error',
+ :Issues => 'issues',
+ :User => 'user',
+ :Users => 'users',
+ :Invitations => 'invitations',
+ :Privileges => 'privileges',
+ :Teams => 'teams'
#:Teams => 'teams',
#:PullRequests => 'pull_requests',
- #:Users => 'users',
#:Events => 'events',
#:Search => 'search',
#:PageLinks => 'page_links',
diff --git a/lib/bitbucket_rest_api/client.rb b/lib/bitbucket_rest_api/client.rb
index bd594e0..d61357c 100644
--- a/lib/bitbucket_rest_api/client.rb
+++ b/lib/bitbucket_rest_api/client.rb
@@ -51,5 +51,9 @@ def user_api(options = {})
def invitations(options = {})
@invitations ||= ApiFactory.new "Invitations", options
end
+
+ def privileges(options = {})
+ @privileges ||= ApiFactory.new 'Privileges', options
+ end
end # Client
end # BitBucket
diff --git a/lib/bitbucket_rest_api/privileges.rb b/lib/bitbucket_rest_api/privileges.rb
new file mode 100644
index 0000000..49beaf5
--- /dev/null
+++ b/lib/bitbucket_rest_api/privileges.rb
@@ -0,0 +1,56 @@
+# encoding: utf-8
+
+module BitBucket
+ class Privileges < API
+ VALID_KEY_PARAM_NAMES = %w(filter).freeze
+
+ # Creates new Privileges API
+ def initialize(options = {})
+ super(options)
+ end
+
+ # Gets a list of the privileges granted on a repository.
+ #
+ # = Parameters
+ # *filter - Filters for a particular privilege. The acceptable values are:read, write and admin.
+ #
+ # = Examples
+ # bitbucket = BitBucket.new
+ # bitbucket.privileges.list 'user-name', 'repo-name', :filter => "admin"
+ #
+ def list_on_repo(user_name, repo_name, params={})
+ _update_user_repo_params(user_name, repo_name)
+ _validate_user_repo_params(user, repo) unless user? && repo?
+
+ normalize! params
+ filter! VALID_KEY_PARAM_NAMES, params
+
+ response = get_request("/1.0/privileges/#{user}/#{repo.downcase}/", params)
+ return response unless block_given?
+ response.each { |el| yield el }
+ end
+ alias :all_on_repo :list_on_repo
+
+ # Gets a list of all the privilege across all an account's repositories.
+ #
+ # = Parameters
+ # *filter - Filters for a particular privilege. The acceptable values are:read, write and admin.
+ #
+ # = Examples
+ # bitbucket = BitBucket.new
+ # bitbucket.privileges.list 'user-name', :filter => "admin"
+ #
+ def list(user_name, params={})
+ _update_user_repo_params(user_name)
+ _validate_presence_of user_name
+
+ normalize! params
+ filter! VALID_KEY_PARAM_NAMES, params
+
+ response = get_request("/1.0/privileges/#{user}/", params)
+ return response unless block_given?
+ response.each { |el| yield el }
+ end
+ alias :all :list
+ end # Privileges
+end # BitBucket
diff --git a/spec/bitbucket_rest_api/client_spec.rb b/spec/bitbucket_rest_api/client_spec.rb
index 7ab068a..736d614 100644
--- a/spec/bitbucket_rest_api/client_spec.rb
+++ b/spec/bitbucket_rest_api/client_spec.rb
@@ -12,5 +12,6 @@
expect(client.teams).to be_a BitBucket::Teams
expect(client.pull_requests).to be_a BitBucket::Repos::PullRequest
expect(client.oauth).to be_a BitBucket::Request::OAuth
+ expect(client.privileges).to be_a BitBucket::Privileges
end
end
diff --git a/spec/bitbucket_rest_api/privileges_spec.rb b/spec/bitbucket_rest_api/privileges_spec.rb
new file mode 100644
index 0000000..7ff2523
--- /dev/null
+++ b/spec/bitbucket_rest_api/privileges_spec.rb
@@ -0,0 +1,35 @@
+require 'spec_helper'
+
+describe BitBucket::Privileges do
+ subject { described_class.new }
+
+ describe '#list_on_repo' do
+ before do
+ expect(subject).to receive(:request).with(
+ :get,
+ "/1.0/privileges/mock_username/mock_repo/",
+ { 'filter' => 'admin' },
+ {}
+ )
+ end
+
+ it 'sends a GET request for privileges granted on the given repo filtered with filter param' do
+ subject.list_on_repo('mock_username', 'mock_repo', filter: "admin")
+ end
+ end
+
+ describe '#list' do
+ before do
+ expect(subject).to receive(:request).with(
+ :get,
+ "/1.0/privileges/mock_username/",
+ { 'filter' => 'admin' },
+ {}
+ )
+ end
+
+ it "sends a GET request for privileges granted on all user's repositories filtered with filter param" do
+ subject.list('mock_username', filter: "admin")
+ end
+ end
+end