Skip to content

Instantly share code, notes, and snippets.

@jonmarkgo
Created May 13, 2013 05:23
Show Gist options
  • Save jonmarkgo/5566321 to your computer and use it in GitHub Desktop.
Save jonmarkgo/5566321 to your computer and use it in GitHub Desktop.
require "google/api_client"
require "sinatra"
require "twilio-ruby"
require "json"
post "/receivesms" do
client = Google::APIClient.new(:key => "ABC123")
client.authorization = nil
search = client.discovered_api('customsearch')
response = client.execute(
:api_method => search.cse.list,
:parameters => {
'q' => params[:Body],
'cx' => "1234:abcd",
'num' => '3'
}
)
body = JSON.parse(response.body)
items = body['items']
twiml = Twilio::TwiML::Response.new do |r|
if items.nil? or items.empty?
r.Sms "No results found!"
else
items.each do |item|
r.Sms "#{item['title']}: #{item['link']}"
end
end
end
twiml.text
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment