2007-10-14 05:33:00 +00:00
|
|
|
class IntegrationsController < ApplicationController
|
2011-10-04 20:14:36 +02:00
|
|
|
require 'mail'
|
|
|
|
|
|
|
|
skip_before_filter :login_required, :only => [:cloudmailin, :search_plugin, :google_gadget]
|
2008-12-10 21:30:43 +01:00
|
|
|
|
2007-10-14 05:33:00 +00:00
|
|
|
def index
|
|
|
|
@page_title = 'TRACKS::Integrations'
|
|
|
|
end
|
|
|
|
|
2007-12-05 06:48:24 +00:00
|
|
|
def rest_api
|
|
|
|
@page_title = 'TRACKS::REST API Documentation'
|
|
|
|
end
|
|
|
|
|
2007-10-14 05:33:00 +00:00
|
|
|
def get_quicksilver_applescript
|
|
|
|
context = current_user.contexts.find params[:context_id]
|
|
|
|
render :partial => 'quicksilver_applescript', :locals => { :context => context }
|
|
|
|
end
|
|
|
|
|
|
|
|
def get_applescript1
|
|
|
|
context = current_user.contexts.find params[:context_id]
|
|
|
|
render :partial => 'applescript1', :locals => { :context => context }
|
|
|
|
end
|
|
|
|
|
|
|
|
def get_applescript2
|
|
|
|
context = current_user.contexts.find params[:context_id]
|
|
|
|
render :partial => 'applescript2', :locals => { :context => context }
|
|
|
|
end
|
2008-12-10 21:30:43 +01:00
|
|
|
|
|
|
|
def search_plugin
|
2012-04-18 14:22:58 +02:00
|
|
|
# TODO: ASSET PATH!!
|
|
|
|
@icon_data = [File.open(Rails.root + '/public/images/done.png').read].
|
2011-10-04 20:14:36 +02:00
|
|
|
pack('m').gsub(/\n/, '')
|
|
|
|
|
|
|
|
render :layout => false
|
2008-12-10 21:30:43 +01:00
|
|
|
end
|
|
|
|
|
2009-08-04 09:54:45 +02:00
|
|
|
def google_gadget
|
|
|
|
render :layout => false, :content_type => Mime::XML
|
|
|
|
end
|
2011-10-04 20:14:36 +02:00
|
|
|
|
|
|
|
def cloudmailin
|
2011-10-05 23:53:49 +02:00
|
|
|
# verify cloudmailin signature
|
|
|
|
provided = request.request_parameters.delete(:signature)
|
|
|
|
signature = Digest::MD5.hexdigest(request.request_parameters.sort{|a,b| a[0].to_s <=> b[0].to_s}.map{|k,v| v}.join + SITE_CONFIG['cloudmailin'])
|
|
|
|
|
|
|
|
# if signature does not match, return 403
|
|
|
|
if provided != signature
|
2011-10-06 16:41:46 +02:00
|
|
|
render :text => "Message signature verification failed.", :status => 403
|
2011-10-05 23:53:49 +02:00
|
|
|
return false
|
|
|
|
end
|
2011-10-04 20:14:36 +02:00
|
|
|
|
2011-10-05 23:53:49 +02:00
|
|
|
# parse message
|
|
|
|
message = Mail.new(params[:message])
|
|
|
|
|
2011-10-04 20:14:36 +02:00
|
|
|
# find user
|
2012-04-18 14:22:58 +02:00
|
|
|
user = User.where("preferences.sms_email = ?", message.from).includes(:preferences).first
|
2011-10-04 20:14:36 +02:00
|
|
|
if user.nil?
|
|
|
|
render :text => "No user found", :status => 404
|
|
|
|
return false
|
|
|
|
end
|
2009-08-04 09:54:45 +02:00
|
|
|
|
2011-10-05 23:53:49 +02:00
|
|
|
# load user settings
|
2011-10-04 20:14:36 +02:00
|
|
|
context = user.prefs.sms_context
|
2011-10-05 23:53:49 +02:00
|
|
|
|
2011-10-04 20:14:36 +02:00
|
|
|
# prepare body
|
|
|
|
if message.body.multipart?
|
|
|
|
body = message.body.preamble
|
|
|
|
else
|
|
|
|
body = message.body.to_s
|
|
|
|
end
|
|
|
|
|
|
|
|
# parse mail
|
|
|
|
if message.subject.to_s.empty?
|
|
|
|
description = body
|
|
|
|
notes = nil
|
|
|
|
else
|
2011-10-05 23:53:49 +02:00
|
|
|
description = message.subject.to_s
|
2011-10-04 20:14:36 +02:00
|
|
|
notes = body
|
|
|
|
end
|
|
|
|
|
2011-10-05 23:53:49 +02:00
|
|
|
# create todo
|
2011-10-04 20:14:36 +02:00
|
|
|
todo = Todo.from_rich_message(user, context.id, description, notes)
|
|
|
|
todo.save!
|
|
|
|
render :text => 'success', :status => 200
|
|
|
|
end
|
2007-10-14 05:33:00 +00:00
|
|
|
end
|