Sha256: b761ee8781673db15f29fe8d5874b02a4a3e6189cb9a1e1fa4a7f750ae4732d4

Contents?: true

Size: 870 Bytes

Versions: 2

Compression:

Stored size: 870 Bytes

Contents

require 'time'

module ThreeScale
  class AuthorizeResponse < Response
    def initialize
      super
      @usage_reports = []
    end

    attr_accessor :plan

    class UsageReport
      attr_reader :metric
      attr_reader :period
      attr_reader :current_value
      attr_reader :max_value

      def initialize(options = {})
        options.each do |name, value|
          instance_variable_set("@#{name}", value)
        end
      end

      def period_start
        @parsed_period_start ||= @period_start && Time.parse(@period_start)
      end

      def period_end
        @parsed_period_end ||= @period_end && Time.parse(@period_end)
      end

      def exceeded?
        current_value > max_value
      end
    end      

    attr_reader :usage_reports

    def add_usage_report(options)
      @usage_reports << UsageReport.new(options)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
3scale_client-2.2.7 lib/3scale/authorize_response.rb
3scale_client-2.2.4 lib/3scale/authorize_response.rb