class SunlightApi::UriGenerator
Attributes
url[R]
Public Class Methods
new( public_key, private_key, test, uri_suffix, get_params={} )
click to toggle source
# File lib/sunlight_api.rb, line 73 def initialize( public_key, private_key, test, uri_suffix, get_params={} ) @public_key = public_key @private_key = private_key @test = test if @test @base_url = "https://hortservices.sunlightsupply.com/v1/#{uri_suffix}?" else @base_url = "https://services.sunlightsupply.com/v1/#{uri_suffix}?" end @get_params = get_params @time_stamp = Time.now.utc.strftime("%Y-%m-%dT%H:%M:%SZ") append_get_params append_api_key append_time_stamp append_signature end
Public Instance Methods
append_api_key()
click to toggle source
# File lib/sunlight_api.rb, line 97 def append_api_key @base_url += "&" if @get_params.size > 0 @base_url += "X-ApiKey=#{@public_key}" end
append_get_params()
click to toggle source
# File lib/sunlight_api.rb, line 90 def append_get_params @get_params.each_with_index do |(key,value), i| @base_url += "#{key}=#{value}" @base_url += "&" unless i == (@get_params.size - 1) end end
append_signature()
click to toggle source
# File lib/sunlight_api.rb, line 106 def append_signature @digest = OpenSSL::Digest::Digest.new('sha256') @signature = OpenSSL::HMAC.hexdigest(@digest, @private_key, @base_url).upcase @url = "#{@base_url}&signature=#{@signature}" end
append_time_stamp()
click to toggle source
# File lib/sunlight_api.rb, line 102 def append_time_stamp @base_url += "&time=#{@time_stamp}" end