Created
November 12, 2017 19:27
-
-
Save b-ggs/b7c6a6cb93e533602ba8801bf11b4d00 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'net/http' | |
require 'json' | |
URL = 'https://quote.coins.ph/v1/markets/BTC-PHP' | |
def get_info | |
Net::HTTP.get(URI.parse(URL)) | |
end | |
def parse_info(raw_response) | |
response = JSON.parse(raw_response) | |
{ | |
symbol: response['market']['symbol'], | |
currency: response['market']['currency'], | |
product: response['market']['product'], | |
sell: response['market']['bid'], | |
buy: response['market']['ask'], | |
expires_in_seconds: response['market']['expires_in_seconds'] | |
} | |
end | |
def format_message(info) | |
message = '' | |
message << "Buy: #{info[:currency]} #{info[:buy]}" | |
message << "\n" | |
message << "Sell: #{info[:currency]} #{info[:sell]}" | |
message | |
end | |
def notify_macos(message, title) | |
`osascript -e 'display notification "#{message}" with title "#{title}"'` | |
end | |
while true | |
raw_response = get_info | |
info = parse_info(raw_response) | |
message = format_message(info) | |
puts message | |
notify_macos(message, info[:symbol]) | |
sleep info[:expires_in_seconds] + 1 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment