gravaty 8.0.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of gravaty might be problematic. Click here for more details.

Files changed (137) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG +587 -0
  3. data/COPYING.md +234 -0
  4. data/Gemfile +17 -0
  5. data/ISSUES.md +40 -0
  6. data/README.md +128 -0
  7. data/Rakefile +48 -0
  8. data/acknowledgements.md +40 -0
  9. data/authors.md +44 -0
  10. data/copyright.md +339 -0
  11. data/examples/avatar.rb +121 -0
  12. data/examples/basics.rb +60 -0
  13. data/examples/profile.rb +143 -0
  14. data/examples/xmlrpc.rb +33 -0
  15. data/gravaty.gemspec +59 -0
  16. data/gravaty.odp +0 -0
  17. data/gravaty.pdf +0 -0
  18. data/html/CHANGELOG.html +876 -0
  19. data/html/COPYING_md.html +803 -0
  20. data/html/Gemfile.html +114 -0
  21. data/html/Gravaty.html +322 -0
  22. data/html/Gravaty/Gravaty.html +997 -0
  23. data/html/Gravaty/ParsableDuckType.html +158 -0
  24. data/html/Gravaty/Parser.html +233 -0
  25. data/html/Gravaty/Parsers.html +94 -0
  26. data/html/Gravaty/Parsers/Avatar.html +166 -0
  27. data/html/Gravaty/Parsers/Callback.html +167 -0
  28. data/html/Gravaty/Parsers/Default.html +174 -0
  29. data/html/Gravaty/Parsers/Force.html +167 -0
  30. data/html/Gravaty/Parsers/Format.html +177 -0
  31. data/html/Gravaty/Parsers/Pixelsize.html +177 -0
  32. data/html/Gravaty/Parsers/Rating.html +177 -0
  33. data/html/Gravaty/Parsers/Secure.html +166 -0
  34. data/html/Gravaty/Parsers/Type.html +177 -0
  35. data/html/Gravaty/Utils.html +107 -0
  36. data/html/Gravaty/Utils/Downloader.html +106 -0
  37. data/html/Gravaty/Utils/Downloader/Downloader.html +224 -0
  38. data/html/Gravaty/Utils/Raisers.html +199 -0
  39. data/html/Gravaty/Utils/Rfc5322.html +149 -0
  40. data/html/Gravaty/Utils/RpcConnector.html +106 -0
  41. data/html/Gravaty/Utils/RpcConnector/RpcConnector.html +241 -0
  42. data/html/ISSUES_md.html +165 -0
  43. data/html/Object.html +183 -0
  44. data/html/README_md.html +436 -0
  45. data/html/Rakefile.html +152 -0
  46. data/html/acknowledgements_md.html +172 -0
  47. data/html/authors_md.html +178 -0
  48. data/html/copyright_md.html +553 -0
  49. data/html/created.rid +59 -0
  50. data/html/css/fonts.css +167 -0
  51. data/html/css/rdoc.css +590 -0
  52. data/html/fonts/Lato-Light.ttf +0 -0
  53. data/html/fonts/Lato-LightItalic.ttf +0 -0
  54. data/html/fonts/Lato-Regular.ttf +0 -0
  55. data/html/fonts/Lato-RegularItalic.ttf +0 -0
  56. data/html/fonts/SourceCodePro-Bold.ttf +0 -0
  57. data/html/fonts/SourceCodePro-Regular.ttf +0 -0
  58. data/html/gravaty_gemspec.html +162 -0
  59. data/html/images/add.png +0 -0
  60. data/html/images/arrow_up.png +0 -0
  61. data/html/images/brick.png +0 -0
  62. data/html/images/brick_link.png +0 -0
  63. data/html/images/bug.png +0 -0
  64. data/html/images/bullet_black.png +0 -0
  65. data/html/images/bullet_toggle_minus.png +0 -0
  66. data/html/images/bullet_toggle_plus.png +0 -0
  67. data/html/images/date.png +0 -0
  68. data/html/images/delete.png +0 -0
  69. data/html/images/find.png +0 -0
  70. data/html/images/loadingAnimation.gif +0 -0
  71. data/html/images/macFFBgHack.png +0 -0
  72. data/html/images/package.png +0 -0
  73. data/html/images/page_green.png +0 -0
  74. data/html/images/page_white_text.png +0 -0
  75. data/html/images/page_white_width.png +0 -0
  76. data/html/images/plugin.png +0 -0
  77. data/html/images/ruby.png +0 -0
  78. data/html/images/tag_blue.png +0 -0
  79. data/html/images/tag_green.png +0 -0
  80. data/html/images/transparent.png +0 -0
  81. data/html/images/wrench.png +0 -0
  82. data/html/images/wrench_orange.png +0 -0
  83. data/html/images/zoom.png +0 -0
  84. data/html/index.html +467 -0
  85. data/html/js/darkfish.js +161 -0
  86. data/html/js/jquery.js +4 -0
  87. data/html/js/navigation.js +142 -0
  88. data/html/js/navigation.js.gz +0 -0
  89. data/html/js/search.js +109 -0
  90. data/html/js/search_index.js +1 -0
  91. data/html/js/search_index.js.gz +0 -0
  92. data/html/js/searcher.js +229 -0
  93. data/html/js/searcher.js.gz +0 -0
  94. data/html/table_of_contents.html +479 -0
  95. data/lib/gravaty.rb +59 -0
  96. data/lib/gravaty/application.rb +272 -0
  97. data/lib/gravaty/constants.rb +53 -0
  98. data/lib/gravaty/locales/en.yml +34 -0
  99. data/lib/gravaty/locales/it.yml +34 -0
  100. data/lib/gravaty/locales/ja.yml +35 -0
  101. data/lib/gravaty/parser.rb +41 -0
  102. data/lib/gravaty/parsers/avatar.rb +33 -0
  103. data/lib/gravaty/parsers/callback.rb +34 -0
  104. data/lib/gravaty/parsers/default.rb +79 -0
  105. data/lib/gravaty/parsers/force.rb +33 -0
  106. data/lib/gravaty/parsers/format.rb +38 -0
  107. data/lib/gravaty/parsers/pixelsize.rb +38 -0
  108. data/lib/gravaty/parsers/rating.rb +38 -0
  109. data/lib/gravaty/parsers/secure.rb +32 -0
  110. data/lib/gravaty/parsers/type.rb +38 -0
  111. data/lib/gravaty/utils/downloader.rb +150 -0
  112. data/lib/gravaty/utils/raisers.rb +50 -0
  113. data/lib/gravaty/utils/rfc5322.rb +102 -0
  114. data/lib/gravaty/utils/rpc_connector.rb +71 -0
  115. data/lib/gravaty/version.rb +20 -0
  116. data/test/gravaty/locales/test_locales.rb +61 -0
  117. data/test/gravaty/parsers/test_avatar.rb +35 -0
  118. data/test/gravaty/parsers/test_callback.rb +37 -0
  119. data/test/gravaty/parsers/test_default.rb +69 -0
  120. data/test/gravaty/parsers/test_force.rb +35 -0
  121. data/test/gravaty/parsers/test_format.rb +48 -0
  122. data/test/gravaty/parsers/test_pixelsize.rb +50 -0
  123. data/test/gravaty/parsers/test_rating.rb +48 -0
  124. data/test/gravaty/parsers/test_secure.rb +35 -0
  125. data/test/gravaty/parsers/test_type.rb +37 -0
  126. data/test/gravaty/test_application.rb +111 -0
  127. data/test/gravaty/test_avatar.rb +115 -0
  128. data/test/gravaty/test_parsable_duck_type.rb +31 -0
  129. data/test/gravaty/test_parser.rb +55 -0
  130. data/test/gravaty/test_profile.rb +63 -0
  131. data/test/gravaty/utils/test_downloader.rb +43 -0
  132. data/test/gravaty/utils/test_raisers.rb +55 -0
  133. data/test/gravaty/utils/test_rfc5322.rb +58 -0
  134. data/test/gravaty/utils/test_rpc_connector.rb +74 -0
  135. data/test/test_gravaty.rb +44 -0
  136. data/test/test_helper.rb +77 -0
  137. metadata +315 -0
@@ -0,0 +1,59 @@
1
+ #
2
+ # gravaty
3
+ # Copyright © 2013, 2014, 2015, 2016 Marco Bresciani
4
+ #
5
+ # This file is part of gravaty.
6
+ #
7
+ # gravaty is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License
8
+ # as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
9
+ #
10
+ # gravaty is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
11
+ # of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU General Public License along with gravaty. If not, see
14
+ # <http://www.gnu.org/licenses/>.
15
+ #
16
+
17
+ require 'digest/md5'
18
+ require 'i18n'
19
+ require 'uri'
20
+
21
+ require_relative 'gravaty/application'
22
+ require_relative 'gravaty/parser'
23
+ require_relative 'gravaty/parsers/avatar'
24
+ require_relative 'gravaty/parsers/callback'
25
+ require_relative 'gravaty/parsers/default'
26
+ require_relative 'gravaty/parsers/force'
27
+ require_relative 'gravaty/parsers/format'
28
+ require_relative 'gravaty/parsers/pixelsize'
29
+ require_relative 'gravaty/parsers/rating'
30
+ require_relative 'gravaty/parsers/secure'
31
+ require_relative 'gravaty/parsers/type'
32
+
33
+ # Author:: {Marco Bresciani}[mailto:m.bresciani@email.it]
34
+ # Copyright:: Copyright © 2013, 2014, 2015, 2016 Marco Bresciani
35
+ # License:: GNU General Public License version 3
36
+ module Gravaty
37
+
38
+ # Creates a new Gravaty described by the user's +email+. Throws a <code>ArgumentError</code> exception if the supplied +email+ address is nil or not valid according to RFC5322.
39
+ #
40
+ # Usage::
41
+ # - <tt>new_gravaty = Gravaty::gravatize email</tt>
42
+ # - <tt>new_gravaty = Gravaty::gravatize(email)</tt>
43
+ # Params:: +email_address+, the user's email address (a syntactically valid one).
44
+ # Returns:: a +Gravaty+ object for the specified +email+ address.
45
+ # Raises:: +ArgumentError+, if the supplied +email+ address is +nil+ or not valid according to RFC 5322.
46
+ def self.gravatize(email_address)
47
+ Gravaty.new email_address, parser
48
+ end
49
+
50
+ # ------------------------------------------------------------------------------ here starts the list of private methods
51
+ private
52
+
53
+ # Provides the parameters' parsers object.
54
+ def self.parser
55
+ parsers = {avatar: Parsers::Avatar.new, callback: Parsers::Callback.new, default: Parsers::Default.new, force: Parsers::Force.new, format: Parsers::Format.new, pixelsize: Parsers::Pixelsize.new, rating: Parsers::Rating.new, secure: Parsers::Secure.new, type: Parsers::Type.new}
56
+
57
+ Parser.new parsers
58
+ end
59
+ end
@@ -0,0 +1,272 @@
1
+ #--
2
+ # gravaty
3
+ # Copyright © 2013, 2014, 2015, 2016 Marco Bresciani
4
+ #
5
+ # This file is part of gravaty.
6
+ #
7
+ # gravaty is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License
8
+ # as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
9
+ #
10
+ # gravaty is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
11
+ # of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU General Public License along with gravaty. If not, see
14
+ # <http://www.gnu.org/licenses/>.
15
+ #++
16
+
17
+ require 'digest/md5'
18
+ require 'i18n'
19
+ require 'json'
20
+ require 'uri'
21
+ require 'xmlrpc/client'
22
+
23
+ require_relative 'utils/downloader'
24
+ require_relative 'utils/rfc5322'
25
+ require_relative 'utils/rpc_connector'
26
+
27
+ module Gravaty
28
+
29
+ # This class is a simple API to retrieve an URL with specified options from Gravatar site. It can be used to read data for avatars, profiles or for XML-RPC APi calls. The only needed parameter to create a Gravaty object is the reference +email+ address.
30
+ # Author:: {Marco Bresciani}[mailto:m.bresciani@email.it]
31
+ # Copyright:: Copyright © 2013, 2014, 2015, 2016 Marco Bresciani
32
+ # License:: GNU General Public License version 3
33
+ class Gravaty
34
+ include Comparable
35
+
36
+ # Provides the MD5 signature (of the small caps version) of the +email+ address used to build the object.
37
+ attr_reader :digest
38
+
39
+ # Provides the (small caps version of) +email+ address used to build the object.
40
+ attr_reader :email
41
+
42
+ # Creates a +Gravaty+ object described by the user's +email+. Throws an +ArgumentError+ exception if the supplied +email+ address is +nil+ or not valid according to RFC5322.
43
+ #
44
+ # Usage:: <tt>new_gravaty = Gravaty.new email, parser</tt>
45
+ # Params::
46
+ # - +email_address+, the user's email address (a syntactically valid one).
47
+ # - +parser+, a parser duck-responding to the +parse+ method with two parameters, +method+ name and +value+ string
48
+ # Returns:: a +Gravaty+ object for the specified +email+ address.
49
+ # Raises:: +ArgumentError+, if the supplied +email+ address is +nil+ or not valid according to RFC 5322.
50
+ def initialize(email_address, parser)
51
+ I18n.load_path = Dir[File.join(File.dirname(__FILE__), '/locales/', '*.yml')]
52
+
53
+ raise ArgumentError, I18n.t('error.nil') if email_address.nil?
54
+ raise ArgumentError, I18n.t('error.invalid', value: email_address) unless Utils::Rfc5322::EMAIL.match email_address # thanks Peter!
55
+
56
+ @email = email_address.strip.downcase
57
+ @digest = Digest::MD5.hexdigest email
58
+ @gravaty = email
59
+ @parser = parser
60
+ end
61
+
62
+ # Returns a string containing the URI of the gravatar associated to internal (provided) email address. Valid keys for the +args+ hash are: :type, :pixel_size, :force, :secure, :rating, :default.
63
+ #
64
+ # Usage::
65
+ # - <tt>a_string = new_gravaty.avatar</tt>
66
+ # - <tt>a_string = new_gravaty.avatar</tt>
67
+ # - <tt>a_string = new_gravaty.avatar pixel_size: 42</tt>
68
+ # - <tt>a_string = new_gravaty.avatar pixel_size: 42, type: 'png'</tt>
69
+ # - <tt>a_string = new_gravaty.avatar secure: false</tt>
70
+ # - <tt>a_string = new_gravaty.avatar type: 'jpg', force: true</tt>
71
+ # - <tt>a_string = new_gravaty.avatar secure: true, pixel_size: 42, type: 'png'</tt>
72
+ # - <tt>a_string = new_gravaty.avatar rating: pg, type: 'gif'</tt>
73
+ # - <tt>a_string = new_gravaty.avatar default: monsterid, pixel_size: 42</tt>
74
+ # Params::
75
+ # - +type+: [String] is the possibly desired specific image format. Valid formats are jp(e)g, png or gif. Default to no extension. Will be downcased. Raises <code>ArgumentError</code> for invalid formats.
76
+ # - +pixel_size+: [Integer] is the size in pixel of the image. From 1 to 2048. Default to no value. Raises <code>ArgumentError</code> for invalid sizes.
77
+ # - +force+: [TrueClass || FalseClass] is a boolean to specify if the default has to be forced when no image is found. Default to false.
78
+ # - +secure+: [TrueClass || FalseClass] is a boolean to specify whether the resulting URL shall be HTTPS or HTTP type. Default to true (HTTPS).
79
+ # - +rating+: [String] is the rating type of the image. Valid values are 'g', 'pg', 'r' and 'x'.
80
+ # - +default+: [String] is the default type of the image (valid values are '404', 'mm', 'identicon', 'monsterid', 'wavatar', 'retro' and 'blank'), or the URI for an own default image. For the URI validation see: http://it.gravatar.com/site/implement/images/#default-image .
81
+ # Returns:: a +String+ containing the Gravatar site URI with specified options and configuration parameters.
82
+ def avatar(args = {})
83
+ secure = true
84
+ type = nil
85
+
86
+ array = []
87
+ unless args.nil?
88
+ type = args.fetch(:type, nil)
89
+ secure = args.fetch(:secure, secure)
90
+
91
+ [:pixelsize, :force, :default, :rating].each do |param|
92
+ array << @parser.parse(param.to_s, args[param]) unless args[param].nil?
93
+ end
94
+ end
95
+
96
+ build_uri(secure, true) + digest + @parser.parse('type', type) + build_query_string(array)
97
+ end
98
+
99
+ # See avatar method. This banged version saves the resulting string as internal state.
100
+ def avatar!(args = {})
101
+ @gravaty = avatar(args)
102
+ end
103
+
104
+ # Returns a string containing the URI of the gravatar profile associated to internal (provided) email address. Valid keys for the +args+ hash are: :secure, :format.
105
+ #
106
+ # Usage::
107
+ # - <tt>a_string = new_gravaty.profile</tt>
108
+ # - <tt>a_string = new_gravaty.profile secure: false</tt>
109
+ # - <tt>a_string = new_gravaty.profile format: 'php', secure: true</tt>
110
+ # Params::
111
+ # - +format+: [String] is the possibly desired specific profile format. Valid formats are 'json', 'xml', 'php', 'vcf' and 'qr'. Default to no extension. Will be downcased. Defaults to no extension for invalid formats.
112
+ # - +secure+: [TrueClass || FalseClass] is a boolean to specify whether the resulting URL shall be HTTPS or HTTP type. Default to true (HTTPS).
113
+ # Returns:: a +String+ containing the Gravatar site URI with specified options and configuration parameters.
114
+ def profile(args = {})
115
+ secure = true
116
+ format = nil
117
+
118
+ array = []
119
+ unless args.nil?
120
+ format = args[:format].downcase unless args[:format].nil?
121
+ secure = args.fetch(:secure, secure)
122
+
123
+ unless (format.nil?) and (PROFILES.include? format)
124
+ selected = (format == 'json' ? 'callback' : 'pixelsize')
125
+
126
+ array << @parser.parse(selected, args[selected.to_sym]) unless args[selected.to_sym].nil?
127
+ end
128
+ end
129
+
130
+ build_uri(secure, false) + digest + @parser.parse('format', format) + build_query_string(array)
131
+ end
132
+
133
+ # See profile method. This banged version saves the resulting string as internal state.
134
+ def profile!(args = {})
135
+ @gravaty = profile(args)
136
+ end
137
+
138
+ # Saves a file, with specified +filename+, that contains the current gravaty configuration. Uses the internal state to retrieve data from the URI. Defaults to 'gravaty' with no specific extension.
139
+ #
140
+ # Usage::
141
+ # - <tt>a_string = new_gravaty.download filename</tt>
142
+ # Params::
143
+ # - +filename+: [String] is the filename to be saved.
144
+ def download(filename = nil)
145
+ filename = URI.parse(@gravaty).path.rpartition('/').last if filename.nil?
146
+ Utils::Downloader::Downloader.download_file @gravaty, filename # thanks Jon!
147
+ end
148
+
149
+ # See profile method. Customized version for QRCode-specific requests.
150
+ #
151
+ # Usage::
152
+ # - <tt>a_string = new_gravaty.qrcode</tt>
153
+ # - <tt>a_string = new_gravaty.qrcode pixel_size: 42</tt>
154
+ # - <tt>a_string = new_gravaty.qrcode secure: false, pixel_size: 42</tt>
155
+ # Params::
156
+ # - +secure+: [TrueClass || FalseClass] is a boolean to specify whether the resulting URL shall be HTTPS or HTTP type. Default to true (HTTPS).
157
+ # - +pixel_size+: [Integer] is the size in pixel of the image. From 1 to 2048. Default to no value. Raises <code>ArgumentError</code> for invalid sizes.
158
+ # Returns:: a +String+ containing the Gravatar site URI with specified options and configuration parameters, in QRCode format.
159
+ def qrcode(args = {})
160
+ secure = true
161
+ size = nil
162
+
163
+ unless args.nil?
164
+ size = args.fetch(:pixelsize, nil)
165
+ secure = args.fetch(:secure, secure)
166
+ end
167
+
168
+ profile format: 'qr', secure: secure, pixelsize: size
169
+ end
170
+
171
+ # See qrcode method. This banged version saves the resulting string as internal state.
172
+ def qrcode!(args = {})
173
+ @gravaty = qrcode(args)
174
+ end
175
+
176
+ # See profile method. Customized version for JSON-specific requests.
177
+ #
178
+ # Usage::
179
+ # - <tt>a_string = new_gravaty.json</tt>
180
+ # - <tt>a_string = new_gravaty.json callback: 'alert'</tt>
181
+ # - <tt>a_string = new_gravaty.qrcode secure: false, callback: 'alert'</tt>
182
+ # Params::
183
+ # - +secure+: [TrueClass || FalseClass] is a boolean to specify whether the resulting URL shall be HTTPS or HTTP type. Default to true (HTTPS).
184
+ # - +callback+: [String] See https://secure.gravatar.com/site/implement/profiles/json/#request-options . No check on parameter meaning or validity, except for +nil+.
185
+ # Returns:: a +String+ containing the Gravatar site URI with specified options and configuration parameters, in JSON format.
186
+ def json(args = {})
187
+ secure = true
188
+ callback = nil
189
+
190
+ unless args.nil?
191
+ callback = args.fetch(:callback, nil)
192
+ secure = args.fetch(:secure, secure)
193
+ end
194
+
195
+ profile format: 'json', secure: secure, callback: callback
196
+ end
197
+
198
+ # See json method. This banged version saves the resulting string as internal state.
199
+ def json!(args = {})
200
+ @gravaty = json(args)
201
+ end
202
+
203
+ # Restores the original status cleaning up the (possibly) previously saved URIs restoring the default +to_s+.
204
+ def reset
205
+ @gravaty = email
206
+ end
207
+
208
+ # Interfaces with the Gravatar XML-RPC API.
209
+ #
210
+ # Usage::
211
+ # - <tt>response = new_gravaty.xmlrpc 'grav.test', my_password</tt>
212
+ # Params::
213
+ # - +a_method+: [String] is a valid method supported by Gravatar XML-RPC API. See https://en.gravatar.com/site/implement/xmlrpc/ .
214
+ # - +password+: [String] is a valid password associated to user's +email_address+ specified to build the Gravaty object.
215
+ # - +args+: See https://en.gravatar.com/site/implement/xmlrpc/ for possible parameters, depending on called method.
216
+ # Returns:: See https://en.gravatar.com/site/implement/xmlrpc/ for possible return values, depending on called method.
217
+ def xmlrpc(a_method = RPC_TEST_METHOD, password = nil, args = {})
218
+ raise ArgumentError, I18n.t('error.nil') if password.nil?
219
+ raise ArgumentError, I18n.t('error.invalid', value: a_method) unless RPC_METHODS.include? a_method
220
+
221
+ @rpc_connector = Utils::RpcConnector::RpcConnector.new(digest, password) if @rpc_connector.nil?
222
+ @rpc_connector.call a_method, args
223
+ end
224
+
225
+ # Returns a JSon object representing the Gravaty object.
226
+ #
227
+ #
228
+ # Usage::
229
+ # - <tt>a_json = new_gravaty.to_json</tt>
230
+ # Returns:: a +JSON+ containing the Gravaty object representation with currently saved options and configuration parameters.
231
+ def to_json
232
+ result = Hash.new
233
+ result[email] = digest
234
+
235
+ result.to_json
236
+ end
237
+
238
+ # Returns a string representing the Gravaty object.
239
+ #
240
+ #
241
+ # Usage::
242
+ # - <tt>a_string = new_gravaty.to_s</tt>
243
+ # Returns:: a +String+ containing the Gravaty object representation with currently saved options and configuration parameters.
244
+ def to_s
245
+ @gravaty.to_s
246
+ end
247
+
248
+ def <=>(other_gravaty)
249
+ @email <=> other_gravaty.email
250
+ end
251
+
252
+ # ------------------------------------------------------------------------------ here starts the list of private methods
253
+ private
254
+
255
+ # Builds the query string with the array of parameters.
256
+ def build_query_string(params_array = [])
257
+ parameters = nil
258
+
259
+ unless params_array.nil?
260
+ parameters = params_array.reject { |p| p.nil? or p.empty? }.join('&')
261
+ end
262
+
263
+ return ('?' + parameters) unless parameters.nil? or parameters.empty?
264
+ ''
265
+ end
266
+
267
+ # Return the basic URI structure according to type and security.
268
+ def build_uri(secure = false, avatar = true)
269
+ @parser.parse('secure', secure) + '.gravatar.com/' + @parser.parse('avatar', avatar)
270
+ end
271
+ end
272
+ end
@@ -0,0 +1,53 @@
1
+ #--
2
+ # gravaty
3
+ # Copyright © 2013, 2014, 2015, 2016 Marco Bresciani
4
+ #
5
+ # This file is part of gravaty.
6
+ #
7
+ # gravaty is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License
8
+ # as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
9
+ #
10
+ # gravaty is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
11
+ # of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU General Public License along with gravaty. If not, see
14
+ # <http://www.gnu.org/licenses/>.
15
+ #++
16
+
17
+ module Gravaty
18
+ # Allowed sizes (in pixels) for images requests. Currently a range from 1 to 2048 (included).
19
+ ALLOWED_SIZES = (1...2048)
20
+
21
+ # Allowed parameters names. Currently: avatar, callback, default, force, format, pixelsize, rating, secure and type.
22
+ ALLOWED_PARAMS = [:avatar, :callback, :default, :force, :format, :pixelsize, :rating, :secure, :type]
23
+
24
+ # Allowed formats (extensions) for avatar requests. Currently: jp(e)g, png and gif.
25
+ AVATAR_FORMATS = %w(jpg jpeg png gif)
26
+
27
+ # Currently allowed default builtin options. Currently: 404, mm, identicon, monsterid,wavatar, retro and blank.
28
+ DEFAULT_OPTIONS = %w(404 mm identicon monsterid wavatar retro blank)
29
+
30
+ # Allowed formats (extensions) for default own images. Currently: jp(e)g, png and gif.
31
+ IMAGES_FORMATS = %w(jpg jpeg png gif)
32
+
33
+ # Allowed formats (extensions) for profile requests. Currently: json, xml, php, vcf and qr.
34
+ PROFILE_FORMATS = %w(json xml php vcf qr)
35
+
36
+ # Formats allowing supplemental options for profile requests. Currently json and qr.
37
+ PROFILES = %w(json qr)
38
+
39
+ # Allowed rating options. Currently: g, pg, r and x.
40
+ RATING_OPTIONS = %w(g pg r x)
41
+
42
+ # Possible XML-RPC API errors.
43
+ RPC_ERRORS = [-7, -8, -9, -10, -11, -100]
44
+
45
+ # Allowed XML-RPC API methods.
46
+ RPC_METHODS = %w(grav.exists grav.addresses grav.userimages grav.saveData grav.saveUrl grav.useUserimage grav.removeImage grav.deleteUserimage grav.test)
47
+
48
+ # Default test method for XML-RPC API.
49
+ RPC_TEST_METHOD = 'grav.test'
50
+
51
+ # Reference URI for XML-RPC API.
52
+ RPC_URI = 'secure.gravatar.com'
53
+ end
@@ -0,0 +1,34 @@
1
+ # gravaty
2
+ # Copyright © 2013, 2014, 2015, 2016 Marco Bresciani
3
+ #
4
+ # This file is part of gravaty.
5
+ #
6
+ # gravaty is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License
7
+ # as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
8
+ #
9
+ # gravaty is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
10
+ # of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
11
+ #
12
+ # You should have received a copy of the GNU General Public License along with gravaty. If not, see
13
+ # <http://www.gnu.org/licenses/>.
14
+
15
+ en:
16
+ error:
17
+ invalid: "Invalid parameter %{value} according to RFC822 at later updates."
18
+ nil: nil parameter not allowed.
19
+ param: "Parameter %{value} is not valid."
20
+ type: "Type %{value} is not a known extension."
21
+ uri: "URI %{value} is not valid."
22
+ value: "Value %{value} is not in allowed range."
23
+ warn:
24
+ deprecated: This method has been deprecated.
25
+ test:
26
+ test: test data
27
+ gravatar:
28
+ errors:
29
+ -7: Use secure.gravatar.com
30
+ -8: Internal error
31
+ -9: Authentication error
32
+ -10: Method parameter missing
33
+ -11: Method parameter incorrect
34
+ -100: Misc error (see text)
@@ -0,0 +1,34 @@
1
+ # gravaty
2
+ # Copyright © 2013, 2014, 2015, 2016 Marco Bresciani
3
+ #
4
+ # This file is part of gravaty.
5
+ #
6
+ # gravaty is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License
7
+ # as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
8
+ #
9
+ # gravaty is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
10
+ # of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
11
+ #
12
+ # You should have received a copy of the GNU General Public License along with gravaty. If not, see
13
+ # <http://www.gnu.org/licenses/>.
14
+
15
+ it:
16
+ error:
17
+ invalid: "Parametro %{value} non valido rispetto a RFC822 e modifiche successive."
18
+ nil: Parametro nil non consentito.
19
+ param: "Il parametro %{value} non è valido."
20
+ type: "Il tipo %{value} non è un'estensione conosciuta."
21
+ uri: "L'URI %{value} non è valido."
22
+ value: "Il valore %{value} non è nell'intervallo previsto."
23
+ warn:
24
+ deprecated: Questo metodo è obsoleto.
25
+ test:
26
+ test: dato di prova
27
+ gravatar:
28
+ errors:
29
+ -7: Utilizzare secure.gravatar.com
30
+ -8: Errore interno
31
+ -9: Errore di autenticazione
32
+ -10: Parametro metodo mancante
33
+ -11: Parametro metodo non corretto
34
+ -100: Errore di altro tipo (vedi testo)