Module: Gzr::User
- Included in:
- Commands::Alert::Import, Commands::Alert::Randomize, Commands::Dashboard::Import, Commands::Look::Import, Commands::Plan::Import, Commands::Plan::Randomize, Commands::User::Cat, Commands::User::Delete, Commands::User::Disable, Commands::User::Enable, Commands::User::Ls, Commands::User::Me
- Defined in:
- lib/gzr/modules/user.rb
Instance Method Summary collapse
- #delete_user(id) ⇒ Object
- #query_all_users(fields = nil, sorts = nil) ⇒ Object
- #query_me(fields = 'id') ⇒ Object
- #query_user(id, fields = 'id') ⇒ Object
- #search_users(filter, fields = nil, sorts = nil) ⇒ Object
- #trim_user(data) ⇒ Object
- #update_user(id, req) ⇒ Object
Instance Method Details
#delete_user(id) ⇒ Object
116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/gzr/modules/user.rb', line 116 def delete_user(id) begin @sdk.delete_user(id) rescue LookerSDK::NotFound => e say_error "delete user(#{id},#{JSON.pretty_generate(req)}) not found" say_error e raise rescue LookerSDK::Error => e say_error "Error deleting user(#{id})" say_error e raise end end |
#query_all_users(fields = nil, sorts = nil) ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/gzr/modules/user.rb', line 77 def query_all_users(fields=nil, sorts=nil) req = { :limit=>64 } req[:fields] = fields if fields req[:sorts] = sorts if sorts data = Array.new begin loop do page = @sdk.all_users(req).collect { |r| r.to_attrs } data+=page break unless page.length == req[:limit] req[:offset] = (req[:offset] || 0) + req[:limit] end rescue LookerSDK::NotFound => e # do nothing rescue LookerSDK::ClientError => e say_error "Unable to get all_users(#{JSON.pretty_generate(req)})" say_error e raise end data end |
#query_me(fields = 'id') ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'lib/gzr/modules/user.rb', line 27 def query_me(fields='id') begin @sdk.me(fields ? {:fields=>fields} : nil ).to_attrs rescue LookerSDK::Error => e say_error "Error querying me({:fields=>\"#{fields}\"})" say_error e raise end end |
#query_user(id, fields = 'id') ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/gzr/modules/user.rb', line 37 def query_user(id,fields='id') begin @sdk.user(id, fields ? {:fields=>fields} : nil ).to_attrs rescue LookerSDK::NotFound => e say_error "user(#{id}) not found" say_error e raise rescue LookerSDK::Error => e say_error "Error querying user(#{id},{:fields=>\"#{fields}\"})" say_error e raise end end |
#search_users(filter, fields = nil, sorts = nil) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/gzr/modules/user.rb', line 51 def search_users(filter, fields=nil, sorts=nil) req = { :limit=>64 } req.merge!(filter) req[:fields] = fields if fields req[:sorts] = sorts if sorts data = Array.new begin loop do page = @sdk.search_users(req).collect { |r| r.to_attrs } data+=page break unless page.length == req[:limit] req[:offset] = (req[:offset] || 0) + req[:limit] end rescue LookerSDK::NotFound => e # do nothing rescue LookerSDK::ClientError => e say_error "Unable to get search_users(#{JSON.pretty_generate(req)})" say_error e raise end data end |
#trim_user(data) ⇒ Object
130 131 132 133 134 |
# File 'lib/gzr/modules/user.rb', line 130 def trim_user(data) data.select do |k,v| (keys_to_keep('create_user') + [:id]).include? k end end |
#update_user(id, req) ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/gzr/modules/user.rb', line 102 def update_user(id,req) begin @sdk.update_user(id,req)&.to_attrs rescue LookerSDK::NotFound => e say_error "updating user(#{id},#{JSON.pretty_generate(req)}) not found" say_error e raise rescue LookerSDK::Error => e say_error "Error updating user(#{id},#{JSON.pretty_generate(req)})" say_error e raise end end |