imgurr 0.2.0 → 1.0.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.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/imgurr.gemspec +2 -2
- data/lib/imgurr.rb +2 -2
- data/lib/imgurr/command.rb +22 -0
- data/lib/imgurr/imgurAPI.rb +4 -4
- data/lib/imgurr/storage.rb +37 -16
- data/test/1-upload.sh +9 -9
- data/test/2-info.sh +9 -5
- data/test/3-delete.sh +3 -3
- data/test/4-misc.sh +9 -0
- data/test/files/habs.png +0 -0
- data/test/files/{imgurr.json → imgurr-old.json} +0 -0
- data/test/run +3 -3
- metadata +6 -6
- data/Gemfile.lock +0 -18
- data/test/files/habs.gif +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 896266ace91ad81bebc3bd35bd2b76c92ee94535
|
4
|
+
data.tar.gz: 87c9c88f338ee26aafe7370ba72b2fa458866850
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 86b3107f8c45e27e4df59bf1927198a7368b6f17c6068ca43c3f37c42cdce88688e7449e2bf0456868110376e7dd7b11017f8725dd2d3c6d2d551577d9ac56ff
|
7
|
+
data.tar.gz: 75f5a0287e0d01ae06655c07b887aa5998960b3b3c4b2d7778d9208be3e1346d778d4a3153644402c792cc05da97ddedc84d5c61f639ba04ffef824c31a2524c
|
data/README.md
CHANGED
@@ -13,13 +13,13 @@ Command line utility for Imgur in Ruby. Imgurr lets you quickly upload images, g
|
|
13
13
|
Uploading screenshot...
|
14
14
|
Copied http://i.imgur.com/rGoGCNb.png to clipboard
|
15
15
|
|
16
|
-
$ imgurr upload image.
|
16
|
+
$ imgurr upload image.gif
|
17
17
|
Copied http://i.imgur.com/PLWGJlc.gif to clipboard
|
18
18
|
|
19
19
|
$ imgurr upload image.jpg --markdown
|
20
20
|
Copied  to clipboard
|
21
21
|
|
22
|
-
imgurr info 2KxrTAK
|
22
|
+
$ imgurr info 2KxrTAK
|
23
23
|
Image ID : 2KxrTAK
|
24
24
|
Views : 14717
|
25
25
|
Bandwidth : 2.296 GiB
|
data/imgurr.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'imgurr'
|
3
|
-
s.version = '0.
|
3
|
+
s.version = '1.0.0'
|
4
4
|
s.summary = "Imgurr lets you upload images to imgur from the command line"
|
5
5
|
s.description = "Imgurr is a ruby gem that lets you upload images to Imgur and manage your account"
|
6
6
|
s.authors = ["Christophe Naud-Dulude"]
|
@@ -23,7 +23,7 @@ Gem::Specification.new do |s|
|
|
23
23
|
|
24
24
|
s.license = 'MIT'
|
25
25
|
|
26
|
-
s.files = %w( README.md LICENSE.md Gemfile
|
26
|
+
s.files = %w( README.md LICENSE.md Gemfile imgurr.gemspec Rakefile)
|
27
27
|
s.files += Dir.glob("lib/**/*")
|
28
28
|
s.files += Dir.glob("bin/**/*")
|
29
29
|
s.files += Dir.glob("test/**/*")
|
data/lib/imgurr.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
|
3
3
|
begin
|
4
|
-
|
4
|
+
require 'rubygems'
|
5
5
|
rescue LoadError
|
6
6
|
end
|
7
7
|
|
@@ -24,7 +24,7 @@ require 'imgurr/imgurErrors'
|
|
24
24
|
require 'imgurr/command'
|
25
25
|
|
26
26
|
module Imgurr
|
27
|
-
VERSION = '0.
|
27
|
+
VERSION = '0.2.0'
|
28
28
|
DEBUG = false
|
29
29
|
|
30
30
|
def self.storage
|
data/lib/imgurr/command.rb
CHANGED
@@ -110,6 +110,8 @@ module Imgurr
|
|
110
110
|
return info(major) if command == 'info' || command == 'i'
|
111
111
|
return delete(major,minor) if command == 'delete' || command == 'd'
|
112
112
|
else
|
113
|
+
return list if command == 'list' || command == 'l'
|
114
|
+
|
113
115
|
puts "Argument required for commmand #{command}."
|
114
116
|
puts "imgurr --help for more information."
|
115
117
|
return
|
@@ -124,6 +126,7 @@ module Imgurr
|
|
124
126
|
puts "File #{major} not found."
|
125
127
|
return
|
126
128
|
end
|
129
|
+
major = File.absolute_path(major)
|
127
130
|
response, success = ImgurAPI.upload(major)
|
128
131
|
puts response unless success
|
129
132
|
if success
|
@@ -160,6 +163,21 @@ module Imgurr
|
|
160
163
|
end
|
161
164
|
end
|
162
165
|
|
166
|
+
# Public: List uploaded images
|
167
|
+
#
|
168
|
+
# Returns nothing
|
169
|
+
def list
|
170
|
+
items = storage.items
|
171
|
+
if items.empty?
|
172
|
+
puts 'No items in the list.'
|
173
|
+
return
|
174
|
+
end
|
175
|
+
|
176
|
+
storage.items.each do |(id, data)|
|
177
|
+
puts "#{id} #{data[:stamp]} #{data[:source].ljust(48)}"
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
163
181
|
# Public: build HTML image tag response
|
164
182
|
#
|
165
183
|
# Returns a properly formatted HTML <img> tag
|
@@ -181,6 +199,7 @@ module Imgurr
|
|
181
199
|
#
|
182
200
|
# Returns nothing
|
183
201
|
def delete(major,minor)
|
202
|
+
major = major.to_sym
|
184
203
|
if minor
|
185
204
|
delete_hash = minor
|
186
205
|
else
|
@@ -194,6 +213,8 @@ module Imgurr
|
|
194
213
|
end
|
195
214
|
if ImgurAPI.delete(delete_hash)
|
196
215
|
puts 'Successfully deleted image from Imgur'
|
216
|
+
storage.delete(major)
|
217
|
+
storage.save
|
197
218
|
else
|
198
219
|
puts 'Unauthorized Access. Wrong delete hash?'
|
199
220
|
end
|
@@ -259,6 +280,7 @@ module Imgurr
|
|
259
280
|
[--tile="Title"] Set image title
|
260
281
|
[--desc="Desc" ] Set image description
|
261
282
|
imgurr capture Capture a screenshot and upload it (OS X only)
|
283
|
+
imgurr list List uploaded images
|
262
284
|
imgurr info <id> Print image information
|
263
285
|
imgurr delete <id> Deletes an image from imgur if the deletehash is found locally
|
264
286
|
imgurr delete <id> <deletehash> Deletes an image from imgur with the provided deletehash
|
data/lib/imgurr/imgurAPI.rb
CHANGED
@@ -51,7 +51,7 @@ module Imgurr
|
|
51
51
|
request.add_field('Authorization', API_PUBLIC_KEY)
|
52
52
|
|
53
53
|
response = web_client.request(request)
|
54
|
-
handle_upload_response(response.body)
|
54
|
+
handle_upload_response(response.body, image_path)
|
55
55
|
end
|
56
56
|
|
57
57
|
# Public: Get info about an image
|
@@ -82,11 +82,11 @@ module Imgurr
|
|
82
82
|
#
|
83
83
|
# args - Response data
|
84
84
|
#
|
85
|
-
def handle_upload_response(response)
|
85
|
+
def handle_upload_response(response, source_path)
|
86
86
|
data = JSON.parse(response)
|
87
87
|
puts JSON.pretty_unparse(data) if Imgurr::DEBUG
|
88
88
|
if data['success']
|
89
|
-
storage.add_hash(data['data']['id'], data['data']['deletehash'])
|
89
|
+
storage.add_hash(data['data']['id'], data['data']['deletehash'], source_path)
|
90
90
|
return [data['data']['link'], true]
|
91
91
|
end
|
92
92
|
[ImgurErrors.handle_error(response), false]
|
@@ -127,4 +127,4 @@ module Imgurr
|
|
127
127
|
|
128
128
|
end
|
129
129
|
end
|
130
|
-
end
|
130
|
+
end
|
data/lib/imgurr/storage.rb
CHANGED
@@ -19,7 +19,7 @@ module Imgurr
|
|
19
19
|
#
|
20
20
|
# Returns the Storage instance.
|
21
21
|
def initialize
|
22
|
-
@hashes =
|
22
|
+
@hashes = Hash.new
|
23
23
|
bootstrap
|
24
24
|
populate
|
25
25
|
end
|
@@ -38,9 +38,8 @@ module Imgurr
|
|
38
38
|
# hash - Delete hash
|
39
39
|
#
|
40
40
|
# Returns nothing
|
41
|
-
def add_hash(id, hash)
|
42
|
-
|
43
|
-
@hashes.push(hash_item)
|
41
|
+
def add_hash(id, hash, source)
|
42
|
+
@hashes[id] = {:deletehash => hash, :source => source, :stamp => Time.now}
|
44
43
|
end
|
45
44
|
|
46
45
|
# Public: test whether out storage contains the delete hash for given id
|
@@ -49,7 +48,7 @@ module Imgurr
|
|
49
48
|
#
|
50
49
|
# Returns true if found, false if not.
|
51
50
|
def hash_exists?(id)
|
52
|
-
@hashes.
|
51
|
+
@hashes.has_key? id
|
53
52
|
end
|
54
53
|
|
55
54
|
# Public: finds any given delete_hash by id.
|
@@ -58,15 +57,22 @@ module Imgurr
|
|
58
57
|
#
|
59
58
|
# Returns the first instance of delete_hash that it finds.
|
60
59
|
def find(id)
|
61
|
-
hash = @hashes
|
62
|
-
hash[:deletehash]
|
60
|
+
hash = @hashes[id]
|
61
|
+
hash ? hash[:deletehash] : nil
|
63
62
|
end
|
64
63
|
|
65
|
-
# Public: all Items in storage.
|
64
|
+
# Public: all Items in storage sorted in chronological order.
|
66
65
|
#
|
67
66
|
# Returns an Array of all Items.
|
68
67
|
def items
|
69
|
-
@hashes.
|
68
|
+
@hashes.to_a.sort {|(_, a), (_, b)| a[:stamp] <=> b[:stamp] }
|
69
|
+
end
|
70
|
+
|
71
|
+
# Public: delete an Item entry from storage.
|
72
|
+
#
|
73
|
+
# Returns the deleted Item or nil.
|
74
|
+
def delete(id)
|
75
|
+
@hashes.delete(id)
|
70
76
|
end
|
71
77
|
|
72
78
|
# Public: creates a Hash of the representation of the in-memory data
|
@@ -75,7 +81,7 @@ module Imgurr
|
|
75
81
|
#
|
76
82
|
# Returns a Hash of the entire data set.
|
77
83
|
def to_hash
|
78
|
-
{
|
84
|
+
{:hashes => @hashes}
|
79
85
|
end
|
80
86
|
|
81
87
|
# Takes care of bootstrapping the Json file, both in terms of creating the
|
@@ -92,14 +98,15 @@ module Imgurr
|
|
92
98
|
# Take a JSON representation of data and explode it out into the constituent
|
93
99
|
# Lists and Items for the given Storage instance.
|
94
100
|
#
|
95
|
-
# Returns
|
101
|
+
# Returns all hashes.
|
96
102
|
def populate
|
97
103
|
file = File.read(json_file)
|
98
|
-
storage = JSON.parse(file)
|
104
|
+
storage = JSON.parse(file, :symbolize_names => true)
|
105
|
+
|
106
|
+
@hashes = storage[:hashes]
|
107
|
+
convert if @hashes.is_a? Array
|
99
108
|
|
100
|
-
|
101
|
-
add_hash(hashes['id'], hashes['deletehash'])
|
102
|
-
end
|
109
|
+
@hashes
|
103
110
|
end
|
104
111
|
|
105
112
|
# Public: persists your in-memory objects to disk in Json format.
|
@@ -118,5 +125,19 @@ module Imgurr
|
|
118
125
|
def to_json
|
119
126
|
JSON.pretty_generate(to_hash)
|
120
127
|
end
|
128
|
+
|
129
|
+
private
|
130
|
+
# Private: convert from old Json representation, filling in the missing data.
|
131
|
+
# Also print a warning message for the user.
|
132
|
+
#
|
133
|
+
# Returns nothing.
|
134
|
+
def convert
|
135
|
+
old = @hashes
|
136
|
+
@hashes = Hash.new
|
137
|
+
|
138
|
+
puts 'Warning: old JSON format detected, converting.'
|
139
|
+
old.each {|i| add_hash(i[:id], i[:deletehash], 'unknown') }
|
140
|
+
save
|
141
|
+
end
|
121
142
|
end
|
122
|
-
end
|
143
|
+
end
|
data/test/1-upload.sh
CHANGED
@@ -1,30 +1,30 @@
|
|
1
1
|
#!/usr/bin/env roundup
|
2
2
|
export IMGURRFILE=test/files/imgurr.json
|
3
3
|
imgurr="./bin/imgurr"
|
4
|
-
image="test/files/habs.
|
4
|
+
image="test/files/habs.png"
|
5
5
|
id_file="test/id"
|
6
6
|
|
7
7
|
describe "upload"
|
8
8
|
|
9
9
|
it_uploads_image() {
|
10
|
-
${imgurr} upload ${image}
|
11
|
-
|
12
|
-
chmod 777 ${id_file}
|
10
|
+
${imgurr} upload ${image} >> test/temp
|
11
|
+
sed 's/.*imgur.com\/\(.*\)\..*/\1/' test/temp > ${id_file}
|
13
12
|
rm test/temp
|
13
|
+
expr `cat ${id_file} | wc -c` ">" 0
|
14
14
|
}
|
15
15
|
|
16
16
|
it_uploads_image_with_markdown() {
|
17
|
-
${imgurr} upload ${image} --markdown | grep "Copied !\[Screenshot\](http://i.imgur.com"
|
17
|
+
${imgurr} upload ${image} --markdown | grep -m 1 "Copied !\[Screenshot\](http://i.imgur.com"
|
18
18
|
}
|
19
19
|
|
20
20
|
it_uploads_image_with_html() {
|
21
|
-
${imgurr} upload ${image} --html | grep "Copied <img src=\"http://i.imgur.com/.*\" alt=\"Screenshot\">"
|
21
|
+
${imgurr} upload ${image} --html | grep -m 1 "Copied <img src=\"http://i.imgur.com/.*\" alt=\"Screenshot\">"
|
22
22
|
}
|
23
23
|
|
24
24
|
it_uploads_image_with_html_and_size() {
|
25
|
-
${imgurr} upload ${image} --html --size 45 | grep "Copied <img src=\"http://i.imgur.com/.*\" alt=\"Screenshot\" width=\"45%\">"
|
25
|
+
${imgurr} upload ${image} --html --size 45 | grep -m 1 "Copied <img src=\"http://i.imgur.com/.*\" alt=\"Screenshot\" width=\"45%\">"
|
26
26
|
}
|
27
27
|
|
28
28
|
it_uploads_image_with_title_desc() {
|
29
|
-
${imgurr} upload ${image} --title "Test" --desc "Test" | grep "Copied http://i.imgur.com"
|
30
|
-
}
|
29
|
+
${imgurr} upload ${image} --title "Test" --desc "Test" | grep -m 1 "Copied http://i.imgur.com"
|
30
|
+
}
|
data/test/2-info.sh
CHANGED
@@ -6,17 +6,21 @@ id_file="test/id"
|
|
6
6
|
describe "info"
|
7
7
|
|
8
8
|
it_gets_image_info() {
|
9
|
-
${imgurr} info `cat ${id_file}` | grep "Width :
|
9
|
+
${imgurr} info `cat ${id_file}` | grep -m 1 "Width : 48 px"
|
10
10
|
}
|
11
11
|
|
12
12
|
it_gets_image_info_from_url() {
|
13
|
-
${imgurr} info http://i.imgur.com/2KxrTAK.jpg | grep "Width : 960 px"
|
13
|
+
${imgurr} info http://i.imgur.com/2KxrTAK.jpg | grep -m 1 "Width : 960 px"
|
14
14
|
}
|
15
15
|
|
16
16
|
it_gets_image_info_from_url_with_title() {
|
17
|
-
${imgurr} info http://i.imgur.com/Wk1iPej.jpg | grep "Title : Imgurr Test"
|
17
|
+
${imgurr} info http://i.imgur.com/Wk1iPej.jpg | grep -m 1 "Title : Imgurr Test"
|
18
18
|
}
|
19
19
|
|
20
20
|
it_gets_image_info_from_url_with_description() {
|
21
|
-
${imgurr} info http://i.imgur.com/Wk1iPej.jpg | grep "Desc : Imgurr Test"
|
22
|
-
}
|
21
|
+
${imgurr} info http://i.imgur.com/Wk1iPej.jpg | grep -m 1 "Desc : Imgurr Test"
|
22
|
+
}
|
23
|
+
|
24
|
+
it_lists_uploaded_images() {
|
25
|
+
${imgurr} list | grep -m 1 `cat ${id_file}`
|
26
|
+
}
|
data/test/3-delete.sh
CHANGED
@@ -6,9 +6,9 @@ id_file="test/id"
|
|
6
6
|
describe "delete"
|
7
7
|
|
8
8
|
it_shows_error_wrong_hash() {
|
9
|
-
${imgurr} delete `cat ${id_file}` random | grep "Unauthorized Access"
|
9
|
+
${imgurr} delete `cat ${id_file}` random | grep -m 1 "Unauthorized Access"
|
10
10
|
}
|
11
11
|
|
12
12
|
it_deletes_from_storage() {
|
13
|
-
${imgurr} delete `cat ${id_file}` | grep "Successfully deleted"
|
14
|
-
}
|
13
|
+
${imgurr} delete `cat ${id_file}` | grep -m 1 "Successfully deleted"
|
14
|
+
}
|
data/test/4-misc.sh
ADDED
data/test/files/habs.png
ADDED
Binary file
|
File without changes
|
data/test/run
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: imgurr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Christophe Naud-Dulude
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-01-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|
@@ -49,7 +49,6 @@ extra_rdoc_files:
|
|
49
49
|
- LICENSE.md
|
50
50
|
files:
|
51
51
|
- Gemfile
|
52
|
-
- Gemfile.lock
|
53
52
|
- LICENSE.md
|
54
53
|
- README.md
|
55
54
|
- Rakefile
|
@@ -66,11 +65,12 @@ files:
|
|
66
65
|
- test/1-upload.sh
|
67
66
|
- test/2-info.sh
|
68
67
|
- test/3-delete.sh
|
68
|
+
- test/4-misc.sh
|
69
69
|
- test/cli.sh
|
70
70
|
- test/error.sh
|
71
71
|
- test/files/github-logo.png
|
72
|
-
- test/files/habs.
|
73
|
-
- test/files/imgurr.json
|
72
|
+
- test/files/habs.png
|
73
|
+
- test/files/imgurr-old.json
|
74
74
|
- test/roundup
|
75
75
|
- test/run
|
76
76
|
homepage: https://github.com/Chris911/imgurr
|
@@ -94,7 +94,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
94
94
|
version: '0'
|
95
95
|
requirements: []
|
96
96
|
rubyforge_project:
|
97
|
-
rubygems_version: 2.
|
97
|
+
rubygems_version: 2.2.2
|
98
98
|
signing_key:
|
99
99
|
specification_version: 4
|
100
100
|
summary: Imgurr lets you upload images to imgur from the command line
|
data/Gemfile.lock
DELETED
data/test/files/habs.gif
DELETED
Binary file
|