From 1405c9e2236fa5960c574f030ae86b03086d911f Mon Sep 17 00:00:00 2001 From: Kyle Decot Date: Thu, 12 Sep 2019 21:03:27 -0400 Subject: [PATCH 1/3] Extract Usage from Client --- lib/app_store_connect/client.rb | 12 +++++++----- lib/app_store_connect/client/usage.rb | 20 ++++++++++++++++++++ 2 files changed, 27 insertions(+), 5 deletions(-) create mode 100644 lib/app_store_connect/client/usage.rb diff --git a/lib/app_store_connect/client.rb b/lib/app_store_connect/client.rb index c098b7f..c450f51 100644 --- a/lib/app_store_connect/client.rb +++ b/lib/app_store_connect/client.rb @@ -1,12 +1,11 @@ # frozen_string_literal: true require 'active_support/all' -require 'mixpanel-ruby' -require 'securerandom' require 'app_store_connect/request' require 'app_store_connect/authorization' require 'app_store_connect/schema' +require 'app_store_connect/client/usage' module AppStoreConnect class Client @@ -23,8 +22,7 @@ def initialize(**kwargs) .web_service_endpoints .map { |s| [s.alias, s] } .to_h - @distinct_id = SecureRandom.uuid - @tracker = Mixpanel::Tracker.new('1213f2b88b9b10b13d321f4c67a55ca8') + @usage = Usage.new end def respond_to_missing?(method_name, include_private = false) @@ -39,6 +37,10 @@ def method_missing(method_name, *kwargs) call(web_service_endpoint, *kwargs) end + def inspect + "#<#{self.class.name}:#{self.object_id}>" + end + def web_service_endpoint_aliases @web_service_endpoints_by_alias.keys end @@ -50,7 +52,7 @@ def call(web_service_endpoint, **kwargs) request = build_request(web_service_endpoint, **kwargs) - @tracker.track(@distinct_id, web_service_endpoint.alias) if @options[:analytics_enabled] + @usage.track if @options[:analytics_enabled] response = request.execute JSON.parse(response.body) if response.body diff --git a/lib/app_store_connect/client/usage.rb b/lib/app_store_connect/client/usage.rb new file mode 100644 index 0000000..46e4c65 --- /dev/null +++ b/lib/app_store_connect/client/usage.rb @@ -0,0 +1,20 @@ +require 'mixpanel-ruby' +require 'securerandom' + +module AppStoreConnect + class Client + class Usage + MIXPANEL_PROJECT_TOKEN = '1213f2b88b9b10b13d321f4c67a55ca8' + private_constant :MIXPANEL_PROJECT_TOKEN + + def initialize + @distinct_id = SecureRandom.uuid + @tracker = Mixpanel::Tracker.new(MIXPANEL_PROJECT_TOKEN) + end + + def track + @tracker.track(@distinct_id, 'usage') + end + end + end +end From e14c11984bae2c432923052571a1ea5dd6de616f Mon Sep 17 00:00:00 2001 From: Kyle Decot Date: Thu, 12 Sep 2019 21:04:11 -0400 Subject: [PATCH 2/3] Fix Formatting --- lib/app_store_connect/client.rb | 6 +++--- lib/app_store_connect/client/usage.rb | 12 +++++++----- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/lib/app_store_connect/client.rb b/lib/app_store_connect/client.rb index c450f51..81abe6f 100644 --- a/lib/app_store_connect/client.rb +++ b/lib/app_store_connect/client.rb @@ -37,9 +37,9 @@ def method_missing(method_name, *kwargs) call(web_service_endpoint, *kwargs) end - def inspect - "#<#{self.class.name}:#{self.object_id}>" - end + def inspect + "#<#{self.class.name}:#{object_id}>" + end def web_service_endpoint_aliases @web_service_endpoints_by_alias.keys diff --git a/lib/app_store_connect/client/usage.rb b/lib/app_store_connect/client/usage.rb index 46e4c65..3b55e46 100644 --- a/lib/app_store_connect/client/usage.rb +++ b/lib/app_store_connect/client/usage.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + require 'mixpanel-ruby' require 'securerandom' module AppStoreConnect - class Client + class Client class Usage MIXPANEL_PROJECT_TOKEN = '1213f2b88b9b10b13d321f4c67a55ca8' private_constant :MIXPANEL_PROJECT_TOKEN @@ -11,10 +13,10 @@ def initialize @distinct_id = SecureRandom.uuid @tracker = Mixpanel::Tracker.new(MIXPANEL_PROJECT_TOKEN) end - + def track @tracker.track(@distinct_id, 'usage') - end + end end - end -end + end +end From e96a8883f81c9df00a5a440a35a146e540a9534d Mon Sep 17 00:00:00 2001 From: Kyle Decot Date: Fri, 13 Sep 2019 09:48:32 -0400 Subject: [PATCH 3/3] Add Spec for Usage --- spec/app_store_connect/client/usage_spec.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 spec/app_store_connect/client/usage_spec.rb diff --git a/spec/app_store_connect/client/usage_spec.rb b/spec/app_store_connect/client/usage_spec.rb new file mode 100644 index 0000000..e3b96a7 --- /dev/null +++ b/spec/app_store_connect/client/usage_spec.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +RSpec.describe AppStoreConnect::Client::Usage do + describe '#track' do + it 'should track usage w/ mixpanel' do + expect_any_instance_of(Mixpanel::Tracker) + .to receive(:track) + .with(String, 'usage') + + described_class.new.track + end + end +end