xmpp4r-robot 0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitmodules +3 -0
- data/.travis.yml +9 -0
- data/Gemfile +11 -0
- data/LICENSE +201 -0
- data/README.md +95 -0
- data/Rakefile +13 -0
- data/lib/xmpp4r/robot.rb +126 -0
- data/lib/xmpp4r-robot.rb +3 -0
- data/task/README.md +54 -0
- data/task/gemgem.rb +262 -0
- data/xmpp4r-robot.gemspec +42 -0
- metadata +69 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 1546d0ef0a762f29b06026368758036e5675b5a8
|
4
|
+
data.tar.gz: 9de0ef3dba793af53cfefbc37260ed778354781e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 31c4b5c1728638a547f2a1b4cd7da0867e062a21c36ebe03c580510e9923374ba4a5cbaa02b72386360ae94de791da82fe233a5446fcb206095ae181ed93fc78
|
7
|
+
data.tar.gz: d78ffd1965952d2cddf91ec99516be7579a3428caa22dfe7bd9a6d52ba22f900ddaba5906740919ba5968fdc915ba78183cb5ae8bf1fd4bf9d0b560a31a41503
|
data/.gitmodules
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,201 @@
|
|
1
|
+
Apache License
|
2
|
+
Version 2.0, January 2004
|
3
|
+
http://www.apache.org/licenses/
|
4
|
+
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
6
|
+
|
7
|
+
1. Definitions.
|
8
|
+
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
11
|
+
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
13
|
+
the copyright owner that is granting the License.
|
14
|
+
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
16
|
+
other entities that control, are controlled by, or are under common
|
17
|
+
control with that entity. For the purposes of this definition,
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
19
|
+
direction or management of such entity, whether by contract or
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
22
|
+
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
24
|
+
exercising permissions granted by this License.
|
25
|
+
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
27
|
+
including but not limited to software source code, documentation
|
28
|
+
source, and configuration files.
|
29
|
+
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
31
|
+
transformation or translation of a Source form, including but
|
32
|
+
not limited to compiled object code, generated documentation,
|
33
|
+
and conversions to other media types.
|
34
|
+
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
36
|
+
Object form, made available under the License, as indicated by a
|
37
|
+
copyright notice that is included in or attached to the work
|
38
|
+
(an example is provided in the Appendix below).
|
39
|
+
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
46
|
+
the Work and Derivative Works thereof.
|
47
|
+
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
49
|
+
the original version of the Work and any modifications or additions
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
61
|
+
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
64
|
+
subsequently incorporated within the Work.
|
65
|
+
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
72
|
+
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
78
|
+
where such license applies only to those patent claims licensable
|
79
|
+
by such Contributor that are necessarily infringed by their
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
82
|
+
institute patent litigation against any entity (including a
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
85
|
+
or contributory patent infringement, then any patent licenses
|
86
|
+
granted to You under this License for that Work shall terminate
|
87
|
+
as of the date such litigation is filed.
|
88
|
+
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
91
|
+
modifications, and in Source or Object form, provided that You
|
92
|
+
meet the following conditions:
|
93
|
+
|
94
|
+
(a) You must give any other recipients of the Work or
|
95
|
+
Derivative Works a copy of this License; and
|
96
|
+
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
98
|
+
stating that You changed the files; and
|
99
|
+
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
102
|
+
attribution notices from the Source form of the Work,
|
103
|
+
excluding those notices that do not pertain to any part of
|
104
|
+
the Derivative Works; and
|
105
|
+
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
108
|
+
include a readable copy of the attribution notices contained
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
111
|
+
of the following places: within a NOTICE text file distributed
|
112
|
+
as part of the Derivative Works; within the Source form or
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
114
|
+
within a display generated by the Derivative Works, if and
|
115
|
+
wherever such third-party notices normally appear. The contents
|
116
|
+
of the NOTICE file are for informational purposes only and
|
117
|
+
do not modify the License. You may add Your own attribution
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
120
|
+
that such additional attribution notices cannot be construed
|
121
|
+
as modifying the License.
|
122
|
+
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
124
|
+
may provide additional or different license terms and conditions
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
128
|
+
the conditions stated in this License.
|
129
|
+
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
133
|
+
this License, without any additional terms or conditions.
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
135
|
+
the terms of any separate license agreement you may have executed
|
136
|
+
with Licensor regarding such Contributions.
|
137
|
+
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
140
|
+
except as required for reasonable and customary use in describing the
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
142
|
+
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
152
|
+
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
158
|
+
incidental, or consequential damages of any character arising as a
|
159
|
+
result of this License or out of the use or inability to use the
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
162
|
+
other commercial damages or losses), even if such Contributor
|
163
|
+
has been advised of the possibility of such damages.
|
164
|
+
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
168
|
+
or other liability obligations and/or rights consistent with this
|
169
|
+
License. However, in accepting such obligations, You may act only
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
174
|
+
of your accepting any such warranty or additional liability.
|
175
|
+
|
176
|
+
END OF TERMS AND CONDITIONS
|
177
|
+
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
179
|
+
|
180
|
+
To apply the Apache License to your work, attach the following
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
182
|
+
replaced with your own identifying information. (Don't include
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
184
|
+
comment syntax for the file format. We also recommend that a
|
185
|
+
file or class name and description of purpose be included on the
|
186
|
+
same "printed page" as the copyright notice for easier
|
187
|
+
identification within third-party archives.
|
188
|
+
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
190
|
+
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
192
|
+
you may not use this file except in compliance with the License.
|
193
|
+
You may obtain a copy of the License at
|
194
|
+
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
196
|
+
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
200
|
+
See the License for the specific language governing permissions and
|
201
|
+
limitations under the License.
|
data/README.md
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
# xmpp4r-robot [![Build Status](https://secure.travis-ci.org/godfat/xmpp4r-robot.png?branch=master)](http://travis-ci.org/godfat/xmpp4r-robot)
|
2
|
+
|
3
|
+
by Lin Jen-Shin ([godfat](http://godfat.org))
|
4
|
+
|
5
|
+
## LINKS:
|
6
|
+
|
7
|
+
* [github](https://github.com/godfat/xmpp4r-robot)
|
8
|
+
* [rubygems](https://rubygems.org/gems/xmpp4r-robot)
|
9
|
+
* [rdoc](http://rdoc.info/github/godfat/xmpp4r-robot)
|
10
|
+
|
11
|
+
## DESCRIPTION:
|
12
|
+
|
13
|
+
Simple XMPP client built upon xmpp4r. Intended for building simple robots.
|
14
|
+
|
15
|
+
## WHY?
|
16
|
+
|
17
|
+
XMPP is such a beast and therefore xmpp4r is quite complex and hard to use
|
18
|
+
for some simple scenario where we merely want to write some XMPP robots.
|
19
|
+
This is an attempt to make it easy for such use cases.
|
20
|
+
|
21
|
+
## REQUIREMENTS:
|
22
|
+
|
23
|
+
* Tested with MRI (official CRuby) 2.0.0, 2.1.0, Rubinius and JRuby.
|
24
|
+
|
25
|
+
## INSTALLATION:
|
26
|
+
|
27
|
+
gem install xmpp4r-robot
|
28
|
+
|
29
|
+
## SYNOPSIS:
|
30
|
+
|
31
|
+
``` ruby
|
32
|
+
require 'xmpp4r/robot'
|
33
|
+
|
34
|
+
robot = Jabber::Robot.new('someone@gmail.com', 'awesome password',
|
35
|
+
:retry_time => 10,
|
36
|
+
:auto_accept_subscription => true)
|
37
|
+
|
38
|
+
robot.notify_presence do |from, reason|
|
39
|
+
# reason could be one of :available, :away, :unavailable
|
40
|
+
puts "#{from} is #{reason}"
|
41
|
+
end
|
42
|
+
|
43
|
+
robot.notify_message do |from, body|
|
44
|
+
puts "#{from} said: #{body}"
|
45
|
+
robot.message(from, "#{from} just told me: #{body}") # echo back
|
46
|
+
|
47
|
+
robot.subscribe(from) if body == 'subscribe' # demonstrate how we subscribe
|
48
|
+
end
|
49
|
+
|
50
|
+
robot.start
|
51
|
+
|
52
|
+
rd, wr = IO.pipe
|
53
|
+
Signal.trap('INT'){ wr.puts
|
54
|
+
rd.gets
|
55
|
+
|
56
|
+
robot.stop
|
57
|
+
```
|
58
|
+
|
59
|
+
## NOTES:
|
60
|
+
|
61
|
+
* If you want to login with a Google Apps Google Talk account, for example,
|
62
|
+
suppose your domain is `example.com`, and your account is `robot`, then
|
63
|
+
you need to login as `robot@example.com` and make sure you have proper
|
64
|
+
`SRV` records. Namely `_xmpp-server._tcp.example.com.` and
|
65
|
+
`_xmpp-client._tcp.example.com.`. Checkout [Olark's SRV instructions][]
|
66
|
+
and Google's manual for [enabling chats outside Google Apps][].
|
67
|
+
|
68
|
+
* You might also want to read the [RFC for XMPP][] occasionally. We would try
|
69
|
+
hard to use the same terms from XMPP, so that it's less confusing.
|
70
|
+
|
71
|
+
[Olark's SRV instructions]: http://www.olark.com/gtalk/check_srv
|
72
|
+
[enabling chats outside Google Apps]: https://support.google.com/a/answer/34143?hl=en
|
73
|
+
[RFC for XMPP]: http://xmpp.org/rfcs/rfc3921.html
|
74
|
+
|
75
|
+
## CONTRIBUTORS:
|
76
|
+
|
77
|
+
* Lin Jen-Shin (@godfat)
|
78
|
+
|
79
|
+
## LICENSE:
|
80
|
+
|
81
|
+
Apache License 2.0
|
82
|
+
|
83
|
+
Copyright (c) 2014, Lin Jen-Shin (godfat)
|
84
|
+
|
85
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
86
|
+
you may not use this file except in compliance with the License.
|
87
|
+
You may obtain a copy of the License at
|
88
|
+
|
89
|
+
<http://www.apache.org/licenses/LICENSE-2.0>
|
90
|
+
|
91
|
+
Unless required by applicable law or agreed to in writing, software
|
92
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
93
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
94
|
+
See the License for the specific language governing permissions and
|
95
|
+
limitations under the License.
|
data/Rakefile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
|
2
|
+
begin
|
3
|
+
require "#{dir = File.dirname(__FILE__)}/task/gemgem"
|
4
|
+
rescue LoadError
|
5
|
+
sh 'git submodule update --init'
|
6
|
+
exec Gem.ruby, '-S', $PROGRAM_NAME, *ARGV
|
7
|
+
end
|
8
|
+
|
9
|
+
Gemgem.init(dir) do |s|
|
10
|
+
s.name = 'xmpp4r-robot'
|
11
|
+
s.version = '0.1'
|
12
|
+
%w[xmpp4r].each{ |g| s.add_runtime_dependency(g) }
|
13
|
+
end
|
data/lib/xmpp4r/robot.rb
ADDED
@@ -0,0 +1,126 @@
|
|
1
|
+
|
2
|
+
require 'xmpp4r'
|
3
|
+
require 'xmpp4r/roster'
|
4
|
+
|
5
|
+
class Jabber::Robot
|
6
|
+
attr_accessor :username, :password, :client, :errback,
|
7
|
+
:retry_time, :auto_accept_subscription
|
8
|
+
|
9
|
+
def initialize username, password, opts={}, &errback
|
10
|
+
@username = username
|
11
|
+
@password = password
|
12
|
+
@errback = errback
|
13
|
+
|
14
|
+
@retry_time = Float(opts[:retry_time] || 0)
|
15
|
+
@auto_accept_subscription = opts[:auto_accept_subscription]
|
16
|
+
end
|
17
|
+
|
18
|
+
# So that you could reset the client by calling:
|
19
|
+
# robot.client = nil
|
20
|
+
# robot.client
|
21
|
+
# This would remove all previously set callbacks.
|
22
|
+
def client
|
23
|
+
@client ||= Jabber::Client.new(Jabber::JID::new(username))
|
24
|
+
end
|
25
|
+
|
26
|
+
def start
|
27
|
+
connect
|
28
|
+
login
|
29
|
+
initialize_callbacks
|
30
|
+
available
|
31
|
+
end
|
32
|
+
|
33
|
+
def stop
|
34
|
+
client.close
|
35
|
+
end
|
36
|
+
|
37
|
+
def connect
|
38
|
+
client.connect
|
39
|
+
end
|
40
|
+
|
41
|
+
def login
|
42
|
+
client.auth(password)
|
43
|
+
end
|
44
|
+
|
45
|
+
##### actions #####
|
46
|
+
|
47
|
+
def available
|
48
|
+
client.send(Jabber::Presence.new.set_type(:available))
|
49
|
+
end
|
50
|
+
|
51
|
+
# e.g. robot.message('someone@example.com', 'Hi!')
|
52
|
+
def message to, body
|
53
|
+
client.send(Jabber::Message::new(to, body).set_type(:chat))
|
54
|
+
end
|
55
|
+
|
56
|
+
# e.g. robot.subscribe('someone@example.com')
|
57
|
+
def subscribe to
|
58
|
+
roster.accept_subscription(to)
|
59
|
+
end
|
60
|
+
|
61
|
+
##### callbacks #####
|
62
|
+
|
63
|
+
# e.g. robot.notify_presence{ |from, reason| puts "#{from} is #{reason}" }
|
64
|
+
def notify_presence
|
65
|
+
client.add_presence_callback do |presence|
|
66
|
+
# :available, :away, :unavailable
|
67
|
+
show = presence.type ||
|
68
|
+
case presence.show # http://xmpp.org/rfcs/rfc3921.html
|
69
|
+
when nil, :chat
|
70
|
+
:available
|
71
|
+
when :away, :dnd, :xa
|
72
|
+
:away
|
73
|
+
else
|
74
|
+
raise "What's this show? #{presence.show}"
|
75
|
+
end
|
76
|
+
|
77
|
+
protect_yield do
|
78
|
+
yield(jid_to_username(presence.from), show)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
# e.g. robot.notify_message{ |from, body| puts "#{from}: #{body}" }
|
84
|
+
def notify_message
|
85
|
+
client.add_message_callback do |message|
|
86
|
+
protect_yield do
|
87
|
+
yield(jid_to_username(message.from), message.body.strip) if
|
88
|
+
message.body
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
##### private #####
|
94
|
+
|
95
|
+
private
|
96
|
+
def roster
|
97
|
+
@roster ||= Jabber::Roster::Helper.new(client)
|
98
|
+
end
|
99
|
+
|
100
|
+
def initialize_callbacks
|
101
|
+
client.on_exception do |exp|
|
102
|
+
errback.call(exp) if errback
|
103
|
+
|
104
|
+
next unless retry_time == 0.0
|
105
|
+
|
106
|
+
$stderr.puts "ERROR: #{exp}: #{exp.backtrace}" +
|
107
|
+
" We'll sleep for #{retry_time} seconds and retry."
|
108
|
+
sleep(retry_time)
|
109
|
+
start
|
110
|
+
end
|
111
|
+
|
112
|
+
roster.add_subscription_request_callback do |_, presence|
|
113
|
+
subscribe(presence.from) if auto_accept_subscription
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
def jid_to_username jid
|
118
|
+
"#{jid.node}@#{jid.domain}"
|
119
|
+
end
|
120
|
+
|
121
|
+
def protect_yield
|
122
|
+
yield
|
123
|
+
rescue => e
|
124
|
+
errback.call(e) if errback
|
125
|
+
end
|
126
|
+
end
|
data/lib/xmpp4r-robot.rb
ADDED
data/task/README.md
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
# Gemgem
|
2
|
+
|
3
|
+
## DESCRIPTION:
|
4
|
+
|
5
|
+
Provided tasks:
|
6
|
+
|
7
|
+
rake clean # Remove ignored files
|
8
|
+
rake gem:build # Build gem
|
9
|
+
rake gem:install # Install gem
|
10
|
+
rake gem:release # Release gem
|
11
|
+
rake gem:spec # Generate gemspec
|
12
|
+
rake test # Run tests in memory
|
13
|
+
|
14
|
+
## REQUIREMENTS:
|
15
|
+
|
16
|
+
* Tested with MRI (official CRuby) 1.9.3, 2.0.0, Rubinius and JRuby.
|
17
|
+
|
18
|
+
## INSTALLATION:
|
19
|
+
|
20
|
+
git submodule add git://github.com/godfat/gemgem.git task
|
21
|
+
|
22
|
+
And in Rakefile:
|
23
|
+
|
24
|
+
``` ruby
|
25
|
+
begin
|
26
|
+
require "#{dir = File.dirname(__FILE__)}/task/gemgem"
|
27
|
+
rescue LoadError
|
28
|
+
sh 'git submodule update --init'
|
29
|
+
exec Gem.ruby, '-S', $PROGRAM_NAME, *ARGV
|
30
|
+
end
|
31
|
+
|
32
|
+
Gemgem.init(dir) do |s|
|
33
|
+
s.name = 'your-gem'
|
34
|
+
s.version = '0.1.0'
|
35
|
+
end
|
36
|
+
```
|
37
|
+
|
38
|
+
## LICENSE:
|
39
|
+
|
40
|
+
Apache License 2.0
|
41
|
+
|
42
|
+
Copyright (c) 2011-2013, Lin Jen-Shin (godfat)
|
43
|
+
|
44
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
45
|
+
you may not use this file except in compliance with the License.
|
46
|
+
You may obtain a copy of the License at
|
47
|
+
|
48
|
+
<http://www.apache.org/licenses/LICENSE-2.0>
|
49
|
+
|
50
|
+
Unless required by applicable law or agreed to in writing, software
|
51
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
52
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
53
|
+
See the License for the specific language governing permissions and
|
54
|
+
limitations under the License.
|
data/task/gemgem.rb
ADDED
@@ -0,0 +1,262 @@
|
|
1
|
+
|
2
|
+
module Gemgem
|
3
|
+
class << self
|
4
|
+
attr_accessor :dir, :spec, :spec_create
|
5
|
+
end
|
6
|
+
|
7
|
+
module_function
|
8
|
+
def gem_tag ; "#{spec.name}-#{spec.version}" ; end
|
9
|
+
def gem_path ; "#{pkg_dir}/#{gem_tag}.gem" ; end
|
10
|
+
def spec_path ; "#{dir}/#{spec.name}.gemspec" ; end
|
11
|
+
def pkg_dir ; "#{dir}/pkg" ; end
|
12
|
+
def escaped_dir; @escaped_dir ||= Regexp.escape(dir); end
|
13
|
+
|
14
|
+
def init dir, &block
|
15
|
+
self.dir = dir
|
16
|
+
$LOAD_PATH.unshift("#{dir}/lib")
|
17
|
+
ENV['RUBYLIB'] = "#{dir}/lib:#{ENV['RUBYLIB']}"
|
18
|
+
ENV['PATH'] = "#{dir}/bin:#{ENV['PATH']}"
|
19
|
+
self.spec_create = block
|
20
|
+
end
|
21
|
+
|
22
|
+
def create
|
23
|
+
spec = Gem::Specification.new do |s|
|
24
|
+
s.authors = ['Lin Jen-Shin (godfat)']
|
25
|
+
s.email = ['godfat (XD) godfat.org']
|
26
|
+
|
27
|
+
s.description = description.join
|
28
|
+
s.summary = description.first
|
29
|
+
s.license = readme['LICENSE'].sub(/.+\n\n/, '').lines.first.strip
|
30
|
+
|
31
|
+
s.date = Time.now.strftime('%Y-%m-%d')
|
32
|
+
s.files = gem_files
|
33
|
+
s.test_files = test_files
|
34
|
+
s.executables = bin_files
|
35
|
+
end
|
36
|
+
spec_create.call(spec)
|
37
|
+
spec.homepage = "https://github.com/godfat/#{spec.name}"
|
38
|
+
self.spec = spec
|
39
|
+
end
|
40
|
+
|
41
|
+
def write
|
42
|
+
File.open(spec_path, 'w'){ |f| f << split_lines(spec.to_ruby) }
|
43
|
+
end
|
44
|
+
|
45
|
+
def split_lines ruby
|
46
|
+
ruby.gsub(/(.+?)\s*=\s*\[(.+?)\]/){ |s|
|
47
|
+
if $2.index(',')
|
48
|
+
"#{$1} = [\n #{$2.split(',').map(&:strip).join(",\n ")}]"
|
49
|
+
else
|
50
|
+
s
|
51
|
+
end
|
52
|
+
}
|
53
|
+
end
|
54
|
+
|
55
|
+
def strip_path path
|
56
|
+
strip_home_path(strip_cwd_path(path))
|
57
|
+
end
|
58
|
+
|
59
|
+
def strip_home_path path
|
60
|
+
path.sub(ENV['HOME'], '~')
|
61
|
+
end
|
62
|
+
|
63
|
+
def strip_cwd_path path
|
64
|
+
path.sub(Dir.pwd, '.')
|
65
|
+
end
|
66
|
+
|
67
|
+
def git *args
|
68
|
+
`git --git-dir=#{dir}/.git #{args.join(' ')}`
|
69
|
+
end
|
70
|
+
|
71
|
+
def sh_git *args
|
72
|
+
Rake.sh('git', "--git-dir=#{dir}/.git", *args)
|
73
|
+
end
|
74
|
+
|
75
|
+
def sh_gem *args
|
76
|
+
Rake.sh(Gem.ruby, '-S', 'gem', *args)
|
77
|
+
end
|
78
|
+
|
79
|
+
def glob path=dir
|
80
|
+
Dir.glob("#{path}/**/*", File::FNM_DOTMATCH)
|
81
|
+
end
|
82
|
+
|
83
|
+
def readme
|
84
|
+
@readme ||=
|
85
|
+
if (path = "#{Gemgem.dir}/README.md") && File.exist?(path)
|
86
|
+
ps = "##{File.read(path)}".
|
87
|
+
scan(/((#+)[^\n]+\n\n.+?(?=(\n\n\2[^#\n]+\n)|\Z))/m).map(&:first)
|
88
|
+
ps.inject('HEADER' => ps.first){ |r, s, i|
|
89
|
+
r[s[/\w+/]] = s
|
90
|
+
r
|
91
|
+
}
|
92
|
+
else
|
93
|
+
{}
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
def description
|
98
|
+
# JRuby String#lines is returning an enumerator
|
99
|
+
@description ||= (readme['DESCRIPTION']||'').sub(/.+\n\n/, '').lines.to_a
|
100
|
+
end
|
101
|
+
|
102
|
+
def all_files
|
103
|
+
@all_files ||= fold_files(glob).sort
|
104
|
+
end
|
105
|
+
|
106
|
+
def fold_files files
|
107
|
+
files.inject([]){ |r, path|
|
108
|
+
if File.file?(path) && path !~ %r{/\.git(/|$)} &&
|
109
|
+
(rpath = path[%r{^#{escaped_dir}/(.*$)}, 1])
|
110
|
+
r << rpath
|
111
|
+
elsif File.symlink?(path) # walk into symlinks...
|
112
|
+
r.concat(fold_files(glob(File.expand_path(path,
|
113
|
+
File.readlink(path)))))
|
114
|
+
else
|
115
|
+
r
|
116
|
+
end
|
117
|
+
}
|
118
|
+
end
|
119
|
+
|
120
|
+
def gem_files
|
121
|
+
@gem_files ||= all_files.reject{ |f|
|
122
|
+
f =~ ignored_pattern && !git_files.include?(f)
|
123
|
+
}
|
124
|
+
end
|
125
|
+
|
126
|
+
def test_files
|
127
|
+
@test_files ||= gem_files.grep(%r{^test/(.+?/)*test_.+?\.rb$})
|
128
|
+
end
|
129
|
+
|
130
|
+
def bin_files
|
131
|
+
@bin_files ||= gem_files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
132
|
+
end
|
133
|
+
|
134
|
+
def git_files
|
135
|
+
@git_files ||= if File.exist?("#{dir}/.git")
|
136
|
+
git('ls-files').split("\n")
|
137
|
+
else
|
138
|
+
[]
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
def ignored_files
|
143
|
+
@ignored_files ||= all_files.grep(ignored_pattern)
|
144
|
+
end
|
145
|
+
|
146
|
+
def ignored_pattern
|
147
|
+
@ignored_pattern ||= if gitignore.empty?
|
148
|
+
/^$/
|
149
|
+
else
|
150
|
+
Regexp.new(expand_patterns(gitignore).join('|'))
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
def expand_patterns pathes
|
155
|
+
# http://git-scm.com/docs/gitignore
|
156
|
+
pathes.flat_map{ |path|
|
157
|
+
# we didn't implement negative pattern for now
|
158
|
+
Regexp.escape(path).sub(%r{^/}, '^').gsub(/\\\*/, '[^/]*')
|
159
|
+
}
|
160
|
+
end
|
161
|
+
|
162
|
+
def gitignore
|
163
|
+
@gitignore ||= if File.exist?(path = "#{dir}/.gitignore")
|
164
|
+
File.read(path).lines.
|
165
|
+
reject{ |l| l == /^\s*(#|\s+$)/ }.map(&:strip)
|
166
|
+
else
|
167
|
+
[]
|
168
|
+
end
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
namespace :gem do
|
173
|
+
|
174
|
+
desc 'Install gem'
|
175
|
+
task :install => [:build] do
|
176
|
+
Gemgem.sh_gem('install', Gemgem.gem_path)
|
177
|
+
end
|
178
|
+
|
179
|
+
desc 'Build gem'
|
180
|
+
task :build => [:spec] do
|
181
|
+
require 'fileutils'
|
182
|
+
require 'rubygems/package'
|
183
|
+
gem = nil
|
184
|
+
Dir.chdir(Gemgem.dir) do
|
185
|
+
gem = Gem::Package.build(Gem::Specification.load(Gemgem.spec_path))
|
186
|
+
FileUtils.mkdir_p(Gemgem.pkg_dir)
|
187
|
+
FileUtils.mv(gem, Gemgem.pkg_dir) # gem is relative path, but might be ok
|
188
|
+
end
|
189
|
+
puts "\e[35mGem built: \e[33m" \
|
190
|
+
"#{Gemgem.strip_path("#{Gemgem.pkg_dir}/#{gem}")}\e[0m"
|
191
|
+
end
|
192
|
+
|
193
|
+
desc 'Generate gemspec'
|
194
|
+
task :spec do
|
195
|
+
Gemgem.create
|
196
|
+
Gemgem.write
|
197
|
+
end
|
198
|
+
|
199
|
+
desc 'Release gem'
|
200
|
+
task :release => [:spec, :check, :build] do
|
201
|
+
Gemgem.module_eval do
|
202
|
+
sh_git('tag', Gemgem.gem_tag)
|
203
|
+
sh_git('push')
|
204
|
+
sh_git('push', '--tags')
|
205
|
+
sh_gem('push', Gemgem.gem_path)
|
206
|
+
end
|
207
|
+
end
|
208
|
+
|
209
|
+
task :check do
|
210
|
+
ver = Gemgem.spec.version.to_s
|
211
|
+
|
212
|
+
if ENV['VERSION'].nil?
|
213
|
+
puts("\e[35mExpected " \
|
214
|
+
"\e[33mVERSION\e[35m=\e[33m#{ver}\e[0m")
|
215
|
+
exit(1)
|
216
|
+
|
217
|
+
elsif ENV['VERSION'] != ver
|
218
|
+
puts("\e[35mExpected \e[33mVERSION\e[35m=\e[33m#{ver} " \
|
219
|
+
"\e[35mbut got\n " \
|
220
|
+
"\e[33mVERSION\e[35m=\e[33m#{ENV['VERSION']}\e[0m")
|
221
|
+
exit(2)
|
222
|
+
end
|
223
|
+
end
|
224
|
+
|
225
|
+
end # of gem namespace
|
226
|
+
|
227
|
+
desc 'Run tests'
|
228
|
+
task :test do
|
229
|
+
next if Gemgem.test_files.empty?
|
230
|
+
|
231
|
+
require 'bacon'
|
232
|
+
Bacon.extend(Bacon::TestUnitOutput)
|
233
|
+
Bacon.summary_on_exit
|
234
|
+
Gemgem.test_files.each{ |file| require "#{Gemgem.dir}/#{file[0..-4]}" }
|
235
|
+
end
|
236
|
+
|
237
|
+
desc 'Trash ignored files'
|
238
|
+
task :clean => ['gem:spec'] do
|
239
|
+
next if Gemgem.ignored_files.empty?
|
240
|
+
|
241
|
+
require 'fileutils'
|
242
|
+
trash = File.expand_path("~/.Trash/#{Gemgem.spec.name}")
|
243
|
+
puts "Move the following files into:" \
|
244
|
+
" \e[35m#{Gemgem.strip_path(trash)}\e[33m"
|
245
|
+
|
246
|
+
Gemgem.ignored_files.each do |file|
|
247
|
+
from = "#{Gemgem.dir}/#{file}"
|
248
|
+
to = "#{trash}/#{File.dirname(file)}"
|
249
|
+
puts Gemgem.strip_path(from)
|
250
|
+
|
251
|
+
FileUtils.mkdir_p(to)
|
252
|
+
FileUtils.mv(from, to)
|
253
|
+
end
|
254
|
+
|
255
|
+
print "\e[0m"
|
256
|
+
end
|
257
|
+
|
258
|
+
task :default do
|
259
|
+
# Is there a reliable way to do this in the current process?
|
260
|
+
# It failed miserably before between Rake versions...
|
261
|
+
exec "#{Gem.ruby} -S #{$PROGRAM_NAME} -f #{Rake.application.rakefile} -T"
|
262
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
# stub: xmpp4r-robot 0.1 ruby lib
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = "xmpp4r-robot"
|
6
|
+
s.version = "0.1"
|
7
|
+
|
8
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
9
|
+
s.require_paths = ["lib"]
|
10
|
+
s.authors = ["Lin Jen-Shin (godfat)"]
|
11
|
+
s.date = "2014-01-22"
|
12
|
+
s.description = "Simple XMPP client built upon xmpp4r. Intended for building simple robots."
|
13
|
+
s.email = ["godfat (XD) godfat.org"]
|
14
|
+
s.files = [
|
15
|
+
".gitmodules",
|
16
|
+
".travis.yml",
|
17
|
+
"Gemfile",
|
18
|
+
"LICENSE",
|
19
|
+
"README.md",
|
20
|
+
"Rakefile",
|
21
|
+
"lib/xmpp4r-robot.rb",
|
22
|
+
"lib/xmpp4r/robot.rb",
|
23
|
+
"task/README.md",
|
24
|
+
"task/gemgem.rb",
|
25
|
+
"xmpp4r-robot.gemspec"]
|
26
|
+
s.homepage = "https://github.com/godfat/xmpp4r-robot"
|
27
|
+
s.licenses = ["Apache License 2.0"]
|
28
|
+
s.rubygems_version = "2.2.1"
|
29
|
+
s.summary = "Simple XMPP client built upon xmpp4r. Intended for building simple robots."
|
30
|
+
|
31
|
+
if s.respond_to? :specification_version then
|
32
|
+
s.specification_version = 4
|
33
|
+
|
34
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
35
|
+
s.add_runtime_dependency(%q<xmpp4r>, [">= 0"])
|
36
|
+
else
|
37
|
+
s.add_dependency(%q<xmpp4r>, [">= 0"])
|
38
|
+
end
|
39
|
+
else
|
40
|
+
s.add_dependency(%q<xmpp4r>, [">= 0"])
|
41
|
+
end
|
42
|
+
end
|
metadata
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: xmpp4r-robot
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.1'
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Lin Jen-Shin (godfat)
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-01-22 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: xmpp4r
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
description: Simple XMPP client built upon xmpp4r. Intended for building simple robots.
|
28
|
+
email:
|
29
|
+
- godfat (XD) godfat.org
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- ".gitmodules"
|
35
|
+
- ".travis.yml"
|
36
|
+
- Gemfile
|
37
|
+
- LICENSE
|
38
|
+
- README.md
|
39
|
+
- Rakefile
|
40
|
+
- lib/xmpp4r-robot.rb
|
41
|
+
- lib/xmpp4r/robot.rb
|
42
|
+
- task/README.md
|
43
|
+
- task/gemgem.rb
|
44
|
+
- xmpp4r-robot.gemspec
|
45
|
+
homepage: https://github.com/godfat/xmpp4r-robot
|
46
|
+
licenses:
|
47
|
+
- Apache License 2.0
|
48
|
+
metadata: {}
|
49
|
+
post_install_message:
|
50
|
+
rdoc_options: []
|
51
|
+
require_paths:
|
52
|
+
- lib
|
53
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '0'
|
58
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
requirements: []
|
64
|
+
rubyforge_project:
|
65
|
+
rubygems_version: 2.2.1
|
66
|
+
signing_key:
|
67
|
+
specification_version: 4
|
68
|
+
summary: Simple XMPP client built upon xmpp4r. Intended for building simple robots.
|
69
|
+
test_files: []
|