diff --git a/CHANGELOG.md b/CHANGELOG.md index 8ccee19..71d0fb2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ Next + * Deprecated: Universal Analytics APIs (Core Reporting v3, Management v3) and ClientLogin used by `Garb` have been shut down by Google; README now points to GA4 replacement gems + * Replaced deprecated `MultiJson` with stdlib `JSON` and dropped the `multi_json` dependency + * Added `ostruct` as a runtime dependency (no longer a default gem starting with Ruby 3.5) + * Declared `required_ruby_version` as `>= 3.2`, matching the CI matrix + * Fixed "method redefined" warning when the same report method is added more than once * [#75](https://github.com/Sija/garb/pull/75): Fixed `Garb::Model#all_results` (`:all => true`) ignoring `:offset` after the first page - [@dblock](https://github.com/dblock) Version 0.9.8 diff --git a/README.md b/README.md index e95db68..6838cfe 100644 --- a/README.md +++ b/README.md @@ -3,16 +3,32 @@ Garb [![Gem Version](https://badge.fury.io/rb/garb.svg)](https://badge.fury.io/r https://github.com/Sija/garb -Google Shutting Down Deprecated Auth on April 20th, 2015 --------------------------------------------------------- +Deprecation Notice +------------------ + +**This gem is no longer functional against Google's live services and is kept for historical purposes only.** + + * `Garb` targets the Google Analytics **Core Reporting API v3** and **Management API v3** (Universal Analytics). Google stopped processing Universal Analytics data in July 2023 (July 2024 for Analytics 360) and has since shut both APIs down. See https://support.google.com/analytics/answer/11583528 + * Username/password authentication (`Garb::Session.login`) relies on **ClientLogin**, which Google shut down on April 20th, 2015. + * Google Analytics 4 (GA4) uses a different API with a different data model (e.g. `sessions`/`screenPageViews` instead of `ga:visits`/`ga:pageviews`, properties instead of profiles), so `Garb` cannot be pointed at it. + +Replacements +------------ + +Use one of these actively maintained, Google-published gems instead: + + | Gem | Replaces | Notes | + | --- | --- | --- | + | [`google-analytics-data`](https://rubygems.org/gems/google-analytics-data) | Reporting (`Garb::Model`, `results`) | Official GA4 Data API client (gRPC-based, recommended) | + | [`google-analytics-admin`](https://rubygems.org/gems/google-analytics-admin) | `Garb::Management::*` | Official GA4 Admin API client (accounts, properties, data streams, key events) | + | [`google-apis-analyticsdata_v1beta`](https://rubygems.org/gems/google-apis-analyticsdata_v1beta) | Reporting | REST-based GA4 Data API client, lighter alternative to the gRPC one | + | [`google-apis-analyticsadmin_v1beta`](https://rubygems.org/gems/google-apis-analyticsadmin_v1beta) | `Garb::Management::*` | REST-based GA4 Admin API client | -On April 20th, Google will be shutting down ClientLogin, AuthSub, and OAuth 1.0. https://groups.google.com/forum/#!topic/google-analytics-api-notify/g8wbdUqEDd0 +Authentication for all of the above is handled by [`googleauth`](https://rubygems.org/gems/googleauth) (service accounts, OAuth 2.0, Application Default Credentials). -Legato ------- +[Legato](https://github.com/tpitale/legato), previously recommended here as a successor, also targets the retired Universal Analytics API and is no longer an option. - There's rewritten and (moar) actively maintained version of the library in the form of [Legato](https://github.com/tpitale/legato). - You might want to check it out as it's mostly compatible with `Garb`. +Getting started with GA4: [Data API overview](https://developers.google.com/analytics/devguides/reporting/data/v1) and [quickstart](https://developers.google.com/analytics/devguides/reporting/data/v1/quickstart) Important Changes ----------------- @@ -35,6 +51,8 @@ Basic Usage Single User Login ----------------- + **Defunct:** ClientLogin was shut down by Google in April 2015; this method no longer works. + ```ruby Garb::Session.api_key = api_key # required for 2-step authentication Garb::Session.login(username, password) @@ -43,6 +61,8 @@ Garb::Session.login(username, password) OAuth Access Token ------------------ + The only authentication method that was still supported until the Universal Analytics APIs were retired. + ```ruby Garb::Session.access_token = access_token # an instance of OAuth2::Client ``` @@ -153,6 +173,8 @@ profile.exits(filters: { :page_path.eql => '/extend/effectively-using-git-with-s SSL --- + **Defunct:** this only applies to single user (ClientLogin) authentication, see above. + Version 0.2.3 includes support for real ssl encryption for SINGLE USER authentication. First do: ```ruby @@ -184,15 +206,19 @@ TODOS Requirements ------------ - * active_support >= 2.2 - * multi_json >= 1.3 + * Ruby (tested on 3.2, 3.3 and 3.4) + * activesupport >= 2.2 + * ostruct + +Running Tests +------------- -Requirements for Testing ------------------------- + The test suite stubs all network calls, so no Google credentials or API keys are needed: - * shoulda - * mocha - * bourne +```sh +bundle install +bundle exec rake +``` Install ------- diff --git a/garb.gemspec b/garb.gemspec index 8534cdb..6aa0c59 100644 --- a/garb.gemspec +++ b/garb.gemspec @@ -15,8 +15,9 @@ Gem::Specification.new do |gem| gem.test_files = gem.files.grep(%r{^(test|spec|features)/}) gem.name = 'garb' gem.require_paths = ['lib'] + gem.required_ruby_version = '>= 3.2' gem.version = Garb::VERSION gem.add_dependency 'activesupport', '>= 2.2' - gem.add_dependency 'multi_json', '>= 1.3' + gem.add_dependency 'ostruct', '~> 0.6' end diff --git a/lib/garb.rb b/lib/garb.rb index b5335f2..b8430d4 100644 --- a/lib/garb.rb +++ b/lib/garb.rb @@ -6,7 +6,7 @@ require 'cgi' require 'ostruct' -require 'multi_json' +require 'json' module Garb autoload :VERSION, 'garb/version' diff --git a/lib/garb/management/feed.rb b/lib/garb/management/feed.rb index 05369b1..145115d 100644 --- a/lib/garb/management/feed.rb +++ b/lib/garb/management/feed.rb @@ -10,7 +10,7 @@ def initialize(session, path) end def parsed_response - @parsed_response ||= MultiJson.load(response.body) + @parsed_response ||= JSON.parse(response.body) end def entries diff --git a/lib/garb/profile_reports.rb b/lib/garb/profile_reports.rb index b713b15..2fbd467 100644 --- a/lib/garb/profile_reports.rb +++ b/lib/garb/profile_reports.rb @@ -6,6 +6,14 @@ def self.add_report_method(klass) method_name = klass.name.to_s.demodulize.underscore return if method_name.empty? + # silence "method redefined" warnings without leaving a window where + # the method is undefined: aliasing marks the current definition as + # referenced, and removing the alias leaves the original in place + if method_defined?(method_name, false) + alias_method :__garb_redefine, method_name + remove_method :__garb_redefine + end + class_eval <<-CODE def #{method_name}(opts = {}, &block) #{klass}.results(self, opts, &block) diff --git a/lib/garb/report_response.rb b/lib/garb/report_response.rb index fa35e47..e7c8610 100644 --- a/lib/garb/report_response.rb +++ b/lib/garb/report_response.rb @@ -44,7 +44,7 @@ def rows def data unless @data - @data = MultiJson.load @response_body + @data = JSON.parse @response_body @data = @data.each_with_object({}) do |pair, data| key, value = pair data[key.underscore.to_sym] = value diff --git a/lib/garb/request/data.rb b/lib/garb/request/data.rb index c349f5a..a100d0f 100644 --- a/lib/garb/request/data.rb +++ b/lib/garb/request/data.rb @@ -47,7 +47,7 @@ def send_request def handle_response(response) unless response.kind_of?(Net::HTTPSuccess) || (response.respond_to?(:status) && response.status == 200) - body, parsed = response.body, MultiJson.load(response.body) rescue nil + body, parsed = response.body, JSON.parse(response.body) rescue nil if parsed && (error = parsed['error']) klass = case error['code'] when 400 then BadRequestError diff --git a/test/unit/garb/management/account_test.rb b/test/unit/garb/management/account_test.rb index d705aea..7405c97 100644 --- a/test/unit/garb/management/account_test.rb +++ b/test/unit/garb/management/account_test.rb @@ -19,7 +19,7 @@ class AccountTest < MiniTest::Unit::TestCase context "an Account" do setup do - entry = MultiJson.load(read_fixture("account_management.json"))['items'].first + entry = JSON.parse(read_fixture('account_management.json'))['items'].first @account = Account.new(entry, Session) end diff --git a/test/unit/garb/management/feed_test.rb b/test/unit/garb/management/feed_test.rb index deb9891..9e6495b 100644 --- a/test/unit/garb/management/feed_test.rb +++ b/test/unit/garb/management/feed_test.rb @@ -11,11 +11,11 @@ class FeedTest < MiniTest::Unit::TestCase end should "have a parsed response" do - MultiJson.stubs(:load) + JSON.stubs(:parse) @feed.stubs(:response).returns(stub(:body => 'response body')) @feed.parsed_response - assert_received(MultiJson, :load) {|e| e.with('response body')} + assert_received(JSON, :parse) { |e| e.with('response body') } end should "have entries from the parsed response" do diff --git a/test/unit/garb/management/goal_test.rb b/test/unit/garb/management/goal_test.rb index 398091e..db1a033 100644 --- a/test/unit/garb/management/goal_test.rb +++ b/test/unit/garb/management/goal_test.rb @@ -37,7 +37,7 @@ class GoalTest < MiniTest::Unit::TestCase context "a Goal" do setup do - entry = MultiJson.load(read_fixture("goal_management.json"))["items"].first + entry = JSON.parse(read_fixture('goal_management.json'))['items'].first @goal = Goal.new(entry, Session) end diff --git a/test/unit/garb/management/profile_test.rb b/test/unit/garb/management/profile_test.rb index b9ab5e8..4b5dad7 100644 --- a/test/unit/garb/management/profile_test.rb +++ b/test/unit/garb/management/profile_test.rb @@ -31,7 +31,7 @@ class ProfileTest < MiniTest::Unit::TestCase context "A Profile" do setup do - entry = MultiJson.load(read_fixture("ga_profile_management.json"))["items"].first + entry = JSON.parse(read_fixture('ga_profile_management.json'))['items'].first @profile = Profile.new(entry, Session) end diff --git a/test/unit/garb/management/segment_test.rb b/test/unit/garb/management/segment_test.rb index cccaf8f..9e66e8c 100644 --- a/test/unit/garb/management/segment_test.rb +++ b/test/unit/garb/management/segment_test.rb @@ -19,7 +19,7 @@ class SegmentTest < MiniTest::Unit::TestCase context "A Segment" do setup do - entry = MultiJson.load(read_fixture("ga_segment_management.json"))["items"].first + entry = JSON.parse(read_fixture('ga_segment_management.json'))['items'].first @segment = Segment.new(entry, Session) end diff --git a/test/unit/garb/management/web_property_test.rb b/test/unit/garb/management/web_property_test.rb index 0d6a13a..2cfb50d 100644 --- a/test/unit/garb/management/web_property_test.rb +++ b/test/unit/garb/management/web_property_test.rb @@ -28,7 +28,7 @@ class WebPropertyTest < MiniTest::Unit::TestCase context "a WebProperty" do setup do - entry = MultiJson.load(read_fixture("ga_webproperty_management.json"))["items"].first + entry = JSON.parse(read_fixture('ga_webproperty_management.json'))['items'].first @web_property = WebProperty.new(entry, Session) end diff --git a/test/unit/garb/model_test.rb b/test/unit/garb/model_test.rb index 58e7969..743d8ad 100644 --- a/test/unit/garb/model_test.rb +++ b/test/unit/garb/model_test.rb @@ -41,7 +41,7 @@ class ModelTest < MiniTest::Unit::TestCase context "with a profile" do setup do - entry = MultiJson.load(read_fixture('ga_profile_management.json'))['items'].first + entry = JSON.parse(read_fixture('ga_profile_management.json'))['items'].first @profile = Garb::Management::Profile.new(entry, Session) end diff --git a/test/unit/garb/report_response_test.rb b/test/unit/garb/report_response_test.rb index e859dfd..479c986 100644 --- a/test/unit/garb/report_response_test.rb +++ b/test/unit/garb/report_response_test.rb @@ -48,7 +48,7 @@ class ReportResponseTest < MiniTest::Unit::TestCase should "return an empty array if there are no results" do response = ReportResponse.new('result json') - MultiJson.stubs(:load).with('result json').returns({'rows' => []}) + JSON.stubs(:parse).with('result json').returns('rows' => []) assert_equal [], response.results.to_a end