mirror of
https://github.com/brmlab/wekan-mailer.git
synced 2025-06-09 02:14:04 +02:00
Some draft of rest api calls
This commit is contained in:
parent
c2bd21df95
commit
28bbf0815e
8 changed files with 141 additions and 0 deletions
9
pom.xml
9
pom.xml
|
@ -37,6 +37,15 @@
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework</groupId>
|
||||||
|
<artifactId>spring-web</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.fasterxml.jackson.core</groupId>
|
||||||
|
<artifactId>jackson-databind</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.github.stefanbirkner</groupId>
|
<groupId>com.github.stefanbirkner</groupId>
|
||||||
<artifactId>system-rules</artifactId>
|
<artifactId>system-rules</artifactId>
|
||||||
|
|
|
@ -2,6 +2,9 @@ package cz.brmlab.wm;
|
||||||
|
|
||||||
import cz.brmlab.wm.utils.Exceptions.BrmException;
|
import cz.brmlab.wm.utils.Exceptions.BrmException;
|
||||||
import cz.brmlab.wm.wekan.WekanConfiguration;
|
import cz.brmlab.wm.wekan.WekanConfiguration;
|
||||||
|
import cz.brmlab.wm.wekan.pojo.card.CardRequest;
|
||||||
|
import cz.brmlab.wm.wekan.rest.CardPost;
|
||||||
|
import cz.brmlab.wm.wekan.rest.LoginPost;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.boot.CommandLineRunner;
|
import org.springframework.boot.CommandLineRunner;
|
||||||
|
@ -23,6 +26,12 @@ public class Application implements CommandLineRunner {
|
||||||
try {
|
try {
|
||||||
WekanConfiguration wekanConfiguration = new WekanConfiguration();
|
WekanConfiguration wekanConfiguration = new WekanConfiguration();
|
||||||
|
|
||||||
|
LoginPost loginPost = new LoginPost(wekanConfiguration);
|
||||||
|
loginPost.login();
|
||||||
|
|
||||||
|
CardPost cardPost = new CardPost(loginPost.getToken(), wekanConfiguration);
|
||||||
|
cardPost.postCard("Test from spring", "Test card from awesome spring app.\nAnd next line");
|
||||||
|
|
||||||
} catch (BrmException ex) {
|
} catch (BrmException ex) {
|
||||||
System.exit(ex.getExitCode().getCode());
|
System.exit(ex.getExitCode().getCode());
|
||||||
}
|
}
|
||||||
|
|
15
src/main/java/cz/brmlab/wm/wekan/pojo/card/CardRequest.java
Normal file
15
src/main/java/cz/brmlab/wm/wekan/pojo/card/CardRequest.java
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
package cz.brmlab.wm.wekan.pojo.card;
|
||||||
|
|
||||||
|
import cz.brmlab.wm.wekan.WekanConfiguration;
|
||||||
|
import cz.brmlab.wm.wekan.pojo.login.LoginToken;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class CardRequest {
|
||||||
|
|
||||||
|
private String title;
|
||||||
|
private String description;
|
||||||
|
private String authorId;
|
||||||
|
private final String swimlaneId = "Default";
|
||||||
|
|
||||||
|
}
|
10
src/main/java/cz/brmlab/wm/wekan/pojo/card/CardResponse.java
Normal file
10
src/main/java/cz/brmlab/wm/wekan/pojo/card/CardResponse.java
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
package cz.brmlab.wm.wekan.pojo.card;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class CardResponse {
|
||||||
|
|
||||||
|
private String id;
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,13 @@
|
||||||
|
package cz.brmlab.wm.wekan.pojo.login;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class LoginRequest implements Serializable {
|
||||||
|
|
||||||
|
private String username;
|
||||||
|
private String password;
|
||||||
|
|
||||||
|
}
|
10
src/main/java/cz/brmlab/wm/wekan/pojo/login/LoginToken.java
Normal file
10
src/main/java/cz/brmlab/wm/wekan/pojo/login/LoginToken.java
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
package cz.brmlab.wm.wekan.pojo.login;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class LoginToken {
|
||||||
|
public String id;
|
||||||
|
public String token;
|
||||||
|
public String tokenExpires;
|
||||||
|
}
|
41
src/main/java/cz/brmlab/wm/wekan/rest/CardPost.java
Normal file
41
src/main/java/cz/brmlab/wm/wekan/rest/CardPost.java
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
package cz.brmlab.wm.wekan.rest;
|
||||||
|
|
||||||
|
import cz.brmlab.wm.wekan.WekanConfiguration;
|
||||||
|
import cz.brmlab.wm.wekan.pojo.card.CardRequest;
|
||||||
|
import cz.brmlab.wm.wekan.pojo.card.CardResponse;
|
||||||
|
import cz.brmlab.wm.wekan.pojo.login.LoginToken;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.web.client.RestTemplate;
|
||||||
|
|
||||||
|
public class CardPost {
|
||||||
|
|
||||||
|
private static final Logger LOG = LoggerFactory.getLogger(CardPost.class);
|
||||||
|
|
||||||
|
private final LoginToken token;
|
||||||
|
private final WekanConfiguration configuration;
|
||||||
|
|
||||||
|
public CardPost(LoginToken token, WekanConfiguration configuration) {
|
||||||
|
this.token = token;
|
||||||
|
this.configuration = configuration;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CardResponse postCard(String title, String description) {
|
||||||
|
CardRequest cardRequest = new CardRequest();
|
||||||
|
cardRequest.setAuthorId(token.getId());
|
||||||
|
cardRequest.setTitle(title);
|
||||||
|
cardRequest.setDescription(description);
|
||||||
|
|
||||||
|
String cardUrl = configuration.getWekanUrl()
|
||||||
|
+ "/api/boards"
|
||||||
|
+ configuration.getWekanBoard()
|
||||||
|
+ "/lists/"
|
||||||
|
+ configuration.getWekanList() + "cards";
|
||||||
|
|
||||||
|
RestTemplate restTemplate = new RestTemplate();
|
||||||
|
LOG.debug("Sending card: {}", cardRequest);
|
||||||
|
CardResponse cardResponse = restTemplate.postForObject(cardUrl, cardRequest, CardResponse.class);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
34
src/main/java/cz/brmlab/wm/wekan/rest/LoginPost.java
Normal file
34
src/main/java/cz/brmlab/wm/wekan/rest/LoginPost.java
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
package cz.brmlab.wm.wekan.rest;
|
||||||
|
|
||||||
|
import cz.brmlab.wm.wekan.WekanConfiguration;
|
||||||
|
import cz.brmlab.wm.wekan.pojo.login.LoginRequest;
|
||||||
|
import cz.brmlab.wm.wekan.pojo.login.LoginToken;
|
||||||
|
import lombok.Getter;
|
||||||
|
import org.springframework.web.client.RestTemplate;
|
||||||
|
|
||||||
|
public class LoginPost {
|
||||||
|
|
||||||
|
private final WekanConfiguration configuration;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
private LoginToken token;
|
||||||
|
|
||||||
|
public LoginPost(WekanConfiguration configuration) {
|
||||||
|
this.configuration = configuration;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void login() {
|
||||||
|
|
||||||
|
String loginUrl = configuration.getWekanUrl() + "/users/login";
|
||||||
|
|
||||||
|
LoginRequest loginRequest = new LoginRequest();
|
||||||
|
loginRequest.setUsername(configuration.getWekanUser());
|
||||||
|
loginRequest.setPassword(configuration.getWekanPassword());
|
||||||
|
|
||||||
|
RestTemplate restTemplate = new RestTemplate();
|
||||||
|
token = restTemplate.postForObject(loginUrl, loginRequest, LoginToken.class);
|
||||||
|
|
||||||
|
System.out.println(token);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue