directlink 0.0.0.0 → 0.0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: eb0c1733a9087846c343a6b85d07175868e481a3
4
- data.tar.gz: fc43c2e7124eab4b2780d0664251e8dfcbbf520a
3
+ metadata.gz: b84cfbbffd90e381fcb0c89da7a19cb921f07d2f
4
+ data.tar.gz: ef309c38ae87c91ac47c6899480e61fd3308a19d
5
5
  SHA512:
6
- metadata.gz: ae8974d44eca18e9c1718e9b5b2ab723ad522afec45e7bf7c96730acaeb6cb09c858d8c4d85645c51629e9d43b8b5752bfdf4edd9b33a5adb81f5add10fe33c4
7
- data.tar.gz: 9367fb91716eecc451ecba7111d8c876f95a3e3d989964ab34c3137e1c2d1321813e2c98e4c879c72a95ae56ee41cc178d85dd66b9cdf237ddedf412ee74dfe2
6
+ metadata.gz: d480c7dcdd89f711f218d0f77569d8bd894701847277449139355984601544863bb807f2ca6b5e97e1a11e9697b15081f1a2632459fa9187c58e7f06925949fe
7
+ data.tar.gz: 01237acfa5cd070fd8afe98d3b1dc655c2dec3f3ed0cc5fde99aea4bcade98dfc2a874a04086f1b05910ca234a28acf82638557db7a5146e9f373c00bb2149f3
data/README.md CHANGED
@@ -1,35 +1,55 @@
1
1
  [![Build Status](https://travis-ci.org/Nakilon/directlink.png?)](https://travis-ci.org/Nakilon/directlink)
2
2
  ![Gem Version](https://badge.fury.io/rb/directlink.png?)
3
3
 
4
- ## Usage:
4
+ ## Usage
5
+
6
+ ### As binary
7
+
5
8
  ```
9
+ $ gem install directlink
6
10
  $ directlink
7
11
  usage: directlink [--debug] [--json] <link1> <link2> <link3> ...
8
12
  ```
13
+ When known image hosting that has handy API is recognized, the API will be used and you'll have to create app there and provide env vars:
14
+ ```
15
+ $ export IMGUR_CLIENT_ID=0f99cd781...
16
+ $ export FLICKR_API_KEY=dc2bfd348b...
17
+ $ export _500PX_CONSUMER_KEY=ESkHT...
18
+ ```
9
19
  Converts `<img src=` attribute value from any Google web service to its high resolution version:
10
20
  ```
11
21
  $ directlink //4.bp.blogspot.com/-5kP8ndL0kuM/Wpt82UCqvmI/AAAAAAAAEjI/ZbbZWs0-kgwRXEJ9JEGioR0bm6U8MOkvQCKgBGAs/w530-h278-p/IMG_20171223_093922.jpg
12
- https://4.bp.blogspot.com/-5kP8ndL0kuM/Wpt82UCqvmI/AAAAAAAAEjI/ZbbZWs0-kgwRXEJ9JEGioR0bm6U8MOkvQCKgBGAs/s0/IMG_20171223_093922.jpg
13
- jpeg 4160x3120
22
+ <= //4.bp.blogspot.com/-5kP8ndL0kuM/Wpt82UCqvmI/AAAAAAAAEjI/ZbbZWs0-kgwRXEJ9JEGioR0bm6U8MOkvQCKgBGAs/w530-h278-p/IMG_20171223_093922.jpg
23
+ => https://4.bp.blogspot.com/-5kP8ndL0kuM/Wpt82UCqvmI/AAAAAAAAEjI/ZbbZWs0-kgwRXEJ9JEGioR0bm6U8MOkvQCKgBGAs/s0/IMG_20171223_093922.jpg
24
+ jpeg 4160x3120
14
25
  ```
15
26
  Retrieves all images from Imgur album or gallery, orders them by resolution from high to low:
16
27
  ```
17
28
  $ directlink https://imgur.com/a/oacI3gl
18
- https://i.imgur.com/QpOBvRY.png
19
- image/png 460x460
20
- https://i.imgur.com/9j4KdkJ.png
21
- image/png 100x100
29
+ <= https://imgur.com/a/oacI3gl
30
+ => https://i.imgur.com/QpOBvRY.png
31
+ image/png 460x460
32
+ => https://i.imgur.com/9j4KdkJ.png
33
+ image/png 100x100
34
+ ```
35
+ Follows redirects:
36
+ ```
37
+ $ directlink https://goo.gl/ySqUb5
38
+ <= https://goo.gl/ySqUb5
39
+ => https://i.imgur.com/QpOBvRY.png
40
+ image/png 460x460
22
41
  ```
23
42
  Accepts multiple input links:
24
43
  ```
25
- $ directlink https://imgur.com/a/oacI3gl https://avatars1.githubusercontent.com/u/2870363?100
26
- https://i.imgur.com/QpOBvRY.png
27
- image/png 460x460
28
- https://i.imgur.com/9j4KdkJ.png
29
- image/png 100x100
30
-
31
- https://avatars1.githubusercontent.com/u/2870363?100
32
- jpeg 460x460
44
+ $ directlink https://imgur.com/a/oacI3gl https://goo.gl/ySqUb5
45
+ <= https://imgur.com/a/oacI3gl
46
+ => https://i.imgur.com/QpOBvRY.png
47
+ image/png 460x460
48
+ => https://i.imgur.com/9j4KdkJ.png
49
+ image/png 100x100
50
+ <= https://goo.gl/ySqUb5
51
+ => https://i.imgur.com/QpOBvRY.png
52
+ image/png 460x460
33
53
  ```
34
54
  Emits JSON:
35
55
  ```
@@ -58,14 +78,63 @@ $ directlink --json https://imgur.com/a/oacI3gl https://avatars1.githubuserconte
58
78
  ]
59
79
  ```
60
80
 
81
+ ### As library
82
+
83
+ ```
84
+ irb> require "directlink"
85
+ irb> require "pp"
86
+
87
+ irb> pp DirectLink "https://imgur.com/a/oacI3gl"
88
+ [#<struct
89
+ url="https://i.imgur.com/QpOBvRY.png",
90
+ width=460,
91
+ height=460,
92
+ type="image/png">,
93
+ #<struct
94
+ url="https://i.imgur.com/9j4KdkJ.png",
95
+ width=100,
96
+ height=100,
97
+ type="image/png">]
98
+
99
+ irb> pp DirectLink "//4.bp.blogspot.com/-5kP8ndL0kuM/Wpt82UCqvmI/AAAAAAAAEjI/ZbbZWs0-kgwRXEJ9JEGioR0bm6U8MOkvQCKgBGAs/w530-h278-p/IMG_20171223_093922.jpg"
100
+ #<struct
101
+ url=
102
+ "https://4.bp.blogspot.com/-5kP8ndL0kuM/Wpt82UCqvmI/AAAAAAAAEjI/ZbbZWs0-kgwRXEJ9JEGioR0bm6U8MOkvQCKgBGAs/s0/IMG_20171223_093922.jpg",
103
+ width=4160,
104
+ height=3120,
105
+ type=:jpeg>
106
+ ```
107
+ Google can serve image in arbitrary resolution so `DirectLink.google` has optional argument to specify the width:
108
+ ```
109
+ irb> DirectLink.google "//4.bp.blogspot.com/-5kP8ndL0kuM/Wpt82UCqvmI/AAAAAAAAEjI/ZbbZWs0-kgwRXEJ9JEGioR0bm6U8MOkvQCKgBGAs/w530-h278-p/IMG_20171223_093922.jpg", 100
110
+ => "https://4.bp.blogspot.com/-5kP8ndL0kuM/Wpt82UCqvmI/AAAAAAAAEjI/ZbbZWs0-kgwRXEJ9JEGioR0bm6U8MOkvQCKgBGAs/s100/IMG_20171223_093922.jpg"
111
+ ```
112
+ To silent the logger that `DirectLink.imgur` uses:
113
+ ```ruby
114
+ DirectLink.silent = true
115
+ ```
116
+
117
+ #### about slow retries
118
+
119
+ Some network exceptions like `SocketError` may be not permanent (local network issues) so `NetHTTPUtils` (that resolves redirect at the beginning of `DirectLink()` call) by default retries exponentially increasing retry delay until it gets to 3600sec, but such exceptions can have permanent for reasons like canceled web domain. To see it:
120
+ ```ruby
121
+ NetHTTPUtils.logger.level = Logger::WARN
122
+ ```
123
+ ```
124
+ W 180507 102210 : NetHTTPUtils : retrying in 10 seconds because of SocketError 'Failed to open TCP connection to minus.com:80 (getaddrinfo: nodename nor servname provided, or not known)' at: http://minus.com/
125
+ ```
126
+ To make `DirectLink()` respond faster pass an optional argument that specifies the max retry delay as any numeric value. Here we get the exception immediately:
127
+ ```ruby
128
+ DirectLink "http://minus.com/", 0
129
+ ```
130
+ ```
131
+ SocketError: Failed to open TCP connection to minus.com:80 (getaddrinfo: nodename nor servname provided, or not known) to http://minus.com/
132
+ ```
133
+
61
134
  ## Notes:
62
- * use `DirectLink.silent = true` to supress the logger -- it is used only by `DirectLink::Imgur` yet
63
- * methods inside `DirectLink` by design return different sets of properties -- DirectLink unites them
64
- * methods may have arguments (`width=` in `google`) so they are public for external usage
65
- * this gem is a 2 or 3 libraries united so don't expect tests to be full and consistent
66
- * when known image hosting is recognized, the API will be used and you'll have to provide env vars:
67
- `IMGUR_CLIENT_ID` or `FLICKR_API_KEY` or `_500PX_CONSUMER_KEY`
135
+
136
+ * `module DirectLink` public methods return different sets of properties -- `DirectLink()` unites them
68
137
  * the `DirectLink::ErrorAssert` should never happen and you might report it if it does
69
138
  * style: `@@` and lambdas are used to keep things private
70
139
  * style: all exceptions should be classified as `DirectLink::Error*` or `FastImage::*`
71
- * we don't pass user input to `NetHTTPUtils` -- we contribute to gem FastImage and expect it to raise
140
+ * this gem is a 2 or 3 libraries united so don't expect tests to be full and consistent
data/bin/directlink CHANGED
@@ -36,15 +36,17 @@ begin
36
36
  end
37
37
  puts JSON.pretty_generate t.size == 1 ? t.first : t
38
38
  else
39
- puts( ARGV.map do |link|
39
+ ARGV.each do |link|
40
40
  t = DirectLink link
41
- (t.is_a?(Array) ? t : [t]).map{ |s| "#{s.url}\n#{s.type} #{s.width}x#{s.height}" }.join("\n")
42
- end.join "\n\n" )
41
+ puts "<= #{link}"
42
+ (t.is_a?(Array) ? t : [t]).each{ |s| puts "=> #{s.url}\n #{s.type} #{s.width}x#{s.height}" }
43
+ end
43
44
  end
44
- rescue FastImage::UnknownImageType,
45
+ rescue NetHTTPUtils::Error,
46
+ FastImage::UnknownImageType,
45
47
  FastImage::ImageFetchFailure,
46
48
  DirectLink::ErrorMissingEnvVar,
47
- DirectLink::ErrorAssert,
49
+ # DirectLink::ErrorAssert,
48
50
  DirectLink::ErrorNotFound,
49
51
  DirectLink::ErrorBadLink => e
50
52
  puts e.backtrace if debug
data/directlink.gemspec CHANGED
@@ -1,14 +1,14 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "directlink"
3
- spec.version = "0.0.0.0"
4
- spec.summary = "converts image page URL to direct link, dimensions and image type"
3
+ spec.version = "0.0.1.0"
4
+ spec.summary = "converts any kind of image hyperlink to direct link, type of image and its resolution"
5
5
 
6
6
  spec.author = "Victor Maslov aka Nakilon"
7
7
  spec.email = "nakilon@gmail.com"
8
8
  spec.license = "MIT"
9
9
  spec.homepage = "https://github.com/nakilon/directlink"
10
10
 
11
- spec.add_dependency "nethttputils", "~>0.2.0.0"
11
+ spec.add_dependency "nethttputils", "~>0.2.2.0"
12
12
  spec.add_dependency "fastimage", "~>2.1.3"
13
13
  spec.add_development_dependency "minitest"
14
14
 
data/lib/directlink.rb CHANGED
@@ -49,6 +49,7 @@ module DirectLink
49
49
 
50
50
  require "json"
51
51
  require "nethttputils"
52
+ NetHTTPUtils.logger.level = Logger::FATAL
52
53
 
53
54
  def self.imgur link
54
55
  raise ErrorMissingEnvVar.new "define IMGUR_CLIENT_ID env var" unless ENV["IMGUR_CLIENT_ID"]
@@ -85,7 +86,7 @@ module DirectLink
85
86
  # one day single-video item should hit this but somehow it didn't yet
86
87
  raise ErrorAssert.new "unknown data format #{data.inspect} for #{link}"
87
88
  end
88
- when /\Ahttps?:\/\/(?:(?:i|m|www)\.)?imgur\.com\/([a-zA-Z0-9]{7})(?:\.(?:gifv|jpg))?\z/,
89
+ when /\Ahttps?:\/\/(?:(?:i|m|www)\.)?imgur\.com\/([a-zA-Z0-9]{7})(?:\.(?:gifv|jpg|png))?\z/,
89
90
  /\Ahttps?:\/\/(?:(?:i|m|www)\.)?imgur\.com\/([a-zA-Z0-9]{5})\.mp4\z/,
90
91
  /\Ahttps?:\/\/imgur\.com\/([a-zA-Z0-9]{5}(?:[a-zA-Z0-9]{2})?)\z/,
91
92
  /\Ahttps?:\/\/imgur\.com\/([a-zA-Z0-9]{7})(?:\?\S+)?\z/,
@@ -162,7 +163,7 @@ end
162
163
 
163
164
  require "fastimage"
164
165
 
165
- def DirectLink link
166
+ def DirectLink link, max_redirect_resolving_retry_delay = nil
166
167
  begin
167
168
  URI link
168
169
  rescue URI::InvalidURIError
@@ -172,7 +173,6 @@ def DirectLink link
172
173
 
173
174
  struct = Module.const_get(__callee__).class_variable_get :@@directlink
174
175
 
175
-
176
176
  if %w{ lh3 googleusercontent com } == URI(link).host.split(?.).last(3) ||
177
177
  %w{ bp blogspot com } == URI(link).host.split(?.).last(3)
178
178
  u = DirectLink.google link
@@ -181,6 +181,21 @@ def DirectLink link
181
181
  return struct.new u, w, h, f.type
182
182
  end
183
183
 
184
+ # to test that we won't hang for too long if someone like aeronautica.difesa.it will be silent for some reason:
185
+ # $ bundle console
186
+ # > NetHTTPUtils.logger.level = Logger::DEBUG
187
+ # > NetHTTPUtils.request_data "http://www.aeronautica.difesa.it/organizzazione/REPARTI/divolo/PublishingImages/6%C2%B0%20Stormo/2013-decollo%20al%20tramonto%20REX%201280.jpg",
188
+ # max_read_retry_delay: 5, timeout: 5
189
+ r = NetHTTPUtils.get_response link, header: {"User-Agent" => "Mozilla"}, **(max_redirect_resolving_retry_delay ? {
190
+ max_timeout_retry_delay: max_redirect_resolving_retry_delay,
191
+ max_sslerror_retry_delay: max_redirect_resolving_retry_delay,
192
+ max_read_retry_delay: max_redirect_resolving_retry_delay,
193
+ max_econnrefused_retry_delay: max_redirect_resolving_retry_delay,
194
+ max_socketerror_retry_delay: max_redirect_resolving_retry_delay,
195
+ } : {})
196
+ raise NetHTTPUtils::Error.new "", r.code.to_i unless "200" == r.code
197
+ link = r.uri.to_s
198
+
184
199
  if %w{ imgur com } == URI(link).host.split(?.).last(2) ||
185
200
  %w{ i imgur com } == URI(link).host.split(?.).last(3) ||
186
201
  %w{ m imgur com } == URI(link).host.split(?.).last(3) ||
@@ -197,8 +212,7 @@ def DirectLink link
197
212
  return struct.new u, w, h, t
198
213
  end
199
214
 
200
- if %w{ www flickr com } == URI(link).host.split(?.).last(3) ||
201
- %w{ flic kr } == URI(link).host.split(?.).last(2)
215
+ if %w{ www flickr com } == URI(link).host.split(?.).last(3)
202
216
  w, h, u = DirectLink.flickr(link)
203
217
  f = FastImage.new(u, raise_on_failure: true, http_header: {"User-Agent" => "Mozilla"})
204
218
  return struct.new u, w, h, f.type
data/test.rb CHANGED
@@ -3,6 +3,9 @@ STDOUT.sync = true
3
3
  require "minitest/autorun"
4
4
  require "minitest/mock"
5
5
 
6
+ # TODO: I'm not sure it's ok that after we started using NetHTTPUtils for redirect resolving
7
+ # we don't raise `FastImage::ImageFetchFailure` anymore in any test
8
+
6
9
  require_relative "lib/directlink"
7
10
  DirectLink.silent = true
8
11
  describe DirectLink do
@@ -104,6 +107,7 @@ describe DirectLink do
104
107
  ["https://imgur.com/3eThW", "https://i.imgur.com/3eThW.jpg", 2560, 1600, "image/jpeg"],
105
108
  ["https://i.imgur.com/RGO6i.mp4", "https://i.imgur.com/RGO6i.gif", 339, 397, "image/gif"],
106
109
  ["https://imgur.com/a/oacI3gl", 2, "https://i.imgur.com/9j4KdkJ.png", "https://i.imgur.com/QpOBvRY.png"],
110
+ ["https://i.imgur.com/QpOBvRY.png", "https://i.imgur.com/QpOBvRY.png", 460, 460, "image/png"],
107
111
  # some other tests not sure we need them
108
112
  ["http://i.imgur.com/7xcxxkR.gifv", "http://i.imgur.com/7xcxxkRh.gif"],
109
113
  ["http://imgur.com/HQHBBBD", "https://i.imgur.com/HQHBBBD.jpg", 1024, 768, "image/jpeg"],
@@ -191,6 +195,7 @@ describe DirectLink do
191
195
  https://i.imgur.com/3eThW
192
196
  https://m.imgur.com/3eThW
193
197
  https://www.imgur.com/3eThW
198
+ https://goo.gl/ySqUb5
194
199
  },
195
200
  _500px: %w{
196
201
  https://500px.com/photo/112134597/milky-way-by-tom-hall
@@ -243,7 +248,7 @@ describe DirectLink do
243
248
  [
244
249
  [:google, "//lh3.googleusercontent.com/proxy/DZtTi5KL7PqiBwJc8weNGLk_Wi2UTaQH0AC_h2kuURiu0AbwyI2ywOk2XgdAjL7ceg=w530-h354-n"],
245
250
  [:imgur, "http://imgur.com/HQHBBBD"],
246
- [:flickr, "https://www.flickr.com/photos/tomas-/17220613278/"],
251
+ [:flickr, "https://www.flickr.com/photos/44133687@N00/17380073505/"],
247
252
  [:_500px, "https://500px.com/photo/112134597/milky-way-by-tom-hall"],
248
253
  [:wiki, "http://commons.wikimedia.org/wiki/File:Eduard_Bohlen_anagoria.jpg"],
249
254
  ].each do |method, link|
@@ -256,8 +261,8 @@ describe DirectLink do
256
261
  assert_equal "\"test\" -- if you think this link is valid, please report the issue", e.message
257
262
  end
258
263
  end
259
- it "raises FastImage::ImageFetchFailure on Net::HTTP failure" do
260
- assert_raises FastImage::ImageFetchFailure do
264
+ it "raises SocketError from the redirect resolving stage" do
265
+ assert_raises SocketError do
261
266
  NetHTTPUtils.stub :get_response, ->*{ raise SocketError.new } do
262
267
  DirectLink "http://example.com/404"
263
268
  end
@@ -268,21 +273,25 @@ describe DirectLink do
268
273
  describe "some other tests" do
269
274
  [
270
275
  ["http://www.aeronautica.difesa.it/organizzazione/REPARTI/divolo/PublishingImages/6%C2%B0%20Stormo/2013-decollo%20al%20tramonto%20REX%201280.jpg", ["http://www.aeronautica.difesa.it/organizzazione/REPARTI/divolo/PublishingImages/6%C2%B0%20Stormo/2013-decollo%20al%20tramonto%20REX%201280.jpg", 1280, 853, :jpeg]],
271
- ["http://example.com", FastImage::UnknownImageType], # was URL2Dimensions::ErrorUnknown
272
- ["http://minus.com/lkP3hgRJd9npi", FastImage::ImageFetchFailure], # was URL2Dimensions::Error404
273
- ["https://i.redd.it/si758zk7r5xz.jpg", FastImage::ImageFetchFailure], # was URL2Dimensions::Error404
274
- ["http://www.cutehalloweencostumeideas.org/wp-content/uploads/2017/10/Niagara-Falls_04.jpg", FastImage::ImageFetchFailure], # was URL2Dimensions::Error404
275
- ].each_with_index do |(input, expectation), i|
276
+ ["http://example.com", FastImage::UnknownImageType, "FastImage::UnknownImageType"], # we explicitly expect this useless `e.message ` to be sure we know how FastImage behaves
277
+ ["http://minus.com/lkP3hgRJd9npi", SocketError, /nodename nor servname provided, or not known|No address associated with hostname/, 0],
278
+ ["https://i.redd.it/si758zk7r5xz.jpg", NetHTTPUtils::Error, "HTTP error #404 "],
279
+ ["http://www.cutehalloweencostumeideas.org/wp-content/uploads/2017/10/Niagara-Falls_04.jpg", SocketError, /nodename nor servname provided, or not known|Name or service not known/, 0],
280
+ ].each_with_index do |(input, expectation, message_string_or_regex, max_redirect_resolving_retry_delay), i|
276
281
  it "##{i + 1}" do
277
282
  if expectation.is_a? Class
278
- assert_raises expectation do
279
- DirectLink input
283
+ e = assert_raises expectation, "for #{input}" do
284
+ DirectLink input, max_redirect_resolving_retry_delay
285
+ end
286
+ if message_string_or_regex.is_a? String
287
+ assert_equal message_string_or_regex, e.message, "for #{input}"
288
+ else
289
+ assert_match message_string_or_regex, e.message, "for #{input}"
280
290
  end
281
291
  else
282
292
  u, w, h, t = expectation
283
- result = DirectLink input
284
- assert_equal DirectLink.class_variable_get(:@@directlink).new(u, w, h, t),
285
- result, "#{input} :: #{result.inspect} != #{expectation.inspect}"
293
+ result = DirectLink input, max_redirect_resolving_retry_delay
294
+ assert_equal DirectLink.class_variable_get(:@@directlink).new(u, w, h, t), result, "for #{input}"
286
295
  end
287
296
  end
288
297
  end
@@ -316,35 +325,37 @@ describe DirectLink do
316
325
  describe "fails" do
317
326
  [
318
327
  [1, "http://example.com/", "FastImage::UnknownImageType"], # TODO: is it possible to obtain it from `.cause`?
319
- [1, "http://example.com/404", "FastImage::ImageFetchFailure"],
328
+ [1, "http://example.com/404", "NetHTTPUtils::Error: HTTP error #404 "],
320
329
  [1, "http://imgur.com/HQHBBBD", "DirectLink::ErrorMissingEnvVar: define IMGUR_CLIENT_ID env var", " && unset IMGUR_CLIENT_ID"], # TODO: make similar test for ./lib
321
330
  # by design it should be impossible to write a test for DirectLink::ErrorAssert
322
- [1, "https://flic.kr/p/DirectLinkErrorNotFound", "DirectLink::ErrorNotFound: \"https://flic.kr/p/DirectLinkErrorNotFound\""],
323
- [1, "https://imgur.com/a/badlinkpattern", "DirectLink::ErrorBadLink: \"https://imgur.com/a/badlinkpattern\" -- if you think this link is valid, please report the issue"],
331
+ [1, "https://flic.kr/p/DirectLinkErrorNotFound", "NetHTTPUtils::Error: HTTP error #404 "],
332
+ [1, "https://imgur.com/a/badlinkpattern", "NetHTTPUtils::Error: HTTP error #404 "],
324
333
  ].each_with_index do |(expected_exit_code, link, expected_output, unset), i|
325
334
  it "##{i + 1}" do
326
335
  string, status = Open3.capture2e "export #{File.read("api_tokens_for_travis.sh").gsub(/\n?export/, ?\s).strip}#{unset} && ruby -Ilib bin/directlink #{link}"
327
- assert_equal [expected_exit_code, "#{expected_output}\n"], [status.exitstatus, string]
336
+ assert_equal [expected_exit_code, "#{expected_output}\n"], [status.exitstatus, string], "for #{link}"
328
337
  end
329
338
  end
330
339
  end
331
340
 
332
- valid_imgur_image_urls = "https://avatars1.githubusercontent.com/u/2870363?100 https://imgur.com/a/oacI3gl"
341
+ valid_imgur_image_url1 = "https://goo.gl/ySqUb5"
342
+ valid_imgur_image_url2 = "https://imgur.com/a/oacI3gl"
333
343
  [
334
- ['https://avatars1.githubusercontent.com/u/2870363?100
335
- jpeg 460x460
336
-
337
- https://i.imgur.com/QpOBvRY.png
338
- image/png 460x460
339
- https://i.imgur.com/9j4KdkJ.png
340
- image/png 100x100
341
- '.gsub(/^ {8}/, "")],
344
+ ["<= #{valid_imgur_image_url1}
345
+ => https://i.imgur.com/QpOBvRY.png
346
+ image/png 460x460
347
+ <= #{valid_imgur_image_url2}
348
+ => https://i.imgur.com/QpOBvRY.png
349
+ image/png 460x460
350
+ => https://i.imgur.com/9j4KdkJ.png
351
+ image/png 100x100
352
+ ".gsub(/^ {8}/, "")],
342
353
  ['[
343
354
  {
344
- "url": "https://avatars1.githubusercontent.com/u/2870363?100",
355
+ "url": "https://i.imgur.com/QpOBvRY.png",
345
356
  "width": 460,
346
357
  "height": 460,
347
- "type": "jpeg"
358
+ "type": "image/png"
348
359
  },
349
360
  [
350
361
  {
@@ -364,7 +375,7 @@ describe DirectLink do
364
375
  '.gsub(/^ {8}/, ""), "json"],
365
376
  ].each do |expected_output, param|
366
377
  it "#{param || "default"} succeeds" do
367
- string, status = Open3.capture2e "export #{File.read("api_tokens_for_travis.sh").gsub(/\n?export/, ?\s).strip} && ruby -Ilib bin/directlink#{" --#{param}" if param} #{valid_imgur_image_urls}"
378
+ string, status = Open3.capture2e "export #{File.read("api_tokens_for_travis.sh").gsub(/\n?export/, ?\s).strip} && ruby -Ilib bin/directlink#{" --#{param}" if param} #{valid_imgur_image_url1} #{valid_imgur_image_url2}"
368
379
  assert_equal [0, expected_output], [status.exitstatus, string]
369
380
  end
370
381
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: directlink
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0.0
4
+ version: 0.0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Victor Maslov aka Nakilon
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-05-06 00:00:00.000000000 Z
11
+ date: 2018-05-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nethttputils
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.2.0.0
19
+ version: 0.2.2.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 0.2.0.0
26
+ version: 0.2.2.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: fastimage
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -95,6 +95,7 @@ rubyforge_project:
95
95
  rubygems_version: 2.5.2
96
96
  signing_key:
97
97
  specification_version: 4
98
- summary: converts image page URL to direct link, dimensions and image type
98
+ summary: converts any kind of image hyperlink to direct link, type of image and its
99
+ resolution
99
100
  test_files:
100
101
  - test.rb