Class: Spaceship::StatsMiddleware
- Inherits:
-
Faraday::Middleware
- Object
- Faraday::Middleware
- Spaceship::StatsMiddleware
- Defined in:
- spaceship/lib/spaceship/stats_middleware.rb
Defined Under Namespace
Classes: ServiceOption, URLLog
Class Method Summary collapse
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app) ⇒ StatsMiddleware
constructor
A new instance of StatsMiddleware.
- #log(env) ⇒ Object
Constructor Details
#initialize(app) ⇒ StatsMiddleware
Returns a new instance of StatsMiddleware.
39 40 41 |
# File 'spaceship/lib/spaceship/stats_middleware.rb', line 39 def initialize(app) super(app) end |
Class Method Details
.request_logs ⇒ Object
33 34 35 36 |
# File 'spaceship/lib/spaceship/stats_middleware.rb', line 33 def request_logs @request_logs ||= [] @request_logs end |
.service_stats ⇒ Object
29 30 31 |
# File 'spaceship/lib/spaceship/stats_middleware.rb', line 29 def service_stats @service_stats ||= Hash.new(0) end |
.services ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'spaceship/lib/spaceship/stats_middleware.rb', line 10 def services return @services if @services require_relative 'tunes/tunes_client' require_relative 'portal/portal_client' require_relative 'connect_api/testflight/client' require_relative 'connect_api/provisioning/client' @services ||= [ ServiceOption.new("App Store Connect API (official)", "api.appstoreconnect.apple.com", "JWT"), ServiceOption.new("App Store Connect API (web session)", Spaceship::ConnectAPI::TestFlight::Client.hostname.gsub("https://", ""), "Web session"), ServiceOption.new("App Store Connect API (web session)", Spaceship::ConnectAPI::Provisioning::Client.hostname.gsub("https://", ""), "Web session"), ServiceOption.new("Legacy iTunesConnect Auth", "idmsa.apple.com", "Web session"), ServiceOption.new("Legacy iTunesConnect Auth", "appstoreconnect.apple.com/olympus/v1/", "Web session"), ServiceOption.new("Legacy iTunesConnect", Spaceship::TunesClient.hostname.gsub("https://", ""), "Web session"), ServiceOption.new("Legacy iTunesConnect Developer Portal", Spaceship::PortalClient.hostname.gsub("https://", ""), "Web session") ] end |
Instance Method Details
#call(env) ⇒ Object
43 44 45 46 |
# File 'spaceship/lib/spaceship/stats_middleware.rb', line 43 def call(env) log(env) @app.call(env) end |
#log(env) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'spaceship/lib/spaceship/stats_middleware.rb', line 48 def log(env) return false unless env && env.url && (uri = URI.parse(env.url.to_s)) service = StatsMiddleware.services.find do |s| uri.to_s.include?(s.url) end service = ServiceOption.new("Unknown", uri.host, "Unknown") if service.nil? StatsMiddleware.service_stats[service] += 1 StatsMiddleware.request_logs << URLLog.new(uri.to_s, service.auth_type) return true rescue => e puts("Failed to log spaceship stats - #{e.}") if Spaceship::Globals.verbose? return false end |