-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Created /api/graph endpoint for Interactive Slack Messages. Updated Market model to include buttons in formatted Slack object. Added condition to Market model to render stock quote's correct graph. * Updated model and endpoint spec to account for new slack message structure, which now includes interactive buttons and a callback id. Refactored Market model per RuboCop. * downgraded firefox to version 46.01 for selenium-webdriver tests * created spec to slack_endpoint test for parsing a good payload and non-matching verification tokens. Updated README with animated GIF and styling. Added parameter validation to slack_endpoint and renamed class to GraphEndpoint. * refactored slack_endpoint_spec * Changed slack_endpoint to be called graph_endpoint
- Loading branch information
Showing
18 changed files
with
336 additions
and
6 deletions.
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 @@ | ||
2.3.1 |
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
Empty file.
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 |
---|---|---|
|
@@ -354,7 +354,7 @@ DEPENDENCIES | |
yahoo-finance | ||
|
||
RUBY VERSION | ||
ruby 2.2.4p230 | ||
ruby 2.2.3p173 | ||
|
||
BUNDLED WITH | ||
1.12.5 |
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
Empty file.
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,4 @@ | ||
LOG: database system was shut down at 2016-06-30 17:56:55 EDT | ||
LOG: MultiXact member wraparound protections are now enabled | ||
LOG: database system is ready to accept connections | ||
LOG: autovacuum launcher started |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
require 'slack-market/api/endpoints/teams_endpoint' | ||
require 'slack-market/api/endpoints/subscriptions_endpoint' | ||
require 'slack-market/api/endpoints/status_endpoint' | ||
require 'slack-market/api/endpoints/graph_endpoint' | ||
require 'slack-market/api/endpoints/root_endpoint' |
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,41 @@ | ||
require 'pp' | ||
module Api | ||
module Endpoints | ||
class GraphEndpoint < Grape::API | ||
format :json | ||
|
||
namespace :graph do | ||
desc 'Select graph.' | ||
|
||
params do | ||
requires :payload, type: String | ||
end | ||
|
||
post do | ||
payload = JSON.parse(params[:payload]) | ||
button_name = payload['actions'][0]['name'] | ||
button_value = payload['actions'][0]['value'] | ||
stock_symbol = button_value.scan(/^[^\-]*/) | ||
channel = payload['channel']['id'] | ||
token = payload['token'] | ||
ts = payload['original_message']['ts'] | ||
chart = true | ||
quotes = Market.quotes([stock_symbol]) | ||
|
||
slack_attachment = Market.to_slack_attachment(quotes[0], charts: chart, button: button_name) | ||
|
||
error! 'Message token is not coming from Slack.', 401 unless token == ENV['SLACK_VERIFICATION_TOKEN'] | ||
# formatted Slack message response | ||
{ | ||
as_user: true, | ||
channel: channel, | ||
ts: ts, | ||
token: token, | ||
text: "Below is the #{button_name} chart", | ||
attachments: [slack_attachment] | ||
} | ||
end | ||
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
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,30 @@ | ||
require 'spec_helper' | ||
|
||
describe Api::Endpoints::GraphEndpoint do | ||
include Api::Test::EndpointTest | ||
|
||
context 'graph' do | ||
it 'parses a good payload', vcr: { cassette_name: 'msft' } do | ||
post '/api/graph', payload: { | ||
'actions': [{ 'name' => '1m', 'value' => 'MSFT- 1m' }], | ||
'channel': { 'id' => '424242424', 'name' => 'directmessage' }, | ||
'token': ENV['SLACK_VERIFICATION_TOKEN'], | ||
'original_message': { | ||
'ts': '1467321295.000010' | ||
} | ||
}.to_json | ||
expect(last_response.status).to eq 201 | ||
end | ||
it 'returns an error with a non-matching verification token', vcr: { cassette_name: 'msft' } do | ||
post '/api/graph', payload: { | ||
'actions': [{ 'name' => '1m', 'value' => 'MSFT- 1m' }], | ||
'channel': { 'id' => '424242424', 'name' => 'directmessage' }, | ||
'token': 'invalid-token', | ||
'original_message': { | ||
'ts': '1467321295.000010' | ||
} | ||
}.to_json | ||
expect(last_response.status).to eq 401 | ||
end | ||
end | ||
end |
Oops, something went wrong.