Class: WebResource
- Inherits:
-
Object
- Object
- WebResource
- Defined in:
- lib/starcraft2/web_resource.rb
Class Method Summary collapse
Class Method Details
.get(url) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/starcraft2/web_resource.rb', line 6 def self.get(url) private_key = ENV['STARCRAFT2_API_PRIVATE_KEY'] public_key = ENV['STARCRAFT2_API_PUBLIC_KEY'] date = Time.now.gmtime.rfc2822.gsub("-0000", "GMT") response = if public_key && private_key HTTParty.get(url, :headers => { "Date" => date, "Authorization" => "BNET #{public_key}:#{signature(url, private_key, date)}"}) else HTTParty.get(url) end end |
.signature(url, private_key, date) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/starcraft2/web_resource.rb', line 19 def self.signature(url, private_key, date) url_path = ::Addressable::URI.parse(url).path signature = <<-EOF GET #{date} #{url_path} EOF hmac = HMAC::SHA1.new(private_key.encode('UTF-8')) hmac.update(signature) Base64.encode64(hmac.digest) end |