Sha256: 258c7bc31e7108bf31b3c2d86960e51c6cf25caf09df8f482fcc7008d818d54c
Contents?: true
Size: 941 Bytes
Versions: 3
Compression:
Stored size: 941 Bytes
Contents
# frozen_string_literal: true require 'json' require 'date' module GoogleAnalyticsV4Api class Report attr_accessor :date_ranges, :dimensions, :metrics, :dimension_filter def initialize(start_date: nil, end_date: nil, dimensions: [], metrics: [], dimension_filter: {}) @date_ranges = [{ "startDate": start_date || (Date.today - 30), "endDate": end_date || Date.today }] @dimensions = dimensions.map { |dimension| { "name": dimension } } @metrics = metrics.map { |metric| { "name": metric } } @dimension_filter = dimension_filter end def to_json output = {} output[:dateRanges] = @date_ranges output[:dimensions] = @dimensions if !@dimensions.nil? && @dimensions.any? output[:metrics] = @metrics if !@metrics.nil? && @metrics.any? output[:dimensionFilter] = @dimension_filter if !@dimension_filter.nil? && @dimension_filter.any? output.to_json end end end
Version data entries
3 entries across 3 versions & 1 rubygems