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
d11dff67
Commit
d11dff67
authored
Mar 27, 2014
by
Greg Messner
Browse files
Added SessionApi.
parent
e8c27ffa
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/main/java/com/messners/gitlab/api/GitLabApi.java
View file @
d11dff67
...
...
@@ -14,6 +14,7 @@ public class GitLabApi {
private
MergeRequestApi
mergeRequestApi
;
private
ProjectApi
projectApi
;
private
RepositoryApi
repositoryApi
;
private
SessionApi
sessoinApi
;
private
UserApi
userApi
;
...
...
@@ -31,6 +32,7 @@ public class GitLabApi {
mergeRequestApi
=
new
MergeRequestApi
(
this
);
projectApi
=
new
ProjectApi
(
this
);
repositoryApi
=
new
RepositoryApi
(
this
);
sessoinApi
=
new
SessionApi
(
this
);
userApi
=
new
UserApi
(
this
);
}
...
...
@@ -98,6 +100,17 @@ public class GitLabApi {
*/
public
RepositoryApi
getRepositoryApi
()
{
return
(
repositoryApi
);
}
/**
* Gets the SessionApi instance owned by this GitLabApi instance. The SessionApi is used
* to perform a login to the GitLab API.
*
* @return the SessionApi instance owned by this GitLabApi instance
*/
public
SessionApi
getSessionApi
()
{
return
(
sessoinApi
);
}
...
...
@@ -105,7 +118,7 @@ public class GitLabApi {
* Gets the UserApi instance owned by this GitLabApi instance. The UserApi is used
* to perform all user related API calls.
*
* @return the
Project
Api instance owned by this GitLabApi instance
* @return the
User
Api instance owned by this GitLabApi instance
*/
public
UserApi
getUserApi
()
{
return
(
userApi
);
...
...
src/main/java/com/messners/gitlab/api/SessionApi.java
0 → 100644
View file @
d11dff67
package
com.messners.gitlab.api
;
import
com.messners.gitlab.api.models.Session
;
import
com.sun.jersey.api.client.ClientResponse
;
import
com.sun.jersey.api.representation.Form
;
/**
* This class implements the client side API for the GitLab login call.
*
* @author Greg Messner <greg@messners.com>
*
*/
public
class
SessionApi
extends
AbstractApi
{
public
SessionApi
(
GitLabApi
gitLabApi
)
{
super
(
gitLabApi
);
}
/**
* Login to get private token.
*
* POST /session
*
* @param username
* @param email
* @param password
* @return
* @throws GitLabApiException
*/
public
Session
login
(
String
username
,
String
email
,
String
password
)
throws
GitLabApiException
{
if
((
username
==
null
||
username
.
trim
().
length
()
==
0
)
&&
(
email
==
null
||
email
.
trim
().
length
()
==
0
))
{
throw
new
IllegalArgumentException
(
"both username and email cannot be empty or null"
);
}
Form
formData
=
new
Form
();
addFormParam
(
formData
,
"email"
,
email
,
false
);
addFormParam
(
formData
,
"password"
,
password
,
true
);
addFormParam
(
formData
,
"login"
,
username
,
false
);
ClientResponse
response
=
post
(
ClientResponse
.
Status
.
OK
,
formData
,
"session"
);
return
(
response
.
getEntity
(
Session
.
class
));
}
}
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