class Recordit::URLBuilder
Public Class Methods
new(client_id, secret)
click to toggle source
Initialize the builder with the client ID and secret.
# File lib/recordit/url_builder.rb, line 40 def initialize(client_id, secret) @client_id = client_id @secret = secret @hasher = Digest::SHA1.new end
Public Instance Methods
generate(params_hash)
click to toggle source
Main API entry point, receives a hash containing the parameters to encode in the URL, returns actual URL.
# File lib/recordit/url_builder.rb, line 48 def generate(params_hash) query_string = queryfy(params_hash) authenticity_token = sign_request(query_string) "#{PROTOCOL}:#{@client_id}-#{authenticity_token}#{query_string}" end
Protected Instance Methods
escape(param)
click to toggle source
Escapes the url, and converts CGI’s + to a proper percent encoded string
# File lib/recordit/url_builder.rb, line 71 def escape(param) CGI.escape(param.to_s).gsub("+", "%20") end
queryfy(params_hash)
click to toggle source
Given the params hash, converts it to a url encoded query string.
# File lib/recordit/url_builder.rb, line 63 def queryfy(params_hash) query_array = params_hash.map do |key, value| "#{escape(key)}=#{escape(value)}" end "?#{query_array.join("&")}" end
sign_request(query_string)
click to toggle source
Hashes the query string
# File lib/recordit/url_builder.rb, line 58 def sign_request(query_string) @hasher.hexdigest(@secret + query_string) end