lib/3scale/authorize_response.rb in 3scale_client-2.8.2 vs lib/3scale/authorize_response.rb in 3scale_client-2.9.0
- old
+ new
@@ -25,10 +25,17 @@
def exceeded?
current_value > max_value
end
end
+ # These 2 constants are defined according to what the 3scale
+ # backend returns in the response of authorize calls.
+ LIMITS_EXCEEDED = 'limits_exceeded'.freeze
+ private_constant :LIMITS_EXCEEDED
+ LIMITS_EXCEEDED_MSG = 'usage limits are exceeded'.freeze
+ private_constant :LIMITS_EXCEEDED_MSG
+
attr_accessor :plan
attr_accessor :app_key
attr_accessor :redirect_url
attr_accessor :service_id
attr_reader :usage_reports
@@ -48,8 +55,14 @@
@usage_reports << UsageReport.new(options)
end
def add_metric_to_hierarchy(metric_name, children)
@hierarchy[metric_name] = children
+ end
+
+ # The response already specifies whether any usage report (if present)
+ # is over the limits, so use that instead of scanning the reports.
+ def limits_exceeded?
+ error_code == LIMITS_EXCEEDED || error_message == LIMITS_EXCEEDED_MSG
end
end
end