directlink 0.0.8.1 → 0.0.8.2

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: a692b5ff0cc96ba9acd3383150c2db6df97cf061
4
- data.tar.gz: ce9ee5b9edc2aafcf717ab4b3574695914a6ce9d
3
+ metadata.gz: 691f70bd0cb87dd6ba19a8a70148ce41cb366082
4
+ data.tar.gz: 84c2af4549db91eda6e08bb8fdd465f6fd451ef1
5
5
  SHA512:
6
- metadata.gz: 965bf3f132fce53ea31ddefea4dab9c901c66d6ffc33a0f2dfe6635847750323481ad34517ee2a03118d128c3aef77f66062021bf538be32e7586cb3050dbc25
7
- data.tar.gz: 37d541655fdb921623fe5acb88eefe35db2d7a3c637dc56231b0fb8159ff9ccc75362c8abbbbcc4a0e26c6949b5ce84b027915765f0b8b20c1b5ca2f9a529f99
6
+ metadata.gz: 62600e89107b2cb3d53c9da8570173f88c389b8d9dde3503ebcafdd4e884fcae8871471aa53f297523683737df288c0127ed1db262e1d64b71ebcd85569fa3e4
7
+ data.tar.gz: ea9c2f936023361b9389404d30830e106a629ead049a1bcdf9631fe057d0e6c7dae8c73b328775ecb7649dbe780864a50d32bf6545f40b40702db40adf585bf4
data/directlink.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "directlink"
3
- spec.version = "0.0.8.1"
3
+ spec.version = "0.0.8.2"
4
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"
data/lib/directlink.rb CHANGED
@@ -242,12 +242,27 @@ module DirectLink
242
242
  end
243
243
 
244
244
  def self.vk link
245
- raise ErrorBadLink.new link unless %r{\Ahttps://vk\.com/id(?<user_id>\d+)\?z=photo(?<id>\k<user_id>_\d+)(%2Falbum\k<user_id>_0)?\z} =~ link
245
+ id, mtd, field, f = case link
246
+ when %r{\Ahttps://vk\.com/id(?<user_id>\d+)\?z=photo(?<id>\k<user_id>_\d+)(%2Falbum\k<user_id>_0)?\z}
247
+ [$2, :photos, :photos, lambda do |t|
248
+ raise ErrorAssert.new "our knowledge about VK API seems to be outdated" unless 1 == t.size
249
+ t.first
250
+ end ]
251
+ when %r{\Ahttps://vk\.com/wall(?<id>-\d+_\d+)\z}
252
+ [$1, :wall, :posts, lambda do |t|
253
+ t.first.fetch("attachments").tap do |t|
254
+ raise ErrorAssert.new "our knowledge about VK API seems to be outdated" unless 1 == t.size
255
+ end.first.tap do |t|
256
+ raise ErrorAssert.new "our knowledge about VK API seems to be outdated" unless %w{ type photo } == t.keys
257
+ end.fetch("photo")
258
+ end ]
259
+ else
260
+ raise ErrorBadLink.new link
261
+ end
246
262
  raise ErrorMissingEnvVar.new "define VK_ACCESS_TOKEN and VK_CLIENT_SECRET env vars" unless ENV["VK_ACCESS_TOKEN"] && ENV["VK_CLIENT_SECRET"]
247
- json = JSON.load NetHTTPUtils.request_data "https://api.vk.com/method/photos.getById", :POST, form: { photos: id, access_token: ENV["VK_ACCESS_TOKEN"], client_secret: ENV["VK_CLIENT_SECRET"], v: "5.101" }
248
- json.fetch("response").tap do |r|
249
- raise ErrorAssert.new unless 1 == r.size
250
- end.first.fetch("sizes").map do |s|
263
+ f.call( JSON.load( NetHTTPUtils.request_data "https://api.vk.com/method/#{mtd}.getById",
264
+ :POST, form: { field => id, :access_token => ENV["VK_ACCESS_TOKEN"], :client_secret => ENV["VK_CLIENT_SECRET"], :v => "5.101" }
265
+ ).fetch("response") ).fetch("sizes").map do |s|
251
266
  s.values_at "width", "height", "url"
252
267
  end.max_by{ |w, h, u| w * h }
253
268
  end
data/test.rb CHANGED
@@ -397,6 +397,7 @@ describe DirectLink do
397
397
  [ :vk, [
398
398
  ["https://vk.com/id57030827?z=photo57030827_456241143", [1920, 1440, "https://sun9-66.userapi.com/c845322/v845322944/167836/bP9z41BybhI.jpg"]],
399
399
  ["https://vk.com/id57030827?z=photo57030827_456241143%2Falbum57030827_0", [1920, 1440, "https://sun9-66.userapi.com/c845322/v845322944/167836/bP9z41BybhI.jpg"]],
400
+ ["https://vk.com/wall-105984091_7806", [960, 1280, "https://sun9-41.userapi.com/c855224/v855224900/a72f1/7OZ8ux9Wcwo.jpg"]],
400
401
  ] ],
401
402
  ].each do |method, tests|
402
403
  describe method do
@@ -451,6 +452,7 @@ describe DirectLink do
451
452
  ],
452
453
  vk: [
453
454
  "https://vk.com/id57030827?z=photo57030827_456241143",
455
+ "https://vk.com/wall-105984091_7806",
454
456
  ],
455
457
  }.each do |method, tests|
456
458
  describe "DirectLink() calls #{method}" do
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.8.1
4
+ version: 0.0.8.2
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: 2019-09-23 00:00:00.000000000 Z
11
+ date: 2019-09-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fastimage