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 +4 -4
- data/directlink.gemspec +1 -1
- data/lib/directlink.rb +20 -5
- data/test.rb +2 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 691f70bd0cb87dd6ba19a8a70148ce41cb366082
|
4
|
+
data.tar.gz: 84c2af4549db91eda6e08bb8fdd465f6fd451ef1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 62600e89107b2cb3d53c9da8570173f88c389b8d9dde3503ebcafdd4e884fcae8871471aa53f297523683737df288c0127ed1db262e1d64b71ebcd85569fa3e4
|
7
|
+
data.tar.gz: ea9c2f936023361b9389404d30830e106a629ead049a1bcdf9631fe057d0e6c7dae8c73b328775ecb7649dbe780864a50d32bf6545f40b40702db40adf585bf4
|
data/directlink.gemspec
CHANGED
data/lib/directlink.rb
CHANGED
@@ -242,12 +242,27 @@ module DirectLink
|
|
242
242
|
end
|
243
243
|
|
244
244
|
def self.vk link
|
245
|
-
|
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
|
-
|
248
|
-
|
249
|
-
|
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.
|
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-
|
11
|
+
date: 2019-09-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fastimage
|