imgur2 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +6 -0
- data/lib/imgur2.rb +22 -1
- metadata +4 -4
data/CHANGELOG.rdoc
CHANGED
data/lib/imgur2.rb
CHANGED
@@ -9,12 +9,13 @@ require 'json'
|
|
9
9
|
# client.upload f
|
10
10
|
# }
|
11
11
|
class Imgur2 < Struct.new(:key)
|
12
|
-
VERSION = '1.
|
12
|
+
VERSION = '1.1.0'
|
13
13
|
|
14
14
|
def self.run argv
|
15
15
|
client = Imgur2.new '65aea9a07b4f6110c90248ffa247d41a'
|
16
16
|
fh = argv[0] ? File.open(argv[0], 'rb') : $stdin
|
17
17
|
link = client.upload(fh)['upload']['links']['original']
|
18
|
+
link = client.follow_redirect link
|
18
19
|
client.paste link
|
19
20
|
puts link
|
20
21
|
ensure
|
@@ -33,6 +34,26 @@ class Imgur2 < Struct.new(:key)
|
|
33
34
|
}
|
34
35
|
end
|
35
36
|
|
37
|
+
def follow_redirect url
|
38
|
+
follower = lambda do |uri, depth|
|
39
|
+
raise "too many redirects" if depth > 3
|
40
|
+
|
41
|
+
parsed = URI.parse uri
|
42
|
+
resp = Net::HTTP.start(parsed.host) { |http|
|
43
|
+
head = Net::HTTP::Head.new parsed.path
|
44
|
+
http.request head
|
45
|
+
}
|
46
|
+
|
47
|
+
if Net::HTTPRedirection === resp
|
48
|
+
follower.call resp['Location'], depth + 1
|
49
|
+
else
|
50
|
+
uri
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
follower.call url, 0
|
55
|
+
end
|
56
|
+
|
36
57
|
##
|
37
58
|
# Tries to find clipboard copy executable and if found puts +link+ in your
|
38
59
|
# clipboard.
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: imgur2
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,12 +9,12 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-03-
|
12
|
+
date: 2011-03-16 00:00:00.000000000 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: hoe
|
17
|
-
requirement: &
|
17
|
+
requirement: &2160778600 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ! '>='
|
@@ -22,7 +22,7 @@ dependencies:
|
|
22
22
|
version: 2.9.1
|
23
23
|
type: :development
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *2160778600
|
26
26
|
description: Upload stuff to imgur. Yay.
|
27
27
|
email:
|
28
28
|
- aaron@tenderlovemaking.com
|