Sha256: 866b3869f548d35f0e983a7c77eedce7efcc722ad77f73d473a4c3cbbd3e3435

Contents?: true

Size: 1.08 KB

Versions: 6

Compression:

Stored size: 1.08 KB

Contents

# frozen_string_literal: true

module Awis
  module API
    class TrafficHistory < Base
      DEFAULT_RESPONSE_GROUP = %w[history].freeze

      def load_request_uri(arguments = {})
        validation_arguments!(arguments)

        super(params)
      end

      private

      def params
        {
          'Action'        => action_name,
          'Url'           => arguments[:url],
          'ResponseGroup' => response_groups,
          'Range'         => arguments[:range],
          'Start'         => start_date
        }
      end

      def validation_arguments!(arguments)
        before_validation_arguments(arguments)

        @arguments = arguments
        @arguments[:range] = arguments.fetch(:range, 31)
        @arguments[:start] = arguments.fetch(:start) { Time.now - (3600 * 24 * @arguments[:range].to_i) }
      end

      def start_date
        arguments[:start].respond_to?(:strftime) ? arguments[:start].strftime('%Y%m%d') : arguments[:start]
      end

      def response_groups
        DEFAULT_RESPONSE_GROUP.map { |group| camelize(group) }.join(',')
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
awis-sdk-ruby-2.1.0 lib/awis/api/traffic_history.rb
awis-sdk-ruby-2.0.0 lib/awis/api/traffic_history.rb
awis-sdk-ruby-1.1.2 lib/awis/api/traffic_history.rb
awis-sdk-ruby_-1.1.1.1 lib/awis/api/traffic_history.rb
awis-sdk-ruby_-1.1.1p1 lib/awis/api/traffic_history.rb
awis-sdk-ruby-1.1.1 lib/awis/api/traffic_history.rb