Skip to content

Commit f8a95b0

Browse files
authored
Merge pull request #31 from merefield/add_opt_date_argument_to_stock_call
IMPROVE: add an optional date parameter to the stock function
2 parents 51e8d48 + 184d265 commit f8a95b0

File tree

2 files changed

+4
-6
lines changed

2 files changed

+4
-6
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}",

plugin.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# frozen_string_literal: true
22
# name: discourse-chatbot
33
# about: a plugin that allows you to have a conversation with a configurable chatbot in Discourse Chat, Topics and Private Messages
4-
# version: 0.28
4+
# version: 0.29
55
# authors: merefield
66
# url: https://github.com/merefield/discourse-chatbot
77

0 commit comments

Comments
 (0)