Sha256: 390605b14df8c7f130667610306582bddeae38171bcfdb1feacf485780fc7b9b

Contents?: true

Size: 1.03 KB

Versions: 1

Compression:

Stored size: 1.03 KB

Contents

# frozen_string_literal: true

require "json"

module GoogleAnalyticsV4Api
  class Property
    attr_accessor :name, :propertyType, :createTime, :updateTime, :parent, :displayName, :industryCategory, :timeZone, :currencyCode, :serviceLevel, :deleteTime, :expireTime

    def initialize(client, attributes = {})
      @client = client
      attributes.each do |k, v|
        send("#{k}=", v) if self.respond_to?("#{k}=")
      end
    end

    def account
      @client.account(parent)
    end

    def run_report(report)
      response = Request.post(access_token: @client.access_token, path: "/#{name}:runReport", payload: report.to_json)
      ReportResponse.new(response)
    end

    def self.parse_list(client, body)
      parsed_body = JSON.parse(body)
      return [] if parsed_body["properties"].nil?

      parsed_body["properties"].map do |attrs|
        GoogleAnalyticsV4Api::Property.new(client, attrs)
      end
    end

    def self.parse(client, body)
      GoogleAnalyticsV4Api::Property.new(client, JSON.parse(body))
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
google_analytics_v4_api-0.0.9 lib/google_analytics_v4_api/property.rb