Skip to content
This repository
tree: 58418d9c8f
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 46 lines (36 sloc) 0.923 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
require 'time'

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

    attr_accessor :plan
    attr_accessor :app_key
    attr_accessor :redirect_url

    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
Something went wrong with that request. Please try again.