dougsko-imagebin 0.2.3 → 0.3.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.
- data/Rakefile +7 -0
- data/VERSION.yml +2 -2
- data/bin/imagebin +13 -5
- data/lib/imagebin.rb +37 -2
- data/spec/ZGrass04.jpg +0 -0
- data/spec/imagebin_spec.rb +20 -3
- metadata +3 -2
data/Rakefile
CHANGED
@@ -23,18 +23,21 @@ require 'spec/rake/spectask'
|
|
23
23
|
Spec::Rake::SpecTask.new(:spec) do |spec|
|
24
24
|
spec.libs << 'lib' << 'spec'
|
25
25
|
spec.spec_files = FileList['spec/**/*_spec.rb']
|
26
|
+
spec.spec_opts = ['--color']
|
26
27
|
end
|
27
28
|
|
28
29
|
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
29
30
|
spec.libs << 'lib' << 'spec'
|
30
31
|
spec.pattern = 'spec/**/*_spec.rb'
|
31
32
|
spec.rcov = true
|
33
|
+
spec.spec_opts = ['--color']
|
32
34
|
end
|
33
35
|
|
34
36
|
|
35
37
|
task :default => :spec
|
36
38
|
|
37
39
|
require 'rake/rdoctask'
|
40
|
+
require 'darkfish-rdoc'
|
38
41
|
Rake::RDocTask.new do |rdoc|
|
39
42
|
if File.exist?('VERSION.yml')
|
40
43
|
config = YAML.load(File.read('VERSION.yml'))
|
@@ -47,5 +50,9 @@ Rake::RDocTask.new do |rdoc|
|
|
47
50
|
rdoc.title = "imagebin #{version}"
|
48
51
|
rdoc.rdoc_files.include('README*')
|
49
52
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
53
|
+
rdoc.options += [
|
54
|
+
'-N',
|
55
|
+
'-f', 'darkfish',
|
56
|
+
]
|
50
57
|
end
|
51
58
|
|
data/VERSION.yml
CHANGED
data/bin/imagebin
CHANGED
@@ -28,6 +28,7 @@ options = { "t" => "file",
|
|
28
28
|
"tags" => "",
|
29
29
|
"description" => "",
|
30
30
|
"adult" => "f",
|
31
|
+
"direct_link" => "0",
|
31
32
|
}
|
32
33
|
|
33
34
|
opts = OptionParser.new do |opts|
|
@@ -57,6 +58,10 @@ opts = OptionParser.new do |opts|
|
|
57
58
|
options["adult"] = "t"
|
58
59
|
end
|
59
60
|
|
61
|
+
opts.on("-l", "--link", "Direct link to picture file") do |direct_link|
|
62
|
+
options["direct_link"] = "1"
|
63
|
+
end
|
64
|
+
|
60
65
|
opts.on_tail("-h", "--help", "Show this message") do
|
61
66
|
puts opts
|
62
67
|
exit
|
@@ -65,9 +70,12 @@ end
|
|
65
70
|
|
66
71
|
opts.parse(ARGV)
|
67
72
|
|
68
|
-
|
69
|
-
options
|
70
|
-
Imagebin.new(options)
|
71
|
-
|
72
|
-
|
73
|
+
if options["direct_link"] == "0"
|
74
|
+
options.delete("direct_link")
|
75
|
+
ibin = Imagebin.new(options)
|
76
|
+
puts ibin.site_link
|
77
|
+
elsif options["direct_link"] == "1"
|
78
|
+
options.delete("direct_link")
|
79
|
+
ibin = Imagebin.new(options)
|
80
|
+
puts ibin.pic_link
|
73
81
|
end
|
data/lib/imagebin.rb
CHANGED
@@ -5,10 +5,45 @@
|
|
5
5
|
|
6
6
|
require 'rubygems'
|
7
7
|
require 'httpclient'
|
8
|
+
require 'hpricot'
|
8
9
|
|
9
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
|
+
#
|
10
22
|
def initialize(options)
|
11
|
-
|
12
|
-
|
23
|
+
File.open(options["f"]) do |file|
|
24
|
+
options["f"] = file
|
25
|
+
clnt = HTTPClient.new
|
26
|
+
res = clnt.post('http://imagebin.ca/upload.php', options).content
|
27
|
+
@doc = Hpricot(res)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
# Returns the link to the HTML site of the post.
|
32
|
+
#
|
33
|
+
# ibin.site_link #=> "http://imagebin.ca/view/xxxxxxx.html"
|
34
|
+
#
|
35
|
+
def site_link
|
36
|
+
@doc.at("a").innerHTML
|
37
|
+
end
|
38
|
+
|
39
|
+
# Returns the direct link to the dile posted.
|
40
|
+
#
|
41
|
+
# ibin.pic_link #=> "http://imagebin.ca/img/xxxxxxx.jpg"
|
42
|
+
#
|
43
|
+
def pic_link
|
44
|
+
clnt = HTTPClient.new
|
45
|
+
res = clnt.get(@doc.at("a").innerHTML).content
|
46
|
+
doc = Hpricot(res)
|
47
|
+
doc.at("#theimg")["src"]
|
13
48
|
end
|
14
49
|
end
|
data/spec/ZGrass04.jpg
ADDED
Binary file
|
data/spec/imagebin_spec.rb
CHANGED
@@ -1,7 +1,24 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe "Imagebin" do
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
before do
|
5
|
+
options = { "t" => "file",
|
6
|
+
"name" => "",
|
7
|
+
"tags" => "",
|
8
|
+
"description" => "",
|
9
|
+
"adult" => "t",
|
10
|
+
"f" => "spec/ZGrass04.jpg",
|
11
|
+
}
|
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
|
+
end
|
19
|
+
|
20
|
+
it "should return a link to the picture file" do
|
21
|
+
link = @ibin.pic_link
|
22
|
+
link.should match(/jpg/)
|
23
|
+
end
|
7
24
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dougsko-imagebin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- dougsko
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-09-11 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -40,6 +40,7 @@ files:
|
|
40
40
|
- bin/imagebin
|
41
41
|
- bin/takeScreenshot.sh
|
42
42
|
- lib/imagebin.rb
|
43
|
+
- spec/ZGrass04.jpg
|
43
44
|
- spec/imagebin_spec.rb
|
44
45
|
- spec/spec_helper.rb
|
45
46
|
has_rdoc: false
|