Sha256: 25fd8422542267463dbd62cf43635d91b67eb5a646e3c39dca3e1a8a1b9f2597

Contents?: true

Size: 914 Bytes

Versions: 2

Compression:

Stored size: 914 Bytes

Contents

# frozen_string_literal: true

require 'json'
require 'date'

module GoogleAnalyticsV4Api
  class ReportResponse

    attr_accessor :body, :raw_dimension_headers, :raw_metric_headers, :rows, :row_count, :metadata, :kind

    def initialize(body)
      @body = JSON.parse body
      @raw_dimension_headers = @body["dimensionHeaders"]
      @raw_metric_headers = @body["metricHeaders"]
      @rows = @body["rows"] || []
      @row_cont = @body["rowCount"] || 0
      @metadata = @body["metadata"]
      @kind = @body["kind"]
    end

    def dimension_headers
      @dimension_headers ||= @raw_dimension_headers.map { |header| header["name"] }
    end

    def metric_headers
      @metric_headers ||= @raw_metric_headers.map { |header| header["name"] }
    end

    def parsed_rows
      @rows.map do |row|
        ReportResponseRow.new(row, @raw_dimension_headers, @raw_metric_headers)
      end
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
google_analytics_v4_api-0.0.5 lib/google_analytics_v4_api/report_response.rb
google_analytics_v4_api-0.0.4 lib/google_analytics_v4_api/report_response.rb