Skip to content

Instantly share code, notes, and snippets.

@b-ggs
Created November 12, 2017 19:27
Show Gist options
  • Save b-ggs/b7c6a6cb93e533602ba8801bf11b4d00 to your computer and use it in GitHub Desktop.
Save b-ggs/b7c6a6cb93e533602ba8801bf11b4d00 to your computer and use it in GitHub Desktop.
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