Sha256: 62469c75922fc6b76952bb6f91ceeba95349bb7043fb8c568795c8b321cb2534

Contents?: true

Size: 952 Bytes

Versions: 11

Compression:

Stored size: 952 Bytes

Contents

require 'time'

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

    attr_accessor :plan
    attr_accessor :app_key
    attr_accessor :redirect_url
    attr_accessor :service_id

    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

11 entries across 11 versions & 1 rubygems

Version Path
3scale_client-2.8.1 lib/3scale/authorize_response.rb
3scale_client-2.8.0 lib/3scale/authorize_response.rb
3scale_client-2.7.0 lib/3scale/authorize_response.rb
3scale_client-2.6.1 lib/3scale/authorize_response.rb
3scale_client-2.6.0 lib/3scale/authorize_response.rb
3scale_client-2.5.0 lib/3scale/authorize_response.rb
3scale_client-2.5.0.pre1 lib/3scale/authorize_response.rb
3scale_client-2.4.2 lib/3scale/authorize_response.rb
3scale_client-2.4.0 lib/3scale/authorize_response.rb
3scale_client-2.4.0.pre.1 lib/3scale/authorize_response.rb
3scale_client-2.3.4 lib/3scale/authorize_response.rb