Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add method to get groups for a user #19

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,17 @@
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).

## upcoming

### Added

- Add `get_groups` method for users: https://help.tableau.com/current/api/rest_api/en-us/REST/rest_api_ref.htm#get_groups_for_a_user

### Changed

- Updated to API version 3.7


## [4.0.0] - 2020-11-30

### Changed/Fixed
Expand Down
2 changes: 1 addition & 1 deletion lib/tableau_api/connection.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module TableauApi
class Connection
API_VERSION = '3.1'.freeze
API_VERSION = '3.7'.freeze

include HTTParty
headers 'User-Agent' => "tableau_api/#{::TableauApi::VERSION} Ruby/#{RUBY_VERSION}"
Expand Down
5 changes: 5 additions & 0 deletions lib/tableau_api/resources/users.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ def create(username:, site_role: 'Viewer')
res['tsResponse']['user'] if res.code == 201
end

def get_groups(user_id:)
url = "sites/#{@client.auth.site_id}/users/#{user_id}/groups"
@client.connection.api_get_collection(url, 'groups.group')
end

def list
url = "sites/#{@client.auth.site_id}/users"
@client.connection.api_get_collection(url, 'users.user')
Expand Down
16 changes: 16 additions & 0 deletions spec/resources/users_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,22 @@
end
end

describe '#get_groups' do
# https://help.tableau.com/current/api/rest_api/en-us/REST/rest_api_ref.htm#get_groups_for_a_user
it 'can retrieve groups for a specific user' do
sleep(15) if VCR.current_cassette.recording?
user = client.users.list.find do |u|
u['name'] == 'test'
end
group = client.groups.create(name: 'get_groups test')
expect(client.groups.add_user(group_id: group['id'], user_id: user['id'])).to be true

groups = client.users.get_groups(user_id: user['id'])
group_ids = groups.map { |group| group['id'] }
expect(group_ids).to include?(groups['id'])
end
end

describe '#list' do
# http://onlinehelp.tableau.com/v9.0/api/rest_api/en-us/help.htm#REST/rest_api_ref.htm#Get_Users_on_Site
it 'can list users in a site' do
Expand Down