author | Mikael Hallendal <micke@imendio.com> |
Fri, 11 Apr 2008 18:15:58 +0200 | |
changeset 392 | 2da579e4780f |
parent 391 | d8b64455b5ee |
permissions | -rw-r--r-- |
391
d8b64455b5ee
Added small example for the ruby bindings
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
1 |
# To change this template, choose Tools | Templates |
d8b64455b5ee
Added small example for the ruby bindings
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
2 |
# and open the template in the editor. |
d8b64455b5ee
Added small example for the ruby bindings
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
3 |
|
d8b64455b5ee
Added small example for the ruby bindings
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
4 |
require 'loudmouth' |
d8b64455b5ee
Added small example for the ruby bindings
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
5 |
require 'glib2' |
d8b64455b5ee
Added small example for the ruby bindings
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
6 |
|
d8b64455b5ee
Added small example for the ruby bindings
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
7 |
puts "Enter your JID: " |
392
2da579e4780f
Fixed some in the send-message example
Mikael Hallendal <micke@imendio.com>
parents:
391
diff
changeset
|
8 |
jid = gets.chomp |
391
d8b64455b5ee
Added small example for the ruby bindings
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
9 |
|
d8b64455b5ee
Added small example for the ruby bindings
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
10 |
puts "Enter connect host: " |
392
2da579e4780f
Fixed some in the send-message example
Mikael Hallendal <micke@imendio.com>
parents:
391
diff
changeset
|
11 |
host = gets.chomp |
391
d8b64455b5ee
Added small example for the ruby bindings
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
12 |
|
d8b64455b5ee
Added small example for the ruby bindings
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
13 |
puts "Enter your password: " |
392
2da579e4780f
Fixed some in the send-message example
Mikael Hallendal <micke@imendio.com>
parents:
391
diff
changeset
|
14 |
password = gets.chomp |
391
d8b64455b5ee
Added small example for the ruby bindings
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
15 |
|
d8b64455b5ee
Added small example for the ruby bindings
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
16 |
if /(.+)@(.+)/ =~ jid |
d8b64455b5ee
Added small example for the ruby bindings
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
17 |
login = $1 |
d8b64455b5ee
Added small example for the ruby bindings
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
18 |
end |
d8b64455b5ee
Added small example for the ruby bindings
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
19 |
|
d8b64455b5ee
Added small example for the ruby bindings
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
20 |
puts "Logging in as '#{login}' to '#{host}'" |
d8b64455b5ee
Added small example for the ruby bindings
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
21 |
|
d8b64455b5ee
Added small example for the ruby bindings
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
22 |
main_loop = GLib::MainLoop.new |
d8b64455b5ee
Added small example for the ruby bindings
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
23 |
|
d8b64455b5ee
Added small example for the ruby bindings
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
24 |
conn = LM::Connection.new(host) |
d8b64455b5ee
Added small example for the ruby bindings
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
25 |
conn.jid = jid |
d8b64455b5ee
Added small example for the ruby bindings
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
26 |
conn.ssl = LM::SSL.new |
d8b64455b5ee
Added small example for the ruby bindings
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
27 |
conn.ssl.use_starttls = true |
d8b64455b5ee
Added small example for the ruby bindings
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
28 |
conn.ssl.require_starttls = true |
d8b64455b5ee
Added small example for the ruby bindings
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
29 |
|
d8b64455b5ee
Added small example for the ruby bindings
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
30 |
recipient = "" |
d8b64455b5ee
Added small example for the ruby bindings
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
31 |
|
d8b64455b5ee
Added small example for the ruby bindings
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
32 |
conn.open do |result| |
d8b64455b5ee
Added small example for the ruby bindings
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
33 |
puts "Connection open block" |
d8b64455b5ee
Added small example for the ruby bindings
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
34 |
if result |
d8b64455b5ee
Added small example for the ruby bindings
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
35 |
puts "Connection opened correctly" |
d8b64455b5ee
Added small example for the ruby bindings
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
36 |
conn.authenticate(login, password, "Test") do |auth_result| |
d8b64455b5ee
Added small example for the ruby bindings
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
37 |
unless auth_result |
d8b64455b5ee
Added small example for the ruby bindings
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
38 |
puts "Failed to authenticate" |
d8b64455b5ee
Added small example for the ruby bindings
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
39 |
end |
392
2da579e4780f
Fixed some in the send-message example
Mikael Hallendal <micke@imendio.com>
parents:
391
diff
changeset
|
40 |
authenticated_cb(conn) |
391
d8b64455b5ee
Added small example for the ruby bindings
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
41 |
main_loop.quit |
d8b64455b5ee
Added small example for the ruby bindings
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
42 |
end |
d8b64455b5ee
Added small example for the ruby bindings
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
43 |
else |
d8b64455b5ee
Added small example for the ruby bindings
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
44 |
puts "Failed to connect" |
392
2da579e4780f
Fixed some in the send-message example
Mikael Hallendal <micke@imendio.com>
parents:
391
diff
changeset
|
45 |
main_loop.quit |
391
d8b64455b5ee
Added small example for the ruby bindings
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
46 |
end |
d8b64455b5ee
Added small example for the ruby bindings
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
47 |
end |
d8b64455b5ee
Added small example for the ruby bindings
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
48 |
|
d8b64455b5ee
Added small example for the ruby bindings
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
49 |
def authenticated_cb(conn) |
d8b64455b5ee
Added small example for the ruby bindings
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
50 |
puts "Authenticated!" |
d8b64455b5ee
Added small example for the ruby bindings
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
51 |
puts "Who do you want to message: " |
392
2da579e4780f
Fixed some in the send-message example
Mikael Hallendal <micke@imendio.com>
parents:
391
diff
changeset
|
52 |
recipient = gets.chomp |
391
d8b64455b5ee
Added small example for the ruby bindings
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
53 |
|
d8b64455b5ee
Added small example for the ruby bindings
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
54 |
puts "Enter message: " |
392
2da579e4780f
Fixed some in the send-message example
Mikael Hallendal <micke@imendio.com>
parents:
391
diff
changeset
|
55 |
body = gets.chomp |
391
d8b64455b5ee
Added small example for the ruby bindings
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
56 |
|
d8b64455b5ee
Added small example for the ruby bindings
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
57 |
m = LM::Message.new(recipient, LM::MessageType::MESSAGE) |
d8b64455b5ee
Added small example for the ruby bindings
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
58 |
m.node.add_child('body', body) |
d8b64455b5ee
Added small example for the ruby bindings
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
59 |
|
d8b64455b5ee
Added small example for the ruby bindings
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
60 |
conn.send(m) |
d8b64455b5ee
Added small example for the ruby bindings
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
61 |
conn.close |
d8b64455b5ee
Added small example for the ruby bindings
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
62 |
|
392
2da579e4780f
Fixed some in the send-message example
Mikael Hallendal <micke@imendio.com>
parents:
391
diff
changeset
|
63 |
puts "Message sent to #{recipient}" |
391
d8b64455b5ee
Added small example for the ruby bindings
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
64 |
end |
d8b64455b5ee
Added small example for the ruby bindings
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
65 |
|
d8b64455b5ee
Added small example for the ruby bindings
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
66 |
main_loop.run |
d8b64455b5ee
Added small example for the ruby bindings
Mikael Hallendal <micke@imendio.com>
parents:
diff
changeset
|
67 |
|
392
2da579e4780f
Fixed some in the send-message example
Mikael Hallendal <micke@imendio.com>
parents:
391
diff
changeset
|
68 |
puts "Quitting" |