require "sinatra"
require 'sinatra/reloader' if development?
require 'twilio-ruby'
require 'spotlite'
enable :sessions
@client = Twilio::REST::Client.new ENV["TWILIO_ACCOUNT_SID"], ENV["TWILIO_AUTH_TOKEN"]
#moviedb api
url = 'https://api.themoviedb.org/3/search/movie?api_key=9ec125b878c86c1f6ce8ca3a234cda31&language=en-US&query=iron%20man'
response = HTTParty.get(url)
results = response["results"].first
title = results["title"].first
vote_average = results["vote_average"].first
popularity = results["popularity"].first
overview = results["overview"].first
configure :development do
require 'dotenv'
Dotenv.load
end
movie_name = String.new
get "/" do
404
end
get "/sms/incoming" do
session["last_intent"] ||= nil
session["counter"] ||= 1
count = session["counter"]
sender = params[:From] || ""
body = params[:Body] || ""
body = body.downcase.strip
if session["counter"] == 1
message = "Hey there, I'm Lumimd. I can share any information about any movie!"
elsif body[0] == "~"
#findmovie
#@movie = TmdbMovie.find keywords
movie_name = body.delete("~")
url = url + movie_name
response = HTTParty.get(url)
title = response["results"][0]["title"]
vote_average = response["results"][0]["vote_average"]
overview = response["results"][0]["overview"]
vote_average = response["results"][0]["vote_average"]
popularity = response["results"][0]["popularity"]
answer = title + vote_average + popularity + overview
message = answer.to_s
elsif body[0] = "l"
location = body.delete("l")
url_location = "https://www.fandango.com/search?q=" + location + "&mode=general"
message = "Here are some movies near" + location +". Reply the number you want to go." + url_location
elsif body[0] = "d"
date = body.delete("d")
url_date = " https://www.fandango.com/" + location + "movietimes?date=" + date
message = "Here we get some shows on" + date + "at" + location + "Please check your tickets in this page." + url_location
end
session["counter"] += 1
twiml = Twilio::TwiML::MessagingResponse.new do |r|
r.message do |m|
m.body( message )
unless media.nil?
m.media( media )
end
end
end
content_type 'text/xml'
twiml.to_s
end
Click to Expand
Content Rating
Is this a good/useful/informative piece of content to include in the project? Have your say!
You must login before you can post a comment. .