Sha256: 209a7dc2c3540396f95ce1cb75635bd79a81738a7b0efdbe0a7413104c572d1c

Contents?: true

Size: 1.33 KB

Versions: 9

Compression:

Stored size: 1.33 KB

Contents

require './auth'
class PushApi < DataSiftExample
  def initialize
    super
  end

  def run
    begin
      @params = {output_type: 'pull'}
      puts 'Validating the Pull subscription'
      fail InvalidParamError unless @datasift.push.valid? @params

      stream = @datasift.compile 'interaction.content contains "music"'
      subscription = create_push(stream[:data][:hash])

      subscription_id = subscription[:data][:id]
      # Pull a bunch of interactions from the push queue. This only works if we had set the
      #   output_type above to "pull"

      2.times do
        puts "\nPulling data, then waiting 10 seconds"
        @datasift.push.pull(subscription_id).each { |e| puts e }
        sleep 10
      end

      puts "\nPulling data the third and final time time"
      # Passing a lambda is more efficient because it is executed once for each interaction
      #   received this saves having to iterate over the array returned so the same iteration
      #   isn't processed twice
      @datasift.push.pull(
        subscription_id,
        20_971_520,
        '',
        lambda{ |e| puts "on_message => #{e}" }
      )

      puts "\nDeleting the Pull subscription"
      @datasift.push.delete subscription_id

        #rescue DataSiftError
    rescue DataSiftError => dse
      puts dse.inspect
    end
  end
end

PushApi.new().run

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
datasift-3.7.2 examples/pull.rb
datasift-3.5.2 examples/pull.rb
datasift-3.5.1 examples/pull.rb
datasift-3.7.1 examples/pull.rb
datasift-3.7.0 examples/pull.rb
datasift-3.6.2 examples/pull.rb
datasift-3.6.1 examples/pull.rb
datasift-3.6.0 examples/pull.rb
datasift-3.5.0 examples/pull.rb