gravaty 10.0.0 → 11.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +7 -0
- data/Gemfile +5 -1
- data/README.md +219 -212
- data/Rakefile +9 -3
- data/copyright.md +33 -136
- data/examples/avatar.rb +70 -43
- data/examples/basics.rb +30 -20
- data/examples/profile.rb +77 -50
- data/examples/xmlrpc.rb +24 -10
- data/gravaty.gemspec +46 -25
- data/html/CHANGELOG.html +13 -20
- data/html/COPYING_md.html +8 -24
- data/html/Gemfile.html +7 -21
- data/html/Gravaty.html +49 -113
- data/html/Gravaty/Gravaty.html +138 -343
- data/html/Gravaty/ParsableDuckType.html +14 -33
- data/html/Gravaty/Parser.html +27 -66
- data/html/Gravaty/Parsers.html +3 -11
- data/html/Gravaty/Parsers/Avatar.html +19 -36
- data/html/Gravaty/Parsers/Callback.html +21 -37
- data/html/Gravaty/Parsers/Default.html +28 -45
- data/html/Gravaty/Parsers/Force.html +21 -37
- data/html/Gravaty/Parsers/Format.html +22 -42
- data/html/Gravaty/Parsers/Pixelsize.html +22 -42
- data/html/Gravaty/Parsers/Rating.html +22 -42
- data/html/Gravaty/Parsers/Secure.html +19 -36
- data/html/Gravaty/Parsers/Type.html +22 -42
- data/html/Gravaty/Utils.html +11 -13
- data/html/Gravaty/Utils/Downloader.html +3 -11
- data/html/Gravaty/Utils/Downloader/Downloader.html +25 -59
- data/html/Gravaty/Utils/Raisers.html +24 -55
- data/html/Gravaty/Utils/Rfc5322.html +12 -19
- data/html/Gravaty/Utils/RpcConnector.html +11 -13
- data/html/Gravaty/Utils/RpcConnector/RpcConnector.html +33 -73
- data/html/Object.html +728 -57
- data/html/README_md.html +105 -100
- data/html/Rakefile.html +9 -23
- data/html/copyright_md.html +17 -119
- data/html/created.rid +48 -55
- data/html/css/rdoc.css +1 -1
- data/html/index.html +97 -114
- data/html/js/navigation.js.gz +0 -0
- data/html/js/search_index.js +1 -1
- data/html/js/search_index.js.gz +0 -0
- data/html/js/searcher.js.gz +0 -0
- data/html/table_of_contents.html +219 -651
- data/lib/gravaty.rb +22 -15
- data/lib/gravaty/application.rb +40 -25
- data/lib/gravaty/constants.rb +20 -11
- data/lib/gravaty/locales/en.yml +9 -3
- data/lib/gravaty/locales/it.yml +9 -3
- data/lib/gravaty/locales/ja.yml +7 -4
- data/lib/gravaty/parser.rb +16 -10
- data/lib/gravaty/parsers/avatar.rb +11 -3
- data/lib/gravaty/parsers/callback.rb +13 -4
- data/lib/gravaty/parsers/default.rb +24 -16
- data/lib/gravaty/parsers/force.rb +12 -2
- data/lib/gravaty/parsers/format.rb +11 -2
- data/lib/gravaty/parsers/pixelsize.rb +12 -3
- data/lib/gravaty/parsers/rating.rb +12 -3
- data/lib/gravaty/parsers/secure.rb +11 -2
- data/lib/gravaty/parsers/type.rb +11 -2
- data/lib/gravaty/utils/downloader.rb +98 -96
- data/lib/gravaty/utils/raisers.rb +19 -12
- data/lib/gravaty/utils/rfc5322.rb +54 -41
- data/lib/gravaty/utils/rpc_connector.rb +19 -11
- data/lib/gravaty/version.rb +10 -2
- data/test/gravaty/locales/en.yml +29 -0
- data/test/gravaty/locales/it.yml +29 -0
- data/test/gravaty/locales/ja.yml +27 -0
- data/test/gravaty/locales/test_locales.rb +17 -13
- data/test/gravaty/parsers/test_avatar.rb +9 -1
- data/test/gravaty/parsers/test_callback.rb +12 -4
- data/test/gravaty/parsers/test_default.rb +25 -21
- data/test/gravaty/parsers/test_force.rb +9 -1
- data/test/gravaty/parsers/test_format.rb +18 -11
- data/test/gravaty/parsers/test_pixelsize.rb +19 -12
- data/test/gravaty/parsers/test_rating.rb +18 -11
- data/test/gravaty/parsers/test_secure.rb +9 -1
- data/test/gravaty/parsers/test_type.rb +14 -5
- data/test/gravaty/test_application.rb +14 -6
- data/test/gravaty/test_avatar.rb +94 -59
- data/test/gravaty/test_parser.rb +11 -5
- data/test/gravaty/test_profile.rb +47 -25
- data/test/gravaty/utils/test_downloader.rb +43 -28
- data/test/gravaty/utils/test_raisers.rb +42 -26
- data/test/gravaty/utils/test_rfc5322.rb +35 -13
- data/test/gravaty/utils/test_rpc_connector.rb +83 -39
- data/test/test_gravaty.rb +12 -4
- data/test/test_helper.rb +15 -9
- metadata +54 -40
- data/ISSUES.md +0 -62
- data/acknowledgements.md +0 -66
- data/authors.md +0 -63
- data/examples/cacert.pem +0 -3466
- data/html/ISSUES_md.html +0 -166
- data/html/acknowledgements_md.html +0 -161
- data/html/authors_md.html +0 -174
- data/html/examples/cacert_pem.html +0 -1078
@@ -1,6 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
#--
|
2
4
|
# gravaty
|
3
|
-
#
|
5
|
+
# rubocop:disable Style/AsciiComments
|
6
|
+
# © 2013 Marco Bresciani
|
7
|
+
# rubocop:enable Style/AsciiComments
|
4
8
|
#
|
5
9
|
# This file is part of gravaty.
|
6
10
|
#
|
@@ -16,20 +20,24 @@
|
|
16
20
|
#
|
17
21
|
# You should have received a copy of the GNU General Public License
|
18
22
|
# along with gravaty. If not, see <http://www.gnu.org/licenses/>.
|
23
|
+
#
|
24
|
+
# SPDX-FileCopyrightText: 2013 Marco Bresciani
|
25
|
+
#
|
26
|
+
# SPDX-License-Identifier: GPL-3.0-or-later
|
19
27
|
#++
|
20
28
|
|
21
29
|
module Gravaty
|
22
30
|
module Parsers
|
23
|
-
|
24
31
|
# This class is an implementation of the Parsable duck type that
|
25
32
|
# checks for avater or profile URI. The only needed parameter is a
|
26
33
|
# boolean, with +true+ for avatar.
|
27
34
|
#
|
28
35
|
# Author:: {Marco Bresciani}[mailto:marcobresciani_1974@libero.it]
|
36
|
+
# rubocop:disable Style/AsciiComments
|
29
37
|
# Copyright:: Copyright © 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020 Marco Bresciani
|
38
|
+
# rubocop:enable Style/AsciiComments
|
30
39
|
# License:: GNU General Public License version 3
|
31
40
|
class Avatar
|
32
|
-
|
33
41
|
# The parsable duck type interface to every parser usage.
|
34
42
|
def parse(value = true)
|
35
43
|
value ? 'avatar/' : ''
|
@@ -1,6 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
#--
|
2
4
|
# gravaty
|
3
|
-
#
|
5
|
+
# rubocop:disable Style/AsciiComments
|
6
|
+
# © 2013 Marco Bresciani
|
7
|
+
# rubocop:enable Style/AsciiComments
|
4
8
|
#
|
5
9
|
# This file is part of gravaty.
|
6
10
|
#
|
@@ -16,23 +20,28 @@
|
|
16
20
|
#
|
17
21
|
# You should have received a copy of the GNU General Public License
|
18
22
|
# along with gravaty. If not, see <http://www.gnu.org/licenses/>.
|
23
|
+
#
|
24
|
+
# SPDX-FileCopyrightText: 2013 Marco Bresciani
|
25
|
+
#
|
26
|
+
# SPDX-License-Identifier: GPL-3.0-or-later
|
19
27
|
#++
|
20
28
|
|
21
29
|
module Gravaty
|
22
30
|
module Parsers
|
23
|
-
|
24
31
|
# This class is an implementation of the Parsable duck type that
|
25
32
|
# provides the callback name. The only needed parameter is a valid
|
26
33
|
# callback +String+ name.
|
27
34
|
#
|
28
35
|
# Author:: {Marco Bresciani}[mailto:marcobresciani_1974@libero.it]
|
36
|
+
# rubocop:disable Style/AsciiComments
|
29
37
|
# Copyright:: Copyright © 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020 Marco Bresciani
|
38
|
+
# rubocop:enable Style/AsciiComments
|
30
39
|
# License:: GNU General Public License version 3
|
31
40
|
class Callback
|
32
|
-
|
33
41
|
# The parsable duck type interface to every parser usage.
|
34
42
|
def parse(value = nil)
|
35
|
-
return "callback=#{value}" unless value.nil?
|
43
|
+
return "callback=#{value}" unless value.nil? || value.empty?
|
44
|
+
|
36
45
|
''
|
37
46
|
end
|
38
47
|
end
|
@@ -1,6 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
#--
|
2
4
|
# gravaty
|
3
|
-
#
|
5
|
+
# rubocop:disable Style/AsciiComments
|
6
|
+
# © 2013 Marco Bresciani
|
7
|
+
# rubocop:enable Style/AsciiComments
|
4
8
|
#
|
5
9
|
# This file is part of gravaty.
|
6
10
|
#
|
@@ -16,6 +20,10 @@
|
|
16
20
|
#
|
17
21
|
# You should have received a copy of the GNU General Public License
|
18
22
|
# along with gravaty. If not, see <http://www.gnu.org/licenses/>.
|
23
|
+
#
|
24
|
+
# SPDX-FileCopyrightText: 2013 Marco Bresciani
|
25
|
+
#
|
26
|
+
# SPDX-License-Identifier: GPL-3.0-or-later
|
19
27
|
#++
|
20
28
|
|
21
29
|
require 'cgi'
|
@@ -24,26 +32,26 @@ require_relative '../constants'
|
|
24
32
|
|
25
33
|
module Gravaty
|
26
34
|
module Parsers
|
27
|
-
|
28
35
|
# This class is an implementation of the Parsable duck type that
|
29
36
|
# checks the default option. The only needed parameter is a valid
|
30
37
|
# default option.
|
31
38
|
#
|
32
39
|
# Author:: {Marco Bresciani}[mailto:marcobresciani_1974@libero.it]
|
40
|
+
# rubocop:disable Style/AsciiComments
|
33
41
|
# Copyright:: Copyright © 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020 Marco Bresciani
|
42
|
+
# rubocop:enable Style/AsciiComments
|
34
43
|
# License:: GNU General Public License version 3
|
35
44
|
class Default
|
36
|
-
|
37
45
|
# The parsable duck type interface to every parser usage.
|
38
46
|
def parse(value = nil)
|
39
|
-
unless value.nil?
|
47
|
+
unless value.nil? || value.empty?
|
40
48
|
unless DEFAULT_OPTIONS.include? value
|
41
|
-
valid = %w
|
49
|
+
valid = %w[http https].index { |scheme| valid?(value, scheme) }
|
42
50
|
|
43
51
|
raise ArgumentError, I18n.t('error.uri', value: value) if valid.nil?
|
44
52
|
end
|
45
53
|
|
46
|
-
return
|
54
|
+
return "d=#{CGI.escape(value)}"
|
47
55
|
end
|
48
56
|
''
|
49
57
|
end
|
@@ -65,23 +73,23 @@ module Gravaty
|
|
65
73
|
begin
|
66
74
|
an_uri = parser.parse an_uri[0]
|
67
75
|
|
68
|
-
#See URI validation rules at
|
76
|
+
# See URI validation rules at
|
69
77
|
# http://en.gravatar.com/site/implement/images/#default-image
|
70
78
|
|
71
|
-
#rule 2
|
72
|
-
return false if (an_uri.scheme == 'http')
|
73
|
-
|
74
|
-
return false if (an_uri.scheme == 'https')
|
75
|
-
|
79
|
+
# rule 2
|
80
|
+
return false if (an_uri.scheme == 'http') &&
|
81
|
+
(an_uri.port != Net::HTTP.http_default_port)
|
82
|
+
return false if (an_uri.scheme == 'https') &&
|
83
|
+
(an_uri.port != Net::HTTP.https_default_port)
|
76
84
|
|
77
|
-
#rule 3
|
85
|
+
# rule 3
|
78
86
|
allowed = IMAGES_FORMATS
|
79
|
-
|
87
|
+
.index { |format| an_uri.path.end_with? format }
|
80
88
|
return false if allowed.nil?
|
81
89
|
|
82
|
-
#rule 4
|
90
|
+
# rule 4
|
83
91
|
return false unless an_uri.query.nil?
|
84
|
-
rescue
|
92
|
+
rescue StandardError
|
85
93
|
return false
|
86
94
|
end
|
87
95
|
true
|
@@ -1,6 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
#--
|
2
4
|
# gravaty
|
3
|
-
#
|
5
|
+
# rubocop:disable Style/AsciiComments
|
6
|
+
# © 2013 Marco Bresciani
|
7
|
+
# rubocop:enable Style/AsciiComments
|
4
8
|
#
|
5
9
|
# This file is part of gravaty.
|
6
10
|
#
|
@@ -16,22 +20,28 @@
|
|
16
20
|
#
|
17
21
|
# You should have received a copy of the GNU General Public License
|
18
22
|
# along with gravaty. If not, see <http://www.gnu.org/licenses/>.
|
23
|
+
#
|
24
|
+
# SPDX-FileCopyrightText: 2013 Marco Bresciani
|
25
|
+
#
|
26
|
+
# SPDX-License-Identifier: GPL-3.0-or-later
|
19
27
|
#++
|
20
28
|
|
21
29
|
module Gravaty
|
22
30
|
module Parsers
|
23
|
-
|
24
31
|
# This class is an implementation of the Parsable duck type that
|
25
32
|
# checks forces the default value. The only needed parameter is a
|
26
33
|
# boolean, with +true+ for forced.
|
27
34
|
#
|
28
35
|
# Author:: {Marco Bresciani}[mailto:marcobresciani_1974@libero.it]
|
36
|
+
# rubocop:disable Style/AsciiComments
|
29
37
|
# Copyright:: Copyright © 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020 Marco Bresciani
|
38
|
+
# rubocop:enable Style/AsciiComments
|
30
39
|
# License:: GNU General Public License version 3
|
31
40
|
class Force
|
32
41
|
# The parsable duck type interface to every parser usage.
|
33
42
|
def parse(value = false)
|
34
43
|
return 'f=y' if value
|
44
|
+
|
35
45
|
''
|
36
46
|
end
|
37
47
|
end
|
@@ -1,6 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
#--
|
2
4
|
# gravaty
|
3
|
-
#
|
5
|
+
# rubocop:disable Style/AsciiComments
|
6
|
+
# © 2013 Marco Bresciani
|
7
|
+
# rubocop:enable Style/AsciiComments
|
4
8
|
#
|
5
9
|
# This file is part of gravaty.
|
6
10
|
#
|
@@ -16,6 +20,10 @@
|
|
16
20
|
#
|
17
21
|
# You should have received a copy of the GNU General Public License
|
18
22
|
# along with gravaty. If not, see <http://www.gnu.org/licenses/>.
|
23
|
+
#
|
24
|
+
# SPDX-FileCopyrightText: 2013 Marco Bresciani
|
25
|
+
#
|
26
|
+
# SPDX-License-Identifier: GPL-3.0-or-later
|
19
27
|
#++
|
20
28
|
|
21
29
|
require_relative '../constants'
|
@@ -23,13 +31,14 @@ require_relative '../utils/raisers'
|
|
23
31
|
|
24
32
|
module Gravaty
|
25
33
|
module Parsers
|
26
|
-
|
27
34
|
# This class is an implementation of the Parsable duck type that
|
28
35
|
# checks the profile type. The only needed parameter is a valid
|
29
36
|
# profile format.
|
30
37
|
#
|
31
38
|
# Author:: {Marco Bresciani}[mailto:marcobresciani_1974@libero.it]
|
39
|
+
# rubocop:disable Style/AsciiComments
|
32
40
|
# Copyright:: Copyright © 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020 Marco Bresciani
|
41
|
+
# rubocop:enable Style/AsciiComments
|
33
42
|
# License:: GNU General Public License version 3
|
34
43
|
class Format
|
35
44
|
include Utils::Raisers
|
@@ -1,6 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
#--
|
2
4
|
# gravaty
|
3
|
-
#
|
5
|
+
# rubocop:disable Style/AsciiComments
|
6
|
+
# © 2013 Marco Bresciani
|
7
|
+
# rubocop:enable Style/AsciiComments
|
4
8
|
#
|
5
9
|
# This file is part of gravaty.
|
6
10
|
#
|
@@ -16,6 +20,10 @@
|
|
16
20
|
#
|
17
21
|
# You should have received a copy of the GNU General Public License
|
18
22
|
# along with gravaty. If not, see <http://www.gnu.org/licenses/>.
|
23
|
+
#
|
24
|
+
# SPDX-FileCopyrightText: 2013 Marco Bresciani
|
25
|
+
#
|
26
|
+
# SPDX-License-Identifier: GPL-3.0-or-later
|
19
27
|
#++
|
20
28
|
|
21
29
|
require_relative '../constants'
|
@@ -23,13 +31,14 @@ require_relative '../utils/raisers'
|
|
23
31
|
|
24
32
|
module Gravaty
|
25
33
|
module Parsers
|
26
|
-
|
27
34
|
# This class is an implementation of the Parsable duck type that
|
28
35
|
# checks the image size. The only needed parameter is a valid image
|
29
36
|
# size.
|
30
37
|
#
|
31
38
|
# Author:: {Marco Bresciani}[mailto:marcobresciani_1974@libero.it]
|
39
|
+
# rubocop:disable Style/AsciiComments
|
32
40
|
# Copyright:: Copyright © 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020 Marco Bresciani
|
41
|
+
# rubocop:enable Style/AsciiComments
|
33
42
|
# License:: GNU General Public License version 3
|
34
43
|
class Pixelsize
|
35
44
|
include Utils::Raisers
|
@@ -37,7 +46,7 @@ module Gravaty
|
|
37
46
|
# The parsable duck type interface to every parser usage.
|
38
47
|
def parse(value = nil)
|
39
48
|
raiser_to_i('error.value', value, ALLOWED_SIZES)
|
40
|
-
value.nil? ? '' : "s=#{value
|
49
|
+
value.nil? ? '' : "s=#{value}"
|
41
50
|
end
|
42
51
|
end
|
43
52
|
end
|
@@ -1,6 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
#--
|
2
4
|
# gravaty
|
3
|
-
#
|
5
|
+
# rubocop:disable Style/AsciiComments
|
6
|
+
# © 2013 Marco Bresciani
|
7
|
+
# rubocop:enable Style/AsciiComments
|
4
8
|
#
|
5
9
|
# This file is part of gravaty.
|
6
10
|
#
|
@@ -16,6 +20,10 @@
|
|
16
20
|
#
|
17
21
|
# You should have received a copy of the GNU General Public License
|
18
22
|
# along with gravaty. If not, see <http://www.gnu.org/licenses/>.
|
23
|
+
#
|
24
|
+
# SPDX-FileCopyrightText: 2013 Marco Bresciani
|
25
|
+
#
|
26
|
+
# SPDX-License-Identifier: GPL-3.0-or-later
|
19
27
|
#++
|
20
28
|
|
21
29
|
require_relative '../constants'
|
@@ -23,13 +31,14 @@ require_relative '../utils/raisers'
|
|
23
31
|
|
24
32
|
module Gravaty
|
25
33
|
module Parsers
|
26
|
-
|
27
34
|
# This class is an implementation of the Parsable duck type that
|
28
35
|
# checks the rating type. The only needed parameter is a valid
|
29
36
|
# rating type.
|
30
37
|
#
|
31
38
|
# Author:: {Marco Bresciani}[mailto:marcobresciani_1974@libero.it]
|
39
|
+
# rubocop:disable Style/AsciiComments
|
32
40
|
# Copyright:: Copyright © 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020 Marco Bresciani
|
41
|
+
# rubocop:enable Style/AsciiComments
|
33
42
|
# License:: GNU General Public License version 3
|
34
43
|
class Rating
|
35
44
|
include Utils::Raisers
|
@@ -37,7 +46,7 @@ module Gravaty
|
|
37
46
|
# the parsable duck type interface to every parser usage.
|
38
47
|
def parse(value = nil)
|
39
48
|
raiser_downcase('error.value', value, RATING_OPTIONS)
|
40
|
-
value.nil? ? '' : "rating=#{value.downcase
|
49
|
+
value.nil? ? '' : "rating=#{value.downcase}"
|
41
50
|
end
|
42
51
|
end
|
43
52
|
end
|
@@ -1,6 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
#--
|
2
4
|
# gravaty
|
3
|
-
#
|
5
|
+
# rubocop:disable Style/AsciiComments
|
6
|
+
# © 2013 Marco Bresciani
|
7
|
+
# rubocop:enable Style/AsciiComments
|
4
8
|
#
|
5
9
|
# This file is part of gravaty.
|
6
10
|
#
|
@@ -16,17 +20,22 @@
|
|
16
20
|
#
|
17
21
|
# You should have received a copy of the GNU General Public License
|
18
22
|
# along with gravaty. If not, see <http://www.gnu.org/licenses/>.
|
23
|
+
#
|
24
|
+
# SPDX-FileCopyrightText: 2013 Marco Bresciani
|
25
|
+
#
|
26
|
+
# SPDX-License-Identifier: GPL-3.0-or-later
|
19
27
|
#++
|
20
28
|
|
21
29
|
module Gravaty
|
22
30
|
module Parsers
|
23
|
-
|
24
31
|
# This class is an implementation of the Parsable duck type that
|
25
32
|
# provides the secure or unsecure URI. The only needed parameter is
|
26
33
|
# a boolean, with +true+ for secure.
|
27
34
|
#
|
28
35
|
# Author:: {Marco Bresciani}[mailto:marcobresciani_1974@libero.it]
|
36
|
+
# rubocop:disable Style/AsciiComments
|
29
37
|
# Copyright:: Copyright © 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020 Marco Bresciani
|
38
|
+
# rubocop:enable Style/AsciiComments
|
30
39
|
# License:: GNU General Public License version 3
|
31
40
|
class Secure
|
32
41
|
# The parsable duck type interface to every parser usage.
|
data/lib/gravaty/parsers/type.rb
CHANGED
@@ -1,6 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
#--
|
2
4
|
# gravaty
|
3
|
-
#
|
5
|
+
# rubocop:disable Style/AsciiComments
|
6
|
+
# © 2013 Marco Bresciani
|
7
|
+
# rubocop:enable Style/AsciiComments
|
4
8
|
#
|
5
9
|
# This file is part of gravaty.
|
6
10
|
#
|
@@ -16,6 +20,10 @@
|
|
16
20
|
#
|
17
21
|
# You should have received a copy of the GNU General Public License
|
18
22
|
# along with gravaty. If not, see <http://www.gnu.org/licenses/>.
|
23
|
+
#
|
24
|
+
# SPDX-FileCopyrightText: 2013 Marco Bresciani
|
25
|
+
#
|
26
|
+
# SPDX-License-Identifier: GPL-3.0-or-later
|
19
27
|
#++
|
20
28
|
|
21
29
|
require_relative '../constants'
|
@@ -23,13 +31,14 @@ require_relative '../utils/raisers'
|
|
23
31
|
|
24
32
|
module Gravaty
|
25
33
|
module Parsers
|
26
|
-
|
27
34
|
# This class is an implementation of the Parsable duck type that
|
28
35
|
# checks the avatar type. The only needed parameter is a valid
|
29
36
|
# avatar format.
|
30
37
|
#
|
31
38
|
# Author:: {Marco Bresciani}[mailto:marcobresciani_1974@libero.it]
|
39
|
+
# rubocop:disable Style/AsciiComments
|
32
40
|
# Copyright:: Copyright © 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020 Marco Bresciani
|
41
|
+
# rubocop:enable Style/AsciiComments
|
33
42
|
# License:: GNU General Public License version 3
|
34
43
|
class Type
|
35
44
|
include Utils::Raisers
|
@@ -1,6 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
#--
|
2
4
|
# gravaty
|
3
|
-
#
|
5
|
+
# rubocop:disable Style/AsciiComments
|
6
|
+
# © 2012 Jon Maken
|
7
|
+
# rubocop:enable Style/AsciiComments
|
4
8
|
#
|
5
9
|
# This file is part of gravaty.
|
6
10
|
#
|
@@ -16,11 +20,14 @@
|
|
16
20
|
#
|
17
21
|
# You should have received a copy of the GNU General Public License
|
18
22
|
# along with gravaty. If not, see <http://www.gnu.org/licenses/>.
|
23
|
+
#
|
24
|
+
# SPDX-FileCopyrightText: 2012 Jon Maken
|
25
|
+
#
|
26
|
+
# SPDX-License-Identifier: BSD-3-Clause
|
19
27
|
#++
|
20
28
|
|
21
29
|
module Gravaty
|
22
30
|
module Utils
|
23
|
-
|
24
31
|
# This module is a simple wrapper container for Peter R. Marreck's
|
25
32
|
# gist.
|
26
33
|
#
|
@@ -28,14 +35,13 @@ module Gravaty
|
|
28
35
|
# License:: 3-clause BSD
|
29
36
|
# Revision:: 2012-03-25 23:01:19 -0600
|
30
37
|
module Downloader
|
31
|
-
|
32
38
|
require 'net/http'
|
33
39
|
require 'net/ftp'
|
34
40
|
require 'openssl'
|
35
41
|
require 'fileutils'
|
36
42
|
require 'tempfile'
|
37
43
|
|
38
|
-
|
44
|
+
# !/usr/bin/env ruby
|
39
45
|
#
|
40
46
|
# An HTTP/HTTPS/FTP file downloader library/CLI based upon
|
41
47
|
# MiniPortile's HTTP implementation.
|
@@ -44,113 +50,109 @@ module Gravaty
|
|
44
50
|
# License:: 3-clause BSD
|
45
51
|
# Revision:: 2012-03-25 23:01:19 -0600
|
46
52
|
class Downloader
|
47
|
-
|
48
53
|
VERSION = '0.1.0'
|
49
54
|
|
50
55
|
class << self
|
51
56
|
attr_accessor :logger, :max_ca_verify_depth, :ftp_data_chunk_size
|
52
57
|
end
|
53
58
|
|
54
|
-
@logger =
|
59
|
+
@logger = $stdout.binmode
|
55
60
|
@max_ca_verify_depth = 5
|
56
61
|
@ftp_data_chunk_size = 8192
|
57
62
|
|
58
|
-
|
59
63
|
def self.download_file(url, full_path, count = 3)
|
60
|
-
raise
|
64
|
+
raise I18n.t('error.nil') if url.nil?
|
61
65
|
return if File.exist?(full_path)
|
62
66
|
|
63
67
|
http_download(url, full_path, count)
|
64
68
|
end
|
65
69
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
end
|
153
|
-
end # Downloader
|
70
|
+
private_class_method def self.message(text)
|
71
|
+
@logger.print text
|
72
|
+
@logger.flush
|
73
|
+
end
|
74
|
+
|
75
|
+
private_class_method def self.output(text = '')
|
76
|
+
@logger.puts text
|
77
|
+
@logger.flush
|
78
|
+
end
|
79
|
+
|
80
|
+
private_class_method def self.http_download(url, full_path, count)
|
81
|
+
uri = URI.parse(url)
|
82
|
+
|
83
|
+
begin
|
84
|
+
filename = File.basename(uri.path)
|
85
|
+
|
86
|
+
if ENV['HTTP_PROXY']
|
87
|
+
# protocol,
|
88
|
+
userinfo, proxy_host, proxy_port = URI.split(ENV['HTTP_PROXY'])
|
89
|
+
proxy_user, proxy_pass = userinfo.split(/:/) if userinfo
|
90
|
+
http = Net::HTTP.new(uri.host, uri.port, proxy_host, proxy_port, proxy_user, proxy_pass)
|
91
|
+
else
|
92
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
93
|
+
end
|
94
|
+
|
95
|
+
if uri.scheme.downcase == 'https'
|
96
|
+
http.use_ssl = true
|
97
|
+
if ENV['SSL_CERT_FILE']
|
98
|
+
cert_file = ENV['SSL_CERT_FILE'].dup
|
99
|
+
cert_file.gsub!(File::ALT_SEPARATOR, File::SEPARATOR) if File::ALT_SEPARATOR
|
100
|
+
end
|
101
|
+
if cert_file && File.exist?(cert_file)
|
102
|
+
http.ca_file = cert_file
|
103
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
104
|
+
http.verify_depth = @max_ca_verify_depth
|
105
|
+
else
|
106
|
+
raise <<~HOWTO_MESSAGE
|
107
|
+
To download using HTTPS you must first set the SSL_CERT_FILE
|
108
|
+
environment variable to the path of a valid CA certificate file.
|
109
|
+
A file of bundled public CA certs may be downloaded from:
|
110
|
+
#{' '}
|
111
|
+
http://curl.haxx.se/ca/cacert.pem
|
112
|
+
#{' '}
|
113
|
+
HOWTO_MESSAGE
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
http.request_get(uri) do |response|
|
118
|
+
case response
|
119
|
+
when Net::HTTPNotFound
|
120
|
+
output '404 - Not Found'
|
121
|
+
return false
|
122
|
+
|
123
|
+
when Net::HTTPClientError
|
124
|
+
output "Error: Client Error: #{response.inspect}"
|
125
|
+
return false
|
126
|
+
|
127
|
+
when Net::HTTPRedirection
|
128
|
+
raise 'Too many redirections, halting.' if count <= 0
|
129
|
+
|
130
|
+
url = response['location']
|
131
|
+
return http_download(url, full_path, count - 1)
|
132
|
+
|
133
|
+
when Net::HTTPOK
|
134
|
+
temp_file = Tempfile
|
135
|
+
.new("download-#{filename}")
|
136
|
+
temp_file.binmode
|
137
|
+
temp_file << response.body
|
138
|
+
|
139
|
+
output
|
140
|
+
|
141
|
+
temp_file.close
|
142
|
+
File.unlink full_path if File.exist?(full_path)
|
143
|
+
FileUtils.mkdir_p File.dirname(full_path)
|
144
|
+
FileUtils.mv temp_file.path, full_path, force: true
|
145
|
+
else
|
146
|
+
puts response
|
147
|
+
end
|
148
|
+
end
|
149
|
+
rescue StandardError => e
|
150
|
+
File.unlink full_path if File.exist?(full_path)
|
151
|
+
output "ERROR: #{e.message}"
|
152
|
+
raise "Failed to download file: #{e.message}"
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
154
156
|
end
|
155
157
|
end
|
156
158
|
end
|