Class: ProctorCam::Proctorserv::HashedAuthenticator
- Inherits:
-
Object
- Object
- ProctorCam::Proctorserv::HashedAuthenticator
- Defined in:
- lib/proctorserv_api/hashed_authenticator.rb
Class Method Summary collapse
- .apply_reverse_guid_and_sign(params, customer_identifier, shared_secret) ⇒ Object
-
.create_complex_query_string(params, shared_secret) ⇒ Object
creates a query string to handle complex data types (arrays and hashes) each data type is encoded differently depending on its class if no complex data type is detected then a standard query string is created.
Class Method Details
.apply_reverse_guid_and_sign(params, customer_identifier, shared_secret) ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/proctorserv_api/hashed_authenticator.rb', line 29 def self.apply_reverse_guid_and_sign(params, customer_identifier, shared_secret) params[:guid] = SecureRandom.hex(32) params[:customer_id] = customer_identifier query_string = create_complex_query_string(params, shared_secret) params[:guid].reverse! params[:signature] = Digest::SHA256.hexdigest query_string end |
.create_complex_query_string(params, shared_secret) ⇒ Object
creates a query string to handle complex data types (arrays and hashes) each data type is encoded differently depending on its class if no complex data type is detected then a standard query string is created
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/proctorserv_api/hashed_authenticator.rb', line 41 def self.create_complex_query_string(params, shared_secret) query_string = [] params.each do |key,value| # one dimensional array # example: params = { ids => [1,2,3,] } # result: "ids[]=1&ids[]=2&ids[]=3" # if value.class == Array query_string << value.map {|v| "#{key}[]=#{v}"} # one dimensional hash # example: params = { :name => {:first_name => "Joe", :last_name => "Smith"} } # result: "name[first_name]=Joe&name[last_name]=Smith" # elsif value.class == Hash query_string << value.map {|k,v| "#{key}[#{k}]=#{v}"} # simple data types (eg booleans, string, int etc..) # example: params = { :session_duration => 60, :num_slots => 10, :exam_code => "exam_1" } # result: "session_duration=60&num_slots=10&exam_code=exam_1" # else query_string << ["#{key}=#{value}"] end end query_string.join('&') + shared_secret end |