Sha256: a7361dafaa61783578934296f1029deb656edf097b38ef2c519fb69155171f69

Contents?: true

Size: 1.01 KB

Versions: 2

Compression:

Stored size: 1.01 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, :account

    def initialize(client, attributes = {})
      @client = client
      attributes.each do |k, v|
        self.send("#{k}=", v)
      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

2 entries across 2 versions & 1 rubygems

Version Path
google_analytics_v4_api-0.0.8 lib/google_analytics_v4_api/property.rb
google_analytics_v4_api-0.0.7 lib/google_analytics_v4_api/property.rb