ruby faye server with scala client - ruby

I have a Faye server running with ruby, and now, I need to send notifications to a client in Scala, but scala can't handle Bayeux, only WebSockets.
Is there a way to change my connection type from Bayeux to using websockets?
Some conf. files I have
faye.ru
require 'faye'
Faye::WebSocket.load_adapter('thin')
bayeux = Faye::RackAdapter.new(:mount => '/faye', :timeout => 25)
run bayeux
sending notifications
def broadcast(channel, data)
message = {:channel => channel, :data => data, :ext => {:auth_token => FAYE_TOKEN}}
uri = URI.parse("http://192.168.0.92:9292/faye")
Net::HTTP.post_form(uri, :message => message.to_json)
end

We migrate our scala app to ruby. Much better now :)

Related

broadcasting data with event machine websocket

I have written a program for reading data from an html file to ruby program using websocket. I am including the code below:
EventMachine::WebSocket.run(:host => "0.0.0.0", :port => 8080) do |ws|
ws.onopen { |handshake|
puts "WebSocket connection open #{ws}"
# Access properties on the EM::WebSocket::Handshake object, e.g.
# path, query_string, origin, headers
# Publish message to the client
# ws.send "Hello Client, you connected to #{handshake.path}"
}
ws.onclose { puts "Connection closed" }
ws.onmessage { |msg|
puts "Recieved message: #{msg}"
ws.send "#{msg}"
}
end
This is working properly.It recieves whatever data send from my html page. Now, what I need is to keep track of the connections to this server and send the recieved message to all the available connections.
The 'send' function here used can send only to a specified connection.
You asking for a basic chat server?
Just store the connections in a list (or hash).
People tend to include in a hash to make it easier to remove them
If this is in a class, use #connections instead of $connections
GL
$connections = {}
EventMachine::WebSocket.run(:host => "0.0.0.0", :port => 8080) do |ws|
ws.onopen
$connections[ws] = true
end
ws.onclose do
$connections.delete(ws)
end
ws.onmessage do |msg|
$connections.each { |c, b| c.send msg }
end
end
You could use EventMachine in combination with Faye and Faye/Websocket
You will need faye/websocket for your browser-based clients or just faye for your ruby clients.
The idea is that with Faye you create a channel and then you subscribe your clients to that channel. Then you push from your server the data you want to this channel and the clients subscribed will receive this data.

Proxy in ruby gem "twitter_oauth"

My test environment for my Ruby (Sinatra + twitter_oauth) project is behind a proxy.
In the documentation, I read how to use the twitter_oauth gem with a proxy. But there the author says:
First you need to authorize the Twitter user via OAuth directly via the Twitter API (this part cannot be proxied)
But unfortunately, on this step I receive an proxy error when testing locally.
Is there any possibility to proxy this?
client = TwitterOAuth::Client.new(
:consumer_key => 'YOUR_APP_CONSUMER_KEY',
:consumer_secret => 'YOURA_APP_CONSUMER_SECRET'
)
request_token = client.request_token(:oauth_callback => 'YOUR_CALLBACK_URL')
Thanks in advance!!
No, but OAuth can be skipped if a check for local environment is wrapped around the authentication:
def localhost
client = "Test"
request_token = "Me"
def webhost
client = TwitterOAuth::Client.new(
:consumer_key => 'YOUR_APP_CONSUMER_KEY',
:consumer_secret => 'YOURA_APP_CONSUMER_SECRET'
)
request_token = client.request_token(:oauth_callback => 'YOUR_CALLBACK_URL')

How to use jabber-bot to connect to chat server

we have a private chat server running on one of the servers we own. for example: company.server.com. We connect to this with our chat clients on port 5223.
How can I get Jabber-bot to connect to this chat? What if I want to connect to a particular room?
Below is what I have but it seems to just hang and do nothing. I believe there should be a property where I should provide the name of the server I'm connecting to but I can't find that property anyplace.
require 'rubygems'
require './jabber/bot'
# Create a public Jabber::Bot
config = {
:jabber_id => 'name#mycompany.com',
:password => 'mypassword',
:master => 'name#mycompany.com',
:presence => :chat,
}
bot = Jabber::Bot.new(config)
# Give your bot a private command, 'rand'
bot.add_command(
:syntax => 'rand',
:description => 'Produce a random number from 0 to 10',
:regex => /^rand$/
) { rand(10).to_s }
# Bring your new bot to life
bot.connect
session = Jabber::Session.bind('account#host/resource', 'password')

Savon: WCF Soap service with wsse auth: AddressFilter mismatch at the EndpointDispatcher

I am trying to create SOAPClient using Savon - rubygem.
Its a WCF soap service with WSSE auth over https. Here is the code that I tried:
require 'savon'
client = Savon::Client.new do
wsdl.document = "https://svc.sxxxxxify.com:8081/ConfSet.svc?wsdl"
config.soap_version = 2
wsse.credentials "aa5#xxasxsaxsh.com", "test123"
end
p client.wsdl.soap_actions
response = client.request :get_user_clients
p response
But I get this error:
http://www.w3.org/2005/08/addressing/soap/fault2012-10-26T06:07:42.247Z2012-10-26T06:12:42.247Zs:Sendera:DestinationUnreachableThe message with To '' cannot be processed at the
receiver, due to an AddressFilter mismatch at the EndpointDispatcher.
Check that the sender and receiver's EndpointAddresses
agree.
.
The message with To '' cannot be processed at the receiver, due to an
AddressFilter mismatch at the EndpointDispatcher. Check that the
sender and receiver's EndpointAddresses agree. (Savon::SOAP::Fault)
Please help me solve this problem
I had the some problem. I've solved the 'To' problem by providing a header entry and a new namespace. The 'Action' header was also necessary though, and I only discovered that after inspecting SoapUI logs. Here is what worked for me:
#service_url = 'https://svc.sxxxxxify.com:8081/ConfSet.svc/service'
#action = 'your_action'
#client = Savon.client(:wsdl => "#{#service_url}?wsdl", :soap_version => 2,
:namespaces => {"xmlns:x" => "http://www.w3.org/2005/08/addressing"},
:soap_header => {"x:To" => #service_url, "x:Action" => "http://tempuri.org/#{#action}"})

Rails savon, two wsdl

I'm developing on Rails and I'm using the gem Savon (http://savonrb.com).
What I have to do is to integrate myself with a service that I wsdl has two, one for authentication and the other for various functions.
There are two wsdl:
"https://.../authentication.asmx?wsdl"
"https://.../lists.asmx?wsdl"
What I do first is this:
client = Savon::Client.new do |wsdl, http|
http.auth.ssl.verify_mode = :none
wsdl.document = "https://.../authentication.asmx?wsdl"
end
response = client.request :soap, :login, :body => {:username => "...", :password => "..."}
Once logged in I would need to use the second wsdl to perform my function, but I can not declare another client within authentication lose the first thing I said.
response = client.request :get_list_collection do
soap.endpoint = URI(URI.escape("https://.../lists.asmx?wsdl"))
end
I've tried many but I found no solution.
Any idea how to solve this problem?

Resources