Sha256: d7851259808c860c62a6ef22adf08411d81c91549bafa512889e5f08833afbc8

Contents?: true

Size: 1.37 KB

Versions: 9

Compression:

Stored size: 1.37 KB

Contents

require './auth'
class CoreApiEg < DataSiftExample
  def initialize
    super
    @datasift = DataSift::Client.new(@config)
    run
  end

  def run
    begin
      csdl = 'interaction.content contains "test"'
      # see docs at http://dev.datasift.com/docs/rest-api/validate
      puts "Is the following CSDL valid? #{csdl}"
      puts @datasift.valid? csdl

      # http://dev.datasift.com/docs/rest-api/compile
      puts "\nCompile the CSDL and get a stream hash"
      stream = @datasift.compile csdl
      puts stream[:data]

      # http://dev.datasift.com/docs/rest-api/dpu
      puts "\nGet the DPU cost of the compiled CSDL"
      dpu = @datasift.dpu stream[:data][:hash]
      puts dpu[:data][:dpu]

      # http://dev.datasift.com/docs/rest-api/balance
      puts "\nGet the remaining balance for my account"
      balance = @datasift.balance
      puts balance[:data]

      #http://dev.datasift.com/docs/rest-api/usage
      puts "\nGet my recent account usage"
      usage = @datasift.usage
      puts usage[:data]

    rescue DataSiftError => dse
      puts dse.message
      # Then match specific one to take action; All errors thrown by the client extend DataSiftError
      case dse
        when ConnectionError
          # some connection error
        when AuthError
        when BadRequestError
        else
          # do something else...
      end
    end
  end
end
CoreApiEg.new

Version data entries

9 entries across 9 versions & 1 rubygems

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