memegen 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/memegen +0 -1
- data/lib/meme_generator.rb +1 -1
- data/lib/meme_generator/campfire.rb +24 -13
- data/lib/meme_generator/cli.rb +4 -8
- metadata +3 -3
data/bin/memegen
CHANGED
data/lib/meme_generator.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
class MemeGenerator
|
2
2
|
class Campfire
|
3
|
-
|
3
|
+
MEMEGEN_PATH = File.expand_path("~/.memegen")
|
4
|
+
CONFIG_PATH = File.join(MEMEGEN_PATH, ".campfire")
|
4
5
|
|
5
6
|
class << self
|
6
7
|
def config
|
@@ -9,13 +10,12 @@ class MemeGenerator
|
|
9
10
|
end
|
10
11
|
|
11
12
|
def prompt_config
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
token
|
17
|
-
|
18
|
-
room = gets.strip
|
13
|
+
require "readline"
|
14
|
+
puts "Set your Campfire credentials..." unless config
|
15
|
+
|
16
|
+
subdomain = Readline.readline("Subdomain : ").strip
|
17
|
+
token = Readline.readline("Token : ").strip
|
18
|
+
room = Readline.readline("Room : ").strip
|
19
19
|
|
20
20
|
write_config([subdomain, token, room])
|
21
21
|
|
@@ -23,15 +23,24 @@ class MemeGenerator
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def upload(path)
|
26
|
-
|
27
|
-
|
26
|
+
prompt_config unless config
|
27
|
+
|
28
|
+
require "tinder"
|
29
|
+
require "open-uri"
|
28
30
|
|
29
31
|
puts "Uploading... "
|
30
32
|
silence_stream(STDERR) do
|
31
|
-
|
32
|
-
|
33
|
-
|
33
|
+
begin
|
34
|
+
campfire = Tinder::Campfire.new config[:subdomain], :token => config[:token]
|
35
|
+
room = campfire.rooms.detect { |room| room.name == config[:room] }
|
36
|
+
room.upload(path)
|
37
|
+
rescue Tinder::AuthenticationFailed
|
38
|
+
puts "Your campfire credentials are incorrect. Please enter them again."
|
39
|
+
prompt_config
|
40
|
+
upload(path)
|
41
|
+
end
|
34
42
|
end
|
43
|
+
puts "Done!"
|
35
44
|
end
|
36
45
|
|
37
46
|
private
|
@@ -57,6 +66,8 @@ class MemeGenerator
|
|
57
66
|
end
|
58
67
|
|
59
68
|
def write_config(config)
|
69
|
+
require "fileutils"
|
70
|
+
FileUtils.mkdir_p(MEMEGEN_PATH)
|
60
71
|
File.open(CONFIG_PATH, "w") do |file|
|
61
72
|
file.write(config.join("|"))
|
62
73
|
end
|
data/lib/meme_generator/cli.rb
CHANGED
@@ -18,18 +18,12 @@ def list_generators
|
|
18
18
|
exit 0
|
19
19
|
end
|
20
20
|
|
21
|
-
def setup_campfire
|
22
|
-
require "meme_generator/campfire"
|
23
|
-
if !MemeGenerator::Campfire.config
|
24
|
-
MemeGenerator::Campfire.prompt_config
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
21
|
def parse_path(string)
|
29
22
|
if string =~ /^(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?$/ix
|
30
23
|
path = "/tmp/memegen-download-#{Time.now.to_i}"
|
31
24
|
`curl "#{image}" -o #{path} --silent`
|
32
|
-
elsif path = images.find { |p| p =~ /#{
|
25
|
+
elsif path = images.find { |p| p =~ /#{string}\./ }
|
26
|
+
|
33
27
|
else
|
34
28
|
puts "Error: Image not found. Use --list to view installed images."
|
35
29
|
exit 1
|
@@ -40,6 +34,8 @@ end
|
|
40
34
|
def generate(path, top, bottom, campfire)
|
41
35
|
if top || bottom
|
42
36
|
require "meme_generator"
|
37
|
+
require "meme_generator/campfire"
|
38
|
+
|
43
39
|
output_path = MemeGenerator.generate(path, top, bottom)
|
44
40
|
|
45
41
|
if campfire
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: memegen
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 21
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 1.0.
|
9
|
+
- 1
|
10
|
+
version: 1.0.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Brandon Keene
|