imagebin 0.3.6 → 1.0.2
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/README.rdoc +10 -6
- data/Rakefile +4 -4
- data/VERSION.yml +4 -3
- data/bin/imagebin +10 -38
- data/bin/take-screenshot +4 -3
- data/lib/imagebin.rb +32 -37
- data/spec/imagebin_spec.rb +9 -13
- metadata +43 -19
data/README.rdoc
CHANGED
@@ -1,17 +1,21 @@
|
|
1
1
|
= imagebin
|
2
2
|
|
3
|
-
imagebin is a CLI to http://
|
3
|
+
imagebin is a CLI to http://imgur.com
|
4
|
+
This program looks for your API key in ~/.imgur.yaml
|
5
|
+
|
4
6
|
Example: imagebin -f <pic.png>
|
5
7
|
|
6
8
|
Options:
|
7
9
|
-f, --file <file> Use a file for input
|
8
|
-
-n, --name [name] Name
|
9
|
-
-t, --tags [tags] Comma separated
|
10
|
-
-d, --description [description] Description
|
11
|
-
-p, --private Private
|
12
|
-
-l, --link Direct link to picture file
|
13
10
|
-h, --help Show this message
|
14
11
|
|
12
|
+
|
13
|
+
Here is an example of what ~/.imgur.yaml should look like:
|
14
|
+
|
15
|
+
---
|
16
|
+
key: 543e908c545620bd1c44d43edf3a35a0
|
17
|
+
|
18
|
+
|
15
19
|
== Copyright
|
16
20
|
|
17
21
|
Copyright (c) 2009 dougsko. See LICENSE for details.
|
data/Rakefile
CHANGED
@@ -5,12 +5,12 @@ begin
|
|
5
5
|
require 'jeweler'
|
6
6
|
Jeweler::Tasks.new do |gem|
|
7
7
|
gem.name = "imagebin"
|
8
|
-
gem.summary = %Q{Command line interface to
|
8
|
+
gem.summary = %Q{Command line interface to imgur.com}
|
9
9
|
gem.email = "dougtko@gmail.com"
|
10
10
|
gem.homepage = "http://github.com/dougsko/imagebin"
|
11
11
|
gem.authors = ["dougsko"]
|
12
12
|
gem.add_dependency 'httpclient'
|
13
|
-
gem.description = 'Command line interface to
|
13
|
+
gem.description = 'Command line interface to imgur.com'
|
14
14
|
gem.require_paths = ['/bin', '/lib']
|
15
15
|
gem.files = FileList["[A-Z]*", "{bin,generators,lib,spec}/**/*"]
|
16
16
|
gem.add_dependency "hpricot"
|
@@ -39,7 +39,7 @@ end
|
|
39
39
|
task :default => :spec
|
40
40
|
|
41
41
|
require 'rake/rdoctask'
|
42
|
-
require 'darkfish-rdoc'
|
42
|
+
#require 'darkfish-rdoc'
|
43
43
|
Rake::RDocTask.new do |rdoc|
|
44
44
|
if File.exist?('VERSION.yml')
|
45
45
|
config = YAML.load(File.read('VERSION.yml'))
|
@@ -54,7 +54,7 @@ Rake::RDocTask.new do |rdoc|
|
|
54
54
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
55
55
|
rdoc.options += [
|
56
56
|
'-N',
|
57
|
-
'-f', 'darkfish',
|
57
|
+
# '-f', 'darkfish',
|
58
58
|
]
|
59
59
|
end
|
60
60
|
|
data/VERSION.yml
CHANGED
data/bin/imagebin
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
#
|
3
3
|
#
|
4
|
-
# CLI to
|
4
|
+
# CLI to imgur.com
|
5
5
|
#
|
6
6
|
# Copyright (C) 2009 dougsko
|
7
7
|
#
|
@@ -23,43 +23,19 @@ require 'rubygems'
|
|
23
23
|
require 'optparse'
|
24
24
|
require 'imagebin'
|
25
25
|
|
26
|
-
options = { "
|
27
|
-
"
|
28
|
-
"tags" => "",
|
29
|
-
"description" => "",
|
30
|
-
"adult" => "f",
|
31
|
-
"direct_link" => "0",
|
26
|
+
options = { "image" => "file",
|
27
|
+
"key" => "",
|
32
28
|
}
|
33
29
|
|
34
30
|
opts = OptionParser.new do |opts|
|
35
|
-
opts.banner = "imagebin is a CLI to http://
|
31
|
+
opts.banner = "imagebin is a CLI to http://imgur.com
|
36
32
|
Example: imagebin -f <pic.png>"
|
37
33
|
|
38
34
|
opts.separator ""
|
39
35
|
opts.separator "Options:"
|
40
36
|
|
41
37
|
opts.on("-f <file>", "--file <file>", String, "Use a file for input") do |file|
|
42
|
-
options["
|
43
|
-
end
|
44
|
-
|
45
|
-
opts.on("-n [name]", "--name [name]", String, "Name") do |n|
|
46
|
-
options["name"] = n
|
47
|
-
end
|
48
|
-
|
49
|
-
opts.on("-t [tags]", "--tags [tags]", String, "Comma separated") do |tags|
|
50
|
-
options["tags"] = tags
|
51
|
-
end
|
52
|
-
|
53
|
-
opts.on("-d [description]", "--description [description]", String, "Description") do |desc|
|
54
|
-
options["description"] = desc
|
55
|
-
end
|
56
|
-
|
57
|
-
opts.on("-p", "--private", "Private") do |priv|
|
58
|
-
options["adult"] = "t"
|
59
|
-
end
|
60
|
-
|
61
|
-
opts.on("-l", "--link", "Direct link to picture file") do |direct_link|
|
62
|
-
options["direct_link"] = "1"
|
38
|
+
options["image"] = file
|
63
39
|
end
|
64
40
|
|
65
41
|
opts.on_tail("-h", "--help", "Show this message") do
|
@@ -70,12 +46,8 @@ end
|
|
70
46
|
|
71
47
|
opts.parse(ARGV)
|
72
48
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
options.delete("direct_link")
|
79
|
-
ibin = Imagebin.new(options)
|
80
|
-
puts ibin.pic_link
|
81
|
-
end
|
49
|
+
conf = YAML.load_file("#{ENV['HOME']}/.imgur.yaml")
|
50
|
+
options['key'] = conf['key']
|
51
|
+
ibin = Imagebin.new(options)
|
52
|
+
puts ibin.original_image
|
53
|
+
|
data/bin/take-screenshot
CHANGED
@@ -27,10 +27,11 @@ sleep delay
|
|
27
27
|
# Take the screenshot with the 'import' command.
|
28
28
|
system("#{import}", "-window", "root", "#{working_dir}/#{prefix}-#{i}.png")
|
29
29
|
|
30
|
-
|
31
|
-
|
30
|
+
conf = YAML.load_file("#{ENV['HOME']}/.imgur.yaml")
|
31
|
+
ibin = Imagebin.new({ "image" => "#{working_dir}/#{prefix}-#{i}.png",
|
32
|
+
"key" => conf['key'],
|
32
33
|
})
|
33
34
|
|
34
|
-
system("#{xmess}", "-nearmouse", "#{ibin.
|
35
|
+
system("#{xmess}", "-nearmouse", "#{ibin.original_image}")
|
35
36
|
|
36
37
|
File.delete("#{working_dir}/#{prefix}-#{i}.png")
|
data/lib/imagebin.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
#
|
3
|
-
#
|
3
|
+
# imgur.com API
|
4
4
|
#
|
5
5
|
|
6
6
|
require 'rubygems'
|
@@ -8,51 +8,46 @@ require 'httpclient'
|
|
8
8
|
require 'hpricot'
|
9
9
|
|
10
10
|
class Imagebin
|
11
|
-
# This method takes a hash containing the variables in the POST
|
12
|
-
# request.
|
13
|
-
#
|
14
|
-
# ibin = Imagebin.new( { "t" => "file",
|
15
|
-
# "name" => "",
|
16
|
-
# "tags" => "",
|
17
|
-
# "description" => "",
|
18
|
-
# "adult" => "f",
|
19
|
-
# "f" => "file_path",
|
20
|
-
# })
|
21
|
-
#
|
22
11
|
def initialize(options)
|
23
|
-
@options = { "
|
24
|
-
"
|
25
|
-
"tags" => "",
|
26
|
-
"description" => "",
|
27
|
-
"adult" => "f",
|
28
|
-
"direct_link" => "0",
|
29
|
-
"f" => "",
|
12
|
+
@options = { "image" => "file",
|
13
|
+
"key" => "api_key",
|
30
14
|
}
|
31
15
|
@options.merge!(options)
|
32
|
-
File.open(@options["
|
33
|
-
@options["
|
16
|
+
File.open(@options["image"]) do |file|
|
17
|
+
@options["image"] = file
|
34
18
|
clnt = HTTPClient.new
|
35
|
-
res = clnt.post('http://
|
19
|
+
res = clnt.post('http://imgur.com/api/upload.xml', @options).content
|
36
20
|
@doc = Hpricot(res)
|
21
|
+
raise @doc.at('error_msg').innerHTML if @doc.at('error_msg') != nil
|
37
22
|
end
|
38
23
|
end
|
39
24
|
|
40
|
-
|
41
|
-
|
42
|
-
# ibin.site_link #=> "http://imagebin.ca/view/xxxxxxx.html"
|
43
|
-
#
|
44
|
-
def site_link
|
45
|
-
@doc.at("a").innerHTML
|
25
|
+
def image_hash
|
26
|
+
@doc.at('image_hash').innerHTML
|
46
27
|
end
|
47
28
|
|
48
|
-
|
49
|
-
|
50
|
-
# ibin.pic_link #=> "http://imagebin.ca/img/xxxxxxx.jpg"
|
51
|
-
#
|
52
|
-
def pic_link
|
53
|
-
clnt = HTTPClient.new
|
54
|
-
res = clnt.get(@doc.at("a").innerHTML).content
|
55
|
-
doc = Hpricot(res)
|
56
|
-
doc.at("#theimg")["src"]
|
29
|
+
def delete_hash
|
30
|
+
@doc.at('delete_hash').innerHTML
|
57
31
|
end
|
32
|
+
|
33
|
+
def original_image
|
34
|
+
@doc.at("original_image").innerHTML
|
35
|
+
end
|
36
|
+
|
37
|
+
def large_thumbnail
|
38
|
+
@doc.at('large_thumbnail').innerHTML
|
39
|
+
end
|
40
|
+
|
41
|
+
def small_thumbnail
|
42
|
+
@doc.at('small_thumbnail').innerHTML
|
43
|
+
end
|
44
|
+
|
45
|
+
def imgur_page
|
46
|
+
@doc.at('imgur_page').innerHTML
|
47
|
+
end
|
48
|
+
|
49
|
+
def delete_page
|
50
|
+
@doc.at('delete_page').innerHTML
|
51
|
+
end
|
52
|
+
|
58
53
|
end
|
data/spec/imagebin_spec.rb
CHANGED
@@ -2,23 +2,19 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe "Imagebin" do
|
4
4
|
before do
|
5
|
-
options = { "
|
6
|
-
|
7
|
-
"tags" => "",
|
8
|
-
"description" => "",
|
9
|
-
"adult" => "t",
|
10
|
-
"f" => "spec/ZGrass04.jpg",
|
5
|
+
@options = { "image" => "spec/ZGrass04.jpg",
|
6
|
+
"key" => "926e908c545620bd1c44d43edf3a35a0",
|
11
7
|
}
|
12
|
-
@ibin = Imagebin.new(options)
|
13
|
-
end
|
14
|
-
|
15
|
-
it "should return a link to the paste's website" do
|
16
|
-
link = @ibin.site_link
|
17
|
-
link.should match(/html/)
|
18
8
|
end
|
19
9
|
|
20
10
|
it "should return a link to the picture file" do
|
21
|
-
|
11
|
+
ibin = Imagebin.new(@options)
|
12
|
+
link = ibin.original_image
|
22
13
|
link.should match(/jpg/)
|
23
14
|
end
|
15
|
+
|
16
|
+
it "should raise an error" do
|
17
|
+
@options['key'] = ''
|
18
|
+
lambda {Imagebin.new(@options)}.should raise_error(RuntimeError)
|
19
|
+
end
|
24
20
|
end
|
metadata
CHANGED
@@ -1,7 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: imagebin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
hash: 19
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
- 2
|
10
|
+
version: 1.0.2
|
5
11
|
platform: ruby
|
6
12
|
authors:
|
7
13
|
- dougsko
|
@@ -9,40 +15,52 @@ autorequire:
|
|
9
15
|
bindir: bin
|
10
16
|
cert_chain: []
|
11
17
|
|
12
|
-
date:
|
18
|
+
date: 2010-08-09 00:00:00 -04:00
|
13
19
|
default_executable:
|
14
20
|
dependencies:
|
15
21
|
- !ruby/object:Gem::Dependency
|
16
22
|
name: httpclient
|
17
|
-
|
18
|
-
|
19
|
-
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
20
26
|
requirements:
|
21
27
|
- - ">="
|
22
28
|
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
30
|
+
segments:
|
31
|
+
- 0
|
23
32
|
version: "0"
|
24
|
-
|
33
|
+
type: :runtime
|
34
|
+
version_requirements: *id001
|
25
35
|
- !ruby/object:Gem::Dependency
|
26
36
|
name: hpricot
|
27
|
-
|
28
|
-
|
29
|
-
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
30
40
|
requirements:
|
31
41
|
- - ">="
|
32
42
|
- !ruby/object:Gem::Version
|
43
|
+
hash: 3
|
44
|
+
segments:
|
45
|
+
- 0
|
33
46
|
version: "0"
|
34
|
-
|
47
|
+
type: :runtime
|
48
|
+
version_requirements: *id002
|
35
49
|
- !ruby/object:Gem::Dependency
|
36
50
|
name: httpclient
|
37
|
-
|
38
|
-
|
39
|
-
|
51
|
+
prerelease: false
|
52
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
40
54
|
requirements:
|
41
55
|
- - ">="
|
42
56
|
- !ruby/object:Gem::Version
|
57
|
+
hash: 3
|
58
|
+
segments:
|
59
|
+
- 0
|
43
60
|
version: "0"
|
44
|
-
|
45
|
-
|
61
|
+
type: :runtime
|
62
|
+
version_requirements: *id003
|
63
|
+
description: Command line interface to imgur.com
|
46
64
|
email: dougtko@gmail.com
|
47
65
|
executables:
|
48
66
|
- take-screenshot
|
@@ -74,24 +92,30 @@ require_paths:
|
|
74
92
|
- /bin
|
75
93
|
- /lib
|
76
94
|
required_ruby_version: !ruby/object:Gem::Requirement
|
95
|
+
none: false
|
77
96
|
requirements:
|
78
97
|
- - ">="
|
79
98
|
- !ruby/object:Gem::Version
|
99
|
+
hash: 3
|
100
|
+
segments:
|
101
|
+
- 0
|
80
102
|
version: "0"
|
81
|
-
version:
|
82
103
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
104
|
+
none: false
|
83
105
|
requirements:
|
84
106
|
- - ">="
|
85
107
|
- !ruby/object:Gem::Version
|
108
|
+
hash: 3
|
109
|
+
segments:
|
110
|
+
- 0
|
86
111
|
version: "0"
|
87
|
-
version:
|
88
112
|
requirements: []
|
89
113
|
|
90
114
|
rubyforge_project:
|
91
|
-
rubygems_version: 1.3.
|
115
|
+
rubygems_version: 1.3.7
|
92
116
|
signing_key:
|
93
117
|
specification_version: 3
|
94
|
-
summary: Command line interface to
|
118
|
+
summary: Command line interface to imgur.com
|
95
119
|
test_files:
|
96
120
|
- spec/imagebin_spec.rb
|
97
121
|
- spec/spec_helper.rb
|