c3s 0.2.2 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +11 -14
- data/Rakefile +1 -1
- data/c3s.gemspec +2 -2
- data/lib/c3s.rb +1 -0
- data/lib/component.rb +47 -0
- data/lib/model.rb +22 -3
- metadata +2 -2
data/README.rdoc
CHANGED
@@ -1,15 +1,12 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
# phrases from standard input and reports whether
|
6
|
-
# they are angrams of the first word.
|
7
|
-
#
|
8
|
-
# Author:: Dave Thomas (mailto:dave@x.y)
|
9
|
-
# Copyright:: Copyright (c) 2002 The Pragmatic Programmers, LLC
|
10
|
-
# License:: Distributes under the same terms as Ruby
|
1
|
+
= Context Content Consuming & Sharing
|
2
|
+
This is a small library to make context entities on c3s project
|
3
|
+
it is basically a set of classes with some work done so that
|
4
|
+
the code on providers and consumers can be as DRY as possible.
|
11
5
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
6
|
+
The library is installed and used as a ruby gem in 3 steps
|
7
|
+
1. sudo gem source -a http://gemcutter.org
|
8
|
+
2. sudo gem install c3s
|
9
|
+
3. require "c3s"
|
10
|
+
|
11
|
+
Author:: Ricardo Otero dos Santos (mailto:oterosantos@gmail.com)
|
12
|
+
Copyright:: Copyright (c) 2009. All rights reserved.
|
data/Rakefile
CHANGED
data/c3s.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{c3s}
|
5
|
-
s.version = "0.2.
|
5
|
+
s.version = "0.2.3"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Ricardo Otero"]
|
9
|
-
s.date = %q{2009-12-
|
9
|
+
s.date = %q{2009-12-05}
|
10
10
|
s.description = %q{C3s library gem.}
|
11
11
|
s.email = %q{oterosantos@gmail.com}
|
12
12
|
s.extra_rdoc_files = ["README.rdoc", "lib/c3s.rb", "lib/c3s_logger.rb", "lib/component.rb", "lib/component_connection.rb", "lib/configreader.rb", "lib/databaseadapter.rb", "lib/model.rb", "lib/nodetracker.rb", "lib/publisher.rb"]
|
data/lib/c3s.rb
CHANGED
data/lib/component.rb
CHANGED
@@ -57,6 +57,25 @@ module C3s
|
|
57
57
|
end
|
58
58
|
end
|
59
59
|
|
60
|
+
##
|
61
|
+
# Reply to discovery info IQ packet
|
62
|
+
# iq:: [Jabber::IQ] the received IQ packet
|
63
|
+
def handle_disco_info(iq)
|
64
|
+
reply = iq.answer
|
65
|
+
|
66
|
+
if iq.type != :get
|
67
|
+
send_error(iq, ['bad-request', nil])
|
68
|
+
return
|
69
|
+
end
|
70
|
+
|
71
|
+
reply.type = :result
|
72
|
+
reply.query.add(Jabber::Discovery::Identity.new(config['category'], config['description'], config['type']))
|
73
|
+
reply.query.add(Jabber::Discovery::Feature.new(Jabber::Discovery::IqQueryDiscoInfo.new.namespace))
|
74
|
+
reply.query.add(Jabber::Discovery::Feature.new(Jabber::Discovery::IqQueryDiscoItems.new.namespace))
|
75
|
+
|
76
|
+
send(reply)
|
77
|
+
end
|
78
|
+
|
60
79
|
##
|
61
80
|
# Sends an error response to a received IQ packet.
|
62
81
|
# iq:: [Jabber::IQ] the received IQ packet
|
@@ -72,6 +91,34 @@ module C3s
|
|
72
91
|
|
73
92
|
send(reply) if iq.type != :error
|
74
93
|
end
|
94
|
+
|
95
|
+
##
|
96
|
+
# Publishes information to pubsub server
|
97
|
+
# iq:: the setter iq
|
98
|
+
# data:: what to publish
|
99
|
+
# changed:: the data is different from last set operation?
|
100
|
+
def publish(iq, data, changed)
|
101
|
+
if changed
|
102
|
+
pub = Publisher.new(self, "pubsub."+config['url'])
|
103
|
+
pub.create_nodes("/#{config['name']}/#{iq.from.bare.to_s}")
|
104
|
+
pub.publish(iq.from.bare.to_s, data)
|
105
|
+
end
|
106
|
+
|
107
|
+
send_ok iq
|
108
|
+
end
|
109
|
+
|
110
|
+
##
|
111
|
+
# Sends an OK response to a given iq
|
112
|
+
# iq:: the iq to respond to
|
113
|
+
def send_ok(iq)
|
114
|
+
reply = Jabber::Iq.new()
|
115
|
+
reply.id = iq.id
|
116
|
+
reply.to = iq.from
|
117
|
+
reply.type = :result
|
118
|
+
reply.add(Jabber::IqQuery::new)
|
119
|
+
|
120
|
+
send(reply) if iq.type != :error
|
121
|
+
end
|
75
122
|
end
|
76
123
|
|
77
124
|
Signal.trap('INT') do
|
data/lib/model.rb
CHANGED
@@ -6,12 +6,31 @@ module C3s
|
|
6
6
|
# Attributes ignored and not included on model xml by default
|
7
7
|
IGNORE_ATTR = ["created_at", "updated_at", "id", "jid"]
|
8
8
|
|
9
|
+
##
|
10
|
+
# Updates multiple attributes at once
|
11
|
+
# attributes:: [Hash] the attributes hash
|
12
|
+
def update_attributes(attributes={})
|
13
|
+
self.send(:attributes=, attributes, false)
|
14
|
+
end
|
15
|
+
|
9
16
|
##
|
10
17
|
# Returns the class name for this model without module name
|
11
18
|
def _class_name
|
12
19
|
@class_name ||= self.class.name.split("::").last.downcase
|
13
20
|
end
|
14
21
|
|
22
|
+
##
|
23
|
+
# Gets the model nodes hash
|
24
|
+
def self.nodes
|
25
|
+
nodes = self.attributes
|
26
|
+
nodes.each do |key, val|
|
27
|
+
if IGNORE_ATTR.include?(key) or key.match(/.+_id/)
|
28
|
+
nodes.delete(key)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
nodes.keys
|
32
|
+
end
|
33
|
+
|
15
34
|
##
|
16
35
|
# Gets the model xml to include in a packet.
|
17
36
|
# options:: [Hash] options
|
@@ -28,12 +47,12 @@ module C3s
|
|
28
47
|
##
|
29
48
|
# Returns the first element for the model xml
|
30
49
|
def first_element(options={})
|
31
|
-
if options[:
|
50
|
+
if options[:parent]
|
51
|
+
first = options[:parent]
|
52
|
+
else
|
32
53
|
name = self._class_name
|
33
54
|
name = name.pluralize if options[:plural]
|
34
55
|
first = REXML::Element.new(name)
|
35
|
-
else
|
36
|
-
first = options[:parent]
|
37
56
|
end
|
38
57
|
end
|
39
58
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: c3s
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ricardo Otero
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-12-
|
12
|
+
date: 2009-12-05 00:00:00 +00:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|