Module: Grafana::Users
- Included in:
- Client
- Defined in:
- lib/grafana/users.rb
Instance Method Summary collapse
- #get_all_users ⇒ Object
- #get_user_by_id(id) ⇒ Object
- #get_user_orgs(userid) ⇒ Object
- #search_for_users_by(search = {}) ⇒ Object
- #update_user_info(id, properties = {}) ⇒ Object
Instance Method Details
#get_all_users ⇒ Object
6 7 8 9 10 |
# File 'lib/grafana/users.rb', line 6 def get_all_users() endpoint = "/api/users" @logger.info("Getting all users (GET #{endpoint})") if @debug return get_request(endpoint) end |
#get_user_by_id(id) ⇒ Object
12 13 14 15 16 |
# File 'lib/grafana/users.rb', line 12 def get_user_by_id(id) endpoint = "/api/users/#{id}" @logger.info("Getting user ID #{id} (GET #{endpoint})") if @debug return get_request(endpoint) end |
#get_user_orgs(userid) ⇒ Object
43 44 45 46 47 |
# File 'lib/grafana/users.rb', line 43 def get_user_orgs(userid) endpoint = "/api/users/#{userid}/orgs" @logger.info("Getting organizations for user #{id} (GET #{endpoint})") if @debug return get_request(endpoint) end |
#search_for_users_by(search = {}) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/grafana/users.rb', line 18 def search_for_users_by(search={}) all_users = self.get_all_users() key, value = search.first @logger.info("Searching for users matching #{key} = #{value}") if @debug users = [] all_users.each do |u| if u[key] && u[key] == value users.push(u) end end return (users.length >= 1 ? users : false) end |
#update_user_info(id, properties = {}) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/grafana/users.rb', line 31 def update_user_info(id, properties={}) endpoint = "/api/users/#{id}" @logger.info("Updating user ID #{id}") if @debug existing_user = self.get_user(id) if !existing_user @logger.error("User #{id} does not exist") if @debug return false end properties = existing_user.merge(properties) return put_request(endpoint,properties.to_json) end |