Module: AnalyticsOps::Clients::AdminGovernance
- Included in:
- Admin
- Defined in:
- lib/analytics_ops/clients/admin_governance.rb
Overview
Experimental read-only Admin API governance operations.
Instance Method Summary collapse
- #access_report(property_id, date_ranges:, limit: 1_000) ⇒ Object
- #change_history(property_id, limit: 100, days: 30) ⇒ Object
- #governance_snapshot(property_id) ⇒ Object
Instance Method Details
#access_report(property_id, date_ranges:, limit: 1_000) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/analytics_ops/clients/admin_governance.rb', line 53 def access_report(property_id, date_ranges:, limit: 1_000) validate_bounded_integer!(limit, "access report limit", 1, 100_000) unless date_ranges.is_a?(Array) && date_ranges.length.between?(1, 2) raise InvalidRequestError, "Access report requires one or two date ranges" end response = get( :run_access_report, entity: property_name(property_id), dimensions: [{ dimension_name: "accessDateHour" }], metrics: [{ metric_name: "dataApiQuotaPropertyTokensConsumed" }], date_ranges: date_ranges.map do |range| { start_date: range.fetch("start_date"), end_date: range.fetch("end_date") } end, limit:, return_entity_quota: true, include_all_users: false, expand_groups: false ) normalize_access_report(property_id, response) rescue KeyError raise InvalidRequestError, "Access report date range is invalid" end |
#change_history(property_id, limit: 100, days: 30) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/analytics_ops/clients/admin_governance.rb', line 29 def change_history(property_id, limit: 100, days: 30) validate_bounded_integer!(limit, "history limit", 1, 200) validate_bounded_integer!(days, "history days", 1, 365) property = property_name(property_id) account = property_access(property_id).parent unless account.is_a?(String) && account.match?(%r{\Aaccounts/\d{1,50}\z}) raise RemoteError, "Google Admin API returned an invalid parent account" end now = Time.now.utc events = list_first( :search_change_history_events, { account:, property:, earliest_change_time: now - (days * 86_400), latest_change_time: now, page_size: limit }, limit ).map { |event| normalize_change_history_event(event) } Governance::ChangeHistory.new(property_id:, events:) end |
#governance_snapshot(property_id) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/analytics_ops/clients/admin_governance.rb', line 7 def governance_snapshot(property_id) property = property_name(property_id) streams = list_streams(property_id).select { |stream| stream.type == "web" }.sort_by(&:id) Governance::Snapshot.new( property_id:, stream_settings: governance_stream_settings(streams), reporting_identity: resource_hash( get(:get_reporting_identity_settings, name: "#{property}/reportingIdentitySettings") ), attribution: resource_hash(get(:get_attribution_settings, name: "#{property}/attributionSettings")), channel_groups: normalized_resource_list(:list_channel_groups, parent: property), calculated_metrics: normalized_resource_list(:list_calculated_metrics, parent: property), event_create_rules: streams.flat_map do |stream| normalized_resource_list(:list_event_create_rules, parent: stream.name) end, event_edit_rules: streams.flat_map do |stream| normalized_resource_list(:list_event_edit_rules, parent: stream.name) end, bigquery_links: normalized_resource_list(:list_big_query_links, parent: property) ) end |