Created
January 22, 2016 12:21
-
-
Save raulbrito/b50a1ce0c3908c000b66 to your computer and use it in GitHub Desktop.
This file contains 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 '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