Skip to content

Instantly share code, notes, and snippets.

@bjhaid
Created August 15, 2011 17:36
Show Gist options
  • Save bjhaid/1147269 to your computer and use it in GitHub Desktop.
Save bjhaid/1147269 to your computer and use it in GitHub Desktop.
job.rb
require File.expand_path("../environment", __FILE__)
require 'faye'
job "sugar.find" do |args|
begin
=begin
faye = Faye::Client.new('http://10.10.5.96:9292/faye')
msge = JSON.dump('channel' => "/ajaxsearches", 'data' => {'exten_no' => "#{@ajaxsearches.extenno}", 'resarray' => "#{@search}"})
uri = URI.parse('http://0.0.0.0:9292/faye')
Net::HTTP.post_form(uri, :message => msge)
=end
faye = Faye::Client.new('http://10.10.5.96:9292/faye')
EM.run {
faye.publish("/ajaxsearches", {'exten_no' => "#{@ajaxsearches.extenno}", 'resarray' => "#{@search}"})
}
@search = Sugar.find(:all, :conditions => {:first_name => "LIKE '%#{args["name"]}%'"}).collect{ |user| "<tr><td><b><a href='http://10.10.5.104:8080/wakanow/index.php?module=Contacts&action=DetailView&record="+"#{user.id}" + "'>" + "#{user.account_name}"+"</b></td>" + "</a><td>Email address: <b>" + "#{user.email1}"+"</b><a href=" + 'http://10.10.5.104:8080/wakanow/index.php?module=Contacts&action=DetailView&record=' + "#{user.id}" + "><img border=0 src='jquery/images/contacts.gif' title=" + "#{user.account_name}" + "/></a></tr>" }
rescue
=begin
faye = Faye::Client.new('http://10.10.5.96:9292/faye')
msge = JSON.dump('channel' => "/ajaxsearches", 'data' => {'exten_no' => "#{@ajaxsearches.extenno}", 'resarray' => "#{@search}"})
uri = URI.parse('http://0.0.0.0:9292/faye')
Net::HTTP.post_form(uri, :message => msge)
=end
faye = Faye::Client.new('http://10.10.5.96:9292/faye')
EM.run {
faye.publish("/ajaxsearches", {'exten_no' => "#{@ajaxsearches.extenno}", 'resarray' => "#{@search}"})
}
@search = Sugar.find(:all, :conditions => {:first_name => "LIKE '%#{args["name"]}%'"}).collect{ |user| "<tr><td><b><a href='http://10.10.5.104:8080/wakanow/index.php?module=Contacts&action=DetailView&record="+"#{user.id}" + "'>" + "#{user.account_name}"+"</b></td>" + "</a><td>Email address: <b>" + "#{user.email1}"+"</b><a href=" + 'http://10.10.5.104:8080/wakanow/index.php?module=Contacts&action=DetailView&record=' + "#{user.id}" + "><img border=0 src='jquery/images/contacts.gif' title=" + "#{user.account_name}" + "/></a></tr>" }
rescue
=begin
msg = JSON.dump('channel' => "/incomings", 'data' => {'exten_id' => "#{@incoming.exten_number}", 'caller_id' => "#{@contact.id}", 'caller_name' => "#{@contact.account_name.split(' ').map {|w| w.capitalize }.join(' ')}", 'caller_number' => "#{params[:cid_number]}" })
uri = URI.parse('http://0.0.0.0:9292/faye')
Net::HTTP.post_form(uri, :message => msg)
=end
faye = Faye::Client.new('http://10.10.5.96:9292/faye')
EM.run {
faye.publish("/ajaxsearches", {'exten_no' => "#{@ajaxsearches.extenno}", 'resarray' => "#{@search}"})
}
=begin
faye = Faye::Client.new('http://10.10.5.96:9292/faye')
msge = JSON.dump('channel' => "/ajaxsearches", 'data' => {'exten_no' => "#{@ajaxsearches.extenno}", 'resarray' => "#{@search}"})
uri = URI.parse('http://0.0.0.0:9292/faye')
Net::HTTP.post_form(uri, :message => msge)
=end
@search = Sugar.find(:all, :conditions => {:first_name => "LIKE '%#{args["name"]}%'"}).collect{ |user| "<tr><td><b><a href='http://10.10.5.104:8080/wakanow/index.php?module=Contacts&action=DetailView&record="+"#{user.id}" + "'>" + "#{user.account_name}"+"</b></td>" + "</a><td>Email address: <b>" + "#{user.email1}"+"</b><a href=" + 'http://10.10.5.104:8080/wakanow/index.php?module=Contacts&action=DetailView&record=' + "#{user.id}" + "><img border=0 src='jquery/images/contacts.gif' title=" + "#{user.account_name}" + "/></a></tr>" }
end
end
ajaxsearch_controller.rb
class AjaxsearchController < ApplicationController
require 'stalker'
def new
=begin
@search = Sugar.find(:all, :conditions => {:first_name => "LIKE '%#{params[:name]}%'"}).collect{ |user| "<tr><td><b><a href='http://10.10.5.104:8080/wakanow/index.php?module=Contacts&action=DetailView&record="+"#{user.id}" + "'>" + "#{user.account_name}"+"</b></td>" + "</a><td>Email address: <b>" + "#{user.email1}"+"</b><a href=" + 'http://10.10.5.104:8080/wakanow/index.php?module=Contacts&action=DetailView&record=' + "#{user.id}" + "><img border=0 src='jquery/images/contacts.gif' title=" + "#{user.account_name}" + "/></a></tr>" }
# @search = Sugar.find(:all, :conditions => {:first_name => "LIKE '%#{params[:name]}'"}).collect{ |user| { :first_name => user.first_name :id => user.account_id, :name => user.account_name }}
rescue
@search = Sugar.find(:all, :conditions => {:first_name => "LIKE '%#{params[:name]}%'"}).collect{ |user| "<tr><td><b><a href='http://10.10.5.104:8080/wakanow/index.php?module=Contacts&action=DetailView&record="+"#{user.id}" + "'>" + "#{user.account_name}"+"</b></td>" + "</a><td>Email address: <b>" + "#{user.email1}"+"</b>&nbsp;<a href=" + 'http://10.10.5.104:8080/wakanow/index.php?module=Contacts&action=DetailView&record=' + "#{user.id}" + "><img border=0 src='jquery/images/contacts.gif' title=" + "#{user.account_name}" + "/></a></tr>" }
# @search = Sugar.find(:all, :conditions => {:first_name => "LIKE '%#{params[:name]}'"}).collect{ |user| { :first_name => user.first_name :id => user.account_id, :name => user.account_name }}
end
=end
#@search = Ajaxsearch.fetch(params[:name])
@ajaxsearches = Ajaxsearch.create({:name => params[:name], :extenno => params[:extenno]})
if @ajaxsearches.update_attributes(params[:ajaxsearch])
#s = Stalker.enqueue('search', :id => @search.id)
Stalker.enqueue("sugar.find", :name => params[:name])
end
end
def create
@ajaxsearches = Ajaxsearch.new(params[:incoming])
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment