muzang-plugins 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/muzang-plugins/muzang-rubygems.rb +46 -17
- data/lib/muzang-plugins/muzang-say.rb +12 -0
- data/lib/muzang-plugins/version.rb +1 -1
- data/spec/rubygems_spec.rb +48 -10
- data/spec/support/responses/acts-as-messageable.response +5 -0
- data/spec/support/responses/acts-as-messageable2.response +5 -0
- metadata +13 -10
@@ -1,40 +1,69 @@
|
|
1
1
|
require "em-http-request"
|
2
2
|
require "json"
|
3
|
+
require "pstore"
|
3
4
|
|
4
5
|
class RubyGems
|
5
6
|
include Muzang::Plugins::Helpers
|
6
7
|
|
7
|
-
attr_accessor :last_gem
|
8
|
+
attr_accessor :last_gem, :store
|
8
9
|
|
9
10
|
def initialize(bot)
|
10
11
|
@bot = bot
|
11
|
-
|
12
|
+
@store = PStore.new("#{ENV["HOME"]}/.muzang/muzang.rubygems")
|
13
|
+
@store.transaction do
|
14
|
+
@store[:gems] ||= {}
|
15
|
+
end
|
12
16
|
end
|
13
17
|
|
14
18
|
def call(connection, message)
|
15
|
-
|
16
|
-
|
17
|
-
http = EventMachine::HttpRequest.new('http://rubygems.org/api/v1/gems/latest.json').get
|
19
|
+
message.message.match(/^watch! (.*?)$/) do |match|
|
20
|
+
@current_gem = match[1]
|
18
21
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
+
@store.transaction do
|
23
|
+
unless @store[:gems][@current_gem]
|
24
|
+
@store[:gems][match[1]] = {:name => @current_gem}
|
25
|
+
@new_gem = true
|
26
|
+
end
|
27
|
+
end
|
22
28
|
|
29
|
+
if @new_gem
|
30
|
+
http = EventMachine::HttpRequest.new("http://rubygems.org/api/v1/gems/#{@current_gem}.json").get
|
23
31
|
http.callback {
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
32
|
+
begin
|
33
|
+
gem = JSON.parse(http.response)
|
34
|
+
@store.transaction do
|
35
|
+
@store[:gems][@current_gem][:version] = gem["version"]
|
36
|
+
end
|
37
|
+
connection.msg(message.channel, "Dodalem gema #{@current_gem} do obserwowanych")
|
38
|
+
connection.msg(message.channel, "Aktualna wersja: #{@current_gem} (#{gem["version"]})")
|
39
|
+
@new_gem = false
|
40
|
+
rescue Exception
|
41
|
+
connection.msg(message.channel, "Niepoprawna nazwa gema")
|
30
42
|
end
|
31
43
|
}
|
44
|
+
else
|
45
|
+
connection.msg(message.channel, "Gem #{@current_gem} jest juz obserwowany")
|
32
46
|
end
|
33
47
|
end
|
34
|
-
end
|
35
48
|
|
36
|
-
|
37
|
-
|
49
|
+
if on_join?(connection, message)
|
50
|
+
EventMachine.add_periodic_timer(period) do
|
51
|
+
gems = @store.transaction{@store[:gems].values}
|
52
|
+
EM::Iterator.new(gems, 1).each do |gem, iter|
|
53
|
+
http = EventMachine::HttpRequest.new("http://rubygems.org/api/v1/gems/#{gem[:name]}.json").get
|
54
|
+
http.callback {
|
55
|
+
iter.next
|
56
|
+
current_gem = JSON.parse(http.response)
|
57
|
+
if Gem::Version.new(gem[:version]) < Gem::Version.new(current_gem["version"])
|
58
|
+
@store.transaction do
|
59
|
+
@store[:gems][gem[:name]][:version] = current_gem["version"]
|
60
|
+
end
|
61
|
+
connection.msg(message.channel, "Nowa wersja #{gem[:name]} (#{current_gem["version"]})")
|
62
|
+
end
|
63
|
+
}
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
38
67
|
end
|
39
68
|
|
40
69
|
def period
|
data/spec/rubygems_spec.rb
CHANGED
@@ -12,26 +12,64 @@ describe "RubyGems" do
|
|
12
12
|
@bot = stub
|
13
13
|
@rubygems = RubyGems.new(@bot)
|
14
14
|
@connection = ConnectionMock.new(:nick => "DRUG-bot")
|
15
|
-
@message = OpenStruct.new({ :command => :
|
16
|
-
@
|
17
|
-
|
18
|
-
EventMachine::MockHttpRequest.
|
15
|
+
@message = OpenStruct.new({ :command => :prvmsg, :channel => "#test", :nick => "DRUG-bot" })
|
16
|
+
@gem = File.expand_path('../support/responses/acts-as-messageable.response', __FILE__)
|
17
|
+
@gem2 = File.expand_path('../support/responses/acts-as-messageable2.response', __FILE__)
|
18
|
+
EventMachine::MockHttpRequest.pass_through_requests = true
|
19
|
+
EventMachine::MockHttpRequest.register_file('http://rubygems.org:80/api/v1/gems/acts-as-messageable.json', :get, @gem)
|
20
|
+
EventMachine::MockHttpRequest.register_file('http://rubygems.org:80/api/v1/gems/acts-as-messageable2.json', :get, @gem2)
|
19
21
|
EventMachine::MockHttpRequest.activate!
|
20
22
|
end
|
21
23
|
|
22
|
-
|
23
|
-
|
24
|
+
after do
|
25
|
+
FileUtils.rm("#{ENV["HOME"]}/.muzang/muzang.rubygems")
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should add gem to watching list" do
|
29
|
+
@message.message = "watch! acts-as-messageable"
|
24
30
|
EM.run do
|
25
31
|
@rubygems.call(@connection, @message)
|
26
|
-
eventually(
|
32
|
+
eventually(true, :times => 10) do
|
33
|
+
@connection.messages.include? "Dodalem gema acts-as-messageable do obserwowanych" and
|
34
|
+
@connection.messages.include? "Aktualna wersja: acts-as-messageable (0.4.2)"
|
35
|
+
end
|
27
36
|
end
|
28
37
|
end
|
29
38
|
|
30
|
-
it "should
|
31
|
-
@
|
39
|
+
it "should raise error" do
|
40
|
+
@message.message = "watch! acts-as-messageable2"
|
32
41
|
EM.run do
|
33
42
|
@rubygems.call(@connection, @message)
|
34
|
-
eventually(
|
43
|
+
eventually(true) do
|
44
|
+
@connection.messages.include? "Niepoprawna nazwa gema"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should not add gem twice to store" do
|
50
|
+
@message.message = "watch! acts-as-messageable"
|
51
|
+
EM.run do
|
52
|
+
2.times{ @rubygems.call(@connection, @message) }
|
53
|
+
eventually(true) do
|
54
|
+
@connection.messages.include? "Gem acts-as-messageable jest juz obserwowany"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should notice about new version of gem" do
|
60
|
+
@message.message = ""
|
61
|
+
@message.command = :join
|
62
|
+
|
63
|
+
EM.run do
|
64
|
+
@rubygems.call(@connection, @message)
|
65
|
+
@message.message = "watch! acts-as-messageable"
|
66
|
+
@rubygems.call(@connection, @message)
|
67
|
+
|
68
|
+
@rubygems.store.transaction{ @rubygems.store[:gems]["acts-as-messageable"][:version] = "0.4.1" }
|
69
|
+
|
70
|
+
eventually(true, :every => 0.1, :total => 100) do
|
71
|
+
@connection.messages.include? "Nowa wersja acts-as-messageable (0.4.2)"
|
72
|
+
end
|
35
73
|
end
|
36
74
|
end
|
37
75
|
end
|
@@ -0,0 +1,5 @@
|
|
1
|
+
HTTP/1.1 200 OK
|
2
|
+
Status: 200
|
3
|
+
Content-Type: application/json; charset=utf-8
|
4
|
+
|
5
|
+
{"dependencies":{"runtime":[{"name":"activerecord","requirements":">= 3.0.0"},{"name":"activesupport","requirements":">= 3.0.0"},{"name":"ancestry","requirements":"~> 1.2.4"},{"name":"railties","requirements":">= 3.0.0"}],"development":[{"name":"jeweler","requirements":"~> 1.6.0"},{"name":"rspec","requirements":"~> 2.6.0"},{"name":"sqlite3-ruby","requirements":">= 0"}]},"name":"acts-as-messageable","downloads":3397,"info":"Make user messageable!;-)","version_downloads":14,"version":"0.4.2","homepage_uri":"http://github.com/LTe/acts-as-messageable","bug_tracker_uri":"https://github.com/LTe/acts-as-messageable/issues","source_code_uri":"","gem_uri":"http://rubygems.org/gems/acts-as-messageable-0.4.2.gem","project_uri":"http://rubygems.org/gems/acts-as-messageable","authors":"Piotr Nielacny","mailing_list_uri":"","documentation_uri":"http://rdoc.info/github/LTe/acts-as-messageable/","wiki_uri":"https://github.com/LTe/acts-as-messageable/wiki/_pages"}
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: muzang-plugins
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-11-
|
12
|
+
date: 2011-11-20 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: em-http-request
|
16
|
-
requirement: &
|
16
|
+
requirement: &70167909877820 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70167909877820
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: muzang
|
27
|
-
requirement: &
|
27
|
+
requirement: &70167909875680 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 1.0.0
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70167909875680
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: em-ventually
|
38
|
-
requirement: &
|
38
|
+
requirement: &70167909874320 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ~>
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: 0.1.2
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70167909874320
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: rspec
|
49
|
-
requirement: &
|
49
|
+
requirement: &70167909873600 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ~>
|
@@ -54,7 +54,7 @@ dependencies:
|
|
54
54
|
version: 2.6.0
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70167909873600
|
58
58
|
description: Plugins for Muzang IRC bot
|
59
59
|
email:
|
60
60
|
- piotr.nielacny@gmail.com
|
@@ -217,6 +217,7 @@ files:
|
|
217
217
|
- lib/muzang-plugins/muzang-plusone.rb
|
218
218
|
- lib/muzang-plugins/muzang-reddit.rb
|
219
219
|
- lib/muzang-plugins/muzang-rubygems.rb
|
220
|
+
- lib/muzang-plugins/muzang-say.rb
|
220
221
|
- lib/muzang-plugins/version.rb
|
221
222
|
- muzang-plugins.gemspec
|
222
223
|
- spec/livereload_spec.rb
|
@@ -229,6 +230,8 @@ files:
|
|
229
230
|
- spec/rubygems_spec.rb
|
230
231
|
- spec/spec_helper.rb
|
231
232
|
- spec/support/connection_mock.rb
|
233
|
+
- spec/support/responses/acts-as-messageable.response
|
234
|
+
- spec/support/responses/acts-as-messageable2.response
|
232
235
|
- spec/support/responses/meme.response
|
233
236
|
- spec/support/responses/reddit.response
|
234
237
|
- spec/support/responses/rubygems.response
|