Skip to content

Commit d0f8915

Browse files
committed
Twitter added
1 parent e543903 commit d0f8915

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,11 @@
7676
<artifactId>spring-boot-starter-data-jpa</artifactId>
7777
</dependency>
7878

79+
<dependency>
80+
<groupId>org.springframework.boot</groupId>
81+
<artifactId>spring-boot-starter-social-twitter</artifactId>
82+
</dependency>
83+
7984
<dependency>
8085
<groupId>org.projectlombok</groupId>
8186
<artifactId>lombok</artifactId>

src/main/java/com/olegshan/service/impl/JobServiceImpl.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.olegshan.entity.Job;
44
import com.olegshan.repository.JobRepository;
55
import com.olegshan.service.JobService;
6+
import com.olegshan.social.JTwitter;
67
import org.slf4j.Logger;
78
import org.slf4j.LoggerFactory;
89
import org.springframework.beans.factory.annotation.Autowired;
@@ -28,6 +29,7 @@ public void save(Job job) {
2829
update(job);
2930
} else {
3031
jobRepository.save(job);
32+
JTwitter.tweet(job);
3133
LOGGER.info("New job '{}' on {} found", job.getTitle(), job.getSource());
3234
}
3335
}
@@ -42,6 +44,7 @@ private void update(Job job) {
4244
LocalDate jobDate = job.getDate().toLocalDate();
4345
if (!jobFromDbDate.equals(jobDate)) {
4446
jobRepository.save(job);
47+
JTwitter.tweet(job);
4548
LOGGER.info("Job '{}', {} updated", job.getTitle(), job.getUrl());
4649
}
4750
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.olegshan.social;
2+
3+
import com.olegshan.entity.Job;
4+
import org.springframework.social.twitter.api.Twitter;
5+
import org.springframework.social.twitter.api.impl.TwitterTemplate;
6+
7+
public class JTwitter {
8+
9+
private static final String CONSUMER_KEY = System.getProperty("CKjP");
10+
private static final String CONSUMER_SECRET = System.getProperty("CSjP");
11+
private static final String ACCESS_TOKEN = System.getProperty("ATjP");
12+
private static final String ACCESS_TOKEN_SECRET = System.getProperty("ATSjP");
13+
14+
private static Twitter twitter = new TwitterTemplate(
15+
CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET);
16+
17+
public static void tweet(Job job) {
18+
twitter.timelineOperations().updateStatus(job.getTitle() + " " + job.getUrl()
19+
+ " More jobs here: http://jparser.info");
20+
}
21+
}

0 commit comments

Comments
 (0)