Skip to content

Instantly share code, notes, and snippets.

@cemre
Last active December 23, 2015 18:59
Show Gist options
  • Save cemre/6679813 to your computer and use it in GitHub Desktop.
Save cemre/6679813 to your computer and use it in GitHub Desktop.
Get a call when Apple has iPhones in stock. https://medium.com/p/7f921ea94e8f
require 'twilio-ruby'
require 'httparty'
require 'json'
class Alerter
def check
# set up a client to talk to the Twilio REST API
account_sid = 'xxxxxx'
auth_token = 'xxxxxx'
@client = Twilio::REST::Client.new account_sid, auth_token
phone = "ME329LL/A" # MODEL NUMBER
zip = "10010" # YOUR ZIP CODE
response = HTTParty.get("http://store.apple.com/us/retail/availabilitySearch?parts.0=#{phone}&zip=#{zip}")
r = JSON::load(response.body)
r['body']['stores'].each_with_index do |store, i|
if i < 5 # Check the 5 nearest stores in this ZIP code
if store['partsAvailability'][phone]['pickupDisplay'] == 'available'
puts "found in #{store['storeEmail']}"
@call = @client.account.calls.create(
:from => '+1347xxxxx',
:to => '+1347xxxxx',
:url => 'http://demo.twilio.com/welcome/voice/',
# This will have a bland default Twilio greeting, but it shouldn't matter, right? :)
)
else
puts "not found in #{store['storeEmail']}"
end
end
end
end
end
Alerter.new.check()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment