Sha256: eacf1a485723fcc44ceaf68f6724a7100a18fd08aee07a9b07ec8317f0359f14

Contents?: true

Size: 1.32 KB

Versions: 9

Compression:

Stored size: 1.32 KB

Contents

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

  def run
    begin
      puts "Create a new identity"
      identity = @datasift.account_identity.create(
        "Ruby Identity #{DateTime.now}", "active", false
      )
      identity_id = identity[:data][:id]
      puts identity[:data].to_json

      puts "\nList all existing identities"
      puts @datasift.account_identity.list[:data].to_json

      puts "\nGet existing identity"
      puts @datasift.account_identity.get(identity_id)[:data].to_json

      puts "\nUpdate an identity"
      puts @datasift.account_identity.update(
        identity_id, "Updated Ruby Identity #{DateTime.now}"
      )[:data].to_json

      puts "\nDelete an identity"
      @datasift.account_identity.delete(identity_id)

    rescue DataSiftError => dse
      puts dse.inspect
      # Then match specific error 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
      puts "\nClean up and delete the identity"
      @datasift.account_identity.delete(identity_id)
    end
  end
end

AccountIdentityEg.new

Version data entries

9 entries across 9 versions & 1 rubygems

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