From 952f9738790718bb78865befe42c7227c9485f36 Mon Sep 17 00:00:00 2001 From: merefield Date: Sat, 19 Aug 2023 11:35:45 +0100 Subject: [PATCH 1/2] IMPROVE: add an optional date parameter to the stock function --- lib/discourse_chatbot/functions/stock_data_function.rb | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/lib/discourse_chatbot/functions/stock_data_function.rb b/lib/discourse_chatbot/functions/stock_data_function.rb index cb204752..166ce0bd 100644 --- a/lib/discourse_chatbot/functions/stock_data_function.rb +++ b/lib/discourse_chatbot/functions/stock_data_function.rb @@ -15,15 +15,14 @@ def name def description <<~EOS - An API for MarketStack stock data - - You need to call it using the stock ticker.#{' '} + An API for MarketStack stock data. You need to call it using the stock ticker. You can optionally also provide a specific date. EOS end def parameters [ { name: 'ticker', type: String, description: "ticker for share or stock query" }, + { name: 'date', type: String, description: "date for data in format YYYY-MM-DD" } ] end @@ -46,8 +45,7 @@ def process(args) api_response = JSON.parse(json) ticker = api_response['data'][0]['symbol'] - - uri = URI("http://api.marketstack.com/v1/eod/latest") + 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]]}") params = { access_key: "#{SiteSetting.chatbot_marketstack_key}", From 184d26524535579d2268c763ef96e5d1edae1c60 Mon Sep 17 00:00:00 2001 From: merefield Date: Sat, 19 Aug 2023 11:38:52 +0100 Subject: [PATCH 2/2] rubocop --- lib/discourse_chatbot/functions/stock_data_function.rb | 2 +- plugin.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/discourse_chatbot/functions/stock_data_function.rb b/lib/discourse_chatbot/functions/stock_data_function.rb index 166ce0bd..46335594 100644 --- a/lib/discourse_chatbot/functions/stock_data_function.rb +++ b/lib/discourse_chatbot/functions/stock_data_function.rb @@ -45,7 +45,7 @@ def process(args) api_response = JSON.parse(json) ticker = api_response['data'][0]['symbol'] - 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]]}") + 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]]}") params = { access_key: "#{SiteSetting.chatbot_marketstack_key}", diff --git a/plugin.rb b/plugin.rb index d2323f93..12e4229f 100644 --- a/plugin.rb +++ b/plugin.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true # name: discourse-chatbot # about: a plugin that allows you to have a conversation with a configurable chatbot in Discourse Chat, Topics and Private Messages -# version: 0.28 +# version: 0.29 # authors: merefield # url: https://github.com/merefield/discourse-chatbot