mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-08-06 05:55:21 +02:00
Integrate investment analytics app
This commit is contained in:
parent
13ec520618
commit
deb228a55e
6 changed files with 38 additions and 11 deletions
|
@ -3,3 +3,7 @@ SELF_HOSTED=false
|
|||
|
||||
# Enable Synth market data (careful, this will use your API credits)
|
||||
SYNTH_API_KEY=yourapikeyhere
|
||||
|
||||
# Enable the Investment Analytics app and configure FMP API access
|
||||
ENABLE_INVESTMENT_ANALYTICS_APP=false
|
||||
FMP_API_KEY=yourfmpapikeyhere
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
# app/apps/investment_analytics/services/investment_analytics/fmp_provider.rb
|
||||
|
||||
module InvestmentAnalytics
|
||||
class FmpProvider
|
||||
include Provider::Base
|
||||
require Rails.root.join("app", "models", "provider")
|
||||
class FmpProvider < ::Provider
|
||||
|
||||
BASE_URL = "https://financialmodelingprep.com/api/v3"
|
||||
|
||||
|
|
|
@ -8,10 +8,17 @@ class Provider::Registry
|
|||
validates :concept, inclusion: { in: CONCEPTS }
|
||||
|
||||
class << self
|
||||
@@additional_providers = {}
|
||||
|
||||
def for_concept(concept)
|
||||
new(concept.to_sym)
|
||||
end
|
||||
|
||||
def register_provider(name, provider_class)
|
||||
@@additional_providers[name.to_sym] = provider_class
|
||||
define_singleton_method(name) { provider_class.new }
|
||||
end
|
||||
|
||||
def get_provider(name)
|
||||
send(name)
|
||||
rescue NoMethodError
|
||||
|
@ -98,7 +105,7 @@ class Provider::Registry
|
|||
when :llm
|
||||
%i[openai]
|
||||
else
|
||||
%i[synth plaid_us plaid_eu github openai]
|
||||
%i[synth plaid_us plaid_eu github openai] + self.class.class_variable_get(:@@additional_providers).keys
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
# Ensure the InvestmentAnalytics module is loaded
|
||||
require_relative '../../app/apps/investment_analytics/investment_analytics'
|
||||
require Rails.root.join('app', 'models', 'provider')
|
||||
require Rails.root.join('app', 'models', 'provider', 'registry')
|
||||
|
||||
# Ensure the FmpProvider class is loaded
|
||||
require_relative '../../app/apps/investment_analytics/services/investment_analytics/fmp_provider'
|
||||
|
|
|
@ -262,14 +262,6 @@ Rails.application.routes.draw do
|
|||
get "privacy", to: redirect("https://maybefinance.com/privacy")
|
||||
get "terms", to: redirect("https://maybefinance.com/tos")
|
||||
|
||||
namespace :investment_analytics do
|
||||
resources :dashboards, only: [:index] do
|
||||
collection do
|
||||
get :portfolio_summary
|
||||
get :dividend_forecast
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Defines the root path route ("/")
|
||||
root "pages#dashboard"
|
||||
|
|
22
test/models/provider/fmp_provider_test.rb
Normal file
22
test/models/provider/fmp_provider_test.rb
Normal file
|
@ -0,0 +1,22 @@
|
|||
require "test_helper"
|
||||
require "ostruct"
|
||||
|
||||
class InvestmentAnalytics::FmpProviderTest < ActiveSupport::TestCase
|
||||
setup do
|
||||
@provider = InvestmentAnalytics::FmpProvider.new(api_key: "test")
|
||||
end
|
||||
|
||||
test "quote returns parsed data" do
|
||||
response = OpenStruct.new(success?: true, body: [{ price: 10 }.to_json])
|
||||
HTTParty.expects(:get).returns(response)
|
||||
|
||||
result = @provider.quote("AAPL")
|
||||
assert_equal({"price" => 10}, result)
|
||||
end
|
||||
|
||||
test "error responses raise provider error" do
|
||||
response = OpenStruct.new(success?: false, code: 404, body: "not found")
|
||||
assert_raises(Provider::Error) { @provider.send(:handle_response, response) }
|
||||
end
|
||||
end
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue