Skip to content

Commit 0a60476

Browse files
committed
Allow using file: scheme for Metrics debugging
1 parent baf5879 commit 0a60476

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

lib/fastlane/plugin/wpmreleasetoolkit/models/app_size_metrics_payload.rb

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,21 +49,28 @@ def to_h
4949
#
5050
def send_metrics(base_url:, api_token:)
5151
uri = URI.parse(base_url)
52+
# Allow using a `file:` URI for debugging
53+
if uri.is_a?(URI::File)
54+
UI.message("Writing metrics payload to file #{uri.path} (instead of sending it to a server)")
55+
File.write(uri.path, to_h.to_json)
56+
return
57+
end
58+
59+
UI.message("Sending metrics to #{uri}...")
5260
headers = {
5361
Authorization: "Bearer #{api_token}",
5462
Accept: 'application/json',
5563
'Content-Type': 'application/json',
5664
'Content-Encoding': 'gzip'
5765
}
5866
request = Net::HTTP::Post.new(uri, headers)
59-
6067
request.body = Zlib.gzip(to_h.to_json)
6168

6269
response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == 'https') do |http|
6370
http.request(request)
6471
end
6572

66-
UI.verbose("#{response.code} #{response.message}")
73+
UI.message("Metrics sent. (Received: #{response.code} #{response.message})")
6774
response.code.to_i
6875
end
6976
end

0 commit comments

Comments
 (0)