-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
added slack client and made the code more testable. Improved coverage #53
Open
jepp3
wants to merge
3
commits into
master
Choose a base branch
from
added-slack-client-and-improved-coverage
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package slack; | ||
|
||
import com.github.seratch.jslack.api.methods.MethodsClient; | ||
import com.github.seratch.jslack.api.methods.request.channels.ChannelsRepliesRequest; | ||
import com.github.seratch.jslack.api.methods.request.chat.ChatPostMessageRequest; | ||
import com.github.seratch.jslack.api.methods.request.users.UsersInfoRequest; | ||
import com.github.seratch.jslack.api.methods.request.users.UsersLookupByEmailRequest; | ||
import com.github.seratch.jslack.api.methods.response.channels.ChannelsRepliesResponse; | ||
import com.github.seratch.jslack.api.methods.response.channels.UsersLookupByEmailResponse; | ||
|
||
import com.github.seratch.jslack.api.methods.response.chat.ChatPostMessageResponse; | ||
import com.github.seratch.jslack.api.methods.response.users.UsersInfoResponse; | ||
import rx.Observable; | ||
|
||
/** | ||
* Observable slack client that wraps the com.github.seratch.jslack.Slack client. | ||
* | ||
* @see "https://github.com/seratch/jslack" | ||
* | ||
*/ | ||
public interface SlackClient { | ||
|
||
/** | ||
* @see MethodsClient#usersLookupByEmail(UsersLookupByEmailRequest) | ||
*/ | ||
Observable<UsersLookupByEmailResponse> usersLookupByEmail(UsersLookupByEmailRequest usersInfoRequest); | ||
|
||
|
||
/** | ||
* @see MethodsClient#usersInfo(UsersInfoRequest) | ||
*/ | ||
Observable<UsersInfoResponse> usersInfo(UsersInfoRequest slackRequest); | ||
|
||
/** | ||
* @see MethodsClient#chatPostMessage(ChatPostMessageRequest) | ||
*/ | ||
Observable<ChatPostMessageResponse> chatPostMessage(ChatPostMessageRequest chatPostMessageRequest); | ||
|
||
/** | ||
* @see MethodsClient#channelsReplies(ChannelsRepliesRequest) | ||
*/ | ||
Observable<ChannelsRepliesResponse> channelsReplies(ChannelsRepliesRequest channelsRepliesRequest); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package slack; | ||
|
||
import com.github.seratch.jslack.Slack; | ||
import com.github.seratch.jslack.api.methods.request.channels.ChannelsRepliesRequest; | ||
import com.github.seratch.jslack.api.methods.request.chat.ChatPostMessageRequest; | ||
import com.github.seratch.jslack.api.methods.request.users.UsersInfoRequest; | ||
import com.github.seratch.jslack.api.methods.request.users.UsersLookupByEmailRequest; | ||
import com.github.seratch.jslack.api.methods.response.channels.ChannelsRepliesResponse; | ||
import com.github.seratch.jslack.api.methods.response.channels.UsersLookupByEmailResponse; | ||
import com.github.seratch.jslack.api.methods.response.chat.ChatPostMessageResponse; | ||
import com.github.seratch.jslack.api.methods.response.users.UsersInfoResponse; | ||
import com.google.inject.Inject; | ||
import com.google.inject.Singleton; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import rx.Observable; | ||
import rx.functions.Action1; | ||
|
||
import java.io.IOException; | ||
import java.util.concurrent.Callable; | ||
|
||
import static rx.Observable.fromCallable; | ||
|
||
|
||
@Singleton | ||
public class SlackClientImpl implements SlackClient { | ||
|
||
private static final Logger LOG = LoggerFactory.getLogger(SlackClientImpl.class); | ||
|
||
private Slack slack; | ||
|
||
@Inject | ||
SlackClientImpl(Slack slack) { | ||
this.slack = slack; | ||
} | ||
|
||
@Override | ||
public Observable<UsersLookupByEmailResponse> usersLookupByEmail(UsersLookupByEmailRequest usersInfoRequest) { | ||
return callSlack(() -> slack.methods().usersLookupByEmail(usersInfoRequest)); | ||
} | ||
|
||
@Override | ||
public Observable<UsersInfoResponse> usersInfo(UsersInfoRequest slackRequest) { | ||
return callSlack(() -> slack.methods().usersInfo(slackRequest)); | ||
} | ||
|
||
|
||
@Override | ||
public Observable<ChatPostMessageResponse> chatPostMessage(ChatPostMessageRequest chatPostMessageRequest) { | ||
return callSlack(() -> slack.methods().chatPostMessage(chatPostMessageRequest)); | ||
} | ||
|
||
|
||
@Override | ||
public Observable<ChannelsRepliesResponse> channelsReplies(ChannelsRepliesRequest channelsRepliesRequest) { | ||
return callSlack(() -> slack.methods().channelsReplies(channelsRepliesRequest)); | ||
} | ||
|
||
<T> Observable<T> callSlack(Callable<T> callable) { | ||
return fromCallable(callable).doOnError(logError()); | ||
} | ||
|
||
private static Action1<Throwable> logError() { | ||
return e -> { | ||
if(e instanceof IOException) { | ||
LOG.error("Failed to communicate with slack", e); | ||
} else { | ||
LOG.warn("Got bad response while communicating with slack", e); | ||
} | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should name the constants to convey the gist of the error rather than the exact words.