Sha256: 0ea9d9ff01971bb4923f0b5f2edfd46815d65505d564c503c46d92d095227c12

Contents?: true

Size: 1.96 KB

Versions: 9

Compression:

Stored size: 1.96 KB

Contents

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

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

      puts "\nCreate a Token for our Identity"
      puts @datasift.account_identity_token.create(
        identity_id,
        'facebook',
        'YOUR_TOKEN'
      )[:data].to_json

      puts "\nList all existing Tokens for this Identity"
      puts @datasift.account_identity_token.list(
        identity_id
      )[:data].to_json

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

      puts "\nUpdate a Token for a given Identity"
      puts @datasift.account_identity_token.update(
        identity_id,
        'facebook',
        'YOUR_NEW_TOKEN'
      )[:data].to_json

      puts "\nDelete an Token for a given Identity and Service"
      puts @datasift.account_identity_token.delete(
        identity_id,
        'facebook'
      )[:data].to_json

      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
          puts '[WARNING] You will need to use a valid token to run through this example'
        else
          # do something else...
      end
      puts "\nCleanup and remove the Identity"
      @datasift.account_identity.delete(identity_id)
    end
  end
end

AccountIdentityTokenEg.new

Version data entries

9 entries across 9 versions & 1 rubygems

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