Sha256: bdde7124124d58aec03fa499647b87ce1de1df31c2629d77f0ba1cdee8d8d9af

Contents?: true

Size: 975 Bytes

Versions: 2

Compression:

Stored size: 975 Bytes

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, 'Content-Type' => 'application/json' }

        request  = Faraday.new
        response = request.put(uri, params, headers)
        response.body
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
lelylan-rb-0.0.3 lib/lelylan/client/physical.rb
lelylan-rb-0.0.2 lib/lelylan/client/physical.rb