Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract Usage from Client #74

Merged
merged 3 commits into from
Sep 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions lib/app_store_connect/client.rb
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)
Expand All @@ -39,6 +37,10 @@ def method_missing(method_name, *kwargs)
call(web_service_endpoint, *kwargs)
end

def inspect
"#<#{self.class.name}:#{object_id}>"
end

def web_service_endpoint_aliases
@web_service_endpoints_by_alias.keys
end
Expand All @@ -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
Expand Down
22 changes: 22 additions & 0 deletions lib/app_store_connect/client/usage.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# frozen_string_literal: true

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
13 changes: 13 additions & 0 deletions spec/app_store_connect/client/usage_spec.rb
Original file line number Diff line number Diff line change
@@ -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