Module: Authy::URL::ClassMethods
- Defined in:
- lib/authy/url_helpers.rb
Instance Method Summary collapse
- #clean_uri_params(uri_params, params) ⇒ Object
- #escape_for_url(field) ⇒ Object
-
#escape_query(query, namespace = nil) ⇒ Object
Copied and extended from httpclient’s HTTP::Message#escape_query().
- #eval_uri(uri, params = {}) ⇒ Object
- #keys_to_verify(uri, params) ⇒ Object
- #params_from_array(left, values) ⇒ Object
- #to_param(left, right) ⇒ Object
- #validate_for_url(names, to_validate = {}) ⇒ Object
Instance Method Details
#clean_uri_params(uri_params, params) ⇒ Object
12 13 14 |
# File 'lib/authy/url_helpers.rb', line 12 def clean_uri_params(uri_params, params) params.reject { |k, v| uri_params.include? k} end |
#escape_for_url(field) ⇒ Object
31 32 33 |
# File 'lib/authy/url_helpers.rb', line 31 def escape_for_url(field) URI.escape(field.to_s.strip, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]")) end |
#escape_query(query, namespace = nil) ⇒ Object
Copied and extended from httpclient’s HTTP::Message#escape_query()
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/authy/url_helpers.rb', line 54 def escape_query(query, namespace = nil) # :nodoc: pairs = [] query.each do |attr, value| left = namespace ? "#{namespace}[#{attr.to_s}]" : attr.to_s if values = Array.try_convert(value) pairs += params_from_array(left, values) elsif values = Hash.try_convert(value) pairs.push(escape_query(values, left.dup)) else if value.respond_to?(:read) value = value.read end pairs.push(to_param(left, value)) end end pairs.join('&') end |
#eval_uri(uri, params = {}) ⇒ Object
16 17 18 |
# File 'lib/authy/url_helpers.rb', line 16 def eval_uri(uri, params = {}) uri.gsub(/:\w+/) {|s| params[s.gsub(":", "")]} end |
#keys_to_verify(uri, params) ⇒ Object
8 9 10 |
# File 'lib/authy/url_helpers.rb', line 8 def keys_to_verify(uri, params) uri.scan(/:(\w+)/).flatten end |
#params_from_array(left, values) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/authy/url_helpers.rb', line 39 def params_from_array(left, values) values.map do |value| if value.respond_to?(:read) value = value.read end if value.kind_of?(Hash) escape_query(value, left+"[]") else to_param(left + '[]', value) end end end |
#to_param(left, right) ⇒ Object
35 36 37 |
# File 'lib/authy/url_helpers.rb', line 35 def to_param(left, right) HTTP::Message.escape(left) + '=' + HTTP::Message.escape(right.to_s) end |
#validate_for_url(names, to_validate = {}) ⇒ Object
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/authy/url_helpers.rb', line 20 def validate_for_url(names, to_validate = {}) names.each do |name| value = to_validate[name] if value.nil? or value.to_s.empty? or value.to_s.split(" ").size == 0 puts "#{name} param is blank." return [ false, "#{name} is blank." ] end end [ true, ""] end |