directlink 0.0.8.8 → 0.0.11.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +0,0 @@
1
- :client_id: SLdfneWbqS6hVw
2
- :client_secret: xNbSyCQrvZrtcN2OfG8sujXH-vw
3
- :password: nakilontravispublicforimgur@gmail.com
4
- :login: nakilontravispublicf
data/test.rb DELETED
@@ -1,827 +0,0 @@
1
- STDOUT.sync = true
2
- require "pp"
3
-
4
- require "minitest/autorun"
5
- require "minitest/mock"
6
-
7
- # TODO: I'm not sure it's ok that after we started using NetHTTPUtils for redirect resolving
8
- # we don't raise `FastImage::ImageFetchFailure` anymore in any test
9
-
10
- fail unless ENV.include? "IMGUR_CLIENT_ID"
11
- fail unless ENV.include? "FLICKR_API_KEY"
12
- fail unless ENV.include? "REDDIT_SECRETS"
13
-
14
- require_relative "lib/directlink"
15
- DirectLink.silent = true
16
- describe DirectLink do
17
-
18
- describe "./lib" do
19
-
20
- describe "google" do
21
-
22
- describe "does not fail" do
23
- # TODO: also check the #google is being called
24
-
25
- "
26
- 1 //1.bp.blogspot.com/-rYk_u-qROQc/WngolJ8M0LI/AAAAAAAAD-w/woivnaIVzasBPG5C2T1t-VrWKRd_U6lMgCLcBGAs/w530-h278-p/i-469.jpg
27
- 2 //4.bp.blogspot.com/-1RlHbRShONs/Wngp9WfxbfI/AAAAAAAAD-8/vnBBXpSZdvUMz4VjJPBpprLBrJ5QpBaqACLcBGAs/w530-h278-p/i-468.jpg
28
- 3 //4.bp.blogspot.com/-5kP8ndL0kuM/Wpt82UCqvmI/AAAAAAAAEjI/ZbbZWs0-kgwRXEJ9JEGioR0bm6U8MOkvQCKgBGAs/w530-h278-p/IMG_20171223_093922.jpg
29
- 4 //4.bp.blogspot.com/-bS1SZxFkvek/Wnjz3D5Il4I/AAAAAAAAD_I/bKYvRLGB7r4NGJ0aR1F-ugsbVm4HUjf5ACLcBGAs/w530-h278-p/i-466.jpg
30
- 5 //lh3.googleusercontent.com/-1CF2jge1MYI/Wmr_kfCQQUI/AAAAAAAClKs/N1F2tz4v0q0i5N7rgso6G8SrhJNzsHEagCJoC/w530-h352-p/2809525%2B%25D0%2593%25D0%2590%25D0%259B%25D0%259E%2B%25D0%259F%25D0%2590%25D0%25A0%25D0%2593%25D0%2595%25D0%259B%25D0%2598%25D0%2599%2B-%2B%25D0%25A7%25D0%25A3%25D0%259A%25D0%259E%25D0%25A2%25D0%259A%25D0%2590%2B-%2B%25D0%25AE%25D0%25A0%25D0%2598%25D0%2599%2B%25D0%25A5%25D0%2590%25D0%25A0%25D0%25A7%25D0%2595%25D0%259D%25D0%259A%25D0%259E.jpg
31
- 6 //lh3.googleusercontent.com/-h1siEcRFqJ8/Wiv1iDQhNVI/AAAAAAAAQV4/9gGepSmYkDMLyVTG_1EBCMmj-UhmclXWwCJoC/w530-h353-p/001
32
- 7 //lh3.googleusercontent.com/-qnZygRb-Tn8/Wlyj4UuKbaI/AAAAAAAATqE/iKWSto-XBZwsh843xJ3cSd0JPt1LedU9gCJoC/w530-h330-p/001
33
- 8 //lh3.googleusercontent.com/-rXO9PzbjNmk/WlNfjJkJBmI/AAAAAAAATNY/4dHLtYtWBzUKWufNXWkK82etw3RKA6jVgCJoC/w530-h361-p/001
34
-
35
- 13 //lh3.googleusercontent.com/proxy/2fsWfEOeeCMNEP8MGvHiJPkBlg47Ifaf8DwpgDPJSPSYsh9iomTrfOA9OuwB60laZimtNr4-1GKA5J2csuVB6-1DLNO30K-fngB8p56ivICWRFAUuOwzizaztBx5gQ=w530-h707-p
36
- 14 //lh3.googleusercontent.com/proxy/2qy3gOwhBT77Ie_qa9VgGz6kgN14tnOh1AMmV9FB65oiXOSAIll1_qmOZdupL3QCcJQL4701YskEgeDUnxJTnFGq4mFEzNFvjpNC-QMX9Jg7mdar3e89u_siA4AD-j1SJ6mrkl2MwSJSu1s2guYn0NR5ND1985lK34_iGiwzjoGHG2a65IbxKDSEzgSGbPQ_CQiQ6rBIvfcgvAxtS6E=s530-p
37
- 28 //lh3.googleusercontent.com/proxy/7N0QCidzIFysO6OhmrG8twRJ74-sboNenI3Nhy3mIWP8C0SSa8J6xFQU3iyBTw4k3QeleiAgXOME3abYutPvBrHGx-0TBUcI-_LsgFa59Zaw6PAGdLndkxp5ReRJnsg=w530-h298-p
38
- 31 //lh3.googleusercontent.com/proxy/7pN3aTE159nEXXQb_KajU1vcnDDzJVpGOv9vlWWPd3CbVuCKu-v4ndr423Mmhx-Zn5vqkVf6-TfZgPA5NyHECsr4w7kaw1jTmQDJbWO-9jU-Cs7ywrzcIRhyYTTZT-hPGiazwI1oEdbooIk=w464-h640-p
39
- 48 //lh3.googleusercontent.com/proxy/DZtTi5KL7PqiBwJc8weNGLk_Wi2UTaQH0AC_h2kuURiu0AbwyI2ywOk2XgdAjL7ceg=w530-h354-n
40
- 74 //lh3.googleusercontent.com/proxy/P4FQdTYwWN8cU_PWmFja1cm3oYu57L_flea7LmKvFjx0Ibdxl3glxcp-KFWsdRxMFTQ3gQkWsWzlrkyCm9QrSjCUcGIgnbsYBCXewnhEwSn0ZgT4XDg485GdXMoGWpNETrLYa8IGvG20_iw=w504-h597-p
41
- 137 //lh3.googleusercontent.com/proxy/kX1ABK6_VjHDU12p-zZN6ciTOzqFcXm7IV41uR9F2sveM2t148nmWBEN1clA-VHvowpkd9T4NOPrAfDaip1o-jJBtBnRBElJuCsKo8FviSIkToZWCY9nQFEj06nHkMNuReBtdbVBlIRSodNJM-_cmqiJ-DnmWNe4dk62EF_kGLS28OWmckDLWVG0YFiZ-lVi8JhgR-ZgRmYWTs8bb_u6v6ucgfo8eh7ewchuZAD9_CoxUlQChAqz0QIfuVuKvmcXE06Ylv2H330btswQotjKDf8AXPe6xcyE9X1JXDYQTsPv-7lftLG9WQp1Mlc9Wu1XbHV7f541L-smt--7YpkW6fbDFYk4_87-pIOcg9UqHKB__DWyMCtH3gs8rv6VCmVwL1a-oAeBWSWk0Tc9R6uSuyCjt0nEBGlZY35aW1Pchz0jXr4lq8Il9m-wbRN9E7Kff1JR89YFOrV2N86w_72YTefFerLFfEsgzmhx3WYwok-4H12RdH7MyiHBQt04uRnb58GA4vl5VBQ=w530-h398-p
42
-
43
- 245 https://lh3.googleusercontent.com/-2JzV0ErXvv8/Wsdr-m5Q_aI/AAAAAAAA_-I/Lw_e6qEMPUck4yW9yWhkC-nBNd5em8c3QCJoC/w530-h795-n/888052_800n.jpg
44
- 346 https://lh3.googleusercontent.com/-8YmBt-SUaJo/War0Un_7YTI/AAAAAAAB9xs/kgXp9QrHZX8mpDfyLwuS9cvUSsXIoH6NgCL0BGAs/w530-d-h443-n/%25D0%259B%25D0%25B5%25D1%2581%2B%25D0%25BD%25D0%25B0%2B%25D0%25B8%25D1%2581%25D1%2585%25D0%25BE%25D0%25B4%25D0%25B5%2B%25D0%25BB%25D0%25B5%25D1%2582%25D0%25B0.JPG
45
- 1317 https://lh3.googleusercontent.com/-tGAyJv4S6gM/WSLy4A7AFaI/AAAAAAABxk4/eq0Aprp2koM6GEti9xEIn-0PLh87bRRdQCL0B/w530-d-h660-n/%25D0%2592%25D0%25B5%25D1%2581%25D0%25BD%25D1%258B%2B%25D1%2586%25D0%25B2%25D0%25B5%25D1%2582%25D0%25B5%25D0%25BD%25D0%25B8%25D0%25B5.JPG
46
-
47
- 178 https://lh3.googleusercontent.com/--Ggbfs9HJZM/Wog1DA2WcFI/AAAAAAAAbdQ/SZKPcnXFIr8MFfl9pddfiLPQnOiJ37muQCJoC/w409-h727-n/11a1c54f37c07d3c04588b40d108b4c2.jpg
48
- 260 https://lh3.googleusercontent.com/-3Fe6CL9RH4o/WnipWY4889I/AAAAAAAAI4I/CPqdKpjqdlwkaBlCqGQ3RdZ9bLJ4nzBwwCJoC/w239-h318-n/gplus1855963830.jpg
49
- 303 https://lh3.googleusercontent.com/-5vPhLnUILsA/WqFhJhu7VlI/AAAAAAAAAhQ/wWSrC8dqZTA7OuzeU3UoXJkNG19tqtAGwCJoC/w265-h353-n/DSC08260.JPG
50
- 668 https://lh3.googleusercontent.com/-NLW68hNxEzU/WrSNfBxFX2I/AAAAAAAAAT8/7cvRM-DUZLoIdlb6CS8pL5-eJ3wbwohlQCJoC/w179-h318-n/23.03.2018%2B-%2B3
51
- 669 https://lh3.googleusercontent.com/-NVJgqmI_2Is/WqMM2OMYg-I/AAAAAAAALrk/5-p3JL3iZt0Ho9dOf_p3gpddzqwr3Wp0ACJoC/w424-h318-n/001
52
- 783 https://lh3.googleusercontent.com/-SqAvt_F__bg/Wq0huHcX2NI/AAAAAAAAVj0/XfnwCU7JwhUh0Knw8rcXA-bhpKYkI4hdwCJoC/w358-h318-n/IMG_20180317_120218-01-01.jpeg
53
- 830 https://lh3.googleusercontent.com/-VB3YlLVL_tQ/Wo21yTbKl_I/AAAAAAAAApU/3DURmsYBklcv0kif2ZRjhoLG4mTHYf8OwCJoC/w254-h318-n/180218_00001.jpg
54
- 1002 https://lh3.googleusercontent.com/-d8FkfLWq-_4/WpQXzEfFgBI/AAAAAAAADww/J32xKSAYUkgIc3pyrZnNmRec6kjdnJBHgCJoC/w239-h318-n/gplus-485739203.jpg
55
- ".scan(/(\S+) (\S+)/).each do |i, link| # some pre-May-2018 urls dump from a community
56
- it "Google Plus community post image ##{i}" do
57
- assert DirectLink.google link
58
- end
59
- end
60
- %w{
61
- https://lh3.googleusercontent.com/-dUQsDY2vWuE/AAAAAAAAAAI/AAAAAAAAAAQ/wVFZagieszU/w530-h176-n/photo.jpg
62
- //lh3.googleusercontent.com/cOh2Nsv7EGo0QbuoKxoKZVZO_NcBzufuvPtzirMJfPmAzCzMtnEncfA7zGIDTJfkc1YZFX2MhgKnjA=w530-h398-p
63
- //lh3.googleusercontent.com/-0Vt5HFpPTVQ/Wnh02Jb4SFI/AAAAAAAAbCU/MtusII6-FcgxuHQWofAaWF01IBUVykMyACJoC/w530-h351-p/DSC_3804%2B-%2B%25D0%25BA%25D0%25BE%25D0%25BF%25D0%25B8%25D1%258F.JPG
64
- https://lh3.googleusercontent.com/-u3yxaS-b85c/WvOtHJn-DxI/AAAAAAAAAKg/A_PoO64o0VkX1erPKebiO7Xcs5Iy3idbACJoC/w424-h318-n/IMG_20180510_082023.jpg
65
- https://lh3.googleusercontent.com/-K2XODEFntJY/Wvl8HLwfF_I/AAAAAAAAA20/mqOtMCFuBkkvtv7jdpVkJv2XSXlOLoXVQCJoC/w212-h318-n/DPP_0006.JPG
66
- https://lh3.googleusercontent.com/-702a8U4EIiw/WuxqzXHQCHI/AAAAAAAABAI/rA0R2UsbxoswvH6nSePnwa5VHG2f5kNOQCJoC/w398-h318-n/Fox-Desktop-1024x1280.jpg
67
- https://lh3.googleusercontent.com/-YQFXT62-1OA/WvMUBWXI0PI/AAAAAAAAC60/gdtkQz9YI0knYkFB8VjC2CpKOD6-Zs6hQCJoC/w408-h318-n/%25D0%25BF%25D0%25BE%25D1%2581.jpg
68
- https://lh3.googleusercontent.com/--P4MRZpGk-A/WveQe_YKbAI/AAAAAAAACkQ/eTz2maXvw7A0iKoPjfuwEgfTiZS3a3HSgCJoC/w318-h318-n/gplus1165736192.jpg
69
- https://lh3.googleusercontent.com/-CH2N9uhwMOg/WtOxVJ1DNxI/AAAAAAAAMGs/pJf8awKJcyMFlx2g89p9_QjqlyQDmYMmACJoC/w424-h318-n/DSC03178.JPG
70
- https://lh3.googleusercontent.com/-NGME5H7fY1o/WtaUJCaDGmI/AAAAAAAAmBQ/jZhatiBmHPEiAAABcY2DoJ6KuzVBvqGxQCJoC/w530-h150-n/%25D0%25A1%25D0%25BD%25D0%25B8%25D0%25BC%25D0%25BE%25D0%25BA%2B%25D1%258D%25D0%25BA%25D1%2580%25D0%25B0%25D0%25BD%25D0%25B0%2B2018-04-18%2B%25D0%25B2%2B3.32.42.png
71
- https://lh3.googleusercontent.com/-40QwR_c58sw/WsLyS3a8uhI/AAAAAAAAAas/ojaQoF1-ZFIboOS6c5kLs7bOl_TAOU6oACJoC/w424-h318-n/271091.jpg
72
- https://lh3.googleusercontent.com/-XhWuVCyNBjY/WvOtHOyaj_I/AAAAAAAAAKo/gOAn__a75NwYSgaBaEBGeCTAFI9MyjqlwCJoC/w239-h318-n/IMG_20180510_081956.jpg
73
- https://lh3.googleusercontent.com/-R19p_rDI8mY/Wwma1oEvD6I/AAAAAAAAEX8/tQc4JOq58REEWlukw2jDCTUjH3ejGZI8gCJoC/w486-h864-n/gplus1392977354.jpg
74
- //2.bp.blogspot.com/-mOnRg-mkojA/W22m79XcT_I/AAAAAAAAHDs/C8yQaOA-ZeEAr3WBG--3wW8VZ5nWV0p7QCEwYBhgL/w530-h353-p/_MG_8809-Edit.jpg
75
- }.each_with_index do |link, i| # March contenstants
76
- it "another (March) Google Plus community post image ##{i + 1}" do
77
- assert DirectLink.google link
78
- end
79
- end
80
- %w{
81
- https://lh3.googleusercontent.com/-mFRn677_gic/WwUz3_Www7I/AAAAAAAABio/MNYvB57tBvIl6Bxp0GsKHvg0hSyHyVWhwCJoC/w265-h353-n/IMG_20180522_210620_317.jpg
82
- https://lh3.googleusercontent.com/-6iAmBl21QVc/Wu4Khtduz-I/AAAAAAAAA_A/lvpwTuatrtkhL31co1n9xa7kwKEVwc6IwCJoC/w301-h318-n/gplus662578195.jpg
83
- https://lh3.googleusercontent.com/-NnKGFBtNG2Q/Wvt9mUDC1QI/AAAAAAAANEw/2uWvIzQmG-Y3CGHuB8-UU114z4Zr8lkLQCJoC/w530-h175-n/PANO_20180516_025747.jpg
84
- https://lh3.googleusercontent.com/-Q7WO7uK6_Ew/WwvJcNQ39BI/AAAAAAAABvI/xb1bdwuEZGM2SmbwamwiMmZKFOW44bhPgCJoC/w239-h318-n/DSC03627.JPG
85
- https://lh3.googleusercontent.com/-Uxa1I3V7WWI/Wu4Khq0IkaI/AAAAAAAAA_A/Dxs9JYJ6f6sv_7jNWMdNl3eo2jh9nYqDwCJoC/w296-h318-n/gplus-328480287.jpg
86
- https://lh3.googleusercontent.com/-xp3mV2iqjyo/Wu4Khr5ZKhI/AAAAAAAAA_A/725HNeKw2hYtuddakPreAkaucQR6HOYGgCJoC/w424-h318-n/20180317_085037.jpg
87
- https://lh3.googleusercontent.com/-oyYSEl5GABY/Wu4Khov2uGI/AAAAAAAAA_A/xFVaLt1emxUtOvys7Mw8QZIF2599lNV6ACJoC/w424-h318-n/20180317_085508.jpg
88
- https://lh3.googleusercontent.com/-69MIjxFjtXg/Wu4KhkZD9nI/AAAAAAAAA_A/lBHtrho7HBQgkZNztMTdR3o1RSu47OnigCJoC/w239-h318-n/gplus1795981938.jpg
89
- https://lh3.googleusercontent.com/-RW-U7dkkT88/Wu4Khs76OSI/AAAAAAAAA_A/2rsXBfNM4Isi3YBNWlgLnPgQpVN72dXiQCJoC/w318-h318-n/gplus-379421668.jpg
90
- }.each_with_index do |link, i| # April contenstants
91
- it "another (April) Google Plus community post image ##{i + 1}" do
92
- assert DirectLink.google link
93
- end
94
- end
95
- %w{
96
- https://lh3.googleusercontent.com/-4pJI5zXoL_k/WvMUBQ6TXMI/AAAAAAAAC60/XRgJlEr5hbgKzYzOQkM8b4_fq2Yp5vNbACJoC/w239-h318-n/%25D0%25B7%25D0%25B0%25D1%2581.jpg
97
- https://lh3.googleusercontent.com/-NNYx8cZYF4Y/Wvl8HH7crSI/AAAAAAAAA20/0vaXtOyqDL0DLx841Gj45ePol01OCOAewCJoC/w212-h318-n/DPP_0007.JPG
98
- https://lh3.googleusercontent.com/-Y9zbAQDAoH8/WyCS3fapzjI/AAAAAAAAB5M/hKzS0cR0MEgnM-YJENsL7dX8Tbch5Z04wCJoC/w265-h353-n/DSC03805.JPG
99
- https://lh3.googleusercontent.com/-cQ1lothweSI/WvMUBS4uAJI/AAAAAAAAC60/tE7aakvztZgTqvRMcrk2FbrauU8LLhGPgCJoC/w239-h318-n/11.jpg
100
- https://lh3.googleusercontent.com/-Aiij3wT_v6g/WyCS3VJ-hVI/AAAAAAAAB5M/qeUFKiNXnwkJ-q2q2VoM2f9ukTqPOGhAACJoC/w265-h353-n/DSC03807.JPG
101
- //2.bp.blogspot.com/-hBOcNikbjOk/WwlXLbeiF9I/AAAAAAAAKKE/zT7sAlaNYIc7lTxZMY1tyND0u3UH5DuKACLcBGAs/w530-h398-p/EdnjF3yEMM8.jpg
102
- https://lh3.googleusercontent.com/-1_J-FT0LhUE/Wx9lWOEXUjI/AAAAAAAAB34/183rqDWZipkaSWyV6qF_Fm7_XQrtYiwdACJoC/w265-h353-n/DSC03800.JPG
103
- https://lh3.googleusercontent.com/-I72-Vlk3Ym4/Wx9lWLfINqI/AAAAAAAAB34/EIOySV-4ny8xMECMSC4TvHV43qUn0HLLwCJoC/w265-h353-n/DSC03797.JPG
104
- https://lh3.googleusercontent.com/-L-RnjWuqyuI/WxZnv-NRXWI/AAAAAAAARVw/Z3yVnOEDU7kDZ-WbRoLbEh8Tao1_DtQbACJoC/w179-h318-n/20160305_134926.jpg
105
- //lh3.googleusercontent.com/-7iXdrlHFM6E/WtRMPtqimXI/AAAAAAAACIo/txJyaoEvnEQu7r2-35SgwFYCWHGmXDQ3QCJoC/w530-h353-p/IMG_3695.jpg
106
- }.each_with_index do |link, i| # May contenstants
107
- it "another (May) Google Plus community post image ##{i + 1}" do
108
- assert DirectLink.google link
109
- end
110
- end
111
- %w{
112
- https://lh3.googleusercontent.com/-dWul1-dnMGE/W1npdlvSenI/AAAAAAAAAJI/jHPhVr5xS98xvFJDNgMgcxrRzPd6gOp9QCJoC/w208-h318-n/alg3_1520-2.jpg
113
- https://lh3.googleusercontent.com/-t_ab__91ChA/VeLaObkUlgI/AAAAAAAAL4s/VjO6KK_lkRw/w530-h351-n/30.08.15%2B-%2B1
114
- https://lh3.googleusercontent.com/-Ry3uDLjGG0E/W13DzrEntEI/AAAAAAAAAdY/7ldMJD-2JPsnuqYq7qtif_eVWhTd0EmnwCJoC/w480-h853-n/gplus-790559743.jpg
115
- }.each_with_index do |link, i| # June contenstants
116
- it "another (June) Google Plus community post image ##{i + 1}" do
117
- assert DirectLink.google link
118
- end
119
- end
120
- %w{
121
- https://lh3.googleusercontent.com/-s655sojwyvw/VcNB4YMCz-I/AAAAAAAALqo/kW98MOcJJ0g/w530-h398-n/06.08.15%2B-%2B1
122
- //4.bp.blogspot.com/-TuMlpg-Q1YY/W3PXkW1lkaI/AAAAAAAAHHg/Bh9IsuLV01kbctIu6lcRJHKkY-ej8oD5gCLcBGAs/w530-h353-p/_MG_2688-Edit.jpg
123
- //lh3.googleusercontent.com/proxy/SEfB6tFuim6X0HdZfEBSxrXtumUdf4Q4y05rUW4wc_clWWVrowuWAGZghx71xwPUmf_8si2VQwnRivsM7PfD2gp3kA=w480-h360-n
124
- https://lh3.googleusercontent.com/-u3FhiUTmLCY/Vk7dMQnxR2I/AAAAAAAAMc0/I76_52swA4s/w530-h322-n/Harekosh_A%252520Concert_YkRqQg.jpg
125
- https://lh3.googleusercontent.com/-t_ab__91ChA/VeLaObkUlgI/AAAAAAAAL4s/VjO6KK_lkRw/w530-d-h351-n/30.08.15%2B-%2B1
126
- //lh3.googleusercontent.com/-u2NzdIQfVyQ/Wy83AzoFT8I/AAAAAAAAh6M/fdpxOUkj5mUIfpvYol_R5dyupnF2nDIEACJoC/w530-h298-p/_DSC9134.jpg
127
- }.each_with_index do |link, i| # July contenstants
128
- it "another (July) Google Plus community post image ##{i + 1}" do
129
- assert DirectLink.google link
130
- end
131
- end
132
- %w{
133
- https://lh3.googleusercontent.com/-f37xWyiyP8U/WvmxOxCd-0I/AAAAAAAACpw/3A2tRj02oY40MzJqZBJyWGImoSer0lwMgCJoC/s0/140809%2B029.jpg
134
- https://lh3.googleusercontent.com/-1s_eiQB4x2k/WvXQEx59z2I/AAAAAAAAcI0/DvKYzWw3g6UNelqAQdOwrdtYdSEqKgkxwCJoC/s0/001
135
- https://lh3.googleusercontent.com/-1Rcbffs4iRI/WvaSsRCrxJI/AAAAAAAAcJs/e-N9tmjaTCIxEBE_jXwFjiYPyZXFwh4owCJoC/s0/001
136
- https://lh3.googleusercontent.com/-VXUjuSl-dZY/WvK340_E9uI/AAAAAAAAVlg/HqKf1LgUcPUJNrLxHebCMuHhpDRq36_bQCJoC/s0/gplus248254159.jpg
137
- https://lh3.googleusercontent.com/-NlZRwcX_Lj8/WvQTijeAfJI/AAAAAAABNyo/jgoDgbZdTvsnLOGmmYlXMr2jL66ieZV4QCJoC/s0/67u8iii.png
138
- https://lh3.googleusercontent.com/-8baBz80pf8Y/Wu8KG5lyGhI/AAAAAAACSyU/s3hasZzObK0VlntA1EBj-WBrTRagzRnLQCJoC/s0/%25D0%2592%25D0%25B5%25D1%2581%25D0%25B5%25D0%25BD%25D0%25BD%25D0%25B8%25D0%25B5%2B%25D0%25BA%25D1%2580%25D0%25B0%25D1%2581%25D0%25B0%25D0%25B2%25D1%2586%25D1%258B.JPG
139
- https://lh3.googleusercontent.com/-BBjhu17YIgg/W-gnZNaZeMI/AAAAAAABA-k/UMlSbNuE0DsSEPV8u3yf_6i2S5H9vFoBgCJoC/s0/gplus320347186.png
140
- }.each_with_index do |link, i|
141
- it "already high res image ##{i + 1}" do
142
- assert DirectLink.google link
143
- end
144
- end
145
- %w{
146
- https://lh3.googleusercontent.com/-5USmSTZHWWI/WMi3q1GdgiI/AAAAAAAAQIA/lu9FTcUL6xMw4wdoW_I148Vm1BtF5mImwCJoC/w346-h195-n-k-no/Good%2BJob.gif
147
- https://lh3.googleusercontent.com/-G8eSL3Xx2Kc/WxWt9M6LptI/AAAAAAAAB_c/KNF9RBxjL04Reb3fBtwYLI2AlnLwJ9w7gCJoC/s0/20180602212016_IMG_0244.JPG
148
- https://lh3.googleusercontent.com/-aUVoiLNsmAg/WzcsUU2xfNI/AAAAAAAAODw/DOBual6E1rkVLHh3SKZSzbpNQzdEoZPOQCJoC/w530-h883-n-k-no/gplus-1797734754.mp4
149
- //lh3.googleusercontent.com/proxy/hOIoIpMEmoVDSP40VRzM92Zw2AeLvEEhxfyKHCOxiNVPyiGvZik5rMvl3jYISLgDJla6mhZuk8pFEYJhX5BU2wy_dw=w530-h822-p
150
- https://lh3.googleusercontent.com/-GP3BA3zGR5A/W0IwuVXlfmI/AAAAAAADROs/SH8rRlBDYTsHZiHpM45S3zpEipu5hJ2PwCJoC/s0/%25D1%2582%25D0%25B0%25D0%25B4%25D0%25B6%25D0%25B8%25D0%25BA%25D1%2581%25D0%25BA%25D0%25BE%25D0%25B5%2B%25D1%2580%25D0%25B0%25D0%25B7%25D0%25BD%25D0%25BE%25D1%2582%25D1%2580%25D0%25B0%25D0%25B2%25D1%258C%25D0%25B5.png
151
- https://lh3.googleusercontent.com/-DLODAbD9W7E/W27ob5XGCOI/AAAAAAADV8g/J_6RYR6UkKsc2RJOWRx6Q-NBVx5RbMoxwCJoC/s0/1236080.jpg
152
- https://lh3.googleusercontent.com/-cJajRreI87w/W4gW5uF4Q7I/AAAAAAADZKI/mw1YayYE-MY2-1OCCmjvgM3kbCK0lmIggCJoC/s0/2504855.jpg
153
- https://lh3.googleusercontent.com/-rm-m1meCOMY/W92GhExMG-I/AAAAAAADsTw/bIAm5-1CIOYEpyPJLnxT8VmI_YNW2W5dACJoC/s0/2659806_800n.jpg
154
- https://lh3.googleusercontent.com/-z1nwsq4NOT4/XETT5qhXP-I/AAAAAAAAC0s/03kJ22drB1EdqZ97gUXCPHkLZbbqrDbOACJoC/w530-h942-n/gplus1629127930.jpg
155
- https://lh3.googleusercontent.com/-NiGph3ObOPg/XE3DgnavXlI/AAAAAAABvgE/pcPPCe88rsU1r941wwP76TVf_o89i74kwCJoC/w530-h353-n/DSCF0753.JPG
156
- https://lh3.googleusercontent.com/-QfChCi9Lj6A/XEciVlXmDhI/AAAAAAACuZw/iYzoMIxr7SsGzEFbk1LrqIdCdWVu8zCHACJoC/w795-h1193-n-rw/z7765765765757575.jpg
157
- }.each_with_index do |link, i|
158
- it "gpluscomm_105636351696833883213_86400 ##{i + 1}" do
159
- assert DirectLink.google link
160
- end
161
- end
162
- %w{
163
- https://4.bp.blogspot.com/--L451qLtGq8/W2MiFy8SVCI/AAAAAAAARgM/9qr4fr2PiV8IE4d3zVmf5dEnlchx1V6vwCLcBGAs/w72-h72-p-k-no-nu/blood_moon_5k.jpg
164
- https://3.bp.blogspot.com/-aZETNznngSo/W2xbe673_6I/AAAAAAAARhs/hkXvEk85ol4SqVeZ1hI3luDGLyT4V45kACLcBGAs/w72-h72-p-k-no-nu/waterfall-1280x800-ireland-4k-19245.jpg
165
- https://3.bp.blogspot.com/-ZmCuJkPliO8/W3WjIWvdjXI/AAAAAAAARi4/qO9I8kzJvCMRWsgxElxzwcOCQPCyu_xDQCLcBGAs/w72-h72-p-k-no-nu/ford_mustang_neon_lights_5k.jpg
166
- https://2.bp.blogspot.com/-rb2PXLGZy0s/W2nQe3mXOSI/AAAAAAAARhQ/P8gV-bMtYbY2xxpTJNcYVxu3XDTUaugxQCLcBGAs/w72-h72-p-k-no-nu/beach-bora-bora-clouds-753626.jpg
167
- https://1.bp.blogspot.com/-FGnZn0040os/W3g7wnT2o-I/AAAAAAAARjE/xfgcR4fyvQgBgV5vFnyLtYOVK4d4dTouwCLcBGAs/w72-h72-p-k-no-nu/axl_2018_movie_4k_8k-7680x4320.jpg
168
- https://1.bp.blogspot.com/-h9kL603XSgY/XCe5rYiOczI/AAAAAAAARmY/qz_kMyR1q-scfs-rEGRzaof_QocYK7RegCLcBGAs/w72-h72-p-k-no-nu/spider_man_into_the_spider_verse_hd_4k.jpg
169
- https://2.bp.blogspot.com/-rb2PXLGZy0s/W2nQe3mXOSI/AAAAAAAARhQ/P8gV-bMtYbY2xxpTJNcYVxu3XDTUaugxQCLcBGAs/s640/beach-bora-bora-clouds-753626.jpg
170
- http://4.bp.blogspot.com/-poH-QXn7YGg/U-3ZTDkeF_I/AAAAAAAAISE/ms2gNIb-v-g/w72-h72-p-k-no-nu/Top-24-Inspired-181.jpg
171
- http://1.bp.blogspot.com/-iSU4orVuR9Y/VFYrwQZ5qYI/AAAAAAAAMnc/WY4VfCaeplw/w72-h72-p-k-no-nu/Wolf%2Bphotography2.jpg
172
- http://1.bp.blogspot.com/-vPQSh6RKijU/VEi7r3D-jJI/AAAAAAAAL2Q/bGHmyuoDp5M/w72-h72-p-k-no-nu/Building%2BIn%2BLondon1-4__880.jpeg
173
- http://1.bp.blogspot.com/-W4xKJSsVf3M/Uz73jPlctbI/AAAAAAAAGz4/K8Tw6PILMeY/w72-h72-p-k-no-nu/Beautiful+Japanese+places4.jpg
174
- https://lh3.googleusercontent.com/-tV86KJvppss/XE2Nb2Z2aAI/AAAAAAAAGu4/94E_AuB4YWAaJ59n43wmmd9rFa--OUuSQCJoC/w530-h338-n/IMG_6845%252C.png
175
- https://lh3.googleusercontent.com/-cr-2ZSQGMPg/XFWLfetwr7I/AAAAAAAAQQQ/TbwDk56BBIwb4IDDO0SwfArFSZyDG0i0wCJoC/w530-h360-n/DSC07294.JPG
176
- }.each_with_index do |link, i|
177
- it "largeimages ##{i + 1}" do
178
- assert DirectLink.google link
179
- end
180
- end
181
- %w{
182
- //lh3.googleusercontent.com/proxy/S-Z1P92Dd_u0DjYrz5Tb7j0mbZsGjPVffx9lHPQZCqqCFr6vAigCPOG0fEYKU6d-wIvwYr2WriAfh97KjBr9Bq1RKgyHzHq2fpAotTnJYOLd3x_tF2chsGBVuAewE7qp2QDtCYyomyn3dGjZ6cKUnYIC8w=s110-p-k
183
- }.each_with_index do |link, i|
184
- it "posted_website_preview_##{i + 1}" do
185
- assert DirectLink.google link
186
- end
187
- end
188
- %w{
189
- 0 https://lh3.googleusercontent.com/-okfI8E6JAgg/AAAAAAAAAAI/AAAAAAAAZa0/FEv9H8woCBg/s30-p-rw-no/photo.jpg
190
- 7 https://lh3.googleusercontent.com/-okfI8E6JAgg/AAAAAAAAAAI/AAAAAAAAZa0/FEv9H8woCBg/s75-p-rw-no/photo.jpg
191
- _ https://lh3.googleusercontent.com/-bhgxgLsFYWI/AAAAAAAAAAI/AAAAAAAA4MI/_KuKE-Goa7E/s35-p-k-rw-no/photo.jpg
192
- - https://lh3.googleusercontent.com/-tl9-AdHhGiY/AAAAAAAAAAI/AAAAAAAA8uY/vVeZX8SbTXI/s35-p-k-rw-no/photo.jpg
193
- 4 https://lh3.googleusercontent.com/-Rb833O10RB4/AAAAAAAAAAI/AAAAAAAAEJc/DawCLQGnaSA/s45-p-k-rw-no/photo.jpg
194
- }.each_slice 2 do |i, link|
195
- it "Google Plus userpic #{i}" do
196
- assert DirectLink.google link
197
- end
198
- end
199
- %w{
200
- - https://lh3.googleusercontent.com/-10bBuroWuoU/AAAAAAAAAAI/AAAAAAAAl90/ed314-fNMGg/s20-c-k-no/photo.jpg
201
- just https://lh5.googleusercontent.com/-RT6j6oYpZzU/AAAAAAAAAAI/AAAAAAAAAO4/WISrqFs1vT8/s46-c-k-no/photo.jpg
202
- no-no https://lh5.googleusercontent.com/-XdUIqdMkCWA/AAAAAAAAAAI/AAAAAAAAAAA/4252rscbv5M/s64-c-k/photo.jpg
203
- no-k-no https://lh3.googleusercontent.com/-okfI8E6JAgg/AAAAAAAAAAI/AAAAAAAAAAA/AIcfdXD1lA9yGoSbsihWmGfnl6Z3Rn43WA/s64-c-mo/photo.jpg
204
- _ https://lh6.googleusercontent.com/-BQEbGrPRFk4/AAAAAAAAAAI/AAAAAAAAAAA/AIcfdXDBweE5VzGGy4zMraO_pqiLuFN3yQ/s46-c-k-no-mo/photo.jpg
205
- }.each_slice 2 do |i, link|
206
- it "Hangout userpic #{i}" do
207
- assert DirectLink.google link
208
- end
209
- end
210
- %w{
211
- https://lh4.googleusercontent.com/KwxMEMlyjNKXqSqszuiCgPMi7_oE5fVv1Sw373HXBYlguP8AnIPAqefTS6DbBuurVGYRSxGrtDyKei1hae9Djf6rjiwjJd0aauA5Bg-z=s615
212
- https://lh5.googleusercontent.com/fRmAL_04p7oomNHCiV4tH4-agHSDBtLaWi_Tb6bgE5ZSHVu5OjQF3iRn06nNwP3ywZwdFP92zWM-o8yw0cn6m0tDTBARuO6F9e0wYu_1=s685
213
- https://lh5.googleusercontent.com/FcYUQBKLXWtFLEvbQduvu7FHUm2f7U_MVdMBVnNbpwfzKHIU-xABkudxw-m21SlM0jFYRHedh7Is5Dg6qlgIQF1iSndlWjiKCTTsUo1w=s1080
214
- https://lh5.googleusercontent.com/gcDb3dxbch9jUKPzKGawJiwtHcNS9wp6o2sc0aJj9wOWQA-u8kXmKIrZ-TkLxajee6qLaT2p6OK2N7klTJ9CxU66OnpBhYJMg0q9QEdq5Q=s2160
215
- }.each_with_index do |link, i|
216
- it "google keep ##{i + 1}" do
217
- assert DirectLink.google link
218
- end
219
- end
220
-
221
- end
222
-
223
- # TODO: expand this for every branch in lib
224
- %w{
225
- https_long_blogspot https://2.bp.blogspot.com/-rb2PXLGZy0s/W2nQe3mXOSI/AAAAAAAARhQ/P8gV-bMtYbY2xxpTJNcYVxu3XDTUaugxQCLcBGAs/s640/beach-bora-bora-clouds-753626.jpg https://2.bp.blogspot.com/-rb2PXLGZy0s/W2nQe3mXOSI/AAAAAAAARhQ/P8gV-bMtYbY2xxpTJNcYVxu3XDTUaugxQCLcBGAs/s0/
226
- http_short_blogspot http://4.bp.blogspot.com/-poH-QXn7YGg/U-3ZTDkeF_I/AAAAAAAAISE/ms2gNIb-v-g/w72-h72-p-k-no-nu/Top-24-Inspired-181.jpg https://4.bp.blogspot.com/-poH-QXn7YGg/U-3ZTDkeF_I/AAAAAAAAISE/ms2gNIb-v-g/s0/
227
- just_gplus https://lh3.googleusercontent.com/-NiGph3ObOPg/XE3DgnavXlI/AAAAAAABvgE/pcPPCe88rsU1r941wwP76TVf_o89i74kwCJoC/w530-h353-n/DSCF0753.JPG https://lh3.googleusercontent.com/-NiGph3ObOPg/XE3DgnavXlI/AAAAAAABvgE/pcPPCe88rsU1r941wwP76TVf_o89i74kwCJoC/s0/
228
- google_keep https://lh5.googleusercontent.com/fRmAL_04p7oomNHCiV4tH4-agHSDBtLaWi_Tb6bgE5ZSHVu5OjQF3iRn06nNwP3ywZwdFP92zWM-o8yw0cn6m0tDTBARuO6F9e0wYu_1=s685 https://lh5.googleusercontent.com/fRmAL_04p7oomNHCiV4tH4-agHSDBtLaWi_Tb6bgE5ZSHVu5OjQF3iRn06nNwP3ywZwdFP92zWM-o8yw0cn6m0tDTBARuO6F9e0wYu_1=s0
229
- }.each_slice 3 do |name, link, o|
230
- it "replaces s0 and schema correctly #{name}" do
231
- assert_equal o, DirectLink.google(link)
232
- end
233
- end
234
-
235
- end
236
-
237
- describe "imgur" do
238
- %w{
239
- https://imgur.com/a/badlinkpattern
240
- http://example.com/
241
- https://imgur.com/gallery/YO49F.
242
- }.each_with_index do |url, i|
243
- it "ErrorBadLink_##{i + 1}" do
244
- assert_raises DirectLink::ErrorBadLink do
245
- DirectLink.imgur url
246
- end
247
- end
248
- end
249
-
250
- it "ErrorNotFound when album is empty" do
251
- e = assert_raises DirectLink::ErrorNotFound do
252
- DirectLink.imgur "https://imgur.com/a/wPi63mj"
253
- end
254
- assert_nil e.cause if Exception.instance_methods.include? :cause # Ruby 2.1
255
- end
256
-
257
- valid_imgur_image_url_direct = "https://i.imgur.com/dCQprEq.jpg"
258
- it 200 do
259
- assert_equal [[valid_imgur_image_url_direct, 5760, 3840, "image/jpeg"]],
260
- DirectLink.imgur(valid_imgur_image_url_direct)
261
- end
262
- valid_imgur_image_url_album = "https://imgur.com/a/wPi63mj"
263
- [400, 500, 503].each do |error_code|
264
- [
265
- [valid_imgur_image_url_direct, :direct],
266
- [valid_imgur_image_url_album, :album],
267
- ].each do |url, kind|
268
- it "retries limited amout of times on error #{error_code} (#{kind})" do
269
- tries = 0
270
- e = assert_raises DirectLink::ErrorAssert do
271
- NetHTTPUtils.stub :request_data, ->*{ tries += 1; raise NetHTTPUtils::Error.new "", error_code } do
272
- DirectLink.imgur url, 4 # do not remove `4` or test will hang
273
- end
274
- end
275
- assert_equal error_code, e.cause.code if Exception.instance_methods.include? :cause # Ruby 2.1
276
- assert_equal 3, tries
277
- end
278
- end
279
- end
280
- it "does not throw 400 after a successfull retry" do
281
- f = 0
282
- m = NetHTTPUtils.method :request_data
283
- NetHTTPUtils.stub :request_data, lambda{ |*args|
284
- raise NetHTTPUtils::Error.new "", 400 if 1 == f += 1
285
- m.call *args
286
- } do
287
- assert_equal [[valid_imgur_image_url_direct, 5760, 3840, "image/jpeg"]],
288
- DirectLink.imgur(valid_imgur_image_url_direct, 4) # do not remove `4` or test may hang
289
- end
290
- end
291
- it 404 do
292
- e = assert_raises DirectLink::ErrorNotFound do
293
- NetHTTPUtils.stub :request_data, ->*{ raise NetHTTPUtils::Error.new "", 404 } do
294
- DirectLink.imgur valid_imgur_image_url_direct
295
- end
296
- end
297
- assert_equal 404, e.cause.code if Exception.instance_methods.include? :cause # Ruby 2.1
298
- end
299
-
300
- [ # TODO: move these end line comments to test names; and do the same in other tests
301
- ["https://imgur.com/a/j5xmY", "https://i.imgur.com/KTTuoyN.jpg", 2828, 2828, "image/jpeg"], # single photo album
302
- ["http://i.imgur.com/7xcxxkR.gifv", "http://i.imgur.com/7xcxxkRh.gif", 718, 404, "image/gif"],
303
- ["https://imgur.com/9yaMdJq", "https://i.imgur.com/9yaMdJq.mp4", 720, 404, "video/mp4"],
304
- ["http://imgur.com/gallery/dCQprEq/new", "https://i.imgur.com/dCQprEq.jpg"],
305
- ["http://imgur.com/HQHBBBD", "https://i.imgur.com/HQHBBBD.jpg"], # http
306
- ["https://imgur.com/BGDh6eu", "https://i.imgur.com/BGDh6eu.jpg"], # https
307
- ["https://imgur.com/a/qNCOo", 6, "https://i.imgur.com/vwqfi3s.jpg", "https://i.imgur.com/CnSMWvo.jpg"], # https album
308
- ["http://imgur.com/a/0MiUo", 49, "https://i.imgur.com/kJ1jrjO.jpg", "https://i.imgur.com/TMQJARX.jpg"], # album, zoomable
309
- ["http://imgur.com/a/WswMg", 20, "https://i.imgur.com/Bt3RWV7.png", "https://i.imgur.com/sRc2lqN.png"], # album image, not zoomable
310
- ["http://imgur.com/a/AdJUK", 3, "https://i.imgur.com/Yunpxnx.jpg", "https://i.imgur.com/2epn2nT.jpg"], # needs https because of authorship # WAT?
311
- ["http://imgur.com/gallery/vR4Am", 7, "https://i.imgur.com/yuUQI25.jpg", "https://i.imgur.com/RdxyAMQ.jpg"],
312
- ["http://imgur.com/gallery/qP2RQtL", "https://i.imgur.com/qP2RQtL.png"], # single image gallery?
313
- ["http://imgur.com/gallery/nKAwE/new", 28, "https://i.imgur.com/VQhR8hB.jpg", "https://i.imgur.com/axlzNRL.jpg"],
314
- ["http://m.imgur.com/rarOohr", "https://i.imgur.com/rarOohr.jpg"],
315
- ["http://imgur.com/r/wallpaper/j39dKMi", "https://i.imgur.com/j39dKMi.jpg?1"],
316
- ["http://imgur.com/gallery/jm0OKQM", DirectLink::ErrorNotFound], # this id does not belong to gallery but to an image, that is probably irrelevant
317
- ["http://imgur.com/gallery/oZXfZ", DirectLink::ErrorNotFound], # this id does not belong to gallery but to an album, that is probably irrelevant
318
- ["http://imgur.com/gallery/dCQprEq/new", "https://i.imgur.com/dCQprEq.jpg", 5760, 3840, "image/jpeg"],
319
- ["https://imgur.com/S5u2xRB?third_party=1#_=_", "https://i.imgur.com/S5u2xRB.jpg", 2448, 2448, "image/jpeg"],
320
- ["https://imgur.com/3eThW", "https://i.imgur.com/3eThW.jpg", 2560, 1600, "image/jpeg"],
321
- ["https://i.imgur.com/RGO6i.mp4", "https://i.imgur.com/RGO6i.gif", 339, 397, "image/gif"],
322
- ["https://imgur.com/a/oacI3gl", 2, "https://i.imgur.com/9j4KdkJ.png", "https://i.imgur.com/QpOBvRY.png"],
323
- ["https://i.imgur.com/QpOBvRY.png", "https://i.imgur.com/QpOBvRY.png", 460, 460, "image/png"],
324
- # some other tests not sure we need them
325
- ["http://i.imgur.com/7xcxxkR.gifv", "http://i.imgur.com/7xcxxkRh.gif"],
326
- ["http://imgur.com/HQHBBBD", "https://i.imgur.com/HQHBBBD.jpg", 1024, 768, "image/jpeg"],
327
- ["http://imgur.com/a/AdJUK", 3, "https://i.imgur.com/Yunpxnx.jpg", "https://i.imgur.com/2epn2nT.jpg", "https://i.imgur.com/3afw2aF.jpg"],
328
- ["https://imgur.com/9yaMdJq", "https://i.imgur.com/9yaMdJq.mp4", 720, 404, "video/mp4"],
329
- ["http://imgur.com/gallery/dCQprEq/new", "https://i.imgur.com/dCQprEq.jpg", 5760, 3840, "image/jpeg"],
330
- ["https://i.imgur.com/fFUTSJu.jpg?fb", "https://i.imgur.com/fFUTSJu.jpg", 1469, 2200, "image/jpeg"], # from reddit.com/93mtba
331
- ].each_with_index do |t, i|
332
- url, n, first, last, type = t
333
- it "##{i + 1}" do
334
- case last
335
- when NilClass
336
- if n.is_a? Class
337
- assert_raises n do
338
- DirectLink.imgur url
339
- end
340
- else
341
- real = DirectLink.imgur url
342
- assert_equal 1, real.size
343
- assert_equal n, real.first.first
344
- end
345
- when Numeric
346
- real = DirectLink.imgur url
347
- assert_equal 1, real.size
348
- assert_equal [n, first, last, type], real.first
349
- when String
350
- real = DirectLink.imgur url
351
- assert_equal n, real.size
352
- assert_equal first, real.first.first
353
- assert_equal last, real.last.first
354
- else
355
- fail "bug in tests"
356
- end
357
- end
358
- end
359
- end
360
-
361
- # TODO we need tests that check we really get dimensions from `DirectLink()` method called on wiki and reddit links
362
- # and maaaaybe move some tests from here to the context about giveup
363
- [
364
- [ :_500px, [
365
- ["https://500px.com/photo/264092015/morning-rider-by-tiger-seo", [1200, 800, "https://drscdn.500px.org/photo/264092015/m%3D900/v2?sig=68a9206477f573d8e2838faa6a929e7267f22dc5f9e98f1771f7a8a63efa2ed7", "jpeg"]],
366
- ] ],
367
- [ :flickr, [
368
- ["https://www.flickr.com/photos/tomas-/17220613278/", DirectLink::ErrorNotFound],
369
- ["https://www.flickr.com/photos/16936123@N07/18835195572", DirectLink::ErrorNotFound],
370
- ["https://www.flickr.com/photos/44133687@N00/17380073505/", [3000, 2000, "https://live.staticflickr.com/7757/17380073505_ed5178cc6a_o.jpg"]], # trailing slash
371
- ["https://www.flickr.com/photos/jacob_schmidt/18414267018/in/album-72157654235845651/", DirectLink::ErrorNotFound], # username in-album
372
- ["https://www.flickr.com/photos/tommygi/5291099420/in/dateposted-public/", [1600, 1062, "https://live.staticflickr.com/5249/5291099420_29fae96e38_h.jpg"]], # username in-public
373
- ["https://www.flickr.com/photos/132249412@N02/18593786659/in/album-72157654521569061/", DirectLink::ErrorNotFound],
374
- ["https://www.flickr.com/photos/130019700@N03/18848891351/in/dateposted-public/", [4621, 3081, "https://live.staticflickr.com/3796/18848891351_f751b35aeb_o.jpg"]], # userid in-public
375
- ["https://www.flickr.com/photos/frank3/3778768209/in/photolist-6KVb92-eCDTCr-ur8K-7qbL5z-c71afh-c6YvXW-7mHG2L-c71ak9-c71aTq-c71azf-c71aq5-ur8Q-6F6YkR-eCDZsD-eCEakg-eCE6DK-4ymYku-7ubEt-51rUuc-buujQE-ur8x-9fuNu7-6uVeiK-qrmcC6-ur8D-eCEbei-eCDY9P-eCEhCk-eCE5a2-eCH457-eCHrcq-eCEdZ4-eCH6Sd-c71b5o-c71auE-eCHa8m-eCDSbz-eCH1dC-eCEg3v-7JZ4rh-9KwxYL-6KV9yR-9tUSbU-p4UKp7-eCHfwS-6KVbAH-5FrdbP-eeQ39v-eeQ1UR-4jHAGN", [4096, 2723, "https://live.staticflickr.com/2499/3778768209_dfa75a41cc_4k.jpg"]],
376
- ["https://www.flickr.com/photos/patricksloan/18230541413/sizes/l", [2048, 491, "https://live.staticflickr.com/5572/18230541413_fec4783d79_k.jpg"]],
377
- ["https://flic.kr/p/vPvCWJ", [2048, 1365, "https://live.staticflickr.com/507/19572004110_d44d1b4ead_k.jpg"]],
378
- ] ],
379
- [ :wiki, [
380
- ["https://en.wikipedia.org/wiki/Prostitution_by_country#/media/File:Prostitution_laws_of_the_world.PNG", "https://upload.wikimedia.org/wikipedia/commons/e/e8/Prostitution_laws_of_the_world.PNG"],
381
- ["https://en.wikipedia.org/wiki/Third_Party_System#/media/File:United_States_presidential_election_results,_1876-1892.svg", DirectLink::ErrorAssert],
382
- ["http://commons.wikimedia.org/wiki/File:Eduard_Bohlen_anagoria.jpg", "https://upload.wikimedia.org/wikipedia/commons/0/0d/Eduard_Bohlen_anagoria.jpg"],
383
- ["https://en.wikipedia.org/wiki/Spanish_Civil_War#/media/File:Alfonso_XIIIdeEspa%C3%B1a.jpg", "https://upload.wikimedia.org/wikipedia/commons/f/fb/Alfonso_XIIIdeEspa%C3%B1a.jpg"], # escaped input URI
384
- ["https://en.wikipedia.org/wiki/File:Tyson_Lewis.jpg", "https://upload.wikimedia.org/wikipedia/en/c/cd/Tyson_Lewis.jpg"], # exists only in en.wiki, not in commons
385
- ] ],
386
- [ :reddit, [
387
- ["https://www.reddit.com/r/cacography/comments/32tq0i/c/", [true, "http://i.imgur.com/vy6Ms4Z.jpg"]],
388
- ["http://redd.it/32tq0i", [true, "http://i.imgur.com/vy6Ms4Z.jpg"]], # TODO maybe check that it calls #imgur recursively
389
- ["https://i.redd.it/c8rk0kjywhy01.jpg", [true, "https://i.redd.it/c8rk0kjywhy01.jpg"]],
390
- ["https://i.redd.it/si758zk7r5xz.jpg", [true, "https://i.redd.it/si758zk7r5xz.jpg"]], # it is 404 but `.reddit` does not care -- it just returns the url
391
- ["https://reddit.com/123456", [true, "https://i.ytimg.com/vi/b9upM4RbIeU/hqdefault.jpg"]],
392
- # ["https://www.reddit.com/r/travel/988889", [true, "https://i.redd.it/3h5xls6ehrg11.jpg"]],
393
- ["http://redd.it/988889", [true, "https://i.redd.it/3h5xls6ehrg11.jpg"]],
394
- ["https://www.reddit.com/r/CatsStandingUp/duplicates/abn0ua/cat/", [true, "https://v.redd.it/s9b86afb6w721/DASH_2_4_M?source=fallback"]],
395
- ["https://www.reddit.com/r/hangers/comments/97you5/tara_radovic/", [true, "https://i.imgur.com/rbLqgOu.jpg"]], # "crossport" from Imgur
396
- ] ],
397
- [ :vk, [
398
- ["https://vk.com/wall-105984091_7806", [960, 1280, "https://sun9-41.userapi.com/c855224/v855224900/a72f1/7OZ8ux9Wcwo.jpg"]],
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-185182611_454?z=photo-185182611_457239340%2Fwall-185182611_454", [1280, 960, "https://sun9-46.userapi.com/c851028/v851028578/1a62f6/VB4SdR1O6Tg.jpg"]],
401
- ["https://vk.com/wall-105984091_7946?z=photo-105984091_457243312%2Falbum-105984091_00%2Frev", [1280, 875, "https://sun9-37.userapi.com/c852020/v852020134/1b6b36/0IsDFb-Hda4.jpg"]],
402
- ["https://vk.com/photo533531776_456239427?all=1", [750, 938, "https://sun9-25.userapi.com/c849416/v849416600/14b949/V01Ch1gYjhc.jpg"]],
403
- ["https://vk.com/photo-155488973_456242404", [1486, 1000, "https://sun9-7.userapi.com/c852132/v852132877/8578e/m6AJWiskiKE.jpg"]],
404
- ["https://vk.com/id2272074?z=photo2272074_264578776%2Fphotos2272074", [604, 484, "https://sun9-10.userapi.com/c10472/u2272074/-7/x_407b2ba2.jpg"]],
405
- ["https://vk.com/feed?section=likes&z=photo-117564754_456261460%2Fliked3902406", [1024, 1335, "https://sun9-72.userapi.com/c854028/v854028353/895b6/izQJresLdf0.jpg"]],
406
- ["https://vk.com/likizimy?z=photo-42543351_456239941%2Fwall-42543351_1908", [1179, 1731, "https://sun9-47.userapi.com/c855036/v855036571/60f7b/ryCPJIMyMkI.jpg"]],
407
- ["https://vk.com/e_rod?z=photo298742340_457247118%2Fphotos298742340", [1728, 2160, "https://sun9-53.userapi.com/c858320/v858320596/c7714/oImGe4o1ZJI.jpg"]],
408
- ] ],
409
- ].each do |method, tests|
410
- next if method == :vk && ENV.include?("TRAVIS")
411
- describe method do
412
- tests.each_with_index do |(input, expectation), i|
413
- it "#{method} ##{i + 1}" do
414
- if expectation.is_a? Class
415
- assert_raises expectation, input do
416
- DirectLink.method(method).call input
417
- end
418
- else
419
- result = DirectLink.method(method).call input
420
- assert_equal expectation, result, "#{input} :: #{result.inspect} != #{expectation.inspect}"
421
- end
422
- end
423
- end
424
- end
425
- end
426
-
427
- {
428
- google: [
429
- "https://lh3.googleusercontent.com/-NVJgqmI_2Is/WqMM2OMYg-I/AAAAAAAALrk/5-p3JL3iZt0Ho9dOf_p3gpddzqwr3Wp0ACJoC/w424-h318-n/001",
430
- "//lh3.googleusercontent.com/proxy/DZtTi5KL7PqiBwJc8weNGLk_Wi2UTaQH0AC_h2kuURiu0AbwyI2ywOk2XgdAjL7ceg=w530-h354-n",
431
- "//1.bp.blogspot.com/-rYk_u-qROQc/WngolJ8M0LI/AAAAAAAAD-w/woivnaIVzasBPG5C2T1t-VrWKRd_U6lMgCLcBGAs/w530-h278-p/i-469.jpg",
432
- "https://2.bp.blogspot.com/-rb2PXLGZy0s/W2nQe3mXOSI/AAAAAAAARhQ/P8gV-bMtYbY2xxpTJNcYVxu3XDTUaugxQCLcBGAs/s640/beach-bora-bora-clouds-753626.jpg",
433
- "http://4.bp.blogspot.com/-poH-QXn7YGg/U-3ZTDkeF_I/AAAAAAAAISE/ms2gNIb-v-g/w72-h72-p-k-no-nu/Top-24-Inspired-181.jpg",
434
- "https://lh5.googleusercontent.com/FcYUQBKLXWtFLEvbQduvu7FHUm2f7U_MVdMBVnNbpwfzKHIU-xABkudxw-m21SlM0jFYRHedh7Is5Dg6qlgIQF1iSndlWjiKCTTsUo1w=s1080",
435
- ],
436
- imgur: [
437
- ["https://imgur.com/3eThW", "https://imgur.com/3eThW"],
438
- ["https://i.imgur.com/3eThW", "https://imgur.com/3eThW"],
439
- ["https://m.imgur.com/3eThW", "https://imgur.com/3eThW"],
440
- ["https://www.imgur.com/3eThW", "https://imgur.com/3eThW"],
441
- ["https://goo.gl/ySqUb5", "https://i.imgur.com/QpOBvRY.png"],
442
- ],
443
- _500px: [
444
- %w{ https://500px.com/photo/112134597/milky-way-by-tom-hall https://web.500px.com/photo/112134597/milky-way-by-tom-hall? },
445
- ],
446
- flickr: [
447
- "https://www.flickr.com/photos/59880970@N07/15773941043/in/dateposted-public/",
448
- ["https://flic.kr/p/vPvCWJ", "https://www.flickr.com/photos/mlopezphotography/19572004110/"],
449
- ],
450
- wiki: [
451
- "https://en.wikipedia.org/wiki/Third_Party_System#/media/File:United_States_presidential_election_results,_1876-1892.svg",
452
- ["http://commons.wikimedia.org/wiki/File:Eduard_Bohlen_anagoria.jpg", "https://commons.wikimedia.org/wiki/File:Eduard_Bohlen_anagoria.jpg"],
453
- ],
454
- reddit: [
455
- "https://www.reddit.com/r/cacography/comments/32tq0i/c/",
456
- ["http://redd.it/32tq0i", "https://www.reddit.com/comments/32tq0i"],
457
- ["https://reddit.com/123456", "https://www.reddit.com/r/funny/comments/123456/im_thinking_about_getting_a_dog_and_youtubed_ways/"],
458
- # ["https://www.reddit.com/r/travel/988889", "https://www.reddit.com/r/travel/comments/988889/playa_miramar_in_guaymas_sonora/"],
459
- "https://www.reddit.com/r/KsyushaEgorova/comments/beuqs2/a_little_shy/", # NSFW causes redirect to /over_18? if the special cookie not provided
460
- ],
461
- vk: [
462
- "https://vk.com/id57030827?z=photo57030827_456241143",
463
- ],
464
- }.each do |method, tests|
465
- describe "DirectLink() calls #{method}" do
466
- tests.each_with_index do |(input, expected), i|
467
- it "##{i + 1}" do
468
- DirectLink.stub method, ->link{
469
- assert_equal (expected || input), link
470
- throw :_
471
- } do
472
- catch :_ do
473
- DirectLink input
474
- fail "DirectLink.#{method} was not called"
475
- end
476
- end
477
- end
478
- end
479
- end
480
- end
481
-
482
- # TODO: make a Reddit describe
483
- it "retries limited amout of times on error JSON::ParserError" do
484
- link = "https://www.reddit.com/r/gifs/comments/9ftc8f/low_pass_wake_vortices/?st=JM2JIKII&sh=c00fea4f"
485
- tries = 0
486
- m = NetHTTPUtils.method :request_data
487
- e = assert_raises DirectLink::ErrorBadLink do
488
- NetHTTPUtils.stub :request_data, lambda{ |*args|
489
- if args.first == "https://www.reddit.com/9ftc8f.json"
490
- tries += 1
491
- raise JSON::ParserError
492
- end
493
- # this gem call should never return success -- it should experience JSON::ParserError
494
- # so I'm not much sure why do we need this line
495
- m.call *args
496
- } do
497
- # why?
498
- t = ENV.delete "REDDIT_SECRETS"
499
- begin
500
- DirectLink.reddit link, 3 # do not remove `4` or test will hang
501
- ensure
502
- ENV["REDDIT_SECRETS"] = t
503
- end
504
- end
505
- end
506
- assert_instance_of JSON::ParserError, e.cause if Exception.instance_methods.include? :cause # Ruby 2.1
507
- assert_equal 3, tries
508
- end
509
- it "Reddit correctly parses out id when no token provided" do
510
- # this URL isn't supposed to not throw exception -- FastImage does not handle this media type (see the next test)
511
- t = ENV.delete "REDDIT_SECRETS"
512
- FastImage.stub :new, lambda{ |link, *|
513
- assert_equal "https://v.redd.it/2tyovczka8m11/DASH_4_8_M?source=fallback", link
514
- throw :_
515
- } do
516
- begin
517
- catch :_ do
518
- DirectLink "https://www.reddit.com/r/gifs/comments/9ftc8f/low_pass_wake_vortices/?st=JM2JIKII&sh=c00fea4f"
519
- end
520
- ensure
521
- ENV["REDDIT_SECRETS"] = t
522
- end
523
- end
524
- end
525
- it "it is really impossible to get dimensions from the shitty Reddit media hosting" do
526
- # TODO: why does it call the same Net::HTTP::Get twice?
527
- assert_raises FastImage::UnknownImageType do
528
- DirectLink "https://v.redd.it/2tyovczka8m11/DASH_4_8_M"
529
- end
530
- end
531
-
532
- describe "throws ErrorBadLink if method does not match the link" do
533
- %i{ google imgur flickr _500px wiki reddit vk }.each do |method|
534
- ["", "test", "http://example.com/"].each_with_index do |url, i|
535
- it "#{method} ##{i + 1}" do
536
- assert_raises DirectLink::ErrorBadLink do
537
- DirectLink.method(method).call url
538
- end
539
- end
540
- end
541
- end
542
- end
543
-
544
- # TODO: test each webservice-specific method
545
- # TODO: check not in OpenSSL but higher -- in Net::HTTP
546
- it "does not cause the SystemStackError" do
547
- OpenSSL::Buffering.module_eval do
548
- old = instance_method :write
549
- depths = []
550
- define_method :write do |arg|
551
- depths.push caller.size
552
- raise "probable infinite recursion" if [1]*10 == depths.each_cons(2).map{ |i,j| j-i } if depths.size > 10
553
- old.bind(self).(arg)
554
- end
555
- end
556
- DirectLink "https://i.redd.it/gdo0cnmeagx01.jpg"
557
- end
558
-
559
- end
560
-
561
- describe "DirectLink()" do
562
-
563
- it "does not raise JSON::ParserError -- Reddit sucks and may respond with wrong content type" do
564
- DirectLink.reddit "https://www.reddit.com/123456" # just to initialize DirectLink.reddit_bot
565
- # I don't remember for what though
566
- # oh, maybe to avoid rasing in initializer
567
- # but why not?
568
- limit = 0
569
- loop do
570
- limit += 1
571
- tries = 0
572
- m = JSON.method :load
573
- JSON.stub :load, ->*args{
574
- if limit == tries += 1
575
- raise JSON::ParserError
576
- else
577
- m.call *args
578
- end
579
- } do
580
- t = ENV.delete "REDDIT_SECRETS"
581
- begin
582
- DirectLink.reddit "https://www.reddit.com/123456"
583
- ensure
584
- ENV["REDDIT_SECRETS"] = t
585
- end
586
- end
587
- break if 1 == tries
588
- end
589
- assert_equal 2, limit, "`JSON.load` was called only once?!"
590
- end
591
-
592
- # thanks to gem addressable
593
- it "does not throw URI::InvalidURIError if there are brackets" do
594
- assert_equal 404, (
595
- assert_raises NetHTTPUtils::Error do
596
- DirectLink "https://www.flickr.com/photos/leogaggl/28488925847/%20[2048x1152]"
597
- end.code
598
- )
599
- end
600
-
601
- it "throws ErrorBadLink if link is invalid" do
602
- assert_equal "test".inspect, (
603
- assert_raises DirectLink::ErrorBadLink do
604
- DirectLink "test"
605
- end
606
- ).message
607
- end
608
-
609
- describe "does not shadow the internal exception" do
610
- [
611
- SocketError,
612
- Errno::ECONNRESET,
613
- ].each do |exception|
614
- it "raises #{exception} from the redirect resolving stage" do
615
- assert_raises exception do
616
- NetHTTPUtils.stub :request_data, ->*{ raise exception.new } do
617
- DirectLink "http://example.com/404"
618
- end
619
- end
620
- end
621
- end
622
- it "raises Net::OpenTimeout -- server side issues can happen (not related to User Agent)" do
623
- assert_raises Net::OpenTimeout do
624
- NetHTTPUtils.stub :request_data, ->*{ raise Net::OpenTimeout.new } do
625
- DirectLink "http://example.com/404"
626
- end
627
- end
628
- end
629
- [ # TODO this URLs may be reused from tests that check that this method calls internal method
630
- [:google, "//lh3.googleusercontent.com/proxy/DZtTi5KL7PqiBwJc8weNGLk_Wi2UTaQH0AC_h2kuURiu0AbwyI2ywOk2XgdAjL7ceg=w530-h354-n"],
631
- [:imgur, "http://imgur.com/HQHBBBD"],
632
- [:flickr, "https://www.flickr.com/photos/44133687@N00/17380073505/"],
633
- [:_500px, "https://500px.com/photo/112134597/milky-way-by-tom-hall"],
634
- [:wiki, "http://commons.wikimedia.org/wiki/File:Eduard_Bohlen_anagoria.jpg"],
635
- [:reddit, "https://www.reddit.com/123456"],
636
- [:vk, "https://vk.com/"],
637
- ].each do |method, link|
638
- it "can otherwise raise DirectLink::ErrorBadLink #{method}" do
639
- e = assert_raises(DirectLink::ErrorBadLink, link) do
640
- DirectLink.stub method, ->*{ raise DirectLink::ErrorBadLink.new "test" } do
641
- DirectLink link
642
- end
643
- end
644
- assert_equal "\"test\" -- if you think this link is valid, please report the issue", e.message
645
- end
646
- end
647
- end
648
-
649
- describe "other domains tests" do
650
- [
651
- ["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], nil, 1],
652
- # ["http://minus.com/lkP3hgRJd9npi", SocketError, /nodename nor servname provided, or not known|No address associated with hostname/, 0],
653
- ["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],
654
- ].each_with_index do |(input, expectation, message_string_or_regex, max_redirect_resolving_retry_delay), i|
655
- it "##{i + 1}" do
656
- if expectation.is_a? Class
657
- e = assert_raises expectation, "for #{input}" do
658
- DirectLink input, max_redirect_resolving_retry_delay
659
- end
660
- if message_string_or_regex.is_a? String
661
- assert_equal message_string_or_regex, e.message, "for #{input}"
662
- else
663
- assert_match message_string_or_regex, e.message, "for #{input}"
664
- end
665
- else
666
- u, w, h, t = expectation
667
- result = DirectLink input, max_redirect_resolving_retry_delay
668
- assert_equal DirectLink.class_variable_get(:@@directlink).new(u, w, h, t), result, "for #{input}"
669
- end
670
- end
671
- end
672
- end
673
-
674
- describe "giving up" do
675
- [
676
- ["http://example.com", FastImage::UnknownImageType],
677
- ["https://www.tic.com/index.html", FastImage::UnknownImageType, true],
678
- ["https://www.tic.com/index.html", 2],
679
- ["http://imgur.com/HQHBBBD", FastImage::UnknownImageType, true],
680
- ["http://imgur.com/HQHBBBD", "https://i.imgur.com/HQHBBBD.jpg?fb"], # .at_css("meta[@property='og:image']")
681
- ["https://www.deviantart.com/nadyasonika/art/Asuka-Langley-Beach-Time-590134861", FastImage::UnknownImageType, true],
682
- ["https://www.deviantart.com/nadyasonika/art/Asuka-Langley-Beach-Time-590134861", "https://images-wixmp-ed30a86b8c4ca887773594c2.wixmp.com/f/943f66cb-78ad-40f2-a086-44420b98b431/d9rcmz1-5cbc5670-0193-485b-ac14-755ddb9562f4.jpg/v1/fill/w_1024,h_732,q_75,strp/asuka_langley_beach_time_by_nadyasonika_d9rcmz1-fullview.jpg?token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ1cm46YXBwOjdlMGQxODg5ODIyNjQzNzNhNWYwZDQxNWVhMGQyNmUwIiwiaXNzIjoidXJuOmFwcDo3ZTBkMTg4OTgyMjY0MzczYTVmMGQ0MTVlYTBkMjZlMCIsIm9iaiI6W1t7ImhlaWdodCI6Ijw9NzMyIiwicGF0aCI6IlwvZlwvOTQzZjY2Y2ItNzhhZC00MGYyLWEwODYtNDQ0MjBiOThiNDMxXC9kOXJjbXoxLTVjYmM1NjcwLTAxOTMtNDg1Yi1hYzE0LTc1NWRkYjk1NjJmNC5qcGciLCJ3aWR0aCI6Ijw9MTAyNCJ9XV0sImF1ZCI6WyJ1cm46c2VydmljZTppbWFnZS5vcGVyYXRpb25zIl19.M-a_heYtVPwnR4eC9KIPk2mIYeNzEaTg4b4jqr_GwyI"],
683
- ["https://calgary.skyrisecities.com/news/2019/11/blue-morning-light", "https://cdn.skyrisecities.com/sites/default/files/images/articles/2019/11/39834/39834-132071.jpg"], # og:image without scheme
684
- ["https://www.reddit.com/r/darksouls3/comments/e59djh/hand_it_over_that_thing_your_wallpaper/", DirectLink::ErrorBadLink, true],
685
- ["https://www.reddit.com/r/darksouls3/comments/e59djh/hand_it_over_that_thing_your_wallpaper/", 6],
686
- ].each_with_index do |(input, expectation, giveup), i|
687
- it "##{i + 1} (#{URI(input).host}) (giveup=#{!!giveup})" do # to match with minitest `-n` run flag
688
- ti = ENV.delete "IMGUR_CLIENT_ID" if %w{ imgur com } == URI(input).host.split(?.).last(2)
689
- tr = ENV.delete "REDDIT_SECRETS" if %w{ reddit com } == URI(input).host.split(?.).last(2)
690
- begin
691
- case expectation
692
- when Class
693
- e = assert_raises expectation, "for #{input} (giveup = #{giveup})" do
694
- DirectLink input, nil, giveup: giveup
695
- end
696
- assert_equal expectation.to_s, e.class.to_s, "for #{input} (giveup = #{giveup})"
697
- when String
698
- result = DirectLink input, nil, giveup: giveup
699
- assert_equal expectation, result.url, "for #{input} (giveup = #{giveup})"
700
- else
701
- result = DirectLink input, nil, giveup: giveup
702
- result = [result] unless result.is_a? Array # we can't do `Array(<Struct>)` because it splats by elements
703
- assert_equal expectation, result.size, ->{
704
- "for #{input} (giveup = #{giveup}): #{result.map &:url}"
705
- }
706
- end
707
- ensure
708
- ENV["IMGUR_CLIENT_ID"] = ti if ti
709
- ENV["REDDIT_SECRETS"] = tr if tr
710
- end
711
- end
712
- end
713
- end
714
-
715
- end
716
-
717
- describe "./bin" do
718
- require "open3"
719
-
720
- describe "shows usage help if misused" do
721
- [
722
- [/\Ausage: directlink \[--debug\] \[--json\] \[--github\] \[--ignore-meta\] <link1> <link2> <link3> \.\.\.\ndirectlink version \d\.\d\.\d\.\d\d? \(https:\/\/github\.com\/nakilon\/directlink\)\n\z/, nil],
723
- [/\Ausage: directlink \[--debug\] \[--json\] \[--github\] \[--ignore-meta\] <link1> <link2> <link3> \.\.\.\ndirectlink version \d\.\d\.\d\.\d\d? \(https:\/\/github\.com\/nakilon\/directlink\)\n\z/, "-h"],
724
- [/\Ausage: directlink \[--debug\] \[--json\] \[--github\] \[--ignore-meta\] <link1> <link2> <link3> \.\.\.\ndirectlink version \d\.\d\.\d\.\d\d? \(https:\/\/github\.com\/nakilon\/directlink\)\n\z/, "--help"],
725
- [/\Ausage: directlink \[--debug\] \[--json\] \[--github\] \[--ignore-meta\] <link1> <link2> <link3> \.\.\.\ndirectlink version \d\.\d\.\d\.\d\d? \(https:\/\/github\.com\/nakilon\/directlink\)\n\z/, "-v"],
726
- [/\Ausage: directlink \[--debug\] \[--json\] \[--github\] \[--ignore-meta\] <link1> <link2> <link3> \.\.\.\ndirectlink version \d\.\d\.\d\.\d\d? \(https:\/\/github\.com\/nakilon\/directlink\)\n\z/, "--version"],
727
- ["DirectLink::ErrorBadLink: \"--\"\n", "--"],
728
- ["DirectLink::ErrorBadLink: \"-\"\n", "-"],
729
- ["DirectLink::ErrorBadLink: \"-\"\n", "- -"],
730
- ["DirectLink::ErrorBadLink: \"asd\"\n", "asd"],
731
- ].each_with_index do |(expectation, param), i|
732
- it "##{i + 1}" do
733
- string, status = Open3.capture2e "RUBYOPT='-rbundler/setup' ./bin/directlink #{param}"
734
- if expectation.is_a? String
735
- assert_equal expectation, string
736
- else
737
- assert_match expectation, string
738
- end
739
- assert_equal 1, status.exitstatus
740
- end
741
- end
742
- end
743
-
744
- # that hack around `export` is for crossplatform Travis test, since Ubuntu uses `sh` that can't `source`
745
- # TODO: but maybe I could make Open3 use the shell I need, since `source` works fine for `.travis.yaml`'s `:script`
746
-
747
- describe "fails" do
748
- [
749
- [1, "http://example.com/", "FastImage::UnknownImageType"],
750
- [1, "http://example.com/404", "NetHTTPUtils::Error: HTTP error #404 "],
751
-
752
- # TODO: a test when the giveup=false fails and reraises the DirectLink::ErrorMissingEnvVar
753
- # maybe put it to ./lib tests
754
-
755
- # by design it should be impossible to write a test for DirectLink::ErrorAssert
756
- [1, "https://flic.kr/p/DirectLinkErrorNotFound", "NetHTTPUtils::Error: HTTP error #404 "],
757
-
758
- [1, "https://imgur.com/a/badlinkpattern", "NetHTTPUtils::Error: HTTP error #404 "],
759
- # TODO: a test that it appends the `exception.cause`
760
- ].each_with_index do |(expected_exit_code, link, expected_output, unset), i| # TODO: unset is not used anymore or I have to go sleep?
761
- it "##{i + 1}" do
762
- string, status = Open3.capture2e "export #{(File.read("api_tokens_for_travis.sh") + File.read("vk.secret")).scan(/(?<=^export )\S+=\S+/).join(" ")}#{unset} && RUBYOPT='-rbundler/setup #{$-I.map{ |i| "-I #{i}" }.join " "}' ./bin/directlink #{link}"
763
- assert_equal [expected_exit_code, "#{expected_output}\n"], [status.exitstatus, string], "for #{link}"
764
- end
765
- end
766
- end
767
-
768
- valid_imgur_image_url1 = "https://goo.gl/ySqUb5"
769
- valid_imgur_image_url2 = "https://imgur.com/a/oacI3gl"
770
- [
771
- ["<= #{valid_imgur_image_url1}
772
- => https://i.imgur.com/QpOBvRY.png
773
- image/png 460x460
774
- <= #{valid_imgur_image_url2}
775
- => https://i.imgur.com/QpOBvRY.png
776
- image/png 460x460
777
- => https://i.imgur.com/9j4KdkJ.png
778
- image/png 100x100
779
- ".gsub(/^ {8}/, "")],
780
- ['[
781
- {
782
- "url": "https://i.imgur.com/QpOBvRY.png",
783
- "width": 460,
784
- "height": 460,
785
- "type": "image/png"
786
- },
787
- [
788
- {
789
- "url": "https://i.imgur.com/QpOBvRY.png",
790
- "width": 460,
791
- "height": 460,
792
- "type": "image/png"
793
- },
794
- {
795
- "url": "https://i.imgur.com/9j4KdkJ.png",
796
- "width": 100,
797
- "height": 100,
798
- "type": "image/png"
799
- }
800
- ]
801
- ]
802
- '.gsub(/^ {8}/, ""), "json"],
803
- ].each do |expected_output, param|
804
- it "#{param || "default"} output format" do
805
- string, status = Open3.capture2e "export #{(File.read("api_tokens_for_travis.sh") + File.read("vk.secret")).scan(/(?<=^export )\S+=\S+/).join(" ")} && RUBYOPT='-rbundler/setup' ./bin/directlink#{" --#{param}" if param} #{valid_imgur_image_url1} #{valid_imgur_image_url2}"
806
- assert_equal [0, expected_output], [status.exitstatus, string]
807
- end
808
- end
809
-
810
- it "reddit_bot gem logger does not flood STDOUT" do
811
- string, status = Open3.capture2e "RUBYOPT='-rbundler/setup' ./bin/directlink http://redd.it/997he7"
812
- assert_equal "<= http://redd.it/997he7\n=> https://i.imgur.com/QpOBvRY.png\n image/png 460x460\n", string
813
- end
814
-
815
- # TODO: test about --json
816
- it "uses <meta> tag" do
817
- string, status = Open3.capture2e "RUBYOPT='-rbundler/setup' ./bin/directlink --json https://www.kp.ru/daily/26342.7/3222103/"
818
- assert_equal [0, "https://s9.stc.all.kpcdn.net/share/i/12/8054352/cr-1200-630.wm-asnpmfru-100-tr-0-0.t-13-3222103-ttps-47-8-0083CD-1010-l-85-b-41.t-13-3222103-ttps-47-8-FFF-1010-l-85-b-42.t-207-5-asb-37-10-FFF-788-l-370-t-68.m2018-03-14x02-10-20.jpg"], [status.exitstatus, JSON.load(string).fetch("url")]
819
- end
820
- it "ignores <meta> tag" do
821
- string, status = Open3.capture2e "RUBYOPT='-rbundler/setup' ./bin/directlink --json --ignore-meta https://www.kp.ru/daily/26342.7/3222103/"
822
- assert_equal [0, 21, "https://s11.stc.all.kpcdn.net/share/i/12/8024261/inx960x640.jpg"], [status.exitstatus, JSON.load(string).size, JSON.load(string).first.fetch("url")]
823
- end
824
-
825
- end
826
-
827
- end