Sha256: 5936b4235925291cbd9b51ae8639169628dfe91526695677a26ebcf5ea2287f6

Contents?: true

Size: 1.84 KB

Versions: 11

Compression:

Stored size: 1.84 KB

Contents

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

  def run_historics
    begin
      stream   = @datasift.compile 'interaction.content contains "datasift"'
      hash     = stream[:data][:hash]
      start    = Time.now.to_i - 10800
      end_time = start + 3600

      puts 'Check the data coverage for this Historic period'
      puts @datasift.historics.status(start, end_time)

      puts "\nPreparing"
      # Prepare an Historics query to start from three hours ago and run for 1
      #   hour using Tumblr as a data source and using only a 10% sample
      historics = @datasift.historics.prepare(
        hash, start, end_time, 'My ruby historics', 'tumblr', 10
      )
      puts historics

      id = historics[:data][:id]

      puts "\nCheck the DPU cost of this Historics query"
      puts "#{@datasift.dpu('', id)[:data][:dpu]} DPUs"

      puts "\nCreating push subscription for historics"
      subscription = create_push(id, true)

      puts "\nStarting historics #{id}"
      puts @datasift.historics.start id

      puts "\nPausing historics #{id}"
      puts @datasift.historics.pause id

      puts "\nResuming historics #{id}"
      puts @datasift.historics.resume id

      puts "\nUpdating historics"
      puts @datasift.historics.update(id, 'The new name of my historics')

      puts "\nGet info for the historics"
      puts @datasift.historics.get_by_id id

      puts "\nGetting info for all my historics"
      puts @datasift.historics.get

      puts "\nStopping historics"
      puts @datasift.historics.stop id

      puts "\nDeleting historics"
      puts @datasift.historics.delete id

      puts "\nCleanup and delete Push subscription"
      puts @datasift.push.delete subscription[:data][:id]
    rescue DataSiftError => dse
      puts dse.message
    end
  end
end

HistoricsApi.new

Version data entries

11 entries across 11 versions & 1 rubygems

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