Module: TreasureData::API::User

Included in:
TreasureData::API
Defined in:
lib/td/client/api/user.rb

Instance Method Summary collapse

Instance Method Details

#add_apikey(user) ⇒ true

Parameters:

  • user (String)

Returns:

  • (true)


89
90
91
92
93
94
95
# File 'lib/td/client/api/user.rb', line 89

def add_apikey(user)
  code, body, res = post("/v3/user/apikey/add/#{e user}")
  if code != "200"
    raise_error("Adding API key failed", res)
  end
  return true
end

#add_user(name, org, email, password) ⇒ true

Parameters:

  • name (String)
  • org (String)
  • email (String)
  • password (String)

Returns:

  • (true)


45
46
47
48
49
50
51
52
# File 'lib/td/client/api/user.rb', line 45

def add_user(name, org, email, password)
  params = {'organization'=>org, :email=>email, :password=>password}
  code, body, res = post("/v3/user/add/#{e name}", params)
  if code != "200"
    raise_error("Adding user failed", res)
  end
  return true
end

#authenticate(user, password) ⇒ String

Returns API key.

Parameters:

  • user (String)
  • password (String)

Returns:

  • (String)

    API key



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/td/client/api/user.rb', line 11

def authenticate(user, password)
  code, body, res = post("/v3/user/authenticate", {'user'=>user, 'password'=>password})
  if code != "200"
    if code == "400"
      raise_error("Authentication failed", res, AuthError)
    else
      raise_error("Authentication failed", res)
    end
  end
  js = checked_json(body, %w[apikey])
  apikey = js['apikey']
  return apikey
end

#change_email(user, email) ⇒ true

Parameters:

  • user (String)
  • email (String)

Returns:

  • (true)


67
68
69
70
71
72
73
74
# File 'lib/td/client/api/user.rb', line 67

def change_email(user, email)
  params = {'email' => email}
  code, body, res = post("/v3/user/email/change/#{e user}", params)
  if code != "200"
    raise_error("Changing email failed", res)
  end
  return true
end

#change_my_password(old_password, password) ⇒ true

Parameters:

  • old_password (String)
  • password (String)

Returns:

  • (true)


124
125
126
127
128
129
130
131
# File 'lib/td/client/api/user.rb', line 124

def change_my_password(old_password, password)
  params = {'old_password' => old_password, 'password' => password}
  code, body, res = post("/v3/user/password/change", params)
  if code != "200"
    raise_error("Changing password failed", res)
  end
  return true
end

#change_password(user, password) ⇒ true

Parameters:

  • user (String)
  • password (String)

Returns:

  • (true)


112
113
114
115
116
117
118
119
# File 'lib/td/client/api/user.rb', line 112

def change_password(user, password)
  params = {'password' => password}
  code, body, res = post("/v3/user/password/change/#{e user}", params)
  if code != "200"
    raise_error("Changing password failed", res)
  end
  return true
end

#list_apikeys(user) ⇒ Array<String>

Returns API keys as array.

Parameters:

  • user (String)

Returns:

  • (Array<String>)

    API keys as array



78
79
80
81
82
83
84
85
# File 'lib/td/client/api/user.rb', line 78

def list_apikeys(user)
  code, body, res = get("/v3/user/apikey/list/#{e user}")
  if code != "200"
    raise_error("List API keys failed", res)
  end
  js = checked_json(body, %w[apikeys])
  return js['apikeys']
end

#list_usersArray

Returns:

  • (Array)


26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/td/client/api/user.rb', line 26

def list_users
  code, body, res = get("/v3/user/list")
  if code != "200"
    raise_error("List users failed", res)
  end
  js = checked_json(body, %w[users])
  result = js["users"].map {|roleinfo|
    name = roleinfo['name']
    email = roleinfo['email']
    [name, nil, nil, email] # set nil to org and role for API compatibility
  }
  return result
end

#remove_apikey(user, apikey) ⇒ true

Parameters:

  • user (String)
  • apikey (String)

Returns:

  • (true)


100
101
102
103
104
105
106
107
# File 'lib/td/client/api/user.rb', line 100

def remove_apikey(user, apikey)
  params = {'apikey' => apikey}
  code, body, res = post("/v3/user/apikey/remove/#{e user}", params)
  if code != "200"
    raise_error("Removing API key failed", res)
  end
  return true
end

#remove_user(user) ⇒ true

Parameters:

  • user (String)

Returns:

  • (true)


56
57
58
59
60
61
62
# File 'lib/td/client/api/user.rb', line 56

def remove_user(user)
  code, body, res = post("/v3/user/remove/#{e user}")
  if code != "200"
    raise_error("Removing user failed", res)
  end
  return true
end