meme_generator 1.0

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.
Binary file
@@ -0,0 +1,6 @@
1
+ === 1.0.0 / 2011-02-08
2
+
3
+ * 1 major enhancement
4
+
5
+ * Birthday!
6
+
@@ -0,0 +1,6 @@
1
+ History.txt
2
+ Manifest.txt
3
+ README.txt
4
+ Rakefile
5
+ bin/meme
6
+ lib/meme.rb
@@ -0,0 +1,62 @@
1
+ = meme
2
+
3
+ * http://github.com/drbrain/meme
4
+ * http://docs.seattlerb.org/meme_generator
5
+
6
+ == DESCRIPTION:
7
+
8
+ Generate meme images using http://memegenerator.net! Save yourself some time!
9
+
10
+ == FEATURES/PROBLEMS:
11
+
12
+ * Only has a static list of three meme images
13
+ * No tests
14
+
15
+ == SYNOPSIS:
16
+
17
+ meme Y-U-NO 'write tests?'
18
+
19
+ You can also drive it like an API.
20
+
21
+ == REQUIREMENTS:
22
+
23
+ * nokogiri
24
+ * internet connection
25
+
26
+ == INSTALL:
27
+
28
+ gem install meme_generator
29
+
30
+ == DEVELOPERS:
31
+
32
+ After checking out the source, run:
33
+
34
+ $ rake newb
35
+
36
+ This task will install any missing dependencies, run the tests/specs,
37
+ and generate the RDoc.
38
+
39
+ == LICENSE:
40
+
41
+ (The MIT License)
42
+
43
+ Copyright (c) 2011 Eric Hodel
44
+
45
+ Permission is hereby granted, free of charge, to any person obtaining
46
+ a copy of this software and associated documentation files (the
47
+ 'Software'), to deal in the Software without restriction, including
48
+ without limitation the rights to use, copy, modify, merge, publish,
49
+ distribute, sublicense, and/or sell copies of the Software, and to
50
+ permit persons to whom the Software is furnished to do so, subject to
51
+ the following conditions:
52
+
53
+ The above copyright notice and this permission notice shall be
54
+ included in all copies or substantial portions of the Software.
55
+
56
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
57
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
58
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
59
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
60
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
61
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
62
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,19 @@
1
+ # -*- ruby -*-
2
+
3
+ require 'rubygems'
4
+ require 'hoe'
5
+
6
+ Hoe.plugin :git
7
+
8
+ Hoe.spec 'meme_generator' do
9
+ developer 'Eric Hodel', 'drbrain@segment7.net'
10
+
11
+ rdoc_locations <<
12
+ 'docs.seattlerb.org:/data/www/docs.seattlerb.org/meme_generator/'
13
+
14
+ extra_deps << ['nokogiri', '~> 1.4']
15
+
16
+ required_ruby_version = '>= 1.9.2'
17
+ end
18
+
19
+ # vim: syntax=ruby
@@ -0,0 +1,6 @@
1
+ #!/usr/local/bin/ruby19
2
+
3
+ require 'meme'
4
+
5
+ Meme.run ARGV
6
+
@@ -0,0 +1,122 @@
1
+ require 'net/http'
2
+ require 'rubygems'
3
+ require 'nokogiri'
4
+ require 'cgi'
5
+
6
+ ##
7
+ # Generate memes using http://memegenerator.net
8
+
9
+ class Meme
10
+
11
+ ##
12
+ # Sometimes your meme will have an error, fix it!
13
+
14
+ class Error < RuntimeError; end
15
+
16
+ ##
17
+ # Every meme generator needs a version
18
+
19
+ VERSION = '1.0'
20
+
21
+ ##
22
+ # For statistics!
23
+
24
+ USER_AGENT = "meme/#{VERSION} Ruby/#{RUBY_VERSION}"
25
+
26
+ ##
27
+ # We have some generators up-in-here
28
+
29
+ GENERATORS = Hash.new do |_, k|
30
+ raise Error, "unknown generator #{k}"
31
+ end
32
+
33
+ GENERATORS['Y_U_NO'] = [165241, 'Y-U-NO', 'Y U NO']
34
+ GENERATORS['B_FROG'] = [1211, 'Foul-Bachelorette-Frog']
35
+ GENERATORS['PHILOSORAPTOR'] = [984, 'Philosoraptor']
36
+
37
+ ##
38
+ # Interface for the executable
39
+
40
+ def self.run argv = ARGV
41
+ generator = ARGV.shift
42
+
43
+ if generator == '--list' then
44
+ width = GENERATORS.keys.map { |command| command.length }.max
45
+
46
+ GENERATORS.each do |command, (id, name, _)|
47
+ puts "%-*s %s" % [width, command, name]
48
+ end
49
+
50
+ exit
51
+ end
52
+
53
+ line1 = ARGV.shift
54
+ line2 = ARGV.shift
55
+
56
+ abort "#{$0} GENERATOR LINE [LINE]" unless line1
57
+
58
+ meme = new generator
59
+ link = meme.generate line1, line2
60
+
61
+ meme.paste link
62
+
63
+ puts link
64
+ end
65
+
66
+ ##
67
+ # Generates links for +generator+
68
+
69
+ def initialize generator
70
+ @template_id, @generator_name, @default_line = GENERATORS[generator]
71
+ end
72
+
73
+ ##
74
+ # Generates a meme with +line1+ and +line2+. For some generators you only
75
+ # have to supply one line because the first line is defaulted for you.
76
+ # Isn't that great?
77
+
78
+ def generate line1, line2 = nil
79
+ url = URI.parse 'http://memegenerator.net/Instance/CreateOrEdit'
80
+ res = nil
81
+ location = nil
82
+
83
+ unless line2 then
84
+ line2 = line1
85
+ line1 = @default_line
86
+ end
87
+
88
+ raise Error, "must supply both lines for #{generator_name}" unless line1
89
+
90
+ Net::HTTP.start url.host do |http|
91
+ post = Net::HTTP::Post.new url.path
92
+ post['User-Agent'] = USER_AGENT
93
+ post.set_form_data('templateType' => 'AdviceDogSpinoff',
94
+ 'text0' => line1,
95
+ 'text1' => line2,
96
+ 'templateID' => @template_id,
97
+ 'generatorName' => @generator_name)
98
+
99
+ res = http.request post
100
+
101
+ location = res['Location']
102
+ redirect = url + location
103
+
104
+ get = Net::HTTP::Get.new redirect.request_uri
105
+ get['User-Agent'] = USER_AGENT
106
+
107
+ res = http.request get
108
+ end
109
+
110
+ doc = Nokogiri.HTML res.body
111
+ doc.css("a[href=\"#{location}\"] img").first['src']
112
+ end
113
+
114
+ ##
115
+ # Puts +link+ in your clipboard, if you're on OS X, that is.
116
+
117
+ def paste link
118
+ IO.popen 'pbcopy', 'w' do |io| io.write link end
119
+ end
120
+
121
+ end
122
+
metadata ADDED
@@ -0,0 +1,126 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: meme_generator
3
+ version: !ruby/object:Gem::Version
4
+ hash: 15
5
+ prerelease:
6
+ segments:
7
+ - 1
8
+ - 0
9
+ version: "1.0"
10
+ platform: ruby
11
+ authors:
12
+ - Eric Hodel
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain:
16
+ - |
17
+ -----BEGIN CERTIFICATE-----
18
+ MIIDNjCCAh6gAwIBAgIBADANBgkqhkiG9w0BAQUFADBBMRAwDgYDVQQDDAdkcmJy
19
+ YWluMRgwFgYKCZImiZPyLGQBGRYIc2VnbWVudDcxEzARBgoJkiaJk/IsZAEZFgNu
20
+ ZXQwHhcNMDcxMjIxMDIwNDE0WhcNMDgxMjIwMDIwNDE0WjBBMRAwDgYDVQQDDAdk
21
+ cmJyYWluMRgwFgYKCZImiZPyLGQBGRYIc2VnbWVudDcxEzARBgoJkiaJk/IsZAEZ
22
+ FgNuZXQwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCbbgLrGLGIDE76
23
+ LV/cvxdEzCuYuS3oG9PrSZnuDweySUfdp/so0cDq+j8bqy6OzZSw07gdjwFMSd6J
24
+ U5ddZCVywn5nnAQ+Ui7jMW54CYt5/H6f2US6U0hQOjJR6cpfiymgxGdfyTiVcvTm
25
+ Gj/okWrQl0NjYOYBpDi+9PPmaH2RmLJu0dB/NylsDnW5j6yN1BEI8MfJRR+HRKZY
26
+ mUtgzBwF1V4KIZQ8EuL6I/nHVu07i6IkrpAgxpXUfdJQJi0oZAqXurAV3yTxkFwd
27
+ g62YrrW26mDe+pZBzR6bpLE+PmXCzz7UxUq3AE0gPHbiMXie3EFE0oxnsU3lIduh
28
+ sCANiQ8BAgMBAAGjOTA3MAkGA1UdEwQCMAAwCwYDVR0PBAQDAgSwMB0GA1UdDgQW
29
+ BBS5k4Z75VSpdM0AclG2UvzFA/VW5DANBgkqhkiG9w0BAQUFAAOCAQEAHagT4lfX
30
+ kP/hDaiwGct7XPuVGbrOsKRVD59FF5kETBxEc9UQ1clKWngf8JoVuEoKD774dW19
31
+ bU0GOVWO+J6FMmT/Cp7nuFJ79egMf/gy4gfUfQMuvfcr6DvZUPIs9P/TlK59iMYF
32
+ DIOQ3DxdF3rMzztNUCizN4taVscEsjCcgW6WkUJnGdqlu3OHWpQxZBJkBTjPCoc6
33
+ UW6on70SFPmAy/5Cq0OJNGEWBfgD9q7rrs/X8GGwUWqXb85RXnUVi/P8Up75E0ag
34
+ 14jEc90kN+C7oI/AGCBN0j6JnEtYIEJZibjjDJTSMWlUKKkj30kq7hlUC2CepJ4v
35
+ x52qPcexcYZR7w==
36
+ -----END CERTIFICATE-----
37
+
38
+ date: 2011-02-08 00:00:00 -08:00
39
+ default_executable:
40
+ dependencies:
41
+ - !ruby/object:Gem::Dependency
42
+ name: nokogiri
43
+ prerelease: false
44
+ requirement: &id001 !ruby/object:Gem::Requirement
45
+ none: false
46
+ requirements:
47
+ - - ~>
48
+ - !ruby/object:Gem::Version
49
+ hash: 7
50
+ segments:
51
+ - 1
52
+ - 4
53
+ version: "1.4"
54
+ type: :runtime
55
+ version_requirements: *id001
56
+ - !ruby/object:Gem::Dependency
57
+ name: hoe
58
+ prerelease: false
59
+ requirement: &id002 !ruby/object:Gem::Requirement
60
+ none: false
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ hash: 43
65
+ segments:
66
+ - 2
67
+ - 9
68
+ - 0
69
+ version: 2.9.0
70
+ type: :development
71
+ version_requirements: *id002
72
+ description: Generate meme images using http://memegenerator.net! Save yourself some time!
73
+ email:
74
+ - drbrain@segment7.net
75
+ executables:
76
+ - meme
77
+ extensions: []
78
+
79
+ extra_rdoc_files:
80
+ - History.txt
81
+ - Manifest.txt
82
+ - README.txt
83
+ files:
84
+ - History.txt
85
+ - Manifest.txt
86
+ - README.txt
87
+ - Rakefile
88
+ - bin/meme
89
+ - lib/meme.rb
90
+ has_rdoc: true
91
+ homepage: http://github.com/drbrain/meme
92
+ licenses: []
93
+
94
+ post_install_message:
95
+ rdoc_options:
96
+ - --main
97
+ - README.txt
98
+ require_paths:
99
+ - lib
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ none: false
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ hash: 3
106
+ segments:
107
+ - 0
108
+ version: "0"
109
+ required_rubygems_version: !ruby/object:Gem::Requirement
110
+ none: false
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ hash: 3
115
+ segments:
116
+ - 0
117
+ version: "0"
118
+ requirements: []
119
+
120
+ rubyforge_project: meme_generator
121
+ rubygems_version: 1.5.0
122
+ signing_key:
123
+ specification_version: 3
124
+ summary: Generate meme images using http://memegenerator.net! Save yourself some time!
125
+ test_files: []
126
+
Binary file