fbomb 1.0.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,17 +3,38 @@
3
3
 
4
4
  Gem::Specification::new do |spec|
5
5
  spec.name = "fbomb"
6
- spec.version = "1.0.0"
6
+ spec.version = "2.0.0"
7
7
  spec.platform = Gem::Platform::RUBY
8
8
  spec.summary = "fbomb"
9
9
  spec.description = "description: fbomb kicks the ass"
10
+ spec.license = "Ruby"
10
11
 
11
12
  spec.files =
12
- ["README",
13
+ ["Gemfile",
14
+ "Gemfile.lock",
15
+ "README.md",
13
16
  "Rakefile",
14
17
  "bin",
15
18
  "bin/fbomb",
16
19
  "fbomb.gemspec",
20
+ "images",
21
+ "images/planet",
22
+ "images/planet/1dEzGbz.jpg",
23
+ "images/planet/3aASzbv.jpg",
24
+ "images/planet/BCfEwgl.jpg",
25
+ "images/planet/EPbgqjy.jpg",
26
+ "images/planet/FoiDgwc.jpg",
27
+ "images/planet/HJiUPV2.jpg",
28
+ "images/planet/KOcvGjw.jpg",
29
+ "images/planet/L5n5lPK.jpg",
30
+ "images/planet/MaGKipv.jpg",
31
+ "images/planet/QVRALtz.jpg",
32
+ "images/planet/W3fWkTZ.jpg",
33
+ "images/planet/about.md",
34
+ "images/planet/nWqdkF7.jpg",
35
+ "images/planet/w41sv1T.jpg",
36
+ "images/planet/xySa4GD.jpg",
37
+ "images/planet/yzw8pOQ.jpg",
17
38
  "lib",
18
39
  "lib/fbomb",
19
40
  "lib/fbomb.rb",
@@ -22,7 +43,11 @@ Gem::Specification::new do |spec|
22
43
  "lib/fbomb/commands",
23
44
  "lib/fbomb/commands/builtin.rb",
24
45
  "lib/fbomb/commands/system.rb",
25
- "lib/fbomb/util.rb"]
46
+ "lib/fbomb/flowdock.rb",
47
+ "lib/fbomb/util.rb",
48
+ "lib/fbomb/uuid.rb",
49
+ "notes",
50
+ "notes/ara.txt"]
26
51
 
27
52
  spec.executables = ["fbomb"]
28
53
 
@@ -31,15 +56,33 @@ Gem::Specification::new do |spec|
31
56
  spec.test_files = nil
32
57
 
33
58
 
34
- spec.add_dependency(*["tinder", "~> 1.4.3"])
59
+ spec.add_dependency(*["flowdock", ">= 0.4.0"])
35
60
 
36
- spec.add_dependency(*["main", "~> 4.7.6"])
61
+ spec.add_dependency(*["eventmachine", ">= 1.0.3"])
37
62
 
38
- spec.add_dependency(*["fukung", "~> 1.1.0"])
63
+ spec.add_dependency(*["em-http-request", ">= 1.1.2"])
39
64
 
40
- spec.add_dependency(*["twitter-stream", "~> 0.1.14"])
65
+ spec.add_dependency(*["json", ">= 1.8.1"])
41
66
 
42
- spec.add_dependency(*["yajl-ruby", "~> 0.8.3"])
67
+ spec.add_dependency(*["coerce", ">= 0.0.6"])
68
+
69
+ spec.add_dependency(*["fukung", ">= 1.1.0"])
70
+
71
+ spec.add_dependency(*["main", ">= 4.7.6"])
72
+
73
+ spec.add_dependency(*["nokogiri", ">= 1.5.0"])
74
+
75
+ spec.add_dependency(*["google-search", ">= 1.0.2"])
76
+
77
+ spec.add_dependency(*["unidecode", ">= 1.0.0"])
78
+
79
+ spec.add_dependency(*["systemu", ">= 2.3.0"])
80
+
81
+ spec.add_dependency(*["pry", ">= 0.9.6.2"])
82
+
83
+ spec.add_dependency(*["mechanize", ">= 2.7.3"])
84
+
85
+ spec.add_dependency(*["mime-types", ">= 1.16"])
43
86
 
44
87
 
45
88
  spec.extensions.push(*[])
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -0,0 +1 @@
1
+ http://imgur.com/a/Ilw2G
Binary file
Binary file
Binary file
Binary file
@@ -5,11 +5,14 @@
5
5
  require 'net/http'
6
6
  require 'net/https'
7
7
  require 'open-uri'
8
+ require 'fileutils'
9
+ require 'tmpdir'
10
+ require 'yaml'
8
11
 
9
12
  # libs
10
13
  #
11
14
  module FBomb
12
- Version = '1.0.0' unless defined?(Version)
15
+ Version = '2.0.0' unless defined?(Version)
13
16
 
14
17
  def version
15
18
  FBomb::Version
@@ -17,11 +20,20 @@
17
20
 
18
21
  def dependencies
19
22
  {
20
- 'tinder' => [ 'tinder' , '~> 1.4.3' ] ,
21
- 'twitter/json_stream' => [ 'twitter-stream' , '~> 0.1.14' ] ,
22
- 'yajl' => [ 'yajl-ruby' , '~> 0.8.3' ] ,
23
- 'fukung' => [ 'fukung' , '~> 1.1.0' ] ,
24
- 'main' => [ 'main' , '~> 4.7.6' ]
23
+ 'flowdock' => [ 'flowdock' , '>= 0.4.0' ] ,
24
+ 'eventmachine' => [ 'eventmachine' , '>= 1.0.3' ] ,
25
+ 'em-http' => [ 'em-http-request' , '>= 1.1.2' ] ,
26
+ 'json' => [ 'json' , '>= 1.8.1' ] ,
27
+ 'coerce' => [ 'coerce' , '>= 0.0.6' ] ,
28
+ 'fukung' => [ 'fukung' , '>= 1.1.0' ] ,
29
+ 'main' => [ 'main' , '>= 4.7.6' ] ,
30
+ 'nokogiri' => [ 'nokogiri' , '>= 1.5.0' ] ,
31
+ 'google-search' => [ 'google-search' , '>= 1.0.2' ] ,
32
+ 'unidecode' => [ 'unidecode' , '>= 1.0.0' ] ,
33
+ 'systemu' => [ 'systemu' , '>= 2.3.0' ] ,
34
+ 'pry' => [ 'pry' , '>= 0.9.6.2' ] ,
35
+ 'mechanize' => [ 'mechanize' , '>= 2.7.3' ] ,
36
+ 'mime/types' => [ 'mime-types' , '>= 1.16' ]
25
37
  }
26
38
  end
27
39
 
@@ -44,39 +56,103 @@
44
56
  FBomb.libdir{ libs.each{|lib| Kernel.load(lib) } }
45
57
  end
46
58
 
59
+ def messages
60
+ @messages ||= Array.new
61
+ end
62
+
63
+ def leader
64
+ '.'
65
+ end
66
+
67
+ def uuid
68
+ UUID.create.to_s
69
+ end
70
+
71
+ attr_accessor :message
72
+ attr_accessor :debug
73
+
47
74
  extend(FBomb)
48
75
  end
49
76
 
50
- # gems
77
+ ## isolate gems
51
78
  #
52
- begin
53
- require 'rubygems'
54
- rescue LoadError
55
- nil
79
+ require 'rubygems'
80
+
81
+ libdir = File.expand_path(File.join('~', '.fbomb', 'isolate'))
82
+ options = {:file => false, :path => libdir}
83
+
84
+ deps = true
85
+ ::FBomb.dependencies.each do |lib, dependency|
86
+ unless Gem.try_activate(dependency.first)
87
+ deps = false
88
+ lib, version = dependency
89
+ command = "gem install #{ lib.inspect } --version #{ version.inspect }"
90
+ #STDERR.puts(command)
91
+ end
56
92
  end
57
93
 
58
- if defined?(gem)
59
- FBomb.dependencies.each do |lib, dependency|
94
+ ::FBomb.dependencies.each do |lib, dependency|
95
+ begin
60
96
  gem(*dependency)
61
- require(lib)
97
+ rescue Gem::LoadError
98
+ raise
99
+ lib, version = dependency
100
+ command = "gem install #{ lib.inspect } --version #{ version.inspect }"
101
+ system(command)
102
+ retry
62
103
  end
63
104
  end
64
105
 
65
- require "yajl/json_gem" ### this *replaces* any other JSON.parse !
66
- require "yajl/http_stream" ### we really do need this
106
+ ## load gems
107
+ #
108
+ ::FBomb.dependencies.each do |lib, dependency|
109
+ require(lib)
110
+ end
67
111
 
112
+ ## load fbomb
113
+ #
68
114
  FBomb.load %w[
69
115
  util.rb
70
- campfire.rb
116
+ flowdock.rb
71
117
  command.rb
118
+ uuid.rb
72
119
  ]
73
120
 
121
+ ##
122
+ #
123
+ if Coerce.boolean(ENV['FBOMB_DEBUG'])
124
+ FBomb.debug = true
125
+ end
126
+
74
127
  ## openssl - STFU!
75
128
  #
129
+ verbose = $VERBOSE
130
+ begin
131
+ require 'openssl'
132
+ $VERBOSE = nil
133
+ OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE
134
+ rescue Object => e
135
+ :STFU
136
+ ensure
137
+ $VERBOSE = verbose
138
+ end
139
+
76
140
  class Net::HTTP
77
- def warn(msg)
78
- Kernel.warn(msg) unless msg == "warning: peer certificate won't be verified in this SSL session"
141
+ require 'net/https'
142
+
143
+ module STFU
144
+ def warn(msg)
145
+ #Kernel.warn(msg) unless msg == "warning: peer certificate won't be verified in this SSL session"
146
+ end
147
+
148
+ def use_ssl=(flag)
149
+ super
150
+ ensure
151
+ @ssl_context.verify_mode = OpenSSL::SSL::VERIFY_NONE
152
+ end
79
153
  end
154
+
155
+ include(STFU)
80
156
  end
81
157
 
82
158
  ## global DSL hook
@@ -84,3 +160,7 @@
84
160
  def FBomb(*args, &block)
85
161
  FBomb::Command::DSL.evaluate(*args, &block)
86
162
  end
163
+
164
+ ##
165
+ #
166
+ Fbomb=FBomb
@@ -2,10 +2,10 @@ module FBomb
2
2
  class Campfire < ::Tinder::Campfire
3
3
  module SearchExtension
4
4
  def search(term)
5
- room = self
5
+ flow = self
6
6
  term = CGI.escape(term.to_s)
7
- return_to_room_id = CGI.escape(room.id.to_s)
8
- messages = connection.get("/search?term=#{ term }&return_to_room_id=#{ return_to_room_id }")
7
+ return_to_flow_id = CGI.escape(flow.id.to_s)
8
+ messages = connection.get("/search?term=#{ term }&return_to_flow_id=#{ return_to_flow_id }")
9
9
  if messages and messages.is_a?(Hash)
10
10
  messages = messages['messages']
11
11
  end
@@ -39,9 +39,9 @@ module FBomb
39
39
  module StreamExtension
40
40
  def stream
41
41
  @stream ||= (
42
- room = self
42
+ flow = self
43
43
  Twitter::JSONStream.connect(
44
- :path => "/room/#{ room.id }/live.json",
44
+ :path => "/flow/#{ flow.id }/live.json",
45
45
  :host => 'streaming.campfirenow.com',
46
46
  :auth => "#{ connection.token }:x"
47
47
  )
@@ -53,19 +53,47 @@ module FBomb
53
53
  end
54
54
  end
55
55
 
56
+ module UrlExtension
57
+ attr_accessor :campfire
58
+
59
+ def url
60
+ File.join(campfire.url, "flow/#{ id }")
61
+ end
62
+ end
63
+
56
64
  def Campfire.new(*args, &block)
57
65
  allocate.tap do |instance|
58
66
  instance.send(:initialize, *args, &block)
59
67
  end
60
68
  end
61
69
 
62
- def room_for(name)
70
+ def flow_for(name)
63
71
  name = name.to_s
64
- room = rooms.detect{|_| _.name == name}
65
- room.extend(SearchExtension)
66
- room.extend(UserExtension)
67
- room.extend(StreamExtension)
68
- room
72
+ flow = flows.detect{|_| _.name == name}
73
+ flow.extend(SearchExtension)
74
+ flow.extend(UserExtension)
75
+ flow.extend(StreamExtension)
76
+ flow.extend(UrlExtension)
77
+ flow.campfire = self
78
+ flow
79
+ end
80
+
81
+ attr_accessor :token
82
+
83
+ def url
84
+ if token
85
+ "#{ scheme }://#{ token }:X@#{ host }"
86
+ else
87
+ "#{ scheme }://#{ host }"
88
+ end
89
+ end
90
+
91
+ def host
92
+ connection.raw_connection.host
93
+ end
94
+
95
+ def scheme
96
+ connection.raw_connection.scheme
69
97
  end
70
98
  end
71
99
  end
@@ -5,9 +5,11 @@ module FBomb
5
5
  class Table < ::Map
6
6
  def help
7
7
  map = Map.new
8
- each do |path, command|
9
- map[path] = command.description
8
+
9
+ each do |key, command|
10
+ map[key] = command.description
10
11
  end
12
+
11
13
  map
12
14
  end
13
15
  end
@@ -15,12 +17,15 @@ module FBomb
15
17
  class << Command
16
18
  fattr(:table){ Table.new }
17
19
  fattr(:dir){ File.join(File.expand_path(File.dirname(__FILE__)), 'commands') }
18
- fattr(:room)
20
+ fattr(:flow)
21
+ fattr(:user)
22
+ fattr(:command_paths){ [] }
19
23
 
20
24
  def load(*args)
21
25
  args.flatten.uniq.each do |arg|
26
+ Command.command_paths << arg
22
27
  case arg.to_s
23
- when %r|^/|
28
+ when %r|^[/~]|
24
29
  load_absolute_path(arg)
25
30
  when %r|://|
26
31
  load_uri(arg)
@@ -48,7 +53,7 @@ module FBomb
48
53
  def load_uri(arg)
49
54
  uri = arg.to_s
50
55
  open(uri) do |fd|
51
- open(path){|fd| load_string(fd.read)}
56
+ open(path){|fd| load_string(fd.read, uri, 1)}
52
57
  end
53
58
  end
54
59
 
@@ -61,22 +66,22 @@ module FBomb
61
66
  def load_absolute_path(arg)
62
67
  path = File.expand_path(arg.to_s)
63
68
  path += '.rb' unless path =~ /\.rb\Z/
64
- open(path){|fd| load_string(fd.read)}
69
+ open(path){|fd| load_string(fd.read, path, 1)}
65
70
  end
66
71
 
67
- def load_string(string, dangerous = true)
72
+ def load_string(string, __file__, __lineno__, dangerous = true)
68
73
  Thread.new(string, dangerous) do |string, dangerous|
69
74
  Thread.current.abort_on_exception = true
70
75
  $SAFE = 12 unless dangerous
71
- Kernel.eval(string)
76
+ module_eval(string, __file__, __lineno__)
72
77
  end.value
73
78
  end
74
79
  end
75
80
 
76
81
  ## instance methods
77
82
  #
78
- fattr(:room){ self.class.room }
79
- fattr(:path)
83
+ fattr(:flow){ self.class.flow }
84
+ fattr(:key)
80
85
  fattr(:help)
81
86
  fattr(:setup)
82
87
 
@@ -85,21 +90,53 @@ module FBomb
85
90
  end
86
91
 
87
92
  def call(*args, &block)
88
- block ? @call=call : instance_exec(*args, &@call)
93
+ arity = @call.arity
94
+
95
+ argv =
96
+ if arity >= 0
97
+ args[0, arity]
98
+ else
99
+ head = []
100
+ tail = []
101
+ n = arity.abs - 1
102
+ head = args[0...n]
103
+ tail = args[n..-1]
104
+ [*(head + tail)]
105
+ end
106
+
107
+ argv.compact!
108
+
109
+ block ? @call=call : instance_exec(*argv, &@call)
89
110
  end
90
111
 
91
112
  def call=(call)
92
113
  @call = call
93
114
  end
94
115
 
95
- %w( speak paste ).each do |method|
116
+ %w( speak paste upload users ).each do |method|
96
117
  module_eval <<-__, __FILE__, __LINE__
97
118
  def #{ method }(*args, &block)
98
- room ? room.#{ method }(*args, &block) : puts(*args, &block)
119
+ flow ? flow.#{ method }(*args, &block) : puts(*args, &block)
99
120
  end
100
121
  __
101
122
  end
102
123
 
124
+ def most_recent_comment
125
+ message =
126
+ catch(:message) do
127
+ FBomb.messages.reverse.each do |message|
128
+ next if message == FBomb.message
129
+
130
+ case message['type'].to_s
131
+ when 'TextMessage'
132
+ throw :message, message
133
+ end
134
+ end
135
+ nil
136
+ end
137
+ message['body'] if message
138
+ end
139
+
103
140
  ## dsl
104
141
  #
105
142
  class DSL
@@ -122,8 +159,8 @@ module FBomb
122
159
  def command(*args, &block)
123
160
  return @command if(args.empty? and block.nil?)
124
161
  @command = Command.new
125
- @command.path = Util.absolute_path_for(args.shift)
126
- @commands[@command.path] ||= @command
162
+ @command.key = Util.absolute_key_for(args.shift)
163
+ @commands[@command.key] ||= @command
127
164
  evaluate(&block)
128
165
  end
129
166
  alias_method('Command', 'command')