Skip to content

Commit 3f845e5

Browse files
authored
Export new API changes in AppDistributionInternal to master (#10999)
1 parent 7220efb commit 3f845e5

File tree

3 files changed

+79
-41
lines changed

3 files changed

+79
-41
lines changed

FirebaseAppDistributionInternal/Resources/AppDistributionInternalStoryboard.storyboard

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="21225" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="21507" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
33
<device id="retina6_0" orientation="portrait" appearance="light"/>
44
<dependencies>
55
<deployment identifier="iOS"/>
6-
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="21207"/>
6+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="21505"/>
77
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
88
<capability name="System colors in document resources" minToolsVersion="11.0"/>
99
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
@@ -87,7 +87,7 @@
8787
<constraint firstItem="B8f-p9-FeY" firstAttribute="top" secondItem="8bC-Xf-vdC" secondAttribute="top" constant="91" id="EFg-iZ-Jzz"/>
8888
<constraint firstItem="5dc-R4-ELB" firstAttribute="trailing" secondItem="B8f-p9-FeY" secondAttribute="trailing" id="EwK-Jx-Hes"/>
8989
<constraint firstItem="6Tk-OE-BBY" firstAttribute="trailing" secondItem="dsI-rN-5aL" secondAttribute="trailing" constant="16" id="I52-Pj-PSq"/>
90-
<constraint firstItem="W0X-zt-uEG" firstAttribute="centerX" secondItem="6Tk-OE-BBY" secondAttribute="centerX" id="Jvv-bL-zyF"/>
90+
<constraint firstAttribute="centerX" secondItem="6Tk-OE-BBY" secondAttribute="centerX" id="Jvv-bL-zyF"/>
9191
<constraint firstAttribute="bottom" secondItem="5dc-R4-ELB" secondAttribute="bottom" constant="583" id="OBu-rX-tfb"/>
9292
<constraint firstItem="Dia-oO-Nu0" firstAttribute="centerX" secondItem="6Tk-OE-BBY" secondAttribute="centerX" id="UDB-uL-1PW"/>
9393
<constraint firstItem="5dc-R4-ELB" firstAttribute="centerX" secondItem="dsI-rN-5aL" secondAttribute="centerX" id="Z7g-ss-vlW"/>
@@ -99,12 +99,13 @@
9999
<constraint firstItem="dsI-rN-5aL" firstAttribute="leading" secondItem="6Tk-OE-BBY" secondAttribute="leading" constant="16" id="vfI-nc-TeW"/>
100100
<constraint firstItem="B8f-p9-FeY" firstAttribute="leading" secondItem="Dia-oO-Nu0" secondAttribute="leading" id="waP-fr-WQe"/>
101101
<constraint firstItem="Dia-oO-Nu0" firstAttribute="leading" secondItem="6Tk-OE-BBY" secondAttribute="leading" id="wg8-jh-o4A"/>
102-
<constraint firstItem="W0X-zt-uEG" firstAttribute="centerY" secondItem="6Tk-OE-BBY" secondAttribute="centerY" id="zZh-sJ-7Gx"/>
102+
<constraint firstAttribute="centerY" secondItem="6Tk-OE-BBY" secondAttribute="centerY" id="zZh-sJ-7Gx"/>
103103
</constraints>
104104
</view>
105105
<connections>
106-
<outlet property="additionalInfoLabel" destination="dmh-tx-P50" id="AYi-ue-FXB"/>
106+
<outlet property="additionalFormTextLabel" destination="dmh-tx-P50" id="heh-EK-oEt"/>
107107
<outlet property="feedbackTextView" destination="iNL-09-ZI6" id="Ur9-nn-jm4"/>
108+
<outlet property="navigationBar" destination="Dia-oO-Nu0" id="eVF-OS-PgH"/>
108109
<outlet property="screenshotUIImageView" destination="dsI-rN-5aL" id="bRf-CH-E8Y"/>
109110
</connections>
110111
</viewController>

FirebaseAppDistributionInternal/Sources/ApiService.swift

Lines changed: 26 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ enum Strings {
2828
static let releaseEndpointUrlTemplate =
2929
"https://firebaseapptesters.googleapis.com/v1alpha/devices/-/testerApps/%@/installations/%@/releases"
3030
static let findReleaseEndpointUrlTemplate =
31-
"https://firebaseapptesters.googleapis.com/v1alpha/projects/%@/installations/%@/releases:find"
31+
"https://firebaseapptesters.googleapis.com/v1alpha/projects/%@/installations/%@/releases:find?compositeBinaryId.displayVersion=%@&compositeBinaryId.buildVersion=%@&compositeBinaryId.codeHash=%@"
3232
static let createFeedbackEndpointUrlTemplate =
3333
"https://firebaseapptesters.googleapis.com/v1alpha/%@/feedbackReports"
3434
static let uploadImageEndpointUrlTemplate =
35-
"https://firebaseapptesters.googleapis.com/v1alpha/%@/feedbackReports"
35+
"https://firebaseapptesters.googleapis.com/upload/v1alpha/%@:uploadArtifact"
3636
static let commitFeedbackEndpointUrlTemplate =
3737
"https://firebaseapptesters.googleapis.com/v1alpha/%@:commit"
3838
static let installationsAuthHeader = "X-Goog-Firebase-Installations-Auth"
@@ -46,6 +46,8 @@ enum Strings {
4646
static let GoogleUploadProtocolRaw = "raw"
4747
static let GoogleUploadFileNameHeader = "X-Goog-Upload-File-Name"
4848
static let GoogleUploadFileName = "screenshot.png"
49+
static let contentTypeHeader = "Content-Type"
50+
static let jsonContentType = "application/json"
4951
}
5052

5153
enum AppDistributionApiError: NSInteger {
@@ -74,10 +76,6 @@ struct FeedbackReport: Codable {
7476
var text: String?
7577
}
7678

77-
struct CreateFeedbackReportRequest: Codable {
78-
var feedbackReport: FeedbackReport
79-
}
80-
8179
@objc(FIRFADApiServiceSwift) open class ApiService: NSObject {
8280
@objc(generateAuthTokenWithCompletion:) public static func generateAuthToken(completion: @escaping (_ identifier: String?,
8381
_ authTokenResult: InstallationsAuthTokenResult?,
@@ -196,6 +194,19 @@ struct CreateFeedbackReportRequest: Codable {
196194
)
197195
}
198196

197+
private static func buildFindReleaseUrl(projectNumber: String, identifier: String,
198+
displayVersion: String, buildVersion: String,
199+
codeHash: String) -> String {
200+
return String(
201+
format: Strings.findReleaseEndpointUrlTemplate,
202+
projectNumber,
203+
identifier,
204+
displayVersion,
205+
buildVersion,
206+
codeHash
207+
)
208+
}
209+
199210
static func findRelease(app: FirebaseApp, installations: InstallationsProtocol,
200211
urlSession: URLSession, displayVersion: String,
201212
buildVersion: String, codeHash: String,
@@ -204,39 +215,17 @@ struct CreateFeedbackReportRequest: Codable {
204215
generateAuthToken(installations: installations) { identifier, authTokenResult, error in
205216
// TODO(tundeagboola) The backend may not accept project ID here in which case
206217
// we'll have to figure out a way to get the project number
207-
let urlString = String(
208-
format: Strings.findReleaseEndpointUrlTemplate,
209-
app,
210-
identifier!
211-
)
212-
guard var urlComponents = URLComponents(string: urlString) else {
213-
// TODO(tundeagboola) We should throw exceptions here insead of piping errors
214-
Logger.logError("Unable to build URL for findRelease request")
215-
return
216-
}
217-
let compositeBinaryId = CompositeBinaryId(
218+
let urlString = buildFindReleaseUrl(
219+
projectNumber: app.options.gcmSenderID,
220+
identifier: identifier!,
218221
displayVersion: displayVersion,
219222
buildVersion: buildVersion,
220223
codeHash: codeHash
221224
)
222-
guard let compositeBinaryIdData = try? JSONEncoder().encode(compositeBinaryId) else {
223-
// TODO(tundeagboola) We should throw exceptions here insead of piping errors
224-
Logger.logError("Unable to build URL for findRelease request")
225-
return
226-
}
227-
urlComponents.queryItems = [URLQueryItem(
228-
name: Strings.compositeBinaryIdQueryParamName,
229-
value: String(data: compositeBinaryIdData, encoding: .utf8)
230-
)]
231-
guard let url = urlComponents.url else {
232-
// TODO(tundeagboola) We should throw exceptions here insead of piping errors
233-
Logger.logError("Unable to build URL for findRelease request")
234-
return
235-
}
236225
let request = self.createHttpRequest(
237226
app: app,
238227
method: Strings.httpGet,
239-
url: url,
228+
url: URL(string: urlString),
240229
authTokenResult: authTokenResult!
241230
)
242231
let findReleaseDataTask = urlSession
@@ -292,9 +281,9 @@ struct CreateFeedbackReportRequest: Codable {
292281
url: urlString,
293282
authTokenResult: authTokenResult
294283
)
295-
let createFeedbackRequest =
296-
CreateFeedbackReportRequest(feedbackReport: FeedbackReport(text: feedbackText))
297-
request.httpBody = try? JSONEncoder().encode(createFeedbackRequest)
284+
request.setValue(Strings.jsonContentType, forHTTPHeaderField: Strings.contentTypeHeader)
285+
let feedbackReport = FeedbackReport(text: feedbackText)
286+
request.httpBody = try? JSONEncoder().encode(feedbackReport)
298287
let createFeedbackTask = urlSession
299288
.dataTask(with: request as URLRequest) { data, response, error in
300289
var fadError = error
@@ -370,6 +359,8 @@ struct CreateFeedbackReportRequest: Codable {
370359
Strings.GoogleUploadFileNameHeader,
371360
forHTTPHeaderField: Strings.GoogleUploadFileName
372361
)
362+
// TODO(tundeagboola) Add support for jpegs
363+
request.httpBody = image.pngData()
373364
let uploadImageTask = urlSession
374365
.dataTask(with: request as URLRequest) { data, response, error in
375366
var fadError = error

FirebaseAppDistributionInternal/Sources/FeedbackViewController.swift

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,48 @@ class FeedbackViewController: UIViewController {
4848
image = nil
4949
}
5050

51-
@IBAction func tappedSend(_ sender: Any) {}
51+
@IBAction func tappedSend(_ sender: Any) {
52+
guard let releaseName = releaseName else {
53+
// TODO(tundeagboola) throw error or
54+
return
55+
}
56+
57+
ApiService
58+
.createFeedback(releaseName: releaseName,
59+
feedbackText: feedbackTextView.text) { feedbackName, error in
60+
if error != nil {
61+
// TODO(tundeaboola) handle error if create feedback fails
62+
return
63+
}
64+
65+
guard let feedbackName = feedbackName else {
66+
// TODO(tundeaboola) handle error if create feedback fails
67+
return
68+
}
69+
70+
guard let image = self.screenshotUIImageView.image else {
71+
return self.commitFeedback(feedbackName: feedbackName)
72+
}
73+
74+
ApiService.uploadImage(feedbackName: feedbackName, image: image) { error in
75+
if error != nil {
76+
// TODO(tundeaboola) handle error if upload image fails
77+
return
78+
}
79+
80+
self.commitFeedback(feedbackName: feedbackName)
81+
}
82+
}
83+
}
84+
85+
private func commitFeedback(feedbackName: String) {
86+
ApiService.commitFeedback(feedbackName: feedbackName) { error in
87+
if error != nil {
88+
// TODO(tundeaboola) handle error if commit feedback fails
89+
}
90+
self.feedbackSubmitted()
91+
}
92+
}
5293

5394
@IBAction func tappedCancel(_ sender: Any) {
5495
dismiss(animated: true)
@@ -57,4 +98,9 @@ class FeedbackViewController: UIViewController {
5798
override func viewDidDisappear(_ animated: Bool) {
5899
viewDidDisappearCallback()
59100
}
101+
102+
func feedbackSubmitted() {
103+
// TODO(tundeagboola) show success toast
104+
dismiss(animated: true)
105+
}
60106
}

0 commit comments

Comments
 (0)