Skip to content

Commit 12328b4

Browse files
committed
Minor refactoring
1 parent ed0969f commit 12328b4

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,22 @@
1717
public class JobServiceImpl implements JobService {
1818

1919
private static final Logger LOGGER = LoggerFactory.getLogger(JobServiceImpl.class);
20+
2021
private JobRepository jobRepository;
22+
private JTwitter twitter;
2123

2224
@Autowired
23-
public JobServiceImpl(JobRepository jobRepository) {
25+
public JobServiceImpl(JobRepository jobRepository, JTwitter twitter) {
2426
this.jobRepository = jobRepository;
27+
this.twitter = twitter;
2528
}
2629

2730
public void save(Job job) {
2831
if (jobExists(job)) {
2932
update(job);
3033
} else {
3134
jobRepository.save(job);
32-
JTwitter.tweet(job);
35+
twitter.tweet(job);
3336
LOGGER.info("New job '{}' on {} found", job.getTitle(), job.getSource());
3437
}
3538
}
@@ -44,7 +47,7 @@ private void update(Job job) {
4447
LocalDate jobDate = job.getDate().toLocalDate();
4548
if (!jobFromDbDate.equals(jobDate)) {
4649
jobRepository.save(job);
47-
JTwitter.tweet(job);
50+
twitter.tweet(job);
4851
LOGGER.info("Job '{}', {} updated", job.getTitle(), job.getUrl());
4952
}
5053
}

src/main/java/com/olegshan/social/JTwitter.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,23 @@
33
import com.olegshan.entity.Job;
44
import org.springframework.social.twitter.api.Twitter;
55
import org.springframework.social.twitter.api.impl.TwitterTemplate;
6+
import org.springframework.stereotype.Component;
67

8+
@Component
79
public class JTwitter {
810

911
private static final String CONSUMER_KEY = System.getProperty("CKjP");
1012
private static final String CONSUMER_SECRET = System.getProperty("CSjP");
1113
private static final String ACCESS_TOKEN = System.getProperty("ATjP");
1214
private static final String ACCESS_TOKEN_SECRET = System.getProperty("ATSjP");
1315

14-
private static Twitter twitter = new TwitterTemplate(
15-
CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET);
16+
private Twitter twitter;
1617

17-
public static void tweet(Job job) {
18+
public JTwitter() {
19+
twitter = new TwitterTemplate(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET);
20+
}
21+
22+
public void tweet(Job job) {
1823
twitter.timelineOperations().updateStatus(job.getTitle() + " " + job.getUrl()
1924
+ " More jobs here: http://jparser.info");
2025
}

0 commit comments

Comments
 (0)