Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
佳 邓
Gitlab4j Api
Commits
41f6f41f
Commit
41f6f41f
authored
Mar 04, 2014
by
Greg Messner
Browse files
Added support for create user API call.
parent
c008705b
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/main/java/com/messners/gitlab/api/AbstractApi.java
View file @
41f6f41f
...
...
@@ -120,5 +120,32 @@ public abstract class AbstractApi {
throws
UniformInterfaceException
,
ClientHandlerException
{
return
(
getApiClient
().
delete
(
queryParams
,
url
));
}
}
/**
*
* @param formData
* @param string
* @param email
* @param required
*/
protected
void
addFormParam
(
Form
formData
,
String
name
,
Object
value
,
boolean
required
)
throws
IllegalArgumentException
{
if
(
value
==
null
)
{
if
(
required
)
{
throw
new
IllegalArgumentException
(
name
+
" cannot be empty or null"
);
}
return
;
}
String
stringValue
=
value
.
toString
().
trim
();
if
(
required
&&
stringValue
.
length
()
==
0
)
{
throw
new
IllegalArgumentException
(
name
+
" cannot be empty or null"
);
}
formData
.
add
(
name
,
stringValue
);
}
}
\ No newline at end of file
src/main/java/com/messners/gitlab/api/UserApi.java
View file @
41f6f41f
package
com.messners.gitlab.api
;
import
java.io.IOException
;
import
java.util.List
;
import
com.messners.gitlab.api.models.ErrorMessage
;
import
com.messners.gitlab.api.models.User
;
import
com.sun.jersey.api.client.ClientResponse
;
import
com.sun.jersey.api.client.GenericType
;
import
com.sun.jersey.api.representation.Form
;
public
class
UserApi
extends
AbstractApi
{
...
...
@@ -11,6 +15,18 @@ public class UserApi extends AbstractApi {
super
(
gitLabApi
);
}
/**
* GET /users
*
* @return
* @throws IOException
*/
public
List
<
User
>
getProjects
()
throws
IOException
{
ClientResponse
response
=
get
(
null
,
"users"
);
return
(
response
.
getEntity
(
new
GenericType
<
List
<
User
>>()
{}));
}
/**
* GET /users/:id
...
...
@@ -23,4 +39,75 @@ public class UserApi extends AbstractApi {
ClientResponse
response
=
get
(
null
,
"users"
,
userId
);
return
(
response
.
getEntity
(
User
.
class
));
}
/**
* POST /users
*
* email (required) - Email
* password (required) - Password
* username (required) - Username
* name (required) - Name
* skype (optional) - Skype ID
* linkedin (optional) - Linkedin
* twitter (optional) - Twitter account
* website_url (optional) - Website url
* projects_limit (optional) - Number of projects user can create
* extern_uid (optional) - External UID
* provider (optional) - External provider name
* bio (optional) - User's bio
* admin (optional) - User is admin - true or false (default)
* can_create_group (optional) - User can create groups - true or false
*
* @param user
* @return
* @throws IOException
*/
public
User
createUser
(
User
user
,
String
password
,
Integer
projectsLimit
)
throws
IOException
{
Form
formData
=
new
Form
();
addFormParam
(
formData
,
"email"
,
user
.
getEmail
(),
true
);
addFormParam
(
formData
,
"password"
,
password
,
true
);
addFormParam
(
formData
,
"username"
,
user
.
getUsername
(),
true
);
addFormParam
(
formData
,
"name"
,
user
.
getName
(),
true
);
addFormParam
(
formData
,
"skype"
,
user
.
getSkype
(),
false
);
addFormParam
(
formData
,
"linkedin"
,
user
.
getLinkedin
(),
false
);
addFormParam
(
formData
,
"twitter"
,
user
.
getTwitter
(),
false
);
addFormParam
(
formData
,
"website_url"
,
user
.
getWebsiteUrl
(),
false
);
addFormParam
(
formData
,
"projects_limit"
,
projectsLimit
,
false
);
addFormParam
(
formData
,
"extern_uid"
,
user
.
getExternUid
(),
false
);
addFormParam
(
formData
,
"provider"
,
user
.
getProvider
(),
false
);
addFormParam
(
formData
,
"bio"
,
user
.
getBio
(),
false
);
addFormParam
(
formData
,
"admin"
,
user
.
getIsAdmin
(),
false
);
addFormParam
(
formData
,
"can_create_group"
,
user
.
getCanCreateGroup
(),
false
);
ClientResponse
response
=
post
(
formData
,
"users"
);
if
(
response
.
getStatus
()
!=
ClientResponse
.
Status
.
CREATED
.
getStatusCode
())
{
ErrorMessage
errorMessage
=
response
.
getEntity
(
ErrorMessage
.
class
);
throw
new
RuntimeException
(
errorMessage
.
getMessage
());
}
return
(
response
.
getEntity
(
User
.
class
));
}
/**
* DELETE /users/:id
*
* @param userId
*/
public
boolean
deleteUser
(
Integer
userId
)
throws
IOException
{
if
(
userId
==
null
)
{
throw
new
RuntimeException
(
"userId cannot be null"
);
}
ClientResponse
response
=
delete
(
null
,
"users"
,
userId
);
return
(
response
.
getStatus
()
==
ClientResponse
.
Status
.
OK
.
getStatusCode
());
}
public
boolean
deleteProject
(
User
user
)
throws
IOException
{
return
(
deleteUser
(
user
.
getId
()));
}
}
src/main/java/com/messners/gitlab/api/models/User.java
View file @
41f6f41f
...
...
@@ -11,13 +11,13 @@ import javax.xml.bind.annotation.XmlRootElement;
public
class
User
{
private
String
bio
;
private
b
oolean
canCreateGroup
;
private
B
oolean
canCreateGroup
;
private
Integer
colorSchemeId
;
private
Date
createdAt
;
private
String
email
;
private
String
externUid
;
private
Integer
id
;
private
b
oolean
isAdmin
;
private
B
oolean
isAdmin
;
private
String
linkedin
;
private
String
name
;
private
String
provider
;
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment