module GroupDocs::Api::Helpers::URL
Public Instance Methods
add_params(params)
click to toggle source
Appends path with parameters.
@param [Hash] params
# File lib/groupdocs/api/helpers/url_helper.rb, line 15 def add_params(params) params.each do |param, value| value = value.join(',') if value.is_a?(Array) options[:path] << "#{separator}#{param}=#{value}" end end
Private Instance Methods
normalize_path()
click to toggle source
Normalizes path replacing two or more slashes with one.
@api private
# File lib/groupdocs/api/helpers/url_helper.rb, line 29 def normalize_path options[:path].gsub!(%r(//+), '/') end
prepend_version()
click to toggle source
Prepends path with version number if it’s set.
@api private
# File lib/groupdocs/api/helpers/url_helper.rb, line 92 def prepend_version if GroupDocs.api_version options[:path] = "/v#{GroupDocs.api_version}#{options[:path]}" end end
replace_client_id()
click to toggle source
Parses path replacing {{client_id}} with real one.
@api private
# File lib/groupdocs/api/helpers/url_helper.rb, line 51 def replace_client_id options[:path].sub!(/\{\{client_id\}\}/, client_id) end
separator()
click to toggle source
Returns separator for GET parameters.
@return [String] Either ? or & @api private
# File lib/groupdocs/api/helpers/url_helper.rb, line 83 def separator options[:path].include?('?') ? '&' : '?' end
sign_url()
click to toggle source
Adds signature to path.
@api private
# File lib/groupdocs/api/helpers/url_helper.rb, line 61 def sign_url # calculate a hash of the path with private key hash = OpenSSL::Digest.new('sha1') # Changed in release 1.5.9 hash = OpenSSL::HMAC.digest(hash, private_key, options[:path]) # convert hash to base64 hash = Base64.strict_encode64(hash) # remove trailing '=' hash.gsub!(/=*$/, '') # URL encode hash hash = CGI.escape(hash) # covert all hexademical characters to upper case hash.gsub!(/(%[A-Fa-f0-9]{1,2})/) { |group| group.upcase } options[:path] << "#{separator}signature=#{hash}" end
url_encode_path()
click to toggle source
URL
encodes path.
@api private
# File lib/groupdocs/api/helpers/url_helper.rb, line 38 def url_encode_path options[:path] = URI.escape(options[:path]) # handle special symbols correctly options[:path].gsub!('[', '%5B') options[:path].gsub!(']', '%5D') options[:path].gsub!('+', '%2B') end