Sha256: b730a7550e45481b9113725a713d3868b0361998edc721abee4677993277b654
Contents?: true
Size: 1.16 KB
Versions: 1
Compression:
Stored size: 1.16 KB
Contents
require 'uri' require 'openssl' require 'securerandom' require 'json' require 'lelylan/authentication' module Lelylan class Client module Physical # # Public: Send a request adding a nonce and a X-Physical-Signature # header. # # uri - A String that represents the uri of the physical device. # secret - The device secret. # params - An object containing the JSON params to send. # # Returns Hashie The JSON resource. # def physical_properties(uri, secret, params) params[:nonce] = SecureRandom.uuid if not params[:nonce] digest = OpenSSL::Digest::Digest.new('sha1') signature = OpenSSL::HMAC.hexdigest(digest, secret, params.to_json.to_s) headers = { 'X-Physical-Signature' => signature } request = Faraday.new do |builder| builder.request :json builder.use Faraday::Response::RaiseHttpError builder.use FaradayMiddleware::Mashify builder.use FaradayMiddleware::ParseJson builder.adapter(adapter) end response = request.put(uri, params, headers) response.body end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
lelylan-rb-0.0.4 | lib/lelylan/client/physical.rb |