yuno 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (8) hide show
  1. data/.gitignore +26 -0
  2. data/Gemfile +4 -0
  3. data/README +19 -0
  4. data/Rakefile +2 -0
  5. data/bin/yuno +5 -0
  6. data/lib/yuno.rb +98 -0
  7. data/yuno.gemspec +21 -0
  8. metadata +64 -0
@@ -0,0 +1,26 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
22
+ examples/wynn.rb
23
+
24
+ ## Bundler
25
+ Gemfile.lock
26
+ *.gem
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in yuno.gemspec
4
+ gemspec
data/README ADDED
@@ -0,0 +1,19 @@
1
+ == Usage
2
+
3
+ gem install yuno
4
+ gem install imgur2
5
+
6
+ >yuno 'first line' 'second line' # first on top, second at bottom
7
+ or
8
+ >yuno 'second line' # the first will default to "Y U NO"
9
+
10
+ you can pipe to imgur (recommended)
11
+
12
+ >yuno 'work' | imgur2
13
+
14
+ It should also add a generated link to your clipboard, so you don't have to copy it manually
15
+
16
+ == Credits
17
+
18
+ All code ripped from https://github.com/drbrain/meme and made worse.
19
+ Gem uses http://diylol.com, please go there and click some ads so the guy earns for the traffic you use
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,5 @@
1
+ #!/usr/local/bin/ruby19
2
+
3
+ require 'yuno'
4
+
5
+ Yuno.run ARGV
@@ -0,0 +1,98 @@
1
+ require 'net/http'
2
+ require 'rubygems'
3
+ require 'nokogiri'
4
+ require 'cgi'
5
+ # everything is stolen from meme_generator gem
6
+ class Yuno
7
+ class Error < RuntimeError; end
8
+ VERSION = '0.0.1'
9
+ USER_AGENT = "yuno/#{VERSION} Ruby/#{RUBY_VERSION}"
10
+
11
+ def self.run argv = ARGV
12
+ generator = ARGV
13
+
14
+ abort "yuno 'first line' 'second line' | yuno 'second line'" if ARGV.empty?
15
+
16
+ yuno = new generator
17
+ link = yuno.generate(*ARGV)
18
+ yuno.paste(link)
19
+
20
+ if $stdout.tty?
21
+ puts link
22
+ else
23
+ puts yuno.fetch link
24
+ end
25
+ link
26
+ rescue Interrupt
27
+ exit
28
+ rescue SystemExit
29
+ raise
30
+ rescue Exception => e
31
+ puts e.backtrace.join "\n\t" if $DEBUG
32
+ abort "ERROR: #{e.message} (#{e.class})"
33
+ end
34
+
35
+ def initialize generator
36
+ end
37
+
38
+ def generate *args
39
+ url = URI.parse 'http://diylol.com/meme-generator/y-u-no/memes'
40
+ res = nil
41
+ location = nil
42
+
43
+ args.unshift "Y U NO" if args.size <= 1
44
+
45
+ post_data = { 'post[line1]' => args[0],
46
+ 'post[line2]' => args[1],
47
+ 'accept_tos[accepted]' => "1" }
48
+
49
+ Net::HTTP.start url.host do |http|
50
+ post = Net::HTTP::Post.new url.path
51
+ post['User-Agent'] = USER_AGENT
52
+ post.set_form_data post_data
53
+
54
+ res = http.request post
55
+
56
+ location = res['Location']
57
+ redirect = url + location
58
+
59
+ get = Net::HTTP::Get.new redirect.request_uri
60
+ get['User-Agent'] = USER_AGENT
61
+
62
+ res = http.request get
63
+ end
64
+
65
+ if Net::HTTPSuccess === res then
66
+ doc = Nokogiri.HTML res.body
67
+ doc.css("link[rel=\"image_src\"]").first['href']
68
+ else
69
+ raise Error, "diylol appears to be down, got #{res.code}"
70
+ end
71
+ end
72
+
73
+ def fetch link
74
+ url = URI.parse link
75
+ res = nil
76
+
77
+ Net::HTTP.start url.host do |http|
78
+ get = Net::HTTP::Get.new url.request_uri
79
+ get['User-Agent'] = USER_AGENT
80
+
81
+ res = http.request get
82
+ end
83
+ res.body
84
+ end
85
+
86
+ def paste link
87
+ require 'pasteboard'
88
+ clipboard = Pasteboard.new
89
+ jpeg = fetch link
90
+ clipboard.put_jpeg_url jpeg, link
91
+ rescue LoadError
92
+ clipboard = %w{/usr/bin/pbcopy /usr/bin/xclip}.find { |path| File.exist? path }
93
+
94
+ if clipboard
95
+ IO.popen clipboard, 'w' do |io| io.write link end
96
+ end
97
+ end
98
+ end
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "yuno"
6
+ s.version = "0.0.1"
7
+ s.platform = Gem::Platform::RUBY
8
+ s.authors = ["Tadas Tamosauskas"]
9
+ s.email = ["tadas@pdfcv.com"]
10
+ s.homepage = "https://github.com/medwezys/yuno"
11
+ s.executables = "yuno"
12
+ s.summary = %q{Y-U-NO generator}
13
+ s.description = %q{Y-U-NO meme cmd line generator}
14
+
15
+ s.rubyforge_project = "yuno"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib", "bin"]
21
+ end
metadata ADDED
@@ -0,0 +1,64 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: yuno
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.1
6
+ platform: ruby
7
+ authors:
8
+ - Tadas Tamosauskas
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-05-16 00:00:00 +01:00
14
+ default_executable:
15
+ dependencies: []
16
+
17
+ description: Y-U-NO meme cmd line generator
18
+ email:
19
+ - tadas@pdfcv.com
20
+ executables:
21
+ - yuno
22
+ extensions: []
23
+
24
+ extra_rdoc_files: []
25
+
26
+ files:
27
+ - .gitignore
28
+ - Gemfile
29
+ - README
30
+ - Rakefile
31
+ - bin/yuno
32
+ - lib/yuno.rb
33
+ - yuno.gemspec
34
+ has_rdoc: true
35
+ homepage: https://github.com/medwezys/yuno
36
+ licenses: []
37
+
38
+ post_install_message:
39
+ rdoc_options: []
40
+
41
+ require_paths:
42
+ - lib
43
+ - bin
44
+ required_ruby_version: !ruby/object:Gem::Requirement
45
+ none: false
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: "0"
50
+ required_rubygems_version: !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: "0"
56
+ requirements: []
57
+
58
+ rubyforge_project: yuno
59
+ rubygems_version: 1.6.2
60
+ signing_key:
61
+ specification_version: 3
62
+ summary: Y-U-NO generator
63
+ test_files: []
64
+