lib/turntabler/connection.rb
def publish_to_http(params)
      api = params.delete(:api)
      message_id = params[:msgid]

      http = EventMachine::HttpRequest.new("http://turntable.fm/api/#{api}").get(:query => params)
      if http.response_header.status == 200
        # Command executed properly: parse the results
        success, data = JSON.parse(http.response)
        data = {'result' => data} unless data.is_a?(Hash)
        message = data.merge('success' => success)
      else
        # Command failed to run
        message = {'success' => false, 'error' => http.error}
      end
      message.merge!('msgid' => message_id)

      # Run the message handler
      event = Faye::WebSocket::API::Event.new('message', :data => "~m~#{Time.now.to_i}~m~#{JSON.generate(message)}")
      on_message(event)
    end
def publish_to_http(params)
      api = params.delete(:api)
      message_id = params[:msgid]

      http = EventMachine::HttpRequest.new("http://turntable.fm/api/#{api}").get(:query => params)
      if http.response_header.status == 200
        # Command executed properly: parse the results
        success, data = JSON.parse(http.response)
        data = {'result' => data} unless data.is_a?(Hash)
        message = data.merge('success' => success)
      else
        # Command failed to run
        message = {'success' => false, 'error' => http.error}
      end
      message.merge!('msgid' => message_id)

      # Run the message handler
      event = Faye::WebSocket::API::Event.new('message', :data => "~m~#{Time.now.to_i}~m~#{JSON.generate(message)}")
      on_message(event)
    end
def publish_to_http ( params ) api = params . delete ( :api ) message_id = params [ :msgid ] http = EventMachine :: HttpRequest . new ( "http://turntable.fm/api/#{api}" ) . get ( :query => params ) if http . response_header . status == 200 # Command executed properly: parse the results success , data = JSON . parse ( http . response ) data = { 'result' => data } unless data . is_a? ( Hash ) message = data . merge ( 'success' => success ) else # Command failed to run message = { 'success' => false , 'error' => http . error } end message . merge! ( 'msgid' => message_id ) # Run the message handler event = Faye :: WebSocket :: API :: Event . new ( 'message' , :data => "~m~#{Time.now.to_i}~m~#{JSON.generate(message)}" ) on_message ( event ) end
Publishes the given params to the HTTP API
Publishes the given params to the HTTP API