Commit 00a9fcc1 authored by Yannick Kirschhoffer's avatar Yannick Kirschhoffer

Import Twitter settings through the application config.

parent 0aac0fee
Pipeline #41687907 passed with stages
in 3 minutes and 53 seconds
......@@ -9,6 +9,7 @@ FROM openjdk:8-jre
#ENV PORT 4567
#EXPOSE 4567
COPY --from=BUILD /usr/src/app/build/libs /opt/target
COPY application.yml /opt/target
WORKDIR /opt/target
CMD ["/bin/bash", "-c", "find -type f -name 'socializer-*.jar' | xargs java -jar"]
......
......@@ -10,6 +10,15 @@ buildscript {
}
}
plugins {
id 'io.franzbecker.gradle-lombok' version '1.14'
}
lombok {
version = '1.18.4'
sha256 = ''
}
apply plugin: 'java'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
......@@ -22,8 +31,9 @@ repositories {
mavenCentral()
}
dependencies {
compileOnly "org.springframework.boot:spring-boot-configuration-processor"
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-social-twitter:1.1.0.RELEASE'
......
package org.alcibiade.socializer.configuration;
import org.alcibiade.socializer.configuration.properties.SocializerProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Configuration;
@Configuration
@EnableConfigurationProperties(SocializerProperties.class)
public class PropertiesConfiguration {
}
package org.alcibiade.socializer.configuration.properties;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.validation.annotation.Validated;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.util.Map;
@Data
@Validated
@ConfigurationProperties(prefix = "socializer")
public class SocializerProperties {
@NotNull
private TwitterProperties twitter;
@Data
public static class TwitterProperties {
private Map<String, AccountProperties> accounts;
@Data
public static class AccountProperties {
@NotBlank
private String apiKey;
@NotBlank
private String apiSecretKey;
@NotBlank
private String accessTokens;
@NotBlank
private String accessTokenSecret;
}
}
}
......@@ -17,7 +17,7 @@ public class RetweetJob {
this.twitterService = twitterService;
}
@Scheduled(fixedRate = 3600_000L)
@Scheduled(initialDelay = 5_000L, fixedRate = 3600_000L)
@Transactional
public void retweet() {
twitterService.retweet();
......
package org.alcibiade.socializer.service;
import lombok.extern.slf4j.Slf4j;
import org.alcibiade.socializer.configuration.properties.SocializerProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Slf4j
@Service
public class TwitterService {
private final SocializerProperties socializerProperties;
@Autowired
public TwitterService(SocializerProperties socializerProperties) {
this.socializerProperties = socializerProperties;
}
public void retweet() {
log.debug("Retweeting for {} twitter accounts",
socializerProperties.getTwitter().getAccounts().size());
}
public void updateActivity() {
log.debug("Updating Activity...");
}
}
package org.alcibiade.socializer;
import org.alcibiade.socializer.configuration.properties.SocializerProperties;
import org.assertj.core.api.Assertions;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import javax.transaction.Transactional;
@RunWith(SpringRunner.class)
@SpringBootTest
public class SocializerApplicationTests {
@Autowired
public SocializerProperties properties;
@Test
@Transactional
public void contextLoads() {
Assertions.assertThat(properties).isNotNull();
Assertions.assertThat(properties.getTwitter()).isNotNull();
Assertions.assertThat(properties.getTwitter().getAccounts()).hasSize(1);
Assertions.assertThat(
properties.getTwitter().getAccounts().get("account1").getAccessTokenSecret()
).isEqualTo("dddddddddddddddddddddddddddddddddd");
}
}
......
......@@ -3,4 +3,13 @@ spring:
url: jdbc:h2:mem:testdb
username: sa
password:
driver-class-name: org.h2.Driver
\ No newline at end of file
driver-class-name: org.h2.Driver
socializer:
twitter:
accounts:
account1:
apiKey: 'aaaaaaaaaaaaaaaaaaaa'
apiSecretKey: 'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb'
accessTokens: 'ccccccccccccc-cccccccccccccccccc'
accessTokenSecret: 'dddddddddddddddddddddddddddddddddd'
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment