hmac_params.rb 509 B

1234567891011121314151617181920212223
  1. # frozen_string_literal: true
  2. require 'webrick/httputils'
  3. module ShopifyAPI
  4. module HmacParams
  5. extend WEBrick::HTTPUtils
  6. def self.encode(params)
  7. params
  8. .except(:signature, :hmac, :action, :controller)
  9. .map { |k,v| sprintf("%s=%s", encode_key(k), encode_value(v)) }
  10. .sort.join("&")
  11. end
  12. def self.encode_key(key)
  13. _escape(key.to_s, _make_regex('&=%'))
  14. end
  15. def self.encode_value(value)
  16. _escape(value.to_s, _make_regex('&%'))
  17. end
  18. end
  19. end