memegen 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/bin/memegen CHANGED
@@ -13,7 +13,6 @@ campfire = ARGV.include?("--campfire") || ARGV.include?("-c")
13
13
 
14
14
  usage if help || ARGV.empty?
15
15
  list_generators if list
16
- setup_campfire if campfire
17
16
 
18
17
  path = parse_path(image)
19
18
  generate(path, top, bottom, campfire)
@@ -2,7 +2,7 @@ require "rubygems"
2
2
  require "bundler/setup"
3
3
 
4
4
  class MemeGenerator
5
- VERSION = "1.0.0"
5
+ VERSION = "1.0.1"
6
6
 
7
7
  class << self
8
8
  def generate(path, top, bottom)
@@ -1,6 +1,7 @@
1
1
  class MemeGenerator
2
2
  class Campfire
3
- CONFIG_PATH = File.join(File.expand_path("~/.memegen"), ".campfire")
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
- puts "Set your Campfire credentials..."
13
- print "Subdomain : "
14
- subdomain = gets.strip
15
- print "Token : "
16
- token = gets.strip
17
- print "Room : "
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
- require 'tinder'
27
- require 'open-uri'
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
- campfire = Tinder::Campfire.new config[:subdomain], :token => config[:token]
32
- room = campfire.rooms.detect { |room| room.name == config[:room] }
33
- room.upload(path)
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
@@ -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 =~ /#{path}\./ }
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: 23
4
+ hash: 21
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 0
9
- - 0
10
- version: 1.0.0
9
+ - 1
10
+ version: 1.0.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Brandon Keene