Skip to content

Instantly share code, notes, and snippets.

@mcansky
Created September 25, 2013 14:06
Show Gist options
  • Save mcansky/6700151 to your computer and use it in GitHub Desktop.
Save mcansky/6700151 to your computer and use it in GitHub Desktop.
domino's pizza has a nice iframe, I wanted to have a json
require 'nokogiri'
require 'open-uri'
require 'sinatra'
require 'json'
helpers do
def status(id)
url = "http://www.dominos.co.uk/checkout/pizzaTrackeriFrame.aspx?id=#{id}"
uri = URI.parse url
blob = uri.open.read
doc = Nokogiri::HTML.parse blob
arr = doc.search('.step-wrap').collect do |s|
s['class'].split(' ').last
end
current_step = arr.select { |s| s.match /select/ }.first
if current_step
case current_step
when /step1/
"placed"
when /step2/
"preparation"
when /step3/
"bake"
when /step4/
"quality control"
else
"delivered"
end
else
"delivered"
end
end
end
get '/:order_id' do
{id: params[:order_id], status: status(params[:order_id])}.to_json
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment