Class: Stonk::Adapter::CoinGeckoAdapter
- Inherits:
-
Object
- Object
- Stonk::Adapter::CoinGeckoAdapter
- Defined in:
- lib/stonk/adapter/coin_gecko_adapter.rb
Instance Method Summary collapse
- #get_stock_price(stock_symbol) ⇒ Object
-
#initialize(api_key) ⇒ CoinGeckoAdapter
constructor
A new instance of CoinGeckoAdapter.
Constructor Details
#initialize(api_key) ⇒ CoinGeckoAdapter
Returns a new instance of CoinGeckoAdapter.
6 7 8 |
# File 'lib/stonk/adapter/coin_gecko_adapter.rb', line 6 def initialize(api_key) @api_key = api_key end |
Instance Method Details
#get_stock_price(stock_symbol) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/stonk/adapter/coin_gecko_adapter.rb', line 10 def get_stock_price(stock_symbol) raise Stonk::Adapter::StockNotFound unless stock_symbol.end_with?(".CRYPTO") coin = stock_symbol.gsub(".CRYPTO", "") make_request(coin).then do |response| raise Stonk::Adapter::StockNotFound if response.empty? Stonk::Money.new(response.first.dig("current_price")) end end |