rubiojr-dropio_xmpp_client 0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +5 -0
- data/Manifest.txt +7 -0
- data/README.txt +48 -0
- data/Rakefile +23 -0
- data/bin/dropio_monitor +60 -0
- data/dropio_xmpp_client.gemspec +43 -0
- data/lib/dropio/xmpp/client.rb +135 -0
- metadata +101 -0
data/Manifest.txt
ADDED
data/README.txt
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
= dropio_push
|
2
|
+
|
3
|
+
* FIX (url)
|
4
|
+
|
5
|
+
== DESCRIPTION:
|
6
|
+
|
7
|
+
FIX (describe your package)
|
8
|
+
|
9
|
+
== FEATURES/PROBLEMS:
|
10
|
+
|
11
|
+
* FIX (list of features or problems)
|
12
|
+
|
13
|
+
== SYNOPSIS:
|
14
|
+
|
15
|
+
FIX (code sample of usage)
|
16
|
+
|
17
|
+
== REQUIREMENTS:
|
18
|
+
|
19
|
+
* FIX (list of requirements)
|
20
|
+
|
21
|
+
== INSTALL:
|
22
|
+
|
23
|
+
* FIX (sudo gem install, anything else)
|
24
|
+
|
25
|
+
== LICENSE:
|
26
|
+
|
27
|
+
(The MIT License)
|
28
|
+
|
29
|
+
Copyright (c) 2009 FIX
|
30
|
+
|
31
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
32
|
+
a copy of this software and associated documentation files (the
|
33
|
+
'Software'), to deal in the Software without restriction, including
|
34
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
35
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
36
|
+
permit persons to whom the Software is furnished to do so, subject to
|
37
|
+
the following conditions:
|
38
|
+
|
39
|
+
The above copyright notice and this permission notice shall be
|
40
|
+
included in all copies or substantial portions of the Software.
|
41
|
+
|
42
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
43
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
44
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
45
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
46
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
47
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
48
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'rake'
|
2
|
+
$:.unshift(File.dirname(__FILE__) + "/lib")
|
3
|
+
require 'hoe'
|
4
|
+
require 'dropio/xmpp/client'
|
5
|
+
|
6
|
+
Hoe.new('dropio_xmpp_client', Dropio::XMPP::VERSION) do |p|
|
7
|
+
p.name = "dropio_xmpp_client"
|
8
|
+
#p.author = "Sergio Rubio"
|
9
|
+
p.description = %q{drop.io XMPP Client}
|
10
|
+
p.email = 'sergio@rubio.name'
|
11
|
+
p.summary = "drop.io XMPP Client Library"
|
12
|
+
p.url = "http://github.com/rubiojr/dropio_xmpp_client"
|
13
|
+
p.remote_rdoc_dir = '' # Release to root
|
14
|
+
p.extra_deps << [ "dropio",">= 0.9" ]
|
15
|
+
p.extra_deps << [ "xmpp4r",">= 0.4" ]
|
16
|
+
p.extra_deps << [ "term-ansicolor",">= 1.0" ]
|
17
|
+
p.developer('Sergio Rubio', 'sergio@rubio.name')
|
18
|
+
end
|
19
|
+
|
20
|
+
task :publish_dev_gem do
|
21
|
+
end
|
22
|
+
task :publish_gem do
|
23
|
+
end
|
data/bin/dropio_monitor
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
begin
|
4
|
+
require "#{File.join(File.dirname(__FILE__), '../lib/dropio/xmpp/client')}"
|
5
|
+
rescue LoadError => e
|
6
|
+
require 'dropio/push_client'
|
7
|
+
end
|
8
|
+
require 'term/ansicolor'
|
9
|
+
require 'highline/import'
|
10
|
+
include Term::ANSIColor
|
11
|
+
include Dropio::XMPP
|
12
|
+
|
13
|
+
drop_name = ARGV.shift
|
14
|
+
if drop_name.nil?
|
15
|
+
$stderr.puts "Usage: dropio_monitor <drop_name>"
|
16
|
+
exit
|
17
|
+
end
|
18
|
+
|
19
|
+
jid = ask("Jabber ID [myjabberick@jabber.org]: ")
|
20
|
+
jid_password = ask("#{jid} password: ") do |q|
|
21
|
+
q.echo = "*"
|
22
|
+
end
|
23
|
+
muc_chat_pass = ask("Drop chat password: ") { |q| q.echo = '*'}
|
24
|
+
nick = ask("Desired nickname: ")
|
25
|
+
|
26
|
+
client = Dropio::XMPP::Client.new(
|
27
|
+
"#{jid}/dropio_xmpp_client",
|
28
|
+
jid_password,
|
29
|
+
drop_name,
|
30
|
+
muc_chat_pass,
|
31
|
+
nick
|
32
|
+
)
|
33
|
+
|
34
|
+
client.on_asset_removed do |message|
|
35
|
+
Dropio::XMPP::Client.notify "drop.io", "#{message} #{drop_name} by #{nick}"
|
36
|
+
puts magenta("*** #{message} #{drop_name}")
|
37
|
+
end
|
38
|
+
|
39
|
+
client.on_asset_added do |asset_name|
|
40
|
+
Dropio::XMPP::Client.notify "drop.io", "'#{asset_name}' was added to #{drop_name} by #{nick}"
|
41
|
+
puts magenta("*** '#{asset_name}' was added to #{drop_name}")
|
42
|
+
end
|
43
|
+
|
44
|
+
client.on_message_received do |time, nick, message|
|
45
|
+
print "[#{blue(time.strftime("%H:%M"))}] " if time
|
46
|
+
puts "<#{yellow(nick)}> #{message}"
|
47
|
+
end
|
48
|
+
|
49
|
+
client.on_join do |time, nick|
|
50
|
+
puts green("*** '#{time}' #{nick} joined the room")
|
51
|
+
end
|
52
|
+
|
53
|
+
client.on_leave do |time, nick|
|
54
|
+
puts red("*** '#{time}' #{nick} left the room")
|
55
|
+
end
|
56
|
+
|
57
|
+
client.connect
|
58
|
+
loop do
|
59
|
+
sleep 0.1
|
60
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = %q{dropio_xmpp_client}
|
3
|
+
s.version = "0.1"
|
4
|
+
|
5
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
6
|
+
s.authors = ["Sergio Rubio"]
|
7
|
+
s.date = %q{2009-05-08}
|
8
|
+
s.default_executable = %q{dropio_monitor}
|
9
|
+
s.description = %q{drop.io XMPP Client}
|
10
|
+
s.email = %q{sergio@rubio.namesergio@rubio.name}
|
11
|
+
s.executables = ["dropio_monitor"]
|
12
|
+
s.extra_rdoc_files = ["History.txt", "Manifest.txt", "README.txt"]
|
13
|
+
s.files = ["History.txt", "Manifest.txt", "README.txt", "Rakefile", "bin/dropio_monitor", "dropio_xmpp_client.gemspec", "lib/dropio/xmpp/client.rb"]
|
14
|
+
s.has_rdoc = true
|
15
|
+
s.homepage = %q{http://github.com/rubiojr/dropio_xmpp_client}
|
16
|
+
s.rdoc_options = ["--main", "README.txt"]
|
17
|
+
s.require_paths = ["lib"]
|
18
|
+
s.rubyforge_project = %q{dropio_xmpp_client}
|
19
|
+
s.rubygems_version = %q{1.3.2}
|
20
|
+
s.summary = %q{drop.io XMPP Client Library}
|
21
|
+
|
22
|
+
if s.respond_to? :specification_version then
|
23
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
24
|
+
s.specification_version = 3
|
25
|
+
|
26
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
27
|
+
s.add_runtime_dependency(%q<dropio>, [">= 0.9"])
|
28
|
+
s.add_runtime_dependency(%q<xmpp4r>, [">= 0.4"])
|
29
|
+
s.add_runtime_dependency(%q<term-ansicolor>, [">= 1.0"])
|
30
|
+
s.add_development_dependency(%q<hoe>, [">= 1.12.1"])
|
31
|
+
else
|
32
|
+
s.add_dependency(%q<dropio>, [">= 0.9"])
|
33
|
+
s.add_dependency(%q<xmpp4r>, [">= 0.4"])
|
34
|
+
s.add_dependency(%q<term-ansicolor>, [">= 1.0"])
|
35
|
+
s.add_dependency(%q<hoe>, [">= 1.12.1"])
|
36
|
+
end
|
37
|
+
else
|
38
|
+
s.add_dependency(%q<dropio>, [">= 0.9"])
|
39
|
+
s.add_dependency(%q<xmpp4r>, [">= 0.4"])
|
40
|
+
s.add_dependency(%q<term-ansicolor>, [">= 1.0"])
|
41
|
+
s.add_dependency(%q<hoe>, [">= 1.12.1"])
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,135 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'xmpp4r'
|
3
|
+
require 'xmpp4r/version'
|
4
|
+
require 'xmpp4r/muc'
|
5
|
+
require 'rexml/document'
|
6
|
+
|
7
|
+
module Dropio
|
8
|
+
module XMPP
|
9
|
+
VERSION = '0.1'
|
10
|
+
class CallbackList
|
11
|
+
def initialize
|
12
|
+
@items = []
|
13
|
+
end
|
14
|
+
|
15
|
+
def <<(cb)
|
16
|
+
@items << cb
|
17
|
+
end
|
18
|
+
|
19
|
+
def notify_event(*event)
|
20
|
+
@items.each do |i|
|
21
|
+
i.call event
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
class Client
|
27
|
+
|
28
|
+
def initialize(jid, password, drop_name, muc_password, nick)
|
29
|
+
@jid = jid
|
30
|
+
@password = password
|
31
|
+
@drop_name = drop_name
|
32
|
+
@muc_password = muc_password
|
33
|
+
@nick = nick
|
34
|
+
@asset_added_cblist = CallbackList.new
|
35
|
+
@asset_deleted_cblist = CallbackList.new
|
36
|
+
@self_join_cblist = CallbackList.new
|
37
|
+
@join_cblist = CallbackList.new
|
38
|
+
@leave_cblist = CallbackList.new
|
39
|
+
@message_received_cblist = CallbackList.new
|
40
|
+
end
|
41
|
+
|
42
|
+
def on_asset_added(&block)
|
43
|
+
@asset_added_cblist << block
|
44
|
+
end
|
45
|
+
|
46
|
+
def on_asset_removed(&block)
|
47
|
+
@asset_deleted_cblist << block
|
48
|
+
end
|
49
|
+
|
50
|
+
def on_self_join(&block)
|
51
|
+
@self_join_cblist << block
|
52
|
+
end
|
53
|
+
|
54
|
+
def on_join(&block)
|
55
|
+
@join_cblist << block
|
56
|
+
end
|
57
|
+
|
58
|
+
def on_leave(&block)
|
59
|
+
@leave_cblist << block
|
60
|
+
end
|
61
|
+
|
62
|
+
def on_message_received(&block)
|
63
|
+
@message_received_cblist << block
|
64
|
+
end
|
65
|
+
|
66
|
+
def self.notify(title, msg)
|
67
|
+
begin
|
68
|
+
require 'growl'
|
69
|
+
Growl.notify msg, :title => title; sleep 0.2
|
70
|
+
rescue
|
71
|
+
puts "#{title}: #{msg}"
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def connect
|
76
|
+
@xmpp_client = Jabber::Client.new(Jabber::JID.new(@jid))
|
77
|
+
Jabber::Version::SimpleResponder.new(@xmpp_client, 'drop.io xmpp rubyclient', Dropio::XMPP::VERSION, "XMPP4R-#{Jabber::XMPP4R_VERSION} on Ruby-#{RUBY_VERSION}")
|
78
|
+
@xmpp_client.connect
|
79
|
+
@xmpp_client.auth @password
|
80
|
+
@muc_client = Jabber::MUC::SimpleMUCClient.new(@xmpp_client)
|
81
|
+
@muc_client.on_message do |time,nick,text|
|
82
|
+
begin
|
83
|
+
@message_received_cblist.notify_event time, nick, text
|
84
|
+
rescue Exception => e
|
85
|
+
puts e.message
|
86
|
+
end
|
87
|
+
end
|
88
|
+
@muc_client.on_join do |time,nick|
|
89
|
+
@join_cblist.notify_event [time, nick]
|
90
|
+
end
|
91
|
+
@muc_client.on_leave do |time,nick|
|
92
|
+
@leave_cblist.notify_event [time, nick]
|
93
|
+
end
|
94
|
+
@muc_client.add_message_callback do |m|
|
95
|
+
doc = REXML::Document.new(m.to_s)
|
96
|
+
begin
|
97
|
+
if not REXML::XPath.match(doc, "message/x/attribute::xmlns").empty?
|
98
|
+
next
|
99
|
+
end
|
100
|
+
rescue Exception => e
|
101
|
+
puts e.message
|
102
|
+
end
|
103
|
+
begin
|
104
|
+
parse_message(doc)
|
105
|
+
rescue Exception => e
|
106
|
+
puts e.message
|
107
|
+
end
|
108
|
+
end
|
109
|
+
@muc_client.join("#{@drop_name}@conference.drop.io/#{@nick}", @muc_password)
|
110
|
+
end
|
111
|
+
|
112
|
+
private
|
113
|
+
def parse_message(doc)
|
114
|
+
doc.elements.each "message/body" do |e|
|
115
|
+
end
|
116
|
+
doc.elements.each "message/dropEventData" do |e|
|
117
|
+
parse_drop_event(doc)
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
def parse_drop_event(doc)
|
122
|
+
evt = REXML::XPath.match(doc, "message/dropEventData/event").first.text
|
123
|
+
case evt
|
124
|
+
when 'assetAdded'
|
125
|
+
asset_name = REXML::XPath.match(doc, "message/dropEventData/params/name").first.text
|
126
|
+
@asset_added_cblist.notify_event asset_name
|
127
|
+
when 'assetDeleted'
|
128
|
+
m = REXML::XPath.match(doc, "message/body").first.text
|
129
|
+
@asset_deleted_cblist.notify_event m
|
130
|
+
else
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
metadata
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rubiojr-dropio_xmpp_client
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: "0.1"
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sergio Rubio
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-05-08 00:00:00 -07:00
|
13
|
+
default_executable: dropio_monitor
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: dropio
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0.9"
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: xmpp4r
|
27
|
+
type: :runtime
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: "0.4"
|
34
|
+
version:
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: term-ansicolor
|
37
|
+
type: :runtime
|
38
|
+
version_requirement:
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: "1.0"
|
44
|
+
version:
|
45
|
+
- !ruby/object:Gem::Dependency
|
46
|
+
name: hoe
|
47
|
+
type: :development
|
48
|
+
version_requirement:
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 1.12.1
|
54
|
+
version:
|
55
|
+
description: drop.io XMPP Client
|
56
|
+
email: sergio@rubio.namesergio@rubio.name
|
57
|
+
executables:
|
58
|
+
- dropio_monitor
|
59
|
+
extensions: []
|
60
|
+
|
61
|
+
extra_rdoc_files:
|
62
|
+
- History.txt
|
63
|
+
- Manifest.txt
|
64
|
+
- README.txt
|
65
|
+
files:
|
66
|
+
- History.txt
|
67
|
+
- Manifest.txt
|
68
|
+
- README.txt
|
69
|
+
- Rakefile
|
70
|
+
- bin/dropio_monitor
|
71
|
+
- dropio_xmpp_client.gemspec
|
72
|
+
- lib/dropio/xmpp/client.rb
|
73
|
+
has_rdoc: true
|
74
|
+
homepage: http://github.com/rubiojr/dropio_xmpp_client
|
75
|
+
post_install_message:
|
76
|
+
rdoc_options:
|
77
|
+
- --main
|
78
|
+
- README.txt
|
79
|
+
require_paths:
|
80
|
+
- lib
|
81
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: "0"
|
86
|
+
version:
|
87
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: "0"
|
92
|
+
version:
|
93
|
+
requirements: []
|
94
|
+
|
95
|
+
rubyforge_project: dropio_xmpp_client
|
96
|
+
rubygems_version: 1.2.0
|
97
|
+
signing_key:
|
98
|
+
specification_version: 3
|
99
|
+
summary: drop.io XMPP Client Library
|
100
|
+
test_files: []
|
101
|
+
|