memegen 1.0.7 → 1.0.8
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +8 -0
- data/bin/memegen +4 -2
- data/lib/meme_generator.rb +1 -1
- data/lib/meme_generator/cli.rb +14 -3
- data/lib/meme_generator/groupme.rb +114 -0
- metadata +58 -61
data/README.md
CHANGED
@@ -56,6 +56,14 @@ If you have a [Campfire](http://campfirenow.com/) account and token, you can aut
|
|
56
56
|
$ memegen a_dog "Hello" "Campfire world" --campfire
|
57
57
|
|
58
58
|
It will prompt you for your subdomain, token, and room name the first time.
|
59
|
+
|
60
|
+
## Upload to GroupMe
|
61
|
+
|
62
|
+
If you have a [GroupMe](http://groupme.com/) account and token, you can automatically upload your image:
|
63
|
+
|
64
|
+
$ memegen a_dog "Hello" "GroupMe world" --groupme
|
65
|
+
|
66
|
+
It will prompt you for your phone number, password, and group id the first time. (your password will NOT be stored in plain text).
|
59
67
|
|
60
68
|
## Bash completion
|
61
69
|
|
data/bin/memegen
CHANGED
@@ -8,6 +8,7 @@ require "meme_generator/cli"
|
|
8
8
|
|
9
9
|
show_preview = ARGV.delete("show")
|
10
10
|
campfire = ARGV.delete("--campfire") || ARGV.delete("-c")
|
11
|
+
groupme = ARGV.delete("--groupme") || ARGV.delete("-g")
|
11
12
|
help = ARGV.delete("--help") || ARGV.delete("-h")
|
12
13
|
list = ARGV.delete("--list") || ARGV.delete("-l")
|
13
14
|
|
@@ -21,11 +22,12 @@ usage if help || ARGV.empty?
|
|
21
22
|
require "rubygems"
|
22
23
|
require "meme_generator"
|
23
24
|
require "meme_generator/campfire" if campfire
|
25
|
+
require "meme_generator/groupme" if groupme
|
24
26
|
|
25
27
|
path = parse_path(image)
|
26
28
|
|
27
29
|
if show_preview
|
28
|
-
system "open #{path} -a
|
30
|
+
system "open #{path} -a Preview"
|
29
31
|
else
|
30
|
-
generate(path, top.to_s, bottom.to_s, campfire)
|
32
|
+
generate(path, top.to_s, bottom.to_s, campfire, groupme)
|
31
33
|
end
|
data/lib/meme_generator.rb
CHANGED
data/lib/meme_generator/cli.rb
CHANGED
@@ -5,7 +5,7 @@ def images
|
|
5
5
|
end
|
6
6
|
|
7
7
|
def usage
|
8
|
-
puts 'usage: memegen <image> <top> <bottom> [--list|-l] [--campfire|-c] [--help|-h] [--install-autocomplete]'
|
8
|
+
puts 'usage: memegen <image> <top> <bottom> [--list|-l] [--campfire|-c] [--groupme|-g] [--help|-h] [--install-autocomplete]'
|
9
9
|
exit 1
|
10
10
|
end
|
11
11
|
|
@@ -30,13 +30,17 @@ def parse_path(string)
|
|
30
30
|
path
|
31
31
|
end
|
32
32
|
|
33
|
-
def generate(path, top, bottom, campfire)
|
33
|
+
def generate(path, top, bottom, campfire, groupme)
|
34
34
|
if top || bottom
|
35
35
|
output_path = MemeGenerator.generate(path, top, bottom)
|
36
36
|
|
37
37
|
if campfire
|
38
38
|
MemeGenerator::Campfire.upload(output_path)
|
39
|
-
|
39
|
+
end
|
40
|
+
if groupme
|
41
|
+
MemeGenerator::GroupMe.upload(output_path)
|
42
|
+
end
|
43
|
+
if (! (campfire || groupme) )
|
40
44
|
puts output_path
|
41
45
|
end
|
42
46
|
exit 0
|
@@ -56,6 +60,13 @@ Source autocomplete.sh in your ~/.bashrc:
|
|
56
60
|
Then source the profile:
|
57
61
|
|
58
62
|
$ source ~/.bashrc
|
63
|
+
|
64
|
+
Or if you're using a mac
|
65
|
+
|
66
|
+
$ echo "source #{path}" >> ~/.bash_profile
|
67
|
+
|
68
|
+
and
|
69
|
+
$ source ~/.bash_profile
|
59
70
|
|
60
71
|
You can copy the path to autocomplete.sh somewhere in your home directory if
|
61
72
|
you upgrade gem versions, but it should always work.
|
@@ -0,0 +1,114 @@
|
|
1
|
+
require 'net/http/post/multipart'
|
2
|
+
require 'net/http'
|
3
|
+
require 'net/https'
|
4
|
+
require 'json'
|
5
|
+
|
6
|
+
class MemeGenerator
|
7
|
+
class GroupMe
|
8
|
+
MEMEGEN_PATH = File.expand_path("~/.memegen")
|
9
|
+
CONFIG_PATH = File.join(MEMEGEN_PATH, ".groupme")
|
10
|
+
|
11
|
+
class << self
|
12
|
+
def config
|
13
|
+
return unless File.exists?(CONFIG_PATH)
|
14
|
+
@config ||= read_config
|
15
|
+
end
|
16
|
+
|
17
|
+
def prompt_config
|
18
|
+
require "readline"
|
19
|
+
require "highline/import"
|
20
|
+
puts "Set your GroupMe credentials..." unless config
|
21
|
+
|
22
|
+
phonenumber = Readline.readline("Phone #: ").strip
|
23
|
+
password = ask("Password: ") { |input| input.echo = false }
|
24
|
+
room = Readline.readline("Group Id: ").strip
|
25
|
+
message = Readline.readline("Message (optional): ").strip
|
26
|
+
|
27
|
+
token = auth_user(phonenumber, password)
|
28
|
+
|
29
|
+
if (token == nil)
|
30
|
+
puts "Error authorizing user"
|
31
|
+
else
|
32
|
+
write_config([token, room, message])
|
33
|
+
puts "Config saved successfully!"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def auth_user(phonenumber, password)
|
38
|
+
groupme_url = "https://v2.groupme.com/access_tokens"
|
39
|
+
uri = URI.parse(groupme_url)
|
40
|
+
request = Net::HTTP::Post.new(uri.request_uri)
|
41
|
+
request.set_form_data({"grant_type" => "password", "phone_number" => phonenumber, "password" => password, "app_id" => "memegen"});
|
42
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
43
|
+
http.use_ssl = true
|
44
|
+
response = http.request(request)
|
45
|
+
json_res = JSON.parse(response.body)
|
46
|
+
token = json_res["response"]["access_token"]
|
47
|
+
return token
|
48
|
+
end
|
49
|
+
|
50
|
+
def upload(path)
|
51
|
+
prompt_config unless config
|
52
|
+
|
53
|
+
puts "Uploading... "
|
54
|
+
silence_stream(STDERR) do
|
55
|
+
|
56
|
+
url = URI.parse('http://groupme-image-service.heroku.com/images');
|
57
|
+
File.open(path) do |jpg|
|
58
|
+
req = Net::HTTP::Post::Multipart.new url.path, "file" => UploadIO.new(jpg, "image/jpeg", "file.jpg")
|
59
|
+
res = Net::HTTP.start(url.host, url.port) do |http|
|
60
|
+
http.request(req)
|
61
|
+
end
|
62
|
+
json_res = JSON.parse(res.body)
|
63
|
+
img_url = json_res['payload']['picture_url']
|
64
|
+
|
65
|
+
groupme_url = "https://v2.groupme.com/groups/#{config[:room]}/messages?app_id=memgen&token=#{config[:token]}"
|
66
|
+
|
67
|
+
msg_json = {'message' => {'text' => config[:message], 'picture_url' => img_url}}.to_json
|
68
|
+
|
69
|
+
puts "Posting Message..."
|
70
|
+
|
71
|
+
url = URI.parse(groupme_url)
|
72
|
+
req = Net::HTTP::Post.new url.request_uri
|
73
|
+
req.body = msg_json.to_s
|
74
|
+
req['Content-Type'] = "text/json"
|
75
|
+
http = Net::HTTP.new(url.host, url.port)
|
76
|
+
http.use_ssl = true
|
77
|
+
http.request(req)
|
78
|
+
|
79
|
+
end
|
80
|
+
end
|
81
|
+
puts "Done!"
|
82
|
+
end
|
83
|
+
|
84
|
+
private
|
85
|
+
|
86
|
+
def silence_stream(stream)
|
87
|
+
old_stream = stream.dup
|
88
|
+
stream.reopen(RbConfig::CONFIG['host_os'] =~ /mswin|mingw/ ? 'NUL:' : '/dev/null')
|
89
|
+
stream.sync = true
|
90
|
+
yield
|
91
|
+
ensure
|
92
|
+
stream.reopen(old_stream)
|
93
|
+
end
|
94
|
+
|
95
|
+
# Lame format is to keep dependencies at a minimum
|
96
|
+
def read_config
|
97
|
+
data = File.read(CONFIG_PATH)
|
98
|
+
values = data.split("|")
|
99
|
+
{
|
100
|
+
:token => values[0],
|
101
|
+
:room => values[1],
|
102
|
+
:message => values[2]
|
103
|
+
}
|
104
|
+
end
|
105
|
+
|
106
|
+
def write_config(config)
|
107
|
+
FileUtils.mkdir_p(MEMEGEN_PATH)
|
108
|
+
File.open(CONFIG_PATH, "w") do |file|
|
109
|
+
file.write(config.join("|"))
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
metadata
CHANGED
@@ -1,63 +1,72 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: memegen
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.8
|
5
5
|
prerelease:
|
6
|
-
segments:
|
7
|
-
- 1
|
8
|
-
- 0
|
9
|
-
- 7
|
10
|
-
version: 1.0.7
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Brandon Keene
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2012-09-11 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
21
15
|
name: rmagick
|
22
|
-
|
23
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
16
|
+
requirement: &70143249364640 !ruby/object:Gem::Requirement
|
24
17
|
none: false
|
25
|
-
requirements:
|
26
|
-
- -
|
27
|
-
- !ruby/object:Gem::Version
|
28
|
-
|
29
|
-
segments:
|
30
|
-
- 0
|
31
|
-
version: "0"
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
32
22
|
type: :runtime
|
33
|
-
|
34
|
-
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70143249364640
|
25
|
+
- !ruby/object:Gem::Dependency
|
35
26
|
name: tinder
|
27
|
+
requirement: &70143249364100 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - =
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 1.4.4
|
33
|
+
type: :runtime
|
36
34
|
prerelease: false
|
37
|
-
|
35
|
+
version_requirements: *70143249364100
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: multipart-post
|
38
|
+
requirement: &70143249363680 !ruby/object:Gem::Requirement
|
38
39
|
none: false
|
39
|
-
requirements:
|
40
|
-
- -
|
41
|
-
- !ruby/object:Gem::Version
|
42
|
-
|
43
|
-
segments:
|
44
|
-
- 0
|
45
|
-
version: "0"
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
46
44
|
type: :runtime
|
47
|
-
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *70143249363680
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: highlight
|
49
|
+
requirement: &70143249363220 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
type: :runtime
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *70143249363220
|
48
58
|
description: Locally generate two-caption 'Advice Dog'-style meme images
|
49
|
-
email:
|
59
|
+
email:
|
50
60
|
- bkeene@gmail.com
|
51
|
-
executables:
|
61
|
+
executables:
|
52
62
|
- memegen
|
53
63
|
extensions: []
|
54
|
-
|
55
64
|
extra_rdoc_files: []
|
56
|
-
|
57
|
-
files:
|
65
|
+
files:
|
58
66
|
- bin/memegen
|
59
67
|
- lib/meme_generator/campfire.rb
|
60
68
|
- lib/meme_generator/cli.rb
|
69
|
+
- lib/meme_generator/groupme.rb
|
61
70
|
- lib/meme_generator.rb
|
62
71
|
- generators/a_dog.jpg
|
63
72
|
- generators/angry_arnold.jpg
|
@@ -112,38 +121,26 @@ files:
|
|
112
121
|
- README.md
|
113
122
|
homepage: http://github.com/cmdrkeene/memegen
|
114
123
|
licenses: []
|
115
|
-
|
116
124
|
post_install_message:
|
117
125
|
rdoc_options: []
|
118
|
-
|
119
|
-
require_paths:
|
126
|
+
require_paths:
|
120
127
|
- lib
|
121
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
128
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
122
129
|
none: false
|
123
|
-
requirements:
|
124
|
-
- -
|
125
|
-
- !ruby/object:Gem::Version
|
126
|
-
|
127
|
-
|
128
|
-
- 0
|
129
|
-
version: "0"
|
130
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
130
|
+
requirements:
|
131
|
+
- - ! '>='
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '0'
|
134
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
131
135
|
none: false
|
132
|
-
requirements:
|
133
|
-
- -
|
134
|
-
- !ruby/object:Gem::Version
|
135
|
-
hash: 23
|
136
|
-
segments:
|
137
|
-
- 1
|
138
|
-
- 3
|
139
|
-
- 6
|
136
|
+
requirements:
|
137
|
+
- - ! '>='
|
138
|
+
- !ruby/object:Gem::Version
|
140
139
|
version: 1.3.6
|
141
140
|
requirements: []
|
142
|
-
|
143
141
|
rubyforge_project:
|
144
|
-
rubygems_version: 1.8.
|
142
|
+
rubygems_version: 1.8.10
|
145
143
|
signing_key:
|
146
144
|
specification_version: 3
|
147
145
|
summary: Two-caption meme generator CLI
|
148
146
|
test_files: []
|
149
|
-
|