bropages 0.0.4 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -13
- data/bin/bro +0 -0
- data/lib/bro/bro_state.rb +66 -0
- data/lib/bro/state.rb +45 -0
- data/lib/bro/string_hacks.rb +25 -0
- data/lib/bro.rb +102 -150
- metadata +17 -14
checksums.yaml
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
data.tar.gz: !binary |-
|
6
|
-
NDRlNTJkNGI0ZmQ2ZjJkOTkxNWIzMWE2MjQyNTYyOGRiNzE1NmIyYw==
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 72eaf532302a8ec6bf8a50eb76b9b3d4368374cb
|
4
|
+
data.tar.gz: 93fc8a746da87159d17b20638ebba107ed2974bd
|
7
5
|
SHA512:
|
8
|
-
metadata.gz:
|
9
|
-
|
10
|
-
NDAyYTNlNDMzYjZjMGRiNDc0YThiNjg2ZTU4ZGE0NTg2OTUwOWY1NmZjZDE1
|
11
|
-
ZWI4NjQ0NjE4NTc4ODljOWRjMDQ5YWZiYzhkMzIyZTY0YjZjZDY=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
NjA4MzQ3YWNiMTNiZGEyNmMwNjA0YTgwMzc3NmU4YjA3Y2JiZGQzNTgxYjM5
|
14
|
-
MTM5NDc0ZWM3NjI0OGFmOTZiOWE5YjJmNWRhYzYyOGY2ZmUxNThmY2Q1ODFk
|
15
|
-
YmU0ZTE4NjAxNzVhYjQ2ODEyZGRkZmM0OTYyZGNhN2UxZWQ4MDg=
|
6
|
+
metadata.gz: 031642ebd06e5a47a0b760bdab559c19cfeb617abf5467ae5f37e1eb4be9ca4715c0ee87809f79ce7e95571a39c8ec91bc064848b9ec11c012afab4af1e9b31d
|
7
|
+
data.tar.gz: cb0aa08173c7dbd0710027d2dea4f7246a4f94a6dd1b3106e9c39a95e67fe9628c48aa21256b69239635e5f8c97fbf83b7fa2cd05b93d149e818a9f99ed20c66
|
data/bin/bro
CHANGED
File without changes
|
@@ -0,0 +1,66 @@
|
|
1
|
+
module Bro
|
2
|
+
class BroState < State
|
3
|
+
def get_arg_or_last_command args
|
4
|
+
cmd = args.first
|
5
|
+
if args.empty?
|
6
|
+
state = read_state
|
7
|
+
cmd = state[:cmd]
|
8
|
+
end
|
9
|
+
cmd
|
10
|
+
end
|
11
|
+
|
12
|
+
def check_email
|
13
|
+
begin
|
14
|
+
is_invalid_code read_state[:code], read_state[:email]
|
15
|
+
rescue => e
|
16
|
+
puts e
|
17
|
+
prompt_email
|
18
|
+
end
|
19
|
+
{code: read_state[:code], email: read_state[:email]}
|
20
|
+
end
|
21
|
+
|
22
|
+
def prompt_email
|
23
|
+
say "Bropages.org requires an email address verification to do this action".colored.yellow
|
24
|
+
say "Your email address and verification code will be saved locally on your machine to a file called #{"~/.bro".colored.yellow} and used for future bropages.org activity"
|
25
|
+
say "When you enter your email, you'll get a verification email with a code. Enter the code when prompted"
|
26
|
+
|
27
|
+
email = ""
|
28
|
+
|
29
|
+
while is_invalid_email email
|
30
|
+
email = ask "What's your email address?".colored.green
|
31
|
+
end
|
32
|
+
|
33
|
+
begin
|
34
|
+
res = RestClient.post URL + '/users.json', { user: { email: email }, format: 'json', multipart: true }
|
35
|
+
rescue => e
|
36
|
+
say "There was an error delivering to your email address. Please try again later".colored.yellow.on_red
|
37
|
+
raise e
|
38
|
+
else
|
39
|
+
say "Great! We're sending an email to #{email}. Enter the verification code below and you'll be all set from now on."
|
40
|
+
|
41
|
+
invalid_code = true
|
42
|
+
begin
|
43
|
+
code = ask "Please enter the verification code: "
|
44
|
+
begin
|
45
|
+
is_invalid_code code, email
|
46
|
+
invalid_code = false
|
47
|
+
say "Great! You're verified! FYI, your email and code are stored locally in ~/.bro"
|
48
|
+
write_state({ email: email, code: code })
|
49
|
+
rescue => e
|
50
|
+
say "Woops, there was a problem verifying your email. Please try again".colored.yellow.on_red
|
51
|
+
end
|
52
|
+
end while invalid_code
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
def is_invalid_code code, email
|
58
|
+
res = RestClient.get URL + "/users/verify?code=#{code}&email=#{email}"
|
59
|
+
end
|
60
|
+
|
61
|
+
def is_invalid_email email
|
62
|
+
regex = /^[a-zA-Z0-9_.+\-]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-.]+$/
|
63
|
+
email.scan(regex).empty?
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
data/lib/bro/state.rb
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
module Bro
|
2
|
+
class State
|
3
|
+
|
4
|
+
def initialize options
|
5
|
+
@file = options[:file]
|
6
|
+
end
|
7
|
+
|
8
|
+
# write state to this file, using the existing key/vals as defaults
|
9
|
+
# format is key=val;key2=val;key3=val
|
10
|
+
def write_state obj, override=false
|
11
|
+
# read the ~/.bro file and load the settings as defaults
|
12
|
+
# we don't want to lose data if we're not writing over it all
|
13
|
+
read_state.each {|k,v|
|
14
|
+
obj[k] = v if obj[k].nil?
|
15
|
+
} unless override # unless we pass in strict parsing
|
16
|
+
|
17
|
+
# actually serialize the data and write the file
|
18
|
+
File.open(@file, 'w') do |file|
|
19
|
+
data_pairs = obj.collect{ |k,v| "#{k}=#{v}" }
|
20
|
+
file.write data_pairs.join(";") + "\n"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def reset_lookup_ids
|
25
|
+
# drop all lookup ids
|
26
|
+
write_state read_state().keep_if { |x| !!!(x =~ /\d+/) }, true
|
27
|
+
end
|
28
|
+
|
29
|
+
# read the ~/.bro file and return a hash of the values
|
30
|
+
def read_state
|
31
|
+
obj = {}
|
32
|
+
begin
|
33
|
+
contents = File.read @file
|
34
|
+
contents.strip.split(";").each {|kv|
|
35
|
+
chunk = kv.split("=")
|
36
|
+
key = chunk[0].intern
|
37
|
+
obj[key] = chunk[1]
|
38
|
+
}
|
39
|
+
rescue => e
|
40
|
+
# ignore file not found
|
41
|
+
end
|
42
|
+
obj
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
class String
|
2
|
+
def unindent
|
3
|
+
gsub(/^#{scan(/^\s*/).min_by{|l|l.length}}/, "")
|
4
|
+
end
|
5
|
+
|
6
|
+
def status
|
7
|
+
self.colored.yellow
|
8
|
+
end
|
9
|
+
|
10
|
+
def success
|
11
|
+
self.colored.green.bold
|
12
|
+
end
|
13
|
+
|
14
|
+
def problem
|
15
|
+
self.colored.yellow_on_red_bold
|
16
|
+
end
|
17
|
+
|
18
|
+
def sorry
|
19
|
+
self.colored.red.bold
|
20
|
+
end
|
21
|
+
|
22
|
+
def important
|
23
|
+
self.colored.magenta
|
24
|
+
end
|
25
|
+
end
|
data/lib/bro.rb
CHANGED
@@ -6,15 +6,22 @@ require 'highline'
|
|
6
6
|
require 'smart_colored'
|
7
7
|
require 'rest-client'
|
8
8
|
|
9
|
+
$LOAD_PATH << "."
|
10
|
+
require_relative 'bro/state.rb'
|
11
|
+
require_relative 'bro/bro_state.rb'
|
12
|
+
require_relative 'bro/string_hacks.rb'
|
13
|
+
include Bro
|
14
|
+
|
9
15
|
URL = ENV["BROPAGES_URL"] || 'http://bropages.org'
|
10
16
|
FILE = ENV["HOME"] + '/.bro'
|
11
17
|
|
12
18
|
program :name, 'bro'
|
13
|
-
program :version, '0.0.
|
19
|
+
program :version, '0.0.6'
|
14
20
|
program :description, "Highly readable supplement to man pages.\n\nShows simple, concise examples for commands."
|
15
|
-
|
16
21
|
default_command :lookup
|
17
22
|
|
23
|
+
state = Bro::BroState.new({:file => FILE})
|
24
|
+
|
18
25
|
command :thanks do |c|
|
19
26
|
c.syntax = 'bro thanks [COMMAND]'
|
20
27
|
c.summary = 'Upvote an entry, bro'
|
@@ -22,15 +29,16 @@ command :thanks do |c|
|
|
22
29
|
c.example 'Upvote the bro entry for curl', 'bro thanks curl'
|
23
30
|
c.action do |args, options|
|
24
31
|
begin
|
25
|
-
login_details = check_email
|
26
|
-
rescue
|
27
|
-
say "Sorry, you can't do this without email verification".
|
32
|
+
login_details = state.check_email
|
33
|
+
rescue => e
|
34
|
+
say "Sorry, you can't do this without email verification".sorry
|
35
|
+
say "#{e}"
|
28
36
|
end
|
29
37
|
unless login_details.nil?
|
30
|
-
cmd = read_state[:cmd]
|
38
|
+
cmd = state.read_state[:cmd]
|
31
39
|
|
32
40
|
if cmd.nil?
|
33
|
-
say "\nYou must first look up a command before downvoting. For example: bro curl\n\n"
|
41
|
+
say "\nYou must first look up a command before downvoting. For example: bro curl\n\n".sorry
|
34
42
|
return
|
35
43
|
end
|
36
44
|
|
@@ -38,43 +46,45 @@ command :thanks do |c|
|
|
38
46
|
if idkey.nil?
|
39
47
|
idkey = "1"
|
40
48
|
end
|
41
|
-
id = read_state[idkey.intern]
|
49
|
+
id = state.read_state[idkey.intern]
|
42
50
|
|
43
51
|
if id.nil?
|
44
|
-
say "
|
45
|
-
return
|
52
|
+
say "That id (#{idkey}) does not exist for #{cmd}, try another one".sorry
|
46
53
|
end
|
47
54
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
55
|
+
unless id.nil?
|
56
|
+
begin
|
57
|
+
res = RestClient.get URL + "/thanks/#{id}", { params: login_details }
|
58
|
+
rescue => e
|
59
|
+
say e.message
|
60
|
+
say "There was a problem thanking the #{cmd} entry. This entry may not exist or bropages.org may be down".problem
|
61
|
+
else
|
62
|
+
say "You just gave thanks to an entry for #{cmd}!".status
|
63
|
+
say "You rock!".success
|
64
|
+
end
|
56
65
|
end
|
57
66
|
end
|
58
67
|
end
|
59
68
|
end
|
60
69
|
|
61
|
-
|
62
|
-
c.syntax = 'bro no [ID]'
|
70
|
+
noblock = lambda { |c|
|
71
|
+
c.syntax = 'bro ...no [ID]'
|
63
72
|
c.summary = 'Downvote an entry, bro'
|
64
73
|
c.description = 'Downvote a bro entry for the last command you looked up. If called without ID, it will downvote the top entry of the last command you looked up.'
|
65
|
-
c.example 'Downvote the bro entry for curl', "bro curl\n\nbro no"
|
74
|
+
c.example 'Downvote the bro entry for curl', "bro curl\n\nbro ...no"
|
66
75
|
c.action do |args, options|
|
67
76
|
begin
|
68
|
-
login_details = check_email
|
77
|
+
login_details = state.check_email
|
69
78
|
rescue
|
70
|
-
say "Sorry, you can't do this without email verification".
|
79
|
+
say "Sorry, you can't do this without email verification".sorry
|
80
|
+
say "#{e}"
|
71
81
|
end
|
72
82
|
unless login_details.nil?
|
73
83
|
|
74
|
-
cmd = read_state[:cmd]
|
84
|
+
cmd = state.read_state[:cmd]
|
75
85
|
|
76
86
|
if cmd.nil?
|
77
|
-
say "\nYou must first look up a command before downvoting. For example: bro curl\n\n"
|
87
|
+
say "\nYou must first look up a command before downvoting. For example: bro curl\n\n".sorry
|
78
88
|
return
|
79
89
|
end
|
80
90
|
|
@@ -82,52 +92,73 @@ command :no do |c|
|
|
82
92
|
if idkey.nil?
|
83
93
|
idkey = "1"
|
84
94
|
end
|
85
|
-
id = read_state[idkey.intern]
|
95
|
+
id = state.read_state[idkey.intern]
|
86
96
|
|
87
97
|
if id.nil?
|
88
|
-
say "
|
89
|
-
return
|
98
|
+
say "That id (#{idkey}) does not exist for #{cmd}, try another one".sorry
|
90
99
|
end
|
91
100
|
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
101
|
+
unless id.nil?
|
102
|
+
begin
|
103
|
+
res = RestClient.get URL + "/no/#{id}", { params: login_details }
|
104
|
+
rescue => e
|
105
|
+
say "There was a problem downvoting the #{cmd} entry. This entry may not exist or bropages.org may be down".problem
|
106
|
+
say e
|
107
|
+
else
|
108
|
+
say "You just downvoted an entry for #{cmd}".status
|
109
|
+
say "You rock!".success
|
110
|
+
end
|
100
111
|
end
|
101
112
|
end
|
102
113
|
end
|
103
|
-
|
114
|
+
}
|
115
|
+
|
116
|
+
command :"...no", &noblock
|
117
|
+
command :no, &noblock
|
104
118
|
|
105
119
|
command :add do |c|
|
106
120
|
c.syntax = 'bro add [COMMAND] [-m MESSAGE]'
|
107
121
|
c.summary = 'Add an entry, bro'
|
108
|
-
c.description =
|
122
|
+
c.description = <<-QQQ.unindent
|
123
|
+
This adds an entry to the http://bropages.org database.
|
124
|
+
|
125
|
+
Called without parameters will add an entry for the last thing you looked up with bro.
|
126
|
+
QQQ
|
109
127
|
c.example 'Launch your editor to add an entry for curl', 'bro add curl'
|
110
128
|
c.example 'Quickly add an entry for curl', 'bro add curl -m "curl http://google.com"'
|
111
|
-
#TODO c.option '-m', 'An optional inline entry. This won\'t trigger a system editor to open'
|
129
|
+
# TODO c.option '-m', 'An optional inline entry. This won\'t trigger a system editor to open'
|
112
130
|
c.action do |args, options|
|
113
131
|
begin
|
114
|
-
login_details = check_email
|
132
|
+
login_details = state.check_email
|
115
133
|
rescue
|
116
|
-
say "Sorry, you can't do this without email verification".
|
134
|
+
say "Sorry, you can't do this without email verification".sorry
|
135
|
+
say e
|
117
136
|
end
|
118
137
|
|
119
138
|
unless login_details.nil?
|
120
139
|
|
121
|
-
cmd = get_arg_or_last_command args
|
140
|
+
cmd = state.get_arg_or_last_command args
|
122
141
|
|
123
142
|
if cmd.nil?
|
124
143
|
say "\nYou must enter a COMMAND after 'bro add'. For example: bro add curl\n\n"
|
125
144
|
else
|
126
|
-
prompt =
|
145
|
+
prompt = <<-QQQ.unindent
|
146
|
+
#~ Bro entry for command '#{cmd}'
|
147
|
+
#~ Provide a useful example for how to use '#{cmd}'
|
148
|
+
#~ Comments starting with #~ are removed
|
149
|
+
#~
|
150
|
+
#~ Example for command 'man':
|
151
|
+
#~ # Opens up the manual page for the command 'ls'
|
152
|
+
#~ man ls
|
153
|
+
#~
|
154
|
+
|
155
|
+
# ex
|
156
|
+
cmd
|
157
|
+
QQQ
|
127
158
|
entry = ask_editor prompt, "vim"
|
128
159
|
if entry.gsub(prompt, '').strip.length > 0
|
129
160
|
if agree "Submit this entry for #{cmd}? [Yn] "
|
130
|
-
say "All right, sending your entry..."
|
161
|
+
say "All right, sending your entry...".status
|
131
162
|
begin
|
132
163
|
res = RestClient.post URL + '/', login_details.merge({ entry: { cmd: cmd, msg: entry}, format: 'json', multipart: true })
|
133
164
|
rescue => e
|
@@ -145,13 +176,13 @@ command :add do |c|
|
|
145
176
|
File.open(file, 'w') do |f|
|
146
177
|
f.write entry
|
147
178
|
end
|
148
|
-
say "Woops. There was an error! Your entry was saved to #{file}".
|
179
|
+
say "Woops. There was an error! Your entry was saved to #{file}".problem
|
149
180
|
else
|
150
|
-
say "Successfully submitted.".
|
181
|
+
say "Successfully submitted.".success
|
151
182
|
end
|
152
183
|
end
|
153
184
|
else
|
154
|
-
say "Canceled. Did not submit entry for '#{cmd}'".
|
185
|
+
say "Canceled. Did not submit entry for '#{cmd}'".status
|
155
186
|
end
|
156
187
|
end
|
157
188
|
end
|
@@ -165,19 +196,35 @@ command :lookup do |c|
|
|
165
196
|
c.example 'Look up the bro entries for curl', 'bro curl'
|
166
197
|
c.action do |args, options|
|
167
198
|
if args.empty?
|
168
|
-
say
|
199
|
+
say <<-QQQ.unindent
|
200
|
+
#{"Bro! Specify a command first!".colored.red}
|
201
|
+
|
202
|
+
\t* For example try #{"bro curl".colored.green}
|
203
|
+
|
204
|
+
\t* Use #{"bro help".colored.yellow} for more info
|
205
|
+
|
206
|
+
QQQ
|
169
207
|
else
|
170
208
|
cmd = args.first
|
171
209
|
|
210
|
+
state.reset_lookup_ids()
|
211
|
+
|
172
212
|
# write to ~/.bro file with last command
|
173
|
-
write_state({ cmd: cmd })
|
213
|
+
state.write_state({ cmd: cmd })
|
174
214
|
|
175
215
|
# connect to webservice for entry
|
176
216
|
error = false
|
177
217
|
begin
|
178
218
|
res = RestClient.get URL + '/' + cmd + '.json'
|
179
219
|
rescue => e
|
180
|
-
say
|
220
|
+
say <<-QQQ.unindent
|
221
|
+
The #{cmd.colored.yellow} command isn't in our database
|
222
|
+
|
223
|
+
\t* Use #{"bro add".colored.green.underline} to add #{cmd.colored.yellow} to our database!
|
224
|
+
|
225
|
+
\t* Need help? Visit #{"http://bropages.org/help".colored.underline}
|
226
|
+
|
227
|
+
QQQ
|
181
228
|
error = true
|
182
229
|
end
|
183
230
|
|
@@ -185,7 +232,7 @@ command :lookup do |c|
|
|
185
232
|
enable_paging
|
186
233
|
list = JSON.parse res
|
187
234
|
s = list.length == 1 ? 'y' : 'ies'
|
188
|
-
say "#{list.length} entr#{s} for #{cmd}\n".
|
235
|
+
say "#{list.length} entr#{s} for #{cmd}\n".status.underline
|
189
236
|
|
190
237
|
sep = ""
|
191
238
|
(HighLine::SystemExtensions.terminal_size[0] - 5).times { sep += "." }
|
@@ -198,13 +245,13 @@ command :lookup do |c|
|
|
198
245
|
|
199
246
|
obj = {}
|
200
247
|
obj["#{i}"] = data['id']
|
201
|
-
write_state(obj)
|
248
|
+
state.write_state(obj)
|
202
249
|
|
203
250
|
days = (DateTime.now - DateTime.parse(data['updated_at'])).ceil.to_i
|
204
251
|
|
205
252
|
body = data['msg']
|
206
253
|
|
207
|
-
body = body.gsub(/^([^#][^\n]*)$/, "\\1".
|
254
|
+
body = body.gsub(/^([^#][^\n]*)$/, "\\1".important)
|
208
255
|
|
209
256
|
say sep + "\n\n" if i > 1
|
210
257
|
|
@@ -212,11 +259,10 @@ command :lookup do |c|
|
|
212
259
|
|
213
260
|
upstr = "bro thanks"
|
214
261
|
upstr += " #{i}" unless isDefault
|
215
|
-
downstr = "bro no"
|
262
|
+
downstr = "bro ...no"
|
216
263
|
downstr += " #{i}" unless isDefault
|
217
|
-
downstr += "\t" if isDefault
|
218
264
|
|
219
|
-
msg = "\t#{upstr.colored.green}\tto upvote (#{data['up']})\n\t#{downstr.colored.red}\tto downvote (#{data['down']})
|
265
|
+
msg = "\t#{upstr.colored.green}\tto upvote (#{data['up']})\n\t#{downstr.colored.red}\tto downvote (#{data['down']})"
|
220
266
|
if days > 0
|
221
267
|
#msg += "\tlast updated\t#{days} days ago"
|
222
268
|
end
|
@@ -227,97 +273,3 @@ command :lookup do |c|
|
|
227
273
|
end
|
228
274
|
end
|
229
275
|
end
|
230
|
-
|
231
|
-
def get_arg_or_last_command args
|
232
|
-
cmd = args.first
|
233
|
-
if args.empty?
|
234
|
-
state = read_state
|
235
|
-
cmd = state[:cmd]
|
236
|
-
end
|
237
|
-
cmd
|
238
|
-
end
|
239
|
-
|
240
|
-
def check_email
|
241
|
-
begin
|
242
|
-
is_invalid_code read_state[:code], read_state[:email]
|
243
|
-
rescue => e
|
244
|
-
prompt_email
|
245
|
-
end
|
246
|
-
{code: read_state[:code], email: read_state[:email]}
|
247
|
-
end
|
248
|
-
|
249
|
-
def prompt_email
|
250
|
-
say "Bropages.org requires an email address verification to do this action".colored.yellow
|
251
|
-
say "Your email address and verification code will be saved locally on your machine to a file called #{"~/.bro".colored.yellow} and used for future bropages.org activity"
|
252
|
-
say "When you enter your email, you'll get a verification email with a code. Enter the code when prompted"
|
253
|
-
|
254
|
-
email = ""
|
255
|
-
|
256
|
-
while is_invalid_email email
|
257
|
-
email = ask "What's your email address?".colored.green
|
258
|
-
end
|
259
|
-
|
260
|
-
begin
|
261
|
-
res = RestClient.post URL + '/users.json', { user: { email: email }, format: 'json', multipart: true }
|
262
|
-
rescue => e
|
263
|
-
say "There was an error delivering to your email address. Please try again later".colored.yellow.on_red
|
264
|
-
raise e
|
265
|
-
else
|
266
|
-
say "Great! We're sending an email to #{email}. Enter the verification code below and you'll be all set from now on."
|
267
|
-
|
268
|
-
invalid_code = true
|
269
|
-
begin
|
270
|
-
code = ask "Please enter the verification code: "
|
271
|
-
begin
|
272
|
-
is_invalid_code code, email
|
273
|
-
invalid_code = false
|
274
|
-
say "Great! You're verified! FYI, your email and code are stored locally in ~/.bro"
|
275
|
-
write_state({ email: email, code: code })
|
276
|
-
rescue => e
|
277
|
-
say "Woops, there was a problem verifying your email. Please try again".colored.yellow.on_red
|
278
|
-
end
|
279
|
-
end while invalid_code
|
280
|
-
end
|
281
|
-
|
282
|
-
end
|
283
|
-
|
284
|
-
def is_invalid_code code, email
|
285
|
-
res = RestClient.get URL + "/users/verify?code=#{code}&email=#{email}"
|
286
|
-
end
|
287
|
-
|
288
|
-
def is_invalid_email email
|
289
|
-
regex = /^[a-zA-Z0-9_.+\-]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-.]+$/
|
290
|
-
email.scan(regex).empty?
|
291
|
-
end
|
292
|
-
|
293
|
-
# write state to this file, using the existing key/vals as defaults
|
294
|
-
# format is key=val;key2=val;key3=val
|
295
|
-
def write_state obj
|
296
|
-
# read the ~/.bro file and load the settings as defaults
|
297
|
-
# we don't want to lose data if we're not writing over it all
|
298
|
-
read_state.each {|k,v|
|
299
|
-
obj[k] = v if obj[k].nil?
|
300
|
-
}
|
301
|
-
|
302
|
-
# actually serialize the data and write the file
|
303
|
-
File.open(FILE, 'w') do |file|
|
304
|
-
data_pairs = obj.collect{ |k,v| "#{k}=#{v}" }
|
305
|
-
file.write data_pairs.join(";") + "\n"
|
306
|
-
end
|
307
|
-
end
|
308
|
-
|
309
|
-
# read the ~/.bro file and return a hash of the values
|
310
|
-
def read_state
|
311
|
-
obj = {}
|
312
|
-
begin
|
313
|
-
contents = File.read FILE
|
314
|
-
contents.strip.split(";").each {|kv|
|
315
|
-
chunk = kv.split("=")
|
316
|
-
key = chunk[0].intern
|
317
|
-
obj[key] = chunk[1]
|
318
|
-
}
|
319
|
-
rescue => e
|
320
|
-
# ignore file not found
|
321
|
-
end
|
322
|
-
obj
|
323
|
-
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bropages
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- bropages.org
|
@@ -11,73 +11,73 @@ cert_chain: []
|
|
11
11
|
date: 2013-12-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: json_pure
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - '>='
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - '>='
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: commander
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - '>='
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - '>='
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rest-client
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - '>='
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0'
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - '>='
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: smart_colored
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - '>='
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - '>='
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: highline
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- -
|
73
|
+
- - '>='
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: '0'
|
76
76
|
type: :runtime
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- -
|
80
|
+
- - '>='
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
83
|
description: Highly readable supplement to man pages. Shows simple, concise examples
|
@@ -90,6 +90,9 @@ extra_rdoc_files: []
|
|
90
90
|
files:
|
91
91
|
- bin/bro
|
92
92
|
- lib/bro.rb
|
93
|
+
- lib/bro/bro_state.rb
|
94
|
+
- lib/bro/state.rb
|
95
|
+
- lib/bro/string_hacks.rb
|
93
96
|
homepage: http://bropages.org
|
94
97
|
licenses: []
|
95
98
|
metadata: {}
|
@@ -99,12 +102,12 @@ require_paths:
|
|
99
102
|
- lib
|
100
103
|
required_ruby_version: !ruby/object:Gem::Requirement
|
101
104
|
requirements:
|
102
|
-
- -
|
105
|
+
- - '>='
|
103
106
|
- !ruby/object:Gem::Version
|
104
107
|
version: '0'
|
105
108
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
106
109
|
requirements:
|
107
|
-
- -
|
110
|
+
- - '>='
|
108
111
|
- !ruby/object:Gem::Version
|
109
112
|
version: '0'
|
110
113
|
requirements: []
|