-
Notifications
You must be signed in to change notification settings - Fork 0
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
Add Tweet Neuron #12
Open
bklang
wants to merge
3
commits into
master
Choose a base branch
from
feature/tweet
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
Add Tweet Neuron #12
Changes from all commits
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
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
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
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,32 @@ | ||
require 'twitter' | ||
|
||
class TweetNeuron | ||
def initialize | ||
end | ||
|
||
def intent | ||
'tweet' | ||
end | ||
|
||
def reply(message, interpretation) | ||
client = get_twitter_client(message.user) | ||
return "You must log in via Twitter so I can help you tweet." unless client | ||
entities = interpretation['outcome']['entities'] | ||
return "You have to tell me what to tweet!" unless entities.has_key? 'message' | ||
|
||
client.update entities['message']['value'] | ||
"Message sent." | ||
end | ||
|
||
def get_twitter_client(user) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be private. |
||
grant = user['auth_grants'].select { |grant| grant[:provider] == :twitter }.first | ||
if grant | ||
Twitter::Client.new do |config| | ||
config.consumer_key = ENV['TWITTER_KEY'] | ||
config.consumer_secret = ENV['TWITTER_SECRET'] | ||
config.access_token = grant[:credentials]['token'] | ||
config.access_token_secret = grant[:credentials]['secret'] | ||
end | ||
end | ||
end | ||
end |
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,32 @@ | ||
require 'spec_helper' | ||
|
||
describe TweetNeuron do | ||
include NeuronMatchers | ||
|
||
let(:subject) { TweetNeuron.new } | ||
|
||
it "should return an error message if no tweet is provided" do | ||
interpretation = wit_interpretation 'Tweet this', 'tweet' | ||
should handle_message('Tweet this', :default_user, interpretation) | ||
.and_respond_with("You have to tell me what to tweet!") | ||
end | ||
|
||
it "should send a tweet" do | ||
interpretation = wit_interpretation 'Tweet Hello from AstriCon', 'tweet', message: 'Hello from AstriCon' | ||
should handle_message('Tweet this Hello from Astricon', :default_user, interpretation) | ||
.and_respond_with("Message sent.") | ||
end | ||
|
||
context "getting a Twitter client" do | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be tested via an attempt to send a tweet. |
||
it "should return nil if the user has no credentials for Twitter" do | ||
subject.get_twitter_client('auth_grants' => []).should be nil | ||
end | ||
|
||
it "should return an instance of Twitter::Client if credentials are supplied" do | ||
user = {'auth_grants' => [{provider: :twitter, credentials: {'token' => 'abcd', 'secret' => 'efgh'}}]} | ||
subject.get_twitter_client(user).should be_a Twitter::Client | ||
end | ||
end | ||
|
||
end | ||
|
Binary file not shown.
Binary file not shown.
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.
Tweet neuron?