Sha256: 22f1df04b5a5375df63ca004121b6cc685c3a6aef12008e8e34a11c789df7193

Contents?: true

Size: 795 Bytes

Versions: 3

Compression:

Stored size: 795 Bytes

Contents

require 'json'

module Faye
  module Authentication
    class HTTPClient

      def self.publish(url, channel, data, key, options = {})
        uri = URI(url)
        req = prepare_request(uri.request_uri, channel, data, key, options)
        Net::HTTP.start(uri.hostname, uri.port, :use_ssl => uri.scheme == 'https') { |http| http.request(req) }
      end

      def self.prepare_request(uri, channel, data, key, options = {})
        req = Net::HTTP::Post.new(uri)
        message = {'channel' => channel, 'clientId' => 'http'}
        message['signature'] = Faye::Authentication.sign(message, key) if Faye::Authentication.authentication_required?(message, options)
        message['data'] = data
        req.set_form_data(message: JSON.dump(message))
        req
      end

    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
faye-authentication-1.13 lib/faye/authentication/http_client.rb
faye-authentication-1.12 lib/faye/authentication/http_client.rb
faye-authentication-1.11.0 lib/faye/authentication/http_client.rb