Sha256: 513ab6e2a59ae31433d5726bf985df2bc5f2e4873cddc8e828067b728bfa20ef

Contents?: true

Size: 926 Bytes

Versions: 4

Compression:

Stored size: 926 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

4 entries across 4 versions & 1 rubygems

Version Path
google_analytics_v4_api-0.0.9 lib/google_analytics_v4_api/report_response.rb
google_analytics_v4_api-0.0.8 lib/google_analytics_v4_api/report_response.rb
google_analytics_v4_api-0.0.7 lib/google_analytics_v4_api/report_response.rb
google_analytics_v4_api-0.0.6 lib/google_analytics_v4_api/report_response.rb