Exception: Whatsapp::RateLimited

Inherits:
Error
  • Object
show all
Defined in:
lib/whatsapp/errors.rb

Overview

Raised when a rate limit threshold is exceeded.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(period:, limit:, current:, recipient: nil) ⇒ RateLimited

Returns a new instance of RateLimited.

Parameters:

  • period (Symbol)

    the rate limit window

  • limit (Integer)

    maximum messages in period

  • current (Integer)

    current message count

  • recipient (String, nil) (defaults to: nil)

    recipient phone number



89
90
91
92
93
94
95
96
97
# File 'lib/whatsapp/errors.rb', line 89

def initialize(period:, limit:, current:, recipient: nil)
  @period = period
  @limit = limit
  @current = current
  @recipient = recipient

  target = recipient ? "to #{recipient} " : ""
  super("Rate limited: #{current}/#{limit} messages #{target}per #{period}")
end

Instance Attribute Details

#currentInteger (readonly)

Returns current message count.

Returns:

  • (Integer)

    current message count



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/whatsapp/errors.rb', line 82

class RateLimited < Error
  attr_reader :period, :limit, :current, :recipient

  # @param period [Symbol] the rate limit window
  # @param limit [Integer] maximum messages in period
  # @param current [Integer] current message count
  # @param recipient [String, nil] recipient phone number
  def initialize(period:, limit:, current:, recipient: nil)
    @period = period
    @limit = limit
    @current = current
    @recipient = recipient

    target = recipient ? "to #{recipient} " : ""
    super("Rate limited: #{current}/#{limit} messages #{target}per #{period}")
  end
end

#limitInteger (readonly)

Returns maximum allowed messages in the period.

Returns:

  • (Integer)

    maximum allowed messages in the period



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/whatsapp/errors.rb', line 82

class RateLimited < Error
  attr_reader :period, :limit, :current, :recipient

  # @param period [Symbol] the rate limit window
  # @param limit [Integer] maximum messages in period
  # @param current [Integer] current message count
  # @param recipient [String, nil] recipient phone number
  def initialize(period:, limit:, current:, recipient: nil)
    @period = period
    @limit = limit
    @current = current
    @recipient = recipient

    target = recipient ? "to #{recipient} " : ""
    super("Rate limited: #{current}/#{limit} messages #{target}per #{period}")
  end
end

#periodSymbol (readonly)

Returns the rate limit window (:minute, :hour, :day, :bridge).

Returns:

  • (Symbol)

    the rate limit window (:minute, :hour, :day, :bridge)



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/whatsapp/errors.rb', line 82

class RateLimited < Error
  attr_reader :period, :limit, :current, :recipient

  # @param period [Symbol] the rate limit window
  # @param limit [Integer] maximum messages in period
  # @param current [Integer] current message count
  # @param recipient [String, nil] recipient phone number
  def initialize(period:, limit:, current:, recipient: nil)
    @period = period
    @limit = limit
    @current = current
    @recipient = recipient

    target = recipient ? "to #{recipient} " : ""
    super("Rate limited: #{current}/#{limit} messages #{target}per #{period}")
  end
end

#recipientString? (readonly)

Returns specific recipient if per-recipient limit.

Returns:

  • (String, nil)

    specific recipient if per-recipient limit



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/whatsapp/errors.rb', line 82

class RateLimited < Error
  attr_reader :period, :limit, :current, :recipient

  # @param period [Symbol] the rate limit window
  # @param limit [Integer] maximum messages in period
  # @param current [Integer] current message count
  # @param recipient [String, nil] recipient phone number
  def initialize(period:, limit:, current:, recipient: nil)
    @period = period
    @limit = limit
    @current = current
    @recipient = recipient

    target = recipient ? "to #{recipient} " : ""
    super("Rate limited: #{current}/#{limit} messages #{target}per #{period}")
  end
end