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,354 @@
|
|
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 'digest'
|
22
|
+
require 'i18n'
|
23
|
+
require 'json'
|
24
|
+
require 'uri'
|
25
|
+
require 'xmlrpc/client'
|
26
|
+
|
27
|
+
require_relative 'utils/downloader'
|
28
|
+
require_relative 'utils/rfc5322'
|
29
|
+
require_relative 'utils/rpc_connector'
|
30
|
+
|
31
|
+
module Gravaty
|
32
|
+
|
33
|
+
# This class is a simple API to retrieve an URL with specified options
|
34
|
+
# from Gravatar site. It can be used to read data for avatars,
|
35
|
+
# profiles or for XML-RPC APi calls. The only needed parameter to
|
36
|
+
# create a Gravaty object is the reference +email+ address.
|
37
|
+
# Author:: {Marco Bresciani}[mailto:marcobresciani_1974@libero.it]
|
38
|
+
# Copyright:: Copyright © 2013, 2014, 2015, 2016, 2017, 2018,
|
39
|
+
# 2019 Marco Bresciani
|
40
|
+
# License:: GNU General Public License version 3
|
41
|
+
class Gravaty
|
42
|
+
include Comparable
|
43
|
+
|
44
|
+
# Provides the MD5 signature (of the small caps version) of the
|
45
|
+
# +email+ address used to build the object.
|
46
|
+
attr_reader :digest
|
47
|
+
|
48
|
+
# Provides the (small caps version of) +email+ address used to build
|
49
|
+
# the object.
|
50
|
+
attr_reader :email
|
51
|
+
|
52
|
+
# Creates a +Gravaty+ object described by the user's +email+. Throws
|
53
|
+
# an +ArgumentError+ exception if the supplied +email+ address is
|
54
|
+
# +nil+ or not valid according to RFC5322.
|
55
|
+
#
|
56
|
+
# Usage:: <tt>new_gravaty = Gravaty.new email, parser</tt>
|
57
|
+
# Params::
|
58
|
+
# - +email_address+, the user's email address (a syntactically
|
59
|
+
# valid one).
|
60
|
+
# - +parser+, a parser duck-responding to the +parse+ method with
|
61
|
+
# two parameters, +method+ name and +value+ string
|
62
|
+
# Returns:: a +Gravaty+ object for the specified +email+ address.
|
63
|
+
# Raises:: +ArgumentError+, if the supplied +email+ address is +nil+
|
64
|
+
# or not valid according to RFC 5322.
|
65
|
+
def initialize(email_address, parser)
|
66
|
+
I18n.load_path = Dir[File.join(File.dirname(__FILE__),
|
67
|
+
'/locales/', '*.yml')]
|
68
|
+
|
69
|
+
raise ArgumentError, I18n.t('error.nil') if email_address.nil?
|
70
|
+
raise ArgumentError, I18n.t('error.invalid', value: email_address) unless Utils::Rfc5322::EMAIL.match email_address # thanks Peter!
|
71
|
+
|
72
|
+
@email = email_address.strip.downcase
|
73
|
+
@digest = Digest::MD5.hexdigest email
|
74
|
+
@gravaty = email
|
75
|
+
@parser = parser
|
76
|
+
end
|
77
|
+
|
78
|
+
# Returns a string containing the URI of the gravatar associated to
|
79
|
+
# internal (provided) email address. Valid keys for the +args+ hash
|
80
|
+
# are: :type, :pixel_size, :force, :secure, :rating, :default.
|
81
|
+
#
|
82
|
+
# Usage::
|
83
|
+
# - <tt>a_string = new_gravaty.avatar</tt>
|
84
|
+
# - <tt>a_string = new_gravaty.avatar</tt>
|
85
|
+
# - <tt>a_string = new_gravaty.avatar pixel_size: 42</tt>
|
86
|
+
# - <tt>a_string = new_gravaty.avatar pixel_size: 42, type:
|
87
|
+
# png'</tt>
|
88
|
+
# - <tt>a_string = new_gravaty.avatar secure: false</tt>
|
89
|
+
# - <tt>a_string = new_gravaty.avatar type: 'jpg', force:
|
90
|
+
# true</tt>
|
91
|
+
# - <tt>a_string = new_gravaty.avatar secure: true, pixel_size:
|
92
|
+
# 42, type: 'png'</tt>
|
93
|
+
# - <tt>a_string = new_gravaty.avatar rating: pg, type: 'gif'</tt>
|
94
|
+
# - <tt>a_string = new_gravaty.avatar default: monsterid,
|
95
|
+
# pixel_size: 42</tt>
|
96
|
+
# Params::
|
97
|
+
# - +type+: [String] is the possibly desired specific image
|
98
|
+
# format. Valid formats are jp(e)g, png or gif. Default to no
|
99
|
+
# extension. Will be downcased. Raises <code>ArgumentError</code>
|
100
|
+
# for invalid formats.
|
101
|
+
# - +pixel_size+: [Integer] is the size in pixel of the image.
|
102
|
+
# From 1 to 2048. Default to no value. Raises
|
103
|
+
# <code>ArgumentError</code> for invalid sizes.
|
104
|
+
# - +force+: [TrueClass || FalseClass] is a boolean to specify if
|
105
|
+
# the default has to be forced when no image is found. Default to
|
106
|
+
# false.
|
107
|
+
# - +secure+: [TrueClass || FalseClass] is a boolean to specify
|
108
|
+
# whether the resulting URL shall be HTTPS or HTTP type. Default to
|
109
|
+
# true (HTTPS).
|
110
|
+
# - +rating+: [String] is the rating type of the image. Valid
|
111
|
+
# values are 'g', 'pg', 'r' and 'x'.
|
112
|
+
# - +default+: [String] is the default type of the image (valid
|
113
|
+
# values are '404', 'mm', 'identicon', 'monsterid', 'wavatar',
|
114
|
+
# 'retro' and 'blank'), or the URI for an own default image. For the
|
115
|
+
# URI validation see:
|
116
|
+
# http://it.gravatar.com/site/implement/images/#default-image .
|
117
|
+
# Returns:: a +String+ containing the Gravatar site URI with
|
118
|
+
# specified options and configuration parameters.
|
119
|
+
def avatar(args = {})
|
120
|
+
secure = true
|
121
|
+
type = nil
|
122
|
+
|
123
|
+
array = []
|
124
|
+
unless args.nil?
|
125
|
+
type = args.fetch(:type, nil)
|
126
|
+
secure = args.fetch(:secure, secure)
|
127
|
+
|
128
|
+
[:pixelsize, :force, :default, :rating].each do |param|
|
129
|
+
array << @parser.parse(param.to_s, args[param]) unless args[param].nil?
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
build_uri(secure, true) + digest +
|
134
|
+
@parser.parse('type', type) + build_query_string(array)
|
135
|
+
end
|
136
|
+
|
137
|
+
# See avatar method. This banged version saves the resulting string
|
138
|
+
# as internal state.
|
139
|
+
def avatar!(args = {})
|
140
|
+
@gravaty = avatar(args)
|
141
|
+
end
|
142
|
+
|
143
|
+
# Returns a string containing the URI of the gravatar profile
|
144
|
+
# associated to internal (provided) email address. Valid keys for
|
145
|
+
# the +args+ hash are: :secure, :format.
|
146
|
+
#
|
147
|
+
# Usage::
|
148
|
+
# - <tt>a_string = new_gravaty.profile</tt>
|
149
|
+
# - <tt>a_string = new_gravaty.profile secure: false</tt>
|
150
|
+
# - <tt>a_string = new_gravaty.profile format: 'php', secure:
|
151
|
+
# true</tt>
|
152
|
+
# Params::
|
153
|
+
# - +format+: [String] is the possibly desired specific profile
|
154
|
+
# format. Valid formats are 'json', 'xml', 'php', 'vcf' and 'qr'.
|
155
|
+
# Default to no extension. Will be downcased. Defaults to no
|
156
|
+
# extension for invalid formats.
|
157
|
+
# - +secure+: [TrueClass || FalseClass] is a boolean to specify
|
158
|
+
# whether the resulting URL shall be HTTPS or HTTP type. Default to
|
159
|
+
# true (HTTPS).
|
160
|
+
# Returns:: a +String+ containing the Gravatar site URI with
|
161
|
+
# specified options and configuration parameters.
|
162
|
+
def profile(args = {})
|
163
|
+
secure = true
|
164
|
+
format = nil
|
165
|
+
|
166
|
+
array = []
|
167
|
+
unless args.nil?
|
168
|
+
format = args[:format].downcase unless args[:format].nil?
|
169
|
+
secure = args.fetch(:secure, secure)
|
170
|
+
|
171
|
+
unless (format.nil?) and (PROFILES.include? format)
|
172
|
+
selected = (format == 'json' ? 'callback' : 'pixelsize')
|
173
|
+
|
174
|
+
array << @parser.parse(selected, args[selected.to_sym]) unless args[selected.to_sym].nil?
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
build_uri(secure, false) + digest +
|
179
|
+
@parser.parse('format', format) + build_query_string(array)
|
180
|
+
end
|
181
|
+
|
182
|
+
# See profile method. This banged version saves the resulting strin
|
183
|
+
# as internal state.
|
184
|
+
def profile!(args = {})
|
185
|
+
@gravaty = profile(args)
|
186
|
+
end
|
187
|
+
|
188
|
+
# Saves a file, with specified +filename+, that contains the current
|
189
|
+
# gravaty configuration. Uses the internal state to retrieve data
|
190
|
+
# from the URI. Defaults to 'gravaty' with no specific extension.
|
191
|
+
#
|
192
|
+
# Usage::
|
193
|
+
# - <tt>a_string = new_gravaty.download filename</tt>
|
194
|
+
# Params::
|
195
|
+
# - +filename+: [String] is the filename to be saved.
|
196
|
+
def download(filename = nil)
|
197
|
+
filename = URI.parse(@gravaty).path.rpartition('/')
|
198
|
+
.last if filename.nil?
|
199
|
+
Utils::Downloader::Downloader
|
200
|
+
.download_file @gravaty, filename # thanks Jon!
|
201
|
+
end
|
202
|
+
|
203
|
+
# See profile method. Customized version for QRCode-specific
|
204
|
+
# requests.
|
205
|
+
#
|
206
|
+
# Usage::
|
207
|
+
# - <tt>a_string = new_gravaty.qrcode</tt>
|
208
|
+
# - <tt>a_string = new_gravaty.qrcode pixel_size: 42</tt>
|
209
|
+
# - <tt>a_string = new_gravaty.qrcode secure: false, pixel_size:
|
210
|
+
# 42</tt>
|
211
|
+
# Params::
|
212
|
+
# - +secure+: [TrueClass || FalseClass] is a boolean to specify
|
213
|
+
# whether the resulting URL shall be HTTPS or HTTP type. Default to
|
214
|
+
# true (HTTPS).
|
215
|
+
# - +pixel_size+: [Integer] is the size in pixel of the image.
|
216
|
+
# From 1 to 2048. Default to no value. Raises
|
217
|
+
# <code>ArgumentError</code> for invalid sizes.
|
218
|
+
# Returns:: a +String+ containing the Gravatar site URI with
|
219
|
+
# specified options and configuration parameters, in QRCode format.
|
220
|
+
def qrcode(args = {})
|
221
|
+
secure = true
|
222
|
+
size = nil
|
223
|
+
|
224
|
+
unless args.nil?
|
225
|
+
size = args.fetch(:pixelsize, nil)
|
226
|
+
secure = args.fetch(:secure, secure)
|
227
|
+
end
|
228
|
+
|
229
|
+
profile format: 'qr', secure: secure, pixelsize: size
|
230
|
+
end
|
231
|
+
|
232
|
+
# See qrcode method. This banged version saves the resulting string
|
233
|
+
# as internal state.
|
234
|
+
def qrcode!(args = {})
|
235
|
+
@gravaty = qrcode(args)
|
236
|
+
end
|
237
|
+
|
238
|
+
# See profile method. Customized version for JSON-specific requests.
|
239
|
+
#
|
240
|
+
# Usage::
|
241
|
+
# - <tt>a_string = new_gravaty.json</tt>
|
242
|
+
# - <tt>a_string = new_gravaty.json callback: 'alert'</tt>
|
243
|
+
# - <tt>a_string = new_gravaty.qrcode secure: false, callback:
|
244
|
+
# 'alert'</tt>
|
245
|
+
# Params::
|
246
|
+
# - +secure+: [TrueClass || FalseClass] is a boolean to specify
|
247
|
+
# whether the resulting URL shall be HTTPS or HTTP type. Default to
|
248
|
+
# true (HTTPS).
|
249
|
+
# - +callback+: [String] See
|
250
|
+
# https://secure.gravatar.com/site/implement/profiles/json/#request-options.
|
251
|
+
# No check on parameter meaning or validity, except for +nil+.
|
252
|
+
# Returns:: a +String+ containing the Gravatar site URI with
|
253
|
+
# specified options and configuration parameters, in JSON format.
|
254
|
+
def json(args = {})
|
255
|
+
secure = true
|
256
|
+
callback = nil
|
257
|
+
|
258
|
+
unless args.nil?
|
259
|
+
callback = args.fetch(:callback, nil)
|
260
|
+
secure = args.fetch(:secure, secure)
|
261
|
+
end
|
262
|
+
|
263
|
+
profile format: 'json', secure: secure, callback: callback
|
264
|
+
end
|
265
|
+
|
266
|
+
# See json method. This banged version saves the resulting string as
|
267
|
+
# internal state.
|
268
|
+
def json!(args = {})
|
269
|
+
@gravaty = json(args)
|
270
|
+
end
|
271
|
+
|
272
|
+
# Restores the original status cleaning up the (possibly) previously
|
273
|
+
# saved URIs restoring the default +to_s+.
|
274
|
+
def reset
|
275
|
+
@gravaty = email
|
276
|
+
end
|
277
|
+
|
278
|
+
# Interfaces with the Gravatar XML-RPC API.
|
279
|
+
#
|
280
|
+
# Usage::
|
281
|
+
# - <tt>response = new_gravaty.xmlrpc 'grav.test',
|
282
|
+
# my_password</tt>
|
283
|
+
# Params::
|
284
|
+
# - +a_method+: [String] is a valid method supported by Gravatar
|
285
|
+
# XML-RPC API. See https://en.gravatar.com/site/implement/xmlrpc/ .
|
286
|
+
# - +password+: [String] is a valid password associated to user's
|
287
|
+
# +email_address+ specified to build the Gravaty object.
|
288
|
+
# - +args+: See https://en.gravatar.com/site/implement/xmlrpc/ for
|
289
|
+
# possible parameters, depending on called method.
|
290
|
+
# Returns:: See https://en.gravatar.com/site/implement/xmlrpc/ for
|
291
|
+
# possible return values, depending on called method.
|
292
|
+
def xmlrpc(a_method = RPC_TEST_METHOD, password = nil, args = {})
|
293
|
+
raise ArgumentError, I18n.t('error.nil') if password.nil?
|
294
|
+
raise ArgumentError, I18n.t('error.invalid', value: a_method) unless RPC_METHODS.include? a_method
|
295
|
+
|
296
|
+
@rpc_connector = Utils::RpcConnector::RpcConnector
|
297
|
+
.new(digest, password) if @rpc_connector.nil?
|
298
|
+
@rpc_connector.call a_method, args unless @rpc_connector.nil?
|
299
|
+
end
|
300
|
+
|
301
|
+
# Returns a JSon object representing the Gravaty object.
|
302
|
+
#
|
303
|
+
#
|
304
|
+
# Usage::
|
305
|
+
# - <tt>a_json = new_gravaty.to_json</tt>
|
306
|
+
# Returns:: a +JSON+ containing the Gravaty object representation
|
307
|
+
# with currently saved options and configuration parameters.
|
308
|
+
def to_json
|
309
|
+
result = Hash.new
|
310
|
+
result[email] = digest
|
311
|
+
|
312
|
+
result.to_json
|
313
|
+
end
|
314
|
+
|
315
|
+
# Returns a string representing the Gravaty object.
|
316
|
+
#
|
317
|
+
#
|
318
|
+
# Usage::
|
319
|
+
# - <tt>a_string = new_gravaty.to_s</tt>
|
320
|
+
# Returns:: a +String+ containing the Gravaty object representation
|
321
|
+
# with currently saved options and configuration parameters.
|
322
|
+
def to_s
|
323
|
+
@gravaty.to_s
|
324
|
+
end
|
325
|
+
|
326
|
+
def <=>(other_gravaty)
|
327
|
+
@email <=> other_gravaty.email
|
328
|
+
end
|
329
|
+
|
330
|
+
# -------------------------- here starts the list of private methods
|
331
|
+
|
332
|
+
private
|
333
|
+
|
334
|
+
# Builds the query string with the array of parameters.
|
335
|
+
def build_query_string(params_array = [])
|
336
|
+
parameters = nil
|
337
|
+
|
338
|
+
unless params_array.nil?
|
339
|
+
parameters = params_array.reject {|p| p.nil? or p.empty?}
|
340
|
+
.join('&')
|
341
|
+
end
|
342
|
+
|
343
|
+
return ('?' + parameters) unless parameters.nil? or parameters
|
344
|
+
.empty?
|
345
|
+
''
|
346
|
+
end
|
347
|
+
|
348
|
+
# Return the basic URI structure according to type and security.
|
349
|
+
def build_uri(secure = false, avatar = true)
|
350
|
+
@parser.parse('secure', secure) + '.gravatar.com/' +
|
351
|
+
@parser.parse('avatar', avatar)
|
352
|
+
end
|
353
|
+
end
|
354
|
+
end
|
@@ -0,0 +1,65 @@
|
|
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
|
+
# Allowed sizes (in pixels) for images requests. Currently a range
|
23
|
+
# from 1 to 2048 (included).
|
24
|
+
ALLOWED_SIZES = (1...2048)
|
25
|
+
|
26
|
+
# Allowed parameters names. Currently: avatar, callback, default,
|
27
|
+
# force, format, pixelsize, rating, secure and type.
|
28
|
+
ALLOWED_PARAMS = [:avatar, :callback, :default, :force, :format,
|
29
|
+
:pixelsize, :rating, :secure, :type]
|
30
|
+
|
31
|
+
# Allowed formats (extensions) for avatar requests. Currently:
|
32
|
+
# jp(e)g, png and gif.
|
33
|
+
AVATAR_FORMATS = %w(jpg jpeg png gif)
|
34
|
+
|
35
|
+
# Currently allowed default builtin options. Currently: 404, mp,
|
36
|
+
# identicon, monsterid,wavatar, retro, robohash and blank.
|
37
|
+
DEFAULT_OPTIONS = %w(404 mp identicon monsterid wavatar retro robohash blank)
|
38
|
+
|
39
|
+
# Allowed formats (extensions) for default own images. Currently:
|
40
|
+
# jp(e)g, png and gif.
|
41
|
+
IMAGES_FORMATS = %w(jpg jpeg png gif)
|
42
|
+
|
43
|
+
# Allowed formats (extensions) for profile requests. Currently: json,
|
44
|
+
# xml, php, vcf and qr.
|
45
|
+
PROFILE_FORMATS = %w(json xml php vcf qr)
|
46
|
+
|
47
|
+
# Formats allowing supplemental options for profile requests.
|
48
|
+
# Currently json and qr.
|
49
|
+
PROFILES = %w(json qr)
|
50
|
+
|
51
|
+
# Allowed rating options. Currently: g, pg, r and x.
|
52
|
+
RATING_OPTIONS = %w(g pg r x)
|
53
|
+
|
54
|
+
# Possible XML-RPC API errors.
|
55
|
+
RPC_ERRORS = [-7, -8, -9, -10, -11, -100]
|
56
|
+
|
57
|
+
# Allowed XML-RPC API methods.
|
58
|
+
RPC_METHODS = %w(grav.exists grav.addresses grav.userimages grav.saveData grav.saveUrl grav.useUserimage grav.removeImage grav.deleteUserimage grav.test)
|
59
|
+
|
60
|
+
# Default test method for XML-RPC API.
|
61
|
+
RPC_TEST_METHOD = 'grav.test'
|
62
|
+
|
63
|
+
# Reference URI for XML-RPC API.
|
64
|
+
RPC_URI = 'secure.gravatar.com'
|
65
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# gravaty
|
2
|
+
# Copyright © 2013, 2014, 2015, 2016, 2017, 2018, 2019 Marco Bresciani
|
3
|
+
#
|
4
|
+
# This file is part of gravaty.
|
5
|
+
#
|
6
|
+
# gravaty is free software: you can redistribute it and/or modify it
|
7
|
+
# under the terms of the GNU General Public License as published by the
|
8
|
+
# Free Software Foundation, either version 3 of the License, or (at your
|
9
|
+
# option) any later version.
|
10
|
+
#
|
11
|
+
# gravaty is distributed in the hope that it will be useful, but WITHOUT
|
12
|
+
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
13
|
+
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
14
|
+
# for more details.
|
15
|
+
#
|
16
|
+
# You should have received a copy of the GNU General Public License
|
17
|
+
# along with gravaty. If not, see <http://www.gnu.org/licenses/>.
|
18
|
+
|
19
|
+
en:
|
20
|
+
error:
|
21
|
+
invalid: "Invalid parameter '%{value}' according to RFC822 at later updates."
|
22
|
+
nil: nil parameter not allowed.
|
23
|
+
param: "Parameter '%{value}' is not valid."
|
24
|
+
type: "Type '%{value}' is not a known extension."
|
25
|
+
uri: "URI '%{value}' is not valid."
|
26
|
+
value: "Value '%{value}' is not in allowed range."
|
27
|
+
warn:
|
28
|
+
deprecated: This method has been deprecated.
|
29
|
+
test:
|
30
|
+
test: test data
|
31
|
+
gravatar:
|
32
|
+
errors:
|
33
|
+
-7: Use secure.gravatar.com
|
34
|
+
-8: Internal error
|
35
|
+
-9: Authentication error
|
36
|
+
-10: Method parameter missing
|
37
|
+
-11: Method parameter incorrect
|
38
|
+
-100: Misc error (see text)
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# gravaty
|
2
|
+
# Copyright © 2013, 2014, 2015, 2016, 2017, 2018, 2019 Marco Bresciani
|
3
|
+
#
|
4
|
+
# This file is part of gravaty.
|
5
|
+
#
|
6
|
+
# gravaty is free software: you can redistribute it and/or modify it
|
7
|
+
# under the terms of the GNU General Public License as published by the
|
8
|
+
# Free Software Foundation, either version 3 of the License, or (at your
|
9
|
+
# option) any later version.
|
10
|
+
#
|
11
|
+
# gravaty is distributed in the hope that it will be useful, but WITHOUT
|
12
|
+
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
13
|
+
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
14
|
+
# for more details.
|
15
|
+
#
|
16
|
+
# You should have received a copy of the GNU General Public License
|
17
|
+
# along with gravaty. If not, see <http://www.gnu.org/licenses/>.
|
18
|
+
|
19
|
+
it:
|
20
|
+
error:
|
21
|
+
invalid: "Parametro '%{value}' non valido rispetto a RFC822 e modifiche successive."
|
22
|
+
nil: Parametro nil non consentito.
|
23
|
+
param: "Il parametro '%{value}' non è valido."
|
24
|
+
type: "Il tipo '%{value}' non è un'estensione conosciuta."
|
25
|
+
uri: "L'URI '%{value}' non è valido."
|
26
|
+
value: "Il valore '%{value}' non è nell'intervallo previsto."
|
27
|
+
warn:
|
28
|
+
deprecated: Questo metodo è obsoleto.
|
29
|
+
test:
|
30
|
+
test: dato di prova
|
31
|
+
gravatar:
|
32
|
+
errors:
|
33
|
+
-7: Utilizzare secure.gravatar.com
|
34
|
+
-8: Errore interno
|
35
|
+
-9: Errore di autenticazione
|
36
|
+
-10: Parametro metodo mancante
|
37
|
+
-11: Parametro metodo non corretto
|
38
|
+
-100: Errore di altro tipo (vedi testo)
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# gravaty
|
2
|
+
# Copyright © 2013 新部裕
|
3
|
+
# Copyright © 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
|
+
ja:
|
21
|
+
error:
|
22
|
+
invalid: "無効なパラメータ '%{value}' です(RFC5322 もしくは以後の更新による)。"
|
23
|
+
nil: nil パラメータは許されません。
|
24
|
+
param: "パラメータ '%{value}' は無効です。"
|
25
|
+
type: "型 '%{value}' は既知の拡張ではありません。"
|
26
|
+
uri: "URI '%{value}' が無効です。"
|
27
|
+
value: "値 '%{value}' が範囲外です。"
|
28
|
+
warn:
|
29
|
+
deprecated: このメソッドはすでに廃止され、推奨されていません。
|
30
|
+
test:
|
31
|
+
test: 試験データ
|
32
|
+
gravatar:
|
33
|
+
errors:
|
34
|
+
-7: secure.gravatar.com を使用
|
35
|
+
-8: 内部エラー
|
36
|
+
-9: 認証エラー
|
37
|
+
-10: メソッド引数がありません
|
38
|
+
-11: メソッド引数が間違っています
|
39
|
+
-100: その他のエラー (テキスト参照)
|
@@ -0,0 +1,50 @@
|
|
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
|
+
|
23
|
+
module Gravaty
|
24
|
+
|
25
|
+
# This class is a simple utility that is used to parse and filter
|
26
|
+
# parameters for gravaty.
|
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 Parser
|
33
|
+
attr_reader :parsers
|
34
|
+
|
35
|
+
def initialize(args = {})
|
36
|
+
@parsers = Hash.new
|
37
|
+
ALLOWED_PARAMS.each do |param|
|
38
|
+
parsers[param] = args[param]
|
39
|
+
end unless args.nil?
|
40
|
+
end
|
41
|
+
|
42
|
+
# Provides the duck type for a generic parsing object.
|
43
|
+
def parse(method = nil, value = nil)
|
44
|
+
a_parser = nil
|
45
|
+
a_parser = parsers[method.to_sym] unless method.nil? or
|
46
|
+
parsers.nil?
|
47
|
+
a_parser.parse value unless a_parser.nil?
|
48
|
+
end
|
49
|
+
end
|
50
|
+
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 for avater or profile URI. The only needed parameter is a
|
26
|
+
# boolean, with +true+ for avatar.
|
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 Avatar
|
33
|
+
|
34
|
+
# The parsable duck type interface to every parser usage.
|
35
|
+
def parse(value = true)
|
36
|
+
value ? 'avatar/' : ''
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,41 @@
|
|
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 callback name. The only needed parameter is a valid
|
26
|
+
# callback +String+ name.
|
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 Callback
|
33
|
+
|
34
|
+
# The parsable duck type interface to every parser usage.
|
35
|
+
def parse(value = nil)
|
36
|
+
return "callback=#{value}" unless value.nil? or value.empty?
|
37
|
+
''
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|