gravaty 9.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG +835 -0
- data/COPYING.md +675 -0
- data/Gemfile +21 -0
- data/ISSUES.md +62 -0
- data/README.md +287 -0
- data/Rakefile +52 -0
- data/acknowledgements.md +66 -0
- data/authors.md +63 -0
- data/copyright.md +468 -0
- data/examples/avatar.rb +159 -0
- data/examples/basics.rb +75 -0
- data/examples/cacert.pem +3401 -0
- data/examples/profile.rb +187 -0
- data/examples/xmlrpc.rb +41 -0
- data/gravaty.gemspec +78 -0
- data/gravaty.odp +0 -0
- data/gravaty.pdf +0 -0
- data/html/CHANGELOG.html +1117 -0
- data/html/COPYING_md.html +393 -0
- data/html/Gemfile.html +108 -0
- data/html/Gravaty/Gravaty.html +1002 -0
- data/html/Gravaty/ParsableDuckType.html +162 -0
- data/html/Gravaty/Parser.html +239 -0
- data/html/Gravaty/Parsers/Avatar.html +169 -0
- data/html/Gravaty/Parsers/Callback.html +170 -0
- data/html/Gravaty/Parsers/Default.html +178 -0
- data/html/Gravaty/Parsers/Force.html +170 -0
- data/html/Gravaty/Parsers/Format.html +181 -0
- data/html/Gravaty/Parsers/Pixelsize.html +181 -0
- data/html/Gravaty/Parsers/Rating.html +181 -0
- data/html/Gravaty/Parsers/Secure.html +169 -0
- data/html/Gravaty/Parsers/Type.html +181 -0
- data/html/Gravaty/Parsers.html +96 -0
- data/html/Gravaty/Utils/Downloader/Downloader.html +227 -0
- data/html/Gravaty/Utils/Downloader.html +108 -0
- data/html/Gravaty/Utils/Raisers.html +203 -0
- data/html/Gravaty/Utils/Rfc5322.html +139 -0
- data/html/Gravaty/Utils/RpcConnector/RpcConnector.html +248 -0
- data/html/Gravaty/Utils/RpcConnector.html +111 -0
- data/html/Gravaty/Utils.html +111 -0
- data/html/Gravaty.html +320 -0
- data/html/ISSUES_md.html +165 -0
- data/html/Object.html +187 -0
- data/html/README_md.html +276 -0
- data/html/Rakefile.html +141 -0
- data/html/acknowledgements_md.html +160 -0
- data/html/authors_md.html +173 -0
- data/html/copyright_md.html +481 -0
- data/html/created.rid +59 -0
- data/html/css/fonts.css +167 -0
- data/html/css/rdoc.css +590 -0
- data/html/examples/cacert_pem.html +1056 -0
- data/html/fonts/Lato-Light.ttf +0 -0
- data/html/fonts/Lato-LightItalic.ttf +0 -0
- data/html/fonts/Lato-Regular.ttf +0 -0
- data/html/fonts/Lato-RegularItalic.ttf +0 -0
- data/html/fonts/SourceCodePro-Bold.ttf +0 -0
- data/html/fonts/SourceCodePro-Regular.ttf +0 -0
- data/html/gravaty_gemspec.html +169 -0
- data/html/images/add.png +0 -0
- data/html/images/arrow_up.png +0 -0
- data/html/images/brick.png +0 -0
- data/html/images/brick_link.png +0 -0
- data/html/images/bug.png +0 -0
- data/html/images/bullet_black.png +0 -0
- data/html/images/bullet_toggle_minus.png +0 -0
- data/html/images/bullet_toggle_plus.png +0 -0
- data/html/images/date.png +0 -0
- data/html/images/delete.png +0 -0
- data/html/images/find.png +0 -0
- data/html/images/loadingAnimation.gif +0 -0
- data/html/images/macFFBgHack.png +0 -0
- data/html/images/package.png +0 -0
- data/html/images/page_green.png +0 -0
- data/html/images/page_white_text.png +0 -0
- data/html/images/page_white_width.png +0 -0
- data/html/images/plugin.png +0 -0
- data/html/images/ruby.png +0 -0
- data/html/images/tag_blue.png +0 -0
- data/html/images/tag_green.png +0 -0
- data/html/images/transparent.png +0 -0
- data/html/images/wrench.png +0 -0
- data/html/images/wrench_orange.png +0 -0
- data/html/images/zoom.png +0 -0
- data/html/index.html +308 -0
- data/html/js/darkfish.js +161 -0
- data/html/js/jquery.js +4 -0
- data/html/js/navigation.js +141 -0
- data/html/js/navigation.js.gz +0 -0
- data/html/js/search.js +109 -0
- data/html/js/search_index.js +1 -0
- data/html/js/search_index.js.gz +0 -0
- data/html/js/searcher.js +229 -0
- data/html/js/searcher.js.gz +0 -0
- data/html/table_of_contents.html +995 -0
- data/lib/gravaty/application.rb +354 -0
- data/lib/gravaty/constants.rb +65 -0
- data/lib/gravaty/locales/en.yml +38 -0
- data/lib/gravaty/locales/it.yml +38 -0
- data/lib/gravaty/locales/ja.yml +39 -0
- data/lib/gravaty/parser.rb +50 -0
- data/lib/gravaty/parsers/avatar.rb +40 -0
- data/lib/gravaty/parsers/callback.rb +41 -0
- data/lib/gravaty/parsers/default.rb +92 -0
- data/lib/gravaty/parsers/force.rb +40 -0
- data/lib/gravaty/parsers/format.rb +45 -0
- data/lib/gravaty/parsers/pixelsize.rb +45 -0
- data/lib/gravaty/parsers/rating.rb +45 -0
- data/lib/gravaty/parsers/secure.rb +39 -0
- data/lib/gravaty/parsers/type.rb +45 -0
- data/lib/gravaty/utils/downloader.rb +156 -0
- data/lib/gravaty/utils/raisers.rb +63 -0
- data/lib/gravaty/utils/rfc5322.rb +110 -0
- data/lib/gravaty/utils/rpc_connector.rb +86 -0
- data/lib/gravaty/version.rb +24 -0
- data/lib/gravaty.rb +75 -0
- data/test/gravaty/locales/test_locales.rb +69 -0
- data/test/gravaty/parsers/test_avatar.rb +39 -0
- data/test/gravaty/parsers/test_callback.rb +42 -0
- data/test/gravaty/parsers/test_default.rb +79 -0
- data/test/gravaty/parsers/test_force.rb +39 -0
- data/test/gravaty/parsers/test_format.rb +54 -0
- data/test/gravaty/parsers/test_pixelsize.rb +56 -0
- data/test/gravaty/parsers/test_rating.rb +54 -0
- data/test/gravaty/parsers/test_secure.rb +39 -0
- data/test/gravaty/parsers/test_type.rb +44 -0
- data/test/gravaty/test_application.rb +126 -0
- data/test/gravaty/test_avatar.rb +122 -0
- data/test/gravaty/test_parser.rb +59 -0
- data/test/gravaty/test_profile.rb +70 -0
- data/test/gravaty/utils/test_downloader.rb +51 -0
- data/test/gravaty/utils/test_raisers.rb +62 -0
- data/test/gravaty/utils/test_rfc5322.rb +82 -0
- data/test/gravaty/utils/test_rpc_connector.rb +82 -0
- data/test/test_gravaty.rb +48 -0
- data/test/test_helper.rb +105 -0
- metadata +348 -0
@@ -0,0 +1,92 @@
|
|
1
|
+
#--
|
2
|
+
# gravaty
|
3
|
+
# Copyright © 2013, 2014, 2015, 2016, 2017, 2018, 2019 Marco Bresciani
|
4
|
+
#
|
5
|
+
# This file is part of gravaty.
|
6
|
+
#
|
7
|
+
# gravaty is free software: you can redistribute it and/or modify it
|
8
|
+
# under the terms of the GNU General Public License as published by the
|
9
|
+
# Free Software Foundation, either version 3 of the License, or (at your
|
10
|
+
# option) any later version.
|
11
|
+
#
|
12
|
+
# gravaty is distributed in the hope that it will be useful, but WITHOUT
|
13
|
+
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
14
|
+
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
15
|
+
# for more details.
|
16
|
+
#
|
17
|
+
# You should have received a copy of the GNU General Public License
|
18
|
+
# along with gravaty. If not, see <http://www.gnu.org/licenses/>.
|
19
|
+
#++
|
20
|
+
|
21
|
+
require 'cgi'
|
22
|
+
|
23
|
+
require_relative '../constants'
|
24
|
+
|
25
|
+
module Gravaty
|
26
|
+
module Parsers
|
27
|
+
|
28
|
+
# This class is an implementation of the Parsable duck type that
|
29
|
+
# checks the default option. The only needed parameter is a valid
|
30
|
+
# default option.
|
31
|
+
#
|
32
|
+
# Author:: {Marco Bresciani}[mailto:marcobresciani_1974@libero.it]
|
33
|
+
# Copyright:: Copyright © 2013, 2014, 2015, 2016, 2017, 2018,
|
34
|
+
# 2019 Marco Bresciani
|
35
|
+
# License:: GNU General Public License version 3
|
36
|
+
class Default
|
37
|
+
|
38
|
+
# The parsable duck type interface to every parser usage.
|
39
|
+
def parse(value = nil)
|
40
|
+
unless value.nil? or value.empty?
|
41
|
+
unless DEFAULT_OPTIONS.include? value
|
42
|
+
valid = %w(http https).index {|scheme| valid?(value, scheme)}
|
43
|
+
|
44
|
+
raise ArgumentError, I18n.t('error.uri', value: value) if valid.nil?
|
45
|
+
end
|
46
|
+
|
47
|
+
return 'd=' + CGI::escape(value).to_s
|
48
|
+
end
|
49
|
+
''
|
50
|
+
end
|
51
|
+
|
52
|
+
# ------------------------ here starts the list of private methods
|
53
|
+
|
54
|
+
private
|
55
|
+
|
56
|
+
def valid?(value, scheme)
|
57
|
+
return false if value.nil?
|
58
|
+
return false if value.empty?
|
59
|
+
|
60
|
+
parser = URI::Parser.new
|
61
|
+
an_uri = parser.extract(value.downcase, scheme)
|
62
|
+
|
63
|
+
return false if an_uri.nil?
|
64
|
+
return false if an_uri.empty?
|
65
|
+
|
66
|
+
begin
|
67
|
+
an_uri = parser.parse an_uri[0]
|
68
|
+
|
69
|
+
#See URI validation rules at
|
70
|
+
# http://en.gravatar.com/site/implement/images/#default-image
|
71
|
+
|
72
|
+
#rule 2
|
73
|
+
return false if (an_uri.scheme == 'http') and
|
74
|
+
(an_uri.port != Net::HTTP.http_default_port)
|
75
|
+
return false if (an_uri.scheme == 'https') and
|
76
|
+
(an_uri.port != Net::HTTP.https_default_port)
|
77
|
+
|
78
|
+
#rule 3
|
79
|
+
allowed = IMAGES_FORMATS
|
80
|
+
.index {|format| an_uri.path.end_with? format}
|
81
|
+
return false if allowed.nil?
|
82
|
+
|
83
|
+
#rule 4
|
84
|
+
return false unless an_uri.query.nil?
|
85
|
+
rescue
|
86
|
+
return false
|
87
|
+
end
|
88
|
+
true
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
#--
|
2
|
+
# gravaty
|
3
|
+
# Copyright © 2013, 2014, 2015, 2016, 2017, 2018, 2019 Marco Bresciani
|
4
|
+
#
|
5
|
+
# This file is part of gravaty.
|
6
|
+
#
|
7
|
+
# gravaty is free software: you can redistribute it and/or modify it
|
8
|
+
# under the terms of the GNU General Public License as published by the
|
9
|
+
# Free Software Foundation, either version 3 of the License, or (at your
|
10
|
+
# option) any later version.
|
11
|
+
#
|
12
|
+
# gravaty is distributed in the hope that it will be useful, but WITHOUT
|
13
|
+
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
14
|
+
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
15
|
+
# for more details.
|
16
|
+
#
|
17
|
+
# You should have received a copy of the GNU General Public License
|
18
|
+
# along with gravaty. If not, see <http://www.gnu.org/licenses/>.
|
19
|
+
#++
|
20
|
+
|
21
|
+
module Gravaty
|
22
|
+
module Parsers
|
23
|
+
|
24
|
+
# This class is an implementation of the Parsable duck type that
|
25
|
+
# checks forces the default value. The only needed parameter is a
|
26
|
+
# boolean, with +true+ for forced.
|
27
|
+
#
|
28
|
+
# Author:: {Marco Bresciani}[mailto:marcobresciani_1974@libero.it]
|
29
|
+
# Copyright:: Copyright © 2013, 2014, 2015, 2016, 2017, 2018,
|
30
|
+
# 2019 Marco Bresciani
|
31
|
+
# License:: GNU General Public License version 3
|
32
|
+
class Force
|
33
|
+
# The parsable duck type interface to every parser usage.
|
34
|
+
def parse(value = false)
|
35
|
+
return 'f=y' if value
|
36
|
+
''
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
#--
|
2
|
+
# gravaty
|
3
|
+
# Copyright © 2013, 2014, 2015, 2016, 2017, 2018, 2019 Marco Bresciani
|
4
|
+
#
|
5
|
+
# This file is part of gravaty.
|
6
|
+
#
|
7
|
+
# gravaty is free software: you can redistribute it and/or modify it
|
8
|
+
# under the terms of the GNU General Public License as published by the
|
9
|
+
# Free Software Foundation, either version 3 of the License, or (at your
|
10
|
+
# option) any later version.
|
11
|
+
#
|
12
|
+
# gravaty is distributed in the hope that it will be useful, but WITHOUT
|
13
|
+
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
14
|
+
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
15
|
+
# for more details.
|
16
|
+
#
|
17
|
+
# You should have received a copy of the GNU General Public License
|
18
|
+
# along with gravaty. If not, see <http://www.gnu.org/licenses/>.
|
19
|
+
#++
|
20
|
+
|
21
|
+
require_relative '../constants'
|
22
|
+
require_relative '../utils/raisers'
|
23
|
+
|
24
|
+
module Gravaty
|
25
|
+
module Parsers
|
26
|
+
|
27
|
+
# This class is an implementation of the Parsable duck type that
|
28
|
+
# checks the profile type. The only needed parameter is a valid
|
29
|
+
# profile format.
|
30
|
+
#
|
31
|
+
# Author:: {Marco Bresciani}[mailto:marcobresciani_1974@libero.it]
|
32
|
+
# Copyright:: Copyright © 2013, 2014, 2015, 2016, 2017, 2018,
|
33
|
+
# 2019 Marco Bresciani
|
34
|
+
# License:: GNU General Public License version 3
|
35
|
+
class Format
|
36
|
+
include Utils::Raisers
|
37
|
+
|
38
|
+
# The parsable duck type interface to every parser usage.
|
39
|
+
def parse(value = nil)
|
40
|
+
raiser_downcase('error.type', value, PROFILE_FORMATS)
|
41
|
+
value.nil? ? '' : ".#{value.downcase}"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
#--
|
2
|
+
# gravaty
|
3
|
+
# Copyright © 2013, 2014, 2015, 2016, 2017, 2018, 2019 Marco Bresciani
|
4
|
+
#
|
5
|
+
# This file is part of gravaty.
|
6
|
+
#
|
7
|
+
# gravaty is free software: you can redistribute it and/or modify it
|
8
|
+
# under the terms of the GNU General Public License as published by the
|
9
|
+
# Free Software Foundation, either version 3 of the License, or (at your
|
10
|
+
# option) any later version.
|
11
|
+
#
|
12
|
+
# gravaty is distributed in the hope that it will be useful, but WITHOUT
|
13
|
+
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
14
|
+
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
15
|
+
# for more details.
|
16
|
+
#
|
17
|
+
# You should have received a copy of the GNU General Public License
|
18
|
+
# along with gravaty. If not, see <http://www.gnu.org/licenses/>.
|
19
|
+
#++
|
20
|
+
|
21
|
+
require_relative '../constants'
|
22
|
+
require_relative '../utils/raisers'
|
23
|
+
|
24
|
+
module Gravaty
|
25
|
+
module Parsers
|
26
|
+
|
27
|
+
# This class is an implementation of the Parsable duck type that
|
28
|
+
# checks the image size. The only needed parameter is a valid image
|
29
|
+
# size.
|
30
|
+
#
|
31
|
+
# Author:: {Marco Bresciani}[mailto:marcobresciani_1974@libero.it]
|
32
|
+
# Copyright:: Copyright © 2013, 2014, 2015, 2016, 2017, 2018,
|
33
|
+
# 2019 Marco Bresciani
|
34
|
+
# License:: GNU General Public License version 3
|
35
|
+
class Pixelsize
|
36
|
+
include Utils::Raisers
|
37
|
+
|
38
|
+
# The parsable duck type interface to every parser usage.
|
39
|
+
def parse(value = nil)
|
40
|
+
raiser_to_i('error.value', value, ALLOWED_SIZES)
|
41
|
+
value.nil? ? '' : "s=#{value.to_s}"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
#--
|
2
|
+
# gravaty
|
3
|
+
# Copyright © 2013, 2014, 2015, 2016, 2017, 2018, 2019 Marco Bresciani
|
4
|
+
#
|
5
|
+
# This file is part of gravaty.
|
6
|
+
#
|
7
|
+
# gravaty is free software: you can redistribute it and/or modify it
|
8
|
+
# under the terms of the GNU General Public License as published by the
|
9
|
+
# Free Software Foundation, either version 3 of the License, or (at your
|
10
|
+
# option) any later version.
|
11
|
+
#
|
12
|
+
# gravaty is distributed in the hope that it will be useful, but WITHOUT
|
13
|
+
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
14
|
+
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
15
|
+
# for more details.
|
16
|
+
#
|
17
|
+
# You should have received a copy of the GNU General Public License
|
18
|
+
# along with gravaty. If not, see <http://www.gnu.org/licenses/>.
|
19
|
+
#++
|
20
|
+
|
21
|
+
require_relative '../constants'
|
22
|
+
require_relative '../utils/raisers'
|
23
|
+
|
24
|
+
module Gravaty
|
25
|
+
module Parsers
|
26
|
+
|
27
|
+
# This class is an implementation of the Parsable duck type that
|
28
|
+
# checks the rating type. The only needed parameter is a valid
|
29
|
+
# rating type.
|
30
|
+
#
|
31
|
+
# Author:: {Marco Bresciani}[mailto:marcobresciani_1974@libero.it]
|
32
|
+
# Copyright:: Copyright © 2013, 2014, 2015, 2016, 2017, 2018,
|
33
|
+
# 2019 Marco Bresciani
|
34
|
+
# License:: GNU General Public License version 3
|
35
|
+
class Rating
|
36
|
+
include Utils::Raisers
|
37
|
+
|
38
|
+
# the parsable duck type interface to every parser usage.
|
39
|
+
def parse(value = nil)
|
40
|
+
raiser_downcase('error.value', value, RATING_OPTIONS)
|
41
|
+
value.nil? ? '' : "rating=#{value.downcase.to_s}"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
#--
|
2
|
+
# gravaty
|
3
|
+
# Copyright © 2013, 2014, 2015, 2016, 2017, 2018, 2019 Marco Bresciani
|
4
|
+
#
|
5
|
+
# This file is part of gravaty.
|
6
|
+
#
|
7
|
+
# gravaty is free software: you can redistribute it and/or modify it
|
8
|
+
# under the terms of the GNU General Public License as published by the
|
9
|
+
# Free Software Foundation, either version 3 of the License, or (at your
|
10
|
+
# option) any later version.
|
11
|
+
#
|
12
|
+
# gravaty is distributed in the hope that it will be useful, but WITHOUT
|
13
|
+
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
14
|
+
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
15
|
+
# for more details.
|
16
|
+
#
|
17
|
+
# You should have received a copy of the GNU General Public License
|
18
|
+
# along with gravaty. If not, see <http://www.gnu.org/licenses/>.
|
19
|
+
#++
|
20
|
+
|
21
|
+
module Gravaty
|
22
|
+
module Parsers
|
23
|
+
|
24
|
+
# This class is an implementation of the Parsable duck type that
|
25
|
+
# provides the secure or unsecure URI. The only needed parameter is
|
26
|
+
# a boolean, with +true+ for secure.
|
27
|
+
#
|
28
|
+
# Author:: {Marco Bresciani}[mailto:marcobresciani_1974@libero.it]
|
29
|
+
# Copyright:: Copyright © 2013, 2014, 2015, 2016, 2017, 2018,
|
30
|
+
# 2019 Marco Bresciani
|
31
|
+
# License:: GNU General Public License version 3
|
32
|
+
class Secure
|
33
|
+
# The parsable duck type interface to every parser usage.
|
34
|
+
def parse(value = false)
|
35
|
+
value ? 'https://secure' : 'http://www'
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
#--
|
2
|
+
# gravaty
|
3
|
+
# Copyright © 2013, 2014, 2015, 2016, 2017, 2018, 2019 Marco Bresciani
|
4
|
+
#
|
5
|
+
# This file is part of gravaty.
|
6
|
+
#
|
7
|
+
# gravaty is free software: you can redistribute it and/or modify it
|
8
|
+
# under the terms of the GNU General Public License as published by the
|
9
|
+
# Free Software Foundation, either version 3 of the License, or (at your
|
10
|
+
# option) any later version.
|
11
|
+
#
|
12
|
+
# gravaty is distributed in the hope that it will be useful, but WITHOUT
|
13
|
+
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
14
|
+
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
15
|
+
# for more details.
|
16
|
+
#
|
17
|
+
# You should have received a copy of the GNU General Public License
|
18
|
+
# along with gravaty. If not, see <http://www.gnu.org/licenses/>.
|
19
|
+
#++
|
20
|
+
|
21
|
+
require_relative '../constants'
|
22
|
+
require_relative '../utils/raisers'
|
23
|
+
|
24
|
+
module Gravaty
|
25
|
+
module Parsers
|
26
|
+
|
27
|
+
# This class is an implementation of the Parsable duck type that
|
28
|
+
# checks the avatar type. The only needed parameter is a valid
|
29
|
+
# avatar format.
|
30
|
+
#
|
31
|
+
# Author:: {Marco Bresciani}[mailto:marcobresciani_1974@libero.it]
|
32
|
+
# Copyright:: Copyright © 2013, 2014, 2015, 2016, 2017, 2018,
|
33
|
+
# 2019 Marco Bresciani
|
34
|
+
# License:: GNU General Public License version 3
|
35
|
+
class Type
|
36
|
+
include Utils::Raisers
|
37
|
+
|
38
|
+
# The parsable duck type interface to every parser usage.
|
39
|
+
def parse(value = nil)
|
40
|
+
raiser_downcase('error.type', value, AVATAR_FORMATS)
|
41
|
+
value.nil? ? '' : ".#{value.downcase}"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,156 @@
|
|
1
|
+
#--
|
2
|
+
# gravaty
|
3
|
+
# Copyright © 2013, 2014, 2015, 2016, 2017, 2018, 2019 Marco Bresciani
|
4
|
+
#
|
5
|
+
# This file is part of gravaty.
|
6
|
+
#
|
7
|
+
# gravaty is free software: you can redistribute it and/or modify it
|
8
|
+
# under the terms of the GNU General Public License as published by the
|
9
|
+
# Free Software Foundation, either version 3 of the License, or (at your
|
10
|
+
# option) any later version.
|
11
|
+
#
|
12
|
+
# gravaty is distributed in the hope that it will be useful, but WITHOUT
|
13
|
+
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
14
|
+
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
15
|
+
# for more details.
|
16
|
+
#
|
17
|
+
# You should have received a copy of the GNU General Public License
|
18
|
+
# along with gravaty. If not, see <http://www.gnu.org/licenses/>.
|
19
|
+
#++
|
20
|
+
|
21
|
+
module Gravaty
|
22
|
+
module Utils
|
23
|
+
|
24
|
+
# This module is a simple wrapper container for Peter R. Marreck's
|
25
|
+
# gist.
|
26
|
+
#
|
27
|
+
# Author:: {Jon Maken}[mailto:jon.forums@gmail.com]
|
28
|
+
# License:: 3-clause BSD
|
29
|
+
# Revision:: 2012-03-25 23:01:19 -0600
|
30
|
+
module Downloader
|
31
|
+
|
32
|
+
require 'net/http'
|
33
|
+
require 'net/ftp'
|
34
|
+
require 'openssl'
|
35
|
+
require 'fileutils'
|
36
|
+
require 'tempfile'
|
37
|
+
|
38
|
+
#!/usr/bin/env ruby
|
39
|
+
#
|
40
|
+
# An HTTP/HTTPS/FTP file downloader library/CLI based upon
|
41
|
+
# MiniPortile's HTTP implementation.
|
42
|
+
#
|
43
|
+
# Author:: Jon Maken
|
44
|
+
# License:: 3-clause BSD
|
45
|
+
# Revision:: 2012-03-25 23:01:19 -0600
|
46
|
+
class Downloader
|
47
|
+
|
48
|
+
VERSION = '0.1.0'
|
49
|
+
|
50
|
+
class << self
|
51
|
+
attr_accessor :logger, :max_ca_verify_depth, :ftp_data_chunk_size
|
52
|
+
end
|
53
|
+
|
54
|
+
@logger = STDOUT.binmode
|
55
|
+
@max_ca_verify_depth = 5
|
56
|
+
@ftp_data_chunk_size = 8192
|
57
|
+
|
58
|
+
|
59
|
+
def self.download_file(url, full_path, count = 3)
|
60
|
+
raise RuntimeError, I18n.t('error.nil') if url.nil?
|
61
|
+
return if File.exist?(full_path)
|
62
|
+
|
63
|
+
http_download(url, full_path, count)
|
64
|
+
end
|
65
|
+
|
66
|
+
private
|
67
|
+
|
68
|
+
def self.message(text)
|
69
|
+
@logger.print text
|
70
|
+
@logger.flush
|
71
|
+
end
|
72
|
+
|
73
|
+
def self.output(text = '')
|
74
|
+
@logger.puts text
|
75
|
+
@logger.flush
|
76
|
+
end
|
77
|
+
|
78
|
+
def self.http_download(url, full_path, count)
|
79
|
+
uri = URI.parse(url)
|
80
|
+
|
81
|
+
begin
|
82
|
+
filename = File.basename(uri.path)
|
83
|
+
|
84
|
+
if ENV['HTTP_PROXY']
|
85
|
+
#protocol,
|
86
|
+
userinfo, proxy_host, proxy_port = URI::split(ENV['HTTP_PROXY'])
|
87
|
+
proxy_user, proxy_pass = userinfo.split(/:/) if userinfo
|
88
|
+
http = Net::HTTP.new(uri.host, uri.port, proxy_host, proxy_port, proxy_user, proxy_pass)
|
89
|
+
else
|
90
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
91
|
+
end
|
92
|
+
|
93
|
+
if uri.scheme.downcase == 'https'
|
94
|
+
http.use_ssl = true
|
95
|
+
if ENV['SSL_CERT_FILE']
|
96
|
+
cert_file = ENV['SSL_CERT_FILE'].dup
|
97
|
+
cert_file.gsub!(File::ALT_SEPARATOR, File::SEPARATOR) if File::ALT_SEPARATOR
|
98
|
+
end
|
99
|
+
if cert_file && File.exists?(cert_file)
|
100
|
+
http.ca_file = cert_file
|
101
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
102
|
+
http.verify_depth = @max_ca_verify_depth
|
103
|
+
else
|
104
|
+
raise <<-EOT
|
105
|
+
To download using HTTPS you must first set the SSL_CERT_FILE
|
106
|
+
environment variable to the path of a valid CA certificate file.
|
107
|
+
A file of bundled public CA certs may be downloaded from:
|
108
|
+
|
109
|
+
http://curl.haxx.se/ca/cacert.pem
|
110
|
+
|
111
|
+
EOT
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
http.request_get(uri) do |response|
|
116
|
+
case response
|
117
|
+
when Net::HTTPNotFound
|
118
|
+
output '404 - Not Found'
|
119
|
+
return false
|
120
|
+
|
121
|
+
when Net::HTTPClientError
|
122
|
+
output "Error: Client Error: #{response.inspect}"
|
123
|
+
return false
|
124
|
+
|
125
|
+
when Net::HTTPRedirection
|
126
|
+
raise 'Too many redirections, halting.' if count <= 0
|
127
|
+
url = response['location']
|
128
|
+
return http_download(url, full_path, count - 1)
|
129
|
+
|
130
|
+
when Net::HTTPOK
|
131
|
+
temp_file = Tempfile
|
132
|
+
.new("download-#{filename}")
|
133
|
+
temp_file.binmode
|
134
|
+
temp_file << response.body
|
135
|
+
|
136
|
+
output
|
137
|
+
|
138
|
+
temp_file.close
|
139
|
+
File.unlink full_path if File.exists?(full_path)
|
140
|
+
FileUtils.mkdir_p File.dirname(full_path)
|
141
|
+
FileUtils.mv temp_file.path, full_path, force: true
|
142
|
+
else
|
143
|
+
puts response
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
rescue Exception => e
|
148
|
+
File.unlink full_path if File.exists?(full_path)
|
149
|
+
output "ERROR: #{e.message}"
|
150
|
+
raise 'Failed to download file'
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end # Downloader
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
#--
|
2
|
+
# gravaty
|
3
|
+
# Copyright © 2013, 2014, 2015, 2016, 2017, 2018, 2019 Marco Bresciani
|
4
|
+
#
|
5
|
+
# This file is part of gravaty.
|
6
|
+
#
|
7
|
+
# gravaty is free software: you can redistribute it and/or modify it
|
8
|
+
# under the terms of the GNU General Public License as published by the
|
9
|
+
# Free Software Foundation, either version 3 of the License, or (at your
|
10
|
+
# option) any later version.
|
11
|
+
#
|
12
|
+
# gravaty is distributed in the hope that it will be useful, but WITHOUT
|
13
|
+
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
14
|
+
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
15
|
+
# for more details.
|
16
|
+
#
|
17
|
+
# You should have received a copy of the GNU General Public License
|
18
|
+
# along with gravaty. If not, see <http://www.gnu.org/licenses/>.
|
19
|
+
#++
|
20
|
+
|
21
|
+
require 'i18n'
|
22
|
+
|
23
|
+
module Gravaty
|
24
|
+
|
25
|
+
# This module is a simple collection of useful things and methods that
|
26
|
+
# I prefer to keep as DRYer as possible. Just include it and use the
|
27
|
+
# methods...
|
28
|
+
#
|
29
|
+
# Author:: {Marco Bresciani}[mailto:marcobresciani_1974@libero.it]
|
30
|
+
# Copyright:: Copyright © 2013, 2014, 2015, 2016, 2017, 2018,
|
31
|
+
# 2019 Marco Bresciani
|
32
|
+
# License:: GNU General Public License version 3
|
33
|
+
module Utils
|
34
|
+
|
35
|
+
# This module contains some utility method to raise errors according
|
36
|
+
# to (possibly) common conditions.
|
37
|
+
#
|
38
|
+
# Author:: {Marco Bresciani}[mailto:marcobresciani_1974@libero.it]
|
39
|
+
# Copyright:: Copyright © 2013, 2014, 2015, 2016, 2017, 2018,
|
40
|
+
# 2019 Marco Bresciani
|
41
|
+
# License:: GNU General Public License version 3
|
42
|
+
module Raisers
|
43
|
+
|
44
|
+
# Raises an +ArgumentError+ according to parameters, unless the
|
45
|
+
# +array+ contains a downcased +value+.
|
46
|
+
def raiser_downcase(name = 'error.value', value = nil, array = nil)
|
47
|
+
unless value.nil?
|
48
|
+
raise ArgumentError,
|
49
|
+
I18n.t(name, value: value) unless array.include? value.downcase
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
# Raises an +ArgumentError+ according to parameters, unless the
|
54
|
+
# +array+ contains the number of the +value+.
|
55
|
+
def raiser_to_i(name = 'error.value', value = nil, array = nil)
|
56
|
+
unless value.nil?
|
57
|
+
raise ArgumentError,
|
58
|
+
I18n.t(name, value: value) unless array.include? value.to_i
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,110 @@
|
|
1
|
+
#--
|
2
|
+
# gravaty
|
3
|
+
# Copyright © 2013, 2014, 2015, 2016, 2017, 2018, 2019 Marco Bresciani
|
4
|
+
#
|
5
|
+
# This file is part of gravaty.
|
6
|
+
#
|
7
|
+
# gravaty is free software: you can redistribute it and/or modify it
|
8
|
+
# under the terms of the GNU General Public License as published by the
|
9
|
+
# Free Software Foundation, either version 3 of the License, or (at your
|
10
|
+
# option) any later version.
|
11
|
+
#
|
12
|
+
# gravaty is distributed in the hope that it will be useful, but WITHOUT
|
13
|
+
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
14
|
+
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
15
|
+
# for more details.
|
16
|
+
#
|
17
|
+
# You should have received a copy of the GNU General Public License
|
18
|
+
# along with gravaty. If not, see <http://www.gnu.org/licenses/>.
|
19
|
+
#++
|
20
|
+
|
21
|
+
module Gravaty
|
22
|
+
module Utils
|
23
|
+
# This module is a simple wrapper container for Peter R. Marreck's gist.
|
24
|
+
#
|
25
|
+
# Author:: {Peter R. Marreck}[mailto:lumbergh@gmail.com]
|
26
|
+
# Copyright:: Copyleft (©) 2013, Peter R. Marreck
|
27
|
+
# License:: This work is released under the BSD 3-Clause License
|
28
|
+
# http://choosealicense.com/licenses/bsd-3-clause/
|
29
|
+
module Rfc5322
|
30
|
+
|
31
|
+
# Author:: {Peter R. Marreck}[mailto:lumbergh@gmail.com]
|
32
|
+
# Copyright:: Copyleft (©) 2013, Peter R. Marreck
|
33
|
+
# License:: This work is released under the BSD 3-Clause License
|
34
|
+
# http://choosealicense.com/licenses/bsd-3-clause/
|
35
|
+
|
36
|
+
# RFC 5322 Email Validation Regex in Ruby
|
37
|
+
|
38
|
+
# This work is released under the BSD 3-Clause License
|
39
|
+
# http://choosealicense.com/licenses/bsd-3-clause/
|
40
|
+
# Copyleft (©) 2013, Peter R. Marreck
|
41
|
+
# All rights reserved.
|
42
|
+
#
|
43
|
+
# Redistribution and use in source and binary forms, with or without
|
44
|
+
# modification, are permitted provided that the following conditions are
|
45
|
+
# met:
|
46
|
+
#
|
47
|
+
# Redistributions of source code must retain the above copyright
|
48
|
+
# notice, this list of conditions and the following disclaimer.
|
49
|
+
#
|
50
|
+
# Redistributions in binary form must reproduce the above copyright
|
51
|
+
# notice, this list of conditions and the following disclaimer in the
|
52
|
+
# documentation and/or other materials provided with the distribution.
|
53
|
+
#
|
54
|
+
# Neither the name of the {organization} nor the names of its
|
55
|
+
# contributors may be used to endorse or promote products derived from
|
56
|
+
# this software without specific prior written permission.
|
57
|
+
#
|
58
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
59
|
+
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
60
|
+
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
61
|
+
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
62
|
+
# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
63
|
+
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
64
|
+
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
65
|
+
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
66
|
+
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
67
|
+
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
68
|
+
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
69
|
+
|
70
|
+
EMAIL = /
|
71
|
+
(?<addr_spec> (?> \g<local_part> @ \g<domain> ) ){0}
|
72
|
+
(?<local_part> (?> \g<dot_atom> | \g<quoted_string> | \g<obs_local_part> ) ){0}
|
73
|
+
(?<domain> (?> \g<dot_atom> | \g<domain_literal> | \g<obs_domain> ) ){0}
|
74
|
+
(?<domain_literal> (?> \g<CFWS>? \[ (?: \g<FWS>? \g<dtext> )* \g<FWS>? \] \g<CFWS>? ) ){0}
|
75
|
+
(?<dtext> (?> [\x21-\x5a] | [\x5e-\x7e] | \g<obs_dtext> ) ){0}
|
76
|
+
(?<quoted_pair> (?> \\ (?: \g<VCHAR> | \g<WSP> ) | \g<obs_qp> ) ){0}
|
77
|
+
(?<dot_atom> (?> \g<CFWS>? \g<dot_atom_text> \g<CFWS>? ) ){0}
|
78
|
+
(?<dot_atom_text> (?> \g<atext> (?: \. \g<atext> )* ) ){0}
|
79
|
+
(?<atext> (?> [a-zA-Z0-9!\#\$%&'*\+\/\=\?\^_`{\|}~\-]+ ) ){0}
|
80
|
+
(?<atom> (?> \g<CFWS>? \g<atext> \g<CFWS>? ) ){0}
|
81
|
+
(?<word> (?> \g<atom> | \g<quoted_string> ) ){0}
|
82
|
+
(?<quoted_string> (?> \g<CFWS>? " (?: \g<FWS>? \g<qcontent> )* \g<FWS>? " \g<CFWS>? ) ){0}
|
83
|
+
(?<qcontent> (?> \g<qtext> | \g<quoted_pair> ) ){0}
|
84
|
+
(?<qtext> (?> \x21 | [\x23-\x5b] | [\x5d-\x7e] | \g<obs_qtext> ) ){0}
|
85
|
+
|
86
|
+
# comments and whitespace
|
87
|
+
(?<FWS> (?> (?: \g<WSP>* \r\n )? \g<WSP>+ | \g<obs_FWS> ) ){0}
|
88
|
+
(?<CFWS> (?> (?: \g<FWS>? \g<comment> )+ \g<FWS>? | \g<FWS> ) ){0}
|
89
|
+
(?<comment> (?> \( (?: \g<FWS>? \g<ccontent> )* \g<FWS>? \) ) ){0}
|
90
|
+
(?<ccontent> (?>\g<ctext> | \g<quoted_pair> | \g<comment> ) ){0}
|
91
|
+
(?<ctext> (?> [\x21-\x27] | [\x2a-\x5b] | [\x5d-\x7e] | \g<obs_ctext> ) ){0}
|
92
|
+
|
93
|
+
# obsolete tokens
|
94
|
+
(?<obs_domain> (?> \g<atom> (?: \. \g<atom> )* ) ){0}
|
95
|
+
(?<obs_local_part> (?> \g<word> (?: \. \g<word> )* ) ){0}
|
96
|
+
(?<obs_dtext> (?> \g<obs_NO_WS_CTL> | \g<quoted_pair> ) ){0}
|
97
|
+
(?<obs_qp> (?> \\ (?: \x00 | \g<obs_NO_WS_CTL> | \n | \r ) ) ){0}
|
98
|
+
(?<obs_FWS> (?> \g<WSP>+ (?: \r\n \g<WSP>+ )* ) ){0}
|
99
|
+
(?<obs_ctext> (?> \g<obs_NO_WS_CTL> ) ){0}
|
100
|
+
(?<obs_qtext> (?> \g<obs_NO_WS_CTL> ) ){0}
|
101
|
+
(?<obs_NO_WS_CTL> (?> [\x01-\x08] | \x0b | \x0c | [\x0e-\x1f] | \x7f ) ){0}
|
102
|
+
|
103
|
+
# character class definitions
|
104
|
+
(?<VCHAR> (?> [\x21-\x7E] ) ){0}
|
105
|
+
(?<WSP> [ \t] ){0}
|
106
|
+
\g<addr_spec>
|
107
|
+
/uix
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|