Skip to content

Commit

Permalink
Merge pull request #166 from rubyforgood/update_stock_price
Browse files Browse the repository at this point in the history
Job now prints full output for all api calls. Next step, extract just…
  • Loading branch information
abachman authored Jun 1, 2024
2 parents e9a4855 + f44abd1 commit ac4dbc2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

# Ignore master key for decrypting credentials and more.
/config/master.key
/config/api_keys.rb

# ignore local database.yml
/config/database.yml
Expand Down
13 changes: 13 additions & 0 deletions app/jobs/stock_prices_update_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,18 @@ class StockPricesUpdateJob < ApplicationJob
def perform(*args)
# For each stock symbol, request the latest closing cost
# update the stocks table with each new closing cost
stock_symbols = ["KO", "SNE", "TWX", "DIS", "SIRI", "F", "EA", "FB", "UA", "LUV", "GPS"]
stock_symbols.each do |symbol|
api_request(symbol)
stock_db = Stock.find_by(ticker: symbol)
end
end

private

def api_request(symbol)
url = "https://www.alphavantage.co/query?function=GLOBAL_QUOTE&symbol=#{symbol}&apikey=#{API_KEY}"
uri = URI.parse(url)
print Net::HTTP.get(uri)
end
end

0 comments on commit ac4dbc2

Please sign in to comment.