Sha256: 008f088963fc7b58e773e5d2ef968ece6903e069c2ea5b7e0b3463f5be1c031b

Contents?: true

Size: 1.83 KB

Versions: 6

Compression:

Stored size: 1.83 KB

Contents

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

  def run
    begin
      puts "Create a new identity to apply Limits to"
      identity = @datasift.account_identity.create(
        "Ruby Identity for Token Limits", "active", false
      )
      identity_id = identity[:data][:id]
      puts identity[:data].to_json

      puts "\nCreate a Limit for our Identity"
      puts @datasift.account_identity_limit.create(
        identity_id,
        'facebook',
        100_000
      )[:data].to_json

      puts "\nList all existing Limits for this Service"
      puts @datasift.account_identity_limit.list(
        'facebook'
      )[:data].to_json

      puts "\nGet existing Limit by Identity and Service"
      puts @datasift.account_identity_limit.get(
        identity_id,
        'facebook'
      )[:data].to_json

      puts "\nUpdate a Limit for a given Identity"
      puts @datasift.account_identity_limit.update(
        identity_id,
        'facebook',
        250_000
      )[:data].to_json

      puts "\nRemove the Limit from a given Identity and Service"
      @datasift.account_identity_limit.delete(
        identity_id,
        'facebook'
      )

      puts "\nCleanup and remove the 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 "\nCleanup and remove the Identity"
      @datasift.account_identity.delete(identity_id)
    end
  end
end

AccountIdentityLimitEg.new

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
datasift-3.5.2 examples/account_identity_limit_eg.rb
datasift-3.5.1 examples/account_identity_limit_eg.rb
datasift-3.6.2 examples/account_identity_limit_eg.rb
datasift-3.6.1 examples/account_identity_limit_eg.rb
datasift-3.6.0 examples/account_identity_limit_eg.rb
datasift-3.5.0 examples/account_identity_limit_eg.rb