Skip to content

Instantly share code, notes, and snippets.

@raulbrito
Created January 22, 2016 12:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save raulbrito/b50a1ce0c3908c000b66 to your computer and use it in GitHub Desktop.
Save raulbrito/b50a1ce0c3908c000b66 to your computer and use it in GitHub Desktop.
require 'pusher-client'
require 'sqlite3'
require 'json'
db = SQLite3::Database.open "blackfriday.db"
#rows = db.execute <<-SQL
# create table orders (
# from_latitude int,
# from_longitude int,
# to_latitude int,
# to_longitude int,
# current_date DATETIME,
# plus int
# );
#SQL
options = { secure: true }
socket = PusherClient::Socket.new('2b7d7c6401ae71700738', options)
socket.subscribe('ordersmap')
socket['ordersmap'].bind('order_marker') do |data|
parsed = JSON.parse(data)
plus_shop = (parsed["plus_shop"] == true ? 1 : 0)
db.execute("INSERT INTO orders (from_latitude, from_longitude, to_latitude, to_longitude, current_date, plus)
VALUES (?, ?, ?, ?, CURRENT_TIMESTAMP, ?)", parsed["from_latitude"], parsed["from_longitude"], parsed["to_latitude"], parsed["to_longitude"], plus_shop)
end
socket.connect
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment