imgurr 0.0.4 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -1
- data/README.md +6 -1
- data/Rakefile +25 -0
- data/imgurr.gemspec +3 -3
- data/lib/imgurr.rb +6 -1
- data/lib/imgurr/command.rb +87 -10
- data/lib/imgurr/imgurAPI.rb +11 -2
- data/test/1-upload.sh +8 -0
- data/test/2-info.sh +12 -0
- data/test/cli.sh +1 -1
- data/test/error.sh +14 -0
- data/test/run +3 -1
- metadata +4 -2
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -13,6 +13,9 @@ Imgurr lets you quickly upload images, get info about an image and delete your o
|
|
13
13
|
imgurr upload image.jpg
|
14
14
|
Copied http://i.imgur.com/PLWGJlc.gif to clipboard
|
15
15
|
|
16
|
+
imgurr upload image.jpg --markdown
|
17
|
+
Copied ![Screenshot](http://i.imgur.com/PLWGJlc.gif) to clipboard
|
18
|
+
|
16
19
|
imgurr info 2KxrTAK
|
17
20
|
Image ID : 2KxrTAK
|
18
21
|
Views : 14717
|
@@ -24,8 +27,10 @@ Imgurr lets you quickly upload images, get info about an image and delete your o
|
|
24
27
|
Height : 540 px
|
25
28
|
Link : http://i.imgur.com/2KxrTAK.jpg
|
26
29
|
|
27
|
-
imgurr delete 2KxrTAK
|
30
|
+
imgurr delete http://i.imgur.com/2KxrTAK.jpg
|
28
31
|
Successfully deleted image from Imgur
|
29
32
|
|
33
|
+
./imgurr --help for more.
|
34
|
+
|
30
35
|
## How it works
|
31
36
|
Imgurr stores the delete hash generated by Imgur locally when uploading an image using imgurr. Most of the time the delete hash gets lost if you don't have an account and you want to takedown an image you have to contact Imgur support which can take a while. With imgurr all your delete hashes are saved so you can delete your images later if needed.
|
data/Rakefile
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
require 'date'
|
4
|
+
|
5
|
+
def name
|
6
|
+
@name ||= Dir['*.gemspec'].first.split('.').first
|
7
|
+
end
|
8
|
+
|
9
|
+
#############################################################################
|
10
|
+
#
|
11
|
+
# Tests
|
12
|
+
#
|
13
|
+
#############################################################################
|
14
|
+
|
15
|
+
task :default => :test
|
16
|
+
|
17
|
+
desc "Run tests for #{name}"
|
18
|
+
task :test do
|
19
|
+
exec "test/run"
|
20
|
+
end
|
21
|
+
|
22
|
+
desc "Open an irb session preloaded with this library"
|
23
|
+
task :console do
|
24
|
+
sh "irb -rubygems -r ./lib/#{name}.rb"
|
25
|
+
end
|
data/imgurr.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'imgurr'
|
3
|
-
s.version = '0.0
|
4
|
-
s.date = '2013-04-
|
3
|
+
s.version = '0.1.0'
|
4
|
+
s.date = '2013-04-17'
|
5
5
|
s.summary = "Imgurr lets you upload images to imgur from the command line"
|
6
6
|
s.description = "Imgurr is a ruby gem that lets you upload images to Imgur and manage your account"
|
7
7
|
s.authors = ["Christophe Naud-Dulude"]
|
@@ -24,7 +24,7 @@ Gem::Specification.new do |s|
|
|
24
24
|
|
25
25
|
s.license = 'MIT'
|
26
26
|
|
27
|
-
s.files = %w( README.md LICENSE.md Gemfile Gemfile.lock imgurr.gemspec )
|
27
|
+
s.files = %w( README.md LICENSE.md Gemfile Gemfile.lock imgurr.gemspec Rakefile)
|
28
28
|
s.files += Dir.glob("lib/**/*")
|
29
29
|
s.files += Dir.glob("bin/**/*")
|
30
30
|
s.files += Dir.glob("test/**/*")
|
data/lib/imgurr.rb
CHANGED
@@ -10,6 +10,7 @@ require 'net/http'
|
|
10
10
|
require 'net/https'
|
11
11
|
require 'open-uri'
|
12
12
|
require 'json'
|
13
|
+
require 'optparse'
|
13
14
|
|
14
15
|
$:.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
|
15
16
|
|
@@ -23,10 +24,14 @@ require 'imgurr/imgurErrors'
|
|
23
24
|
require 'imgurr/command'
|
24
25
|
|
25
26
|
module Imgurr
|
26
|
-
VERSION = '0.0
|
27
|
+
VERSION = '0.1.0'
|
27
28
|
DEBUG = false
|
28
29
|
|
29
30
|
def self.storage
|
30
31
|
@storage ||= Storage.new
|
31
32
|
end
|
33
|
+
|
34
|
+
def self.options
|
35
|
+
@options ||= {}
|
36
|
+
end
|
32
37
|
end
|
data/lib/imgurr/command.rb
CHANGED
@@ -10,6 +10,7 @@
|
|
10
10
|
module Imgurr
|
11
11
|
class Command
|
12
12
|
class << self
|
13
|
+
|
13
14
|
#include Imgurr::Color
|
14
15
|
|
15
16
|
# Public: executes a command.
|
@@ -22,9 +23,45 @@ module Imgurr
|
|
22
23
|
minor = args.empty? ? nil : args.join(' ')
|
23
24
|
|
24
25
|
return help unless command
|
26
|
+
parse_options
|
25
27
|
delegate(command, major, minor)
|
26
28
|
end
|
27
29
|
|
30
|
+
# Public: Parse extra options
|
31
|
+
#
|
32
|
+
# returns nothing
|
33
|
+
def parse_options
|
34
|
+
options[:markdown] = false
|
35
|
+
o = OptionParser.new do |opts|
|
36
|
+
opts.on('-m', '--markdown', 'Use Markdown Syntax') do
|
37
|
+
options[:markdown] = true
|
38
|
+
end
|
39
|
+
opts.on('-t', '--title TITLE', 'Image Title') do |value|
|
40
|
+
options[:title] = value
|
41
|
+
end
|
42
|
+
opts.on('-d', '--desc DESC', 'Image Title') do |value|
|
43
|
+
options[:desc] = value
|
44
|
+
end
|
45
|
+
opts.on('-v', '--version', 'Print Version') do
|
46
|
+
version
|
47
|
+
quit
|
48
|
+
end
|
49
|
+
opts.on('-h', '--help', 'Print Help') do
|
50
|
+
help
|
51
|
+
quit
|
52
|
+
end
|
53
|
+
end
|
54
|
+
begin
|
55
|
+
o.parse!
|
56
|
+
rescue OptionParser::MissingArgument => e
|
57
|
+
puts "Error: #{e.message}"
|
58
|
+
quit
|
59
|
+
rescue OptionParser::InvalidOption => e
|
60
|
+
puts "Error: #{e.message}"
|
61
|
+
quit
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
28
65
|
# Public: gets $stdin.
|
29
66
|
#
|
30
67
|
# Returns the $stdin object. This method exists to help with easy mocking
|
@@ -40,6 +77,13 @@ module Imgurr
|
|
40
77
|
Imgurr.storage
|
41
78
|
end
|
42
79
|
|
80
|
+
# Public: accesses the global options
|
81
|
+
#
|
82
|
+
# Returns Options dictionary
|
83
|
+
def options
|
84
|
+
Imgurr.options
|
85
|
+
end
|
86
|
+
|
43
87
|
# Public: allows main access to most commands.
|
44
88
|
#
|
45
89
|
# Returns output based on method calls.
|
@@ -47,13 +91,22 @@ module Imgurr
|
|
47
91
|
return help unless command
|
48
92
|
return no_internet unless self.internet_connection?
|
49
93
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
return upload(major) if command == 'upload' || command == 'up' || command == 'u'
|
54
|
-
return info(major) if command == 'info' || command == 'i'
|
55
|
-
return delete(major,minor) if command == 'delete' || command == 'd'
|
94
|
+
# Get image ID from URL
|
95
|
+
if major
|
96
|
+
return upload(major) if command == 'upload' || command == 'up' || command == 'u'
|
56
97
|
|
98
|
+
if major =~ /.*imgur\.com\/[a-zA-Z0-9]*\.[a-zA-Z]*/
|
99
|
+
major = /com\/[a-zA-Z0-9]*/.match(major).to_s.gsub('com/','')
|
100
|
+
end
|
101
|
+
|
102
|
+
return unless valid_id major
|
103
|
+
return info(major) if command == 'info' || command == 'i'
|
104
|
+
return delete(major,minor) if command == 'delete' || command == 'd'
|
105
|
+
else
|
106
|
+
puts "Argument required for commmand #{command}."
|
107
|
+
puts "imgurr --help for more information."
|
108
|
+
return
|
109
|
+
end
|
57
110
|
end
|
58
111
|
|
59
112
|
# Public: Upload an image to Imgur
|
@@ -66,7 +119,10 @@ module Imgurr
|
|
66
119
|
end
|
67
120
|
response = ImgurAPI.upload(major)
|
68
121
|
puts response if response.start_with?('Imgur Error')
|
69
|
-
|
122
|
+
if response.start_with?('http')
|
123
|
+
response = "![#{options[:title].nil? ? 'Screenshot' : options[:title]}](#{response})" if options[:markdown]
|
124
|
+
puts "Copied #{Platform.copy(response)} to clipboard"
|
125
|
+
end
|
70
126
|
storage.save
|
71
127
|
end
|
72
128
|
|
@@ -122,7 +178,25 @@ module Imgurr
|
|
122
178
|
#
|
123
179
|
# Returns nothing
|
124
180
|
def no_internet
|
125
|
-
puts
|
181
|
+
puts 'An Internet connection is required to use this command.'
|
182
|
+
end
|
183
|
+
|
184
|
+
# Public: Quit / Exit program
|
185
|
+
#
|
186
|
+
# Returns nothing
|
187
|
+
def quit
|
188
|
+
exit(1)
|
189
|
+
end
|
190
|
+
|
191
|
+
# Public: Validate id (major)
|
192
|
+
#
|
193
|
+
# Returns true if valid id
|
194
|
+
def valid_id(major)
|
195
|
+
unless major =~ /^[a-zA-Z0-9]*$/
|
196
|
+
puts "#{major} is not a valid imgur ID or URL"
|
197
|
+
return false
|
198
|
+
end
|
199
|
+
return true
|
126
200
|
end
|
127
201
|
|
128
202
|
# Public: prints all the commands of boom.
|
@@ -132,10 +206,13 @@ module Imgurr
|
|
132
206
|
text = '
|
133
207
|
- imgurr: help ---------------------------------------------------
|
134
208
|
|
135
|
-
imgurr help
|
136
|
-
imgurr version
|
209
|
+
imgurr --help This help text
|
210
|
+
imgurr --version Print current version
|
137
211
|
|
138
212
|
imgurr upload <image> Upload image and copy link to clipboard
|
213
|
+
imgurr upload <image> [-m|--markdown ] Upload image and copy link to clipboard with markdown syntax
|
214
|
+
[--tile="Title"] Set image title
|
215
|
+
[--desc="Desc" ] Set image description
|
139
216
|
imgurr info <id> Print image information
|
140
217
|
imgurr delete <id> Deletes an image from imgur if the deletehash is found locally
|
141
218
|
imgurr delete <id> <deletehash> Deletes an image from imgur with the provided deletehash
|
data/lib/imgurr/imgurAPI.rb
CHANGED
@@ -22,6 +22,13 @@ module Imgurr
|
|
22
22
|
Imgurr.storage
|
23
23
|
end
|
24
24
|
|
25
|
+
# Public: accesses the global options
|
26
|
+
#
|
27
|
+
# Returns Options dictionary
|
28
|
+
def options
|
29
|
+
Imgurr.options
|
30
|
+
end
|
31
|
+
|
25
32
|
# HTTP Client used for API requests
|
26
33
|
# TODO: Confirm SSL Certificate
|
27
34
|
def web_client
|
@@ -37,6 +44,8 @@ module Imgurr
|
|
37
44
|
#
|
38
45
|
def upload(image_path)
|
39
46
|
params = {:image => File.read(image_path)}
|
47
|
+
params[:title] = options[:title] unless options[:title].nil?
|
48
|
+
params[:description] = options[:desc] unless options[:desc].nil?
|
40
49
|
request = Net::HTTP::Post.new(API_URI.request_uri + ENDPOINTS[:image])
|
41
50
|
request.set_form_data(params)
|
42
51
|
request.add_field('Authorization', API_PUBLIC_KEY)
|
@@ -95,8 +104,8 @@ module Imgurr
|
|
95
104
|
Image ID : #{data['data']['id']}
|
96
105
|
Views : #{data['data']['views']}
|
97
106
|
Bandwidth : #{Numbers.to_human(data['data']['bandwidth'])}
|
98
|
-
Title : #{'None'
|
99
|
-
Desc : #{'None'
|
107
|
+
Title : #{data['data']['title'].nil? ? 'None' : data['data']['title']}
|
108
|
+
Desc : #{data['data']['description'].nil? ? 'None' : data['data']['description']}
|
100
109
|
Animated : #{data['data']['animated']}
|
101
110
|
Width : #{data['data']['width']} px
|
102
111
|
Height : #{data['data']['height']} px
|
data/test/1-upload.sh
CHANGED
@@ -12,3 +12,11 @@ it_uploads_image() {
|
|
12
12
|
chmod 777 ${id_file}
|
13
13
|
rm test/temp
|
14
14
|
}
|
15
|
+
|
16
|
+
it_uploads_image_with_markdown() {
|
17
|
+
${imgurr} upload ${image} --markdown | grep "Copied !\[Screenshot\](http://i.imgur.com"
|
18
|
+
}
|
19
|
+
|
20
|
+
it_uploads_image_with_title_desc() {
|
21
|
+
${imgurr} upload ${image} --title "Test" --desc "Test" | grep "Copied http://i.imgur.com"
|
22
|
+
}
|
data/test/2-info.sh
CHANGED
@@ -8,3 +8,15 @@ describe "info"
|
|
8
8
|
it_gets_image_info() {
|
9
9
|
${imgurr} info `cat ${id_file}` | grep "Width : 96 px"
|
10
10
|
}
|
11
|
+
|
12
|
+
it_gets_image_info_from_url() {
|
13
|
+
${imgurr} info http://i.imgur.com/2KxrTAK.jpg | grep "Width : 960 px"
|
14
|
+
}
|
15
|
+
|
16
|
+
it_gets_image_info_from_url_with_title() {
|
17
|
+
${imgurr} info http://i.imgur.com/Wk1iPej.jpg | grep "Title : Imgurr Test"
|
18
|
+
}
|
19
|
+
|
20
|
+
it_gets_image_info_from_url_with_description() {
|
21
|
+
${imgurr} info http://i.imgur.com/Wk1iPej.jpg | grep "Desc : Imgurr Test"
|
22
|
+
}
|
data/test/cli.sh
CHANGED
data/test/error.sh
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env roundup
|
2
|
+
export IMGURRFILE=test/files/imgurr.json
|
3
|
+
imgurr="./bin/imgurr"
|
4
|
+
image="test/files/habs.gif"
|
5
|
+
|
6
|
+
describe "errors"
|
7
|
+
|
8
|
+
it_shows_missing_arg_error() {
|
9
|
+
${imgurr} upload ${image} --title | grep "Error: missing argument"
|
10
|
+
}
|
11
|
+
|
12
|
+
it_shows_invalid_option_error() {
|
13
|
+
${imgurr} upload ${image} --unknown | grep "Error: invalid option"
|
14
|
+
}
|
data/test/run
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: imgurr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-04-
|
12
|
+
date: 2013-04-17 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: json
|
@@ -58,6 +58,7 @@ files:
|
|
58
58
|
- Gemfile
|
59
59
|
- Gemfile.lock
|
60
60
|
- imgurr.gemspec
|
61
|
+
- Rakefile
|
61
62
|
- bin/imgurr
|
62
63
|
- lib/imgurr/color.rb
|
63
64
|
- lib/imgurr/command.rb
|
@@ -71,6 +72,7 @@ files:
|
|
71
72
|
- test/2-info.sh
|
72
73
|
- test/3-delete.sh
|
73
74
|
- test/cli.sh
|
75
|
+
- test/error.sh
|
74
76
|
- test/files/github-logo.png
|
75
77
|
- test/files/habs.gif
|
76
78
|
- test/files/imgurr.json
|