Skip to content

Commit 952f973

Browse files
committed
IMPROVE: add an optional date parameter to the stock function
1 parent 1bf0165 commit 952f973

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

lib/discourse_chatbot/functions/stock_data_function.rb

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,14 @@ def name
1515

1616
def description
1717
<<~EOS
18-
An API for MarketStack stock data
19-
20-
You need to call it using the stock ticker.#{' '}
18+
An API for MarketStack stock data. You need to call it using the stock ticker. You can optionally also provide a specific date.
2119
EOS
2220
end
2321

2422
def parameters
2523
[
2624
{ name: 'ticker', type: String, description: "ticker for share or stock query" },
25+
{ name: 'date', type: String, description: "date for data in format YYYY-MM-DD" }
2726
]
2827
end
2928

@@ -46,8 +45,7 @@ def process(args)
4645
api_response = JSON.parse(json)
4746

4847
ticker = api_response['data'][0]['symbol']
49-
50-
uri = URI("http://api.marketstack.com/v1/eod/latest")
48+
uri = args[parameters[1][:name]].blank? ? URI("http://api.marketstack.com/v1/eod/latest") : URI("http://api.marketstack.com/v1/eod/#{args[parameters[1][:name]]}")
5149

5250
params = {
5351
access_key: "#{SiteSetting.chatbot_marketstack_key}",

0 commit comments

Comments
 (0)