Skip to content

Commit

Permalink
support get flows and screens by Version
Browse files Browse the repository at this point in the history
  • Loading branch information
underthestars-zhy committed Apr 30, 2023
1 parent d946341 commit a9cbec7
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 9 deletions.
16 changes: 12 additions & 4 deletions Sources/MobbinAPI/IOS/GetiOSDetails.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Foundation
import SwiftyJSON

extension MobbinAPI {
public func getiOSScreens(of app: App) async throws -> [Screen] {
public func getiOSScreens(by version: Version) async throws -> [Screen] {
guard let token else { throw MobbinError.cannotFindToken }

guard var URL = URL(string: "https://ujasntkfphywizsdaapi.supabase.co/rest/v1/rpc/get_app_screens_filter") else { throw HTTPError.wrongUrlFormat }
Expand Down Expand Up @@ -45,7 +45,7 @@ extension MobbinAPI {
// JSON Body

let bodyObject: [String : Any] = [
"filterAppVersionId": app.appVersionId,
"filterAppVersionId": version.id,
"filterOperator": "and",
"filterScreenElements": NSNull(),
"filterScreenPatterns": NSNull(),
Expand Down Expand Up @@ -83,7 +83,11 @@ extension MobbinAPI {
} ?? []
}

public func getiOSFlows(of app: App) async throws -> [Flow] {
public func getiOSScreens(of app: App) async throws -> [Screen] {
try await getiOSScreens(by: Version(id: app.appVersionId, createdAt: app.appVersionCreatedAt, publishedAt: app.appVersionPublishedAt))
}

public func getiOSFlows(by version: Version) async throws -> [Flow] {
guard let token else { throw MobbinError.cannotFindToken }

guard var URL = URL(string: "https://ujasntkfphywizsdaapi.supabase.co/rest/v1/rpc/get_app_sections_filter") else { throw HTTPError.wrongUrlFormat }
Expand Down Expand Up @@ -120,7 +124,7 @@ extension MobbinAPI {
// JSON Body

let bodyObject: [String : Any] = [
"filterAppVersionId": app.appVersionId,
"filterAppVersionId": version.id,
"filterOperator": "and",
"filterFlowTitles": NSNull(),
"filterScreenPatterns": NSNull(),
Expand Down Expand Up @@ -169,4 +173,8 @@ extension MobbinAPI {
return Flow(id: id, name: name, actions: actions, parentAppSectionId: parentAppSectionId, order: order, updatedAt: updatedAt, appVersionId: appVersionId, screens: screens)
} ?? []
}

public func getiOSFlows(of app: App) async throws -> [Flow] {
try await getiOSFlows(by: Version(id: app.appVersionId, createdAt: app.appVersionCreatedAt, publishedAt: app.appVersionPublishedAt))
}
}
2 changes: 1 addition & 1 deletion Sources/MobbinAPI/Mobbin/AppVersion.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import Foundation

extension MobbinAPI {
func versions(of app: App, mobbinToken: String? = nil) async throws -> [Version] {
public func versions(of app: App, mobbinToken: String? = nil) async throws -> [Version] {
let json = try await mobbinAppInfo(of: app, mobbinToken: mobbinToken)

return try json["pageProps"]["app"]["appVersions"].array?.map({ json in
Expand Down
2 changes: 1 addition & 1 deletion Sources/MobbinAPI/Mobbin/DownloadURL.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Foundation
import SwiftyJSON

extension MobbinAPI {
func downloadURL(of app: App, mobbinToken: String? = nil) async throws -> URL {
public func downloadURL(of app: App, mobbinToken: String? = nil) async throws -> URL {
let json = try await mobbinAppInfo(of: app, mobbinToken: mobbinToken)

guard let url = json["pageProps"]["app"]["appStoreUrl"].url else { throw MobbinError.wrongURL(json["pageProps"]["app"]["appStoreUrl"].stringValue) }
Expand Down
2 changes: 1 addition & 1 deletion Sources/MobbinAPI/Mobbin/MobbinAppInfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ extension MobbinAPI {
} else {
token = try await getMobbinQueryToken()
}

guard var URL = URL(string: "https://mobbin.com/_next/data/\(token)/apps/\(app.appName.lowercased().replacing(" ", with: "-"))-\(app.platform)-\(app.id)/_/screens.json") else {
throw HTTPError.wrongUrlFormat }
let URLParams = [
Expand Down
2 changes: 1 addition & 1 deletion Sources/MobbinAPI/Mobbin/MobbinQueryToken.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import Foundation

extension MobbinAPI {
func getMobbinQueryToken() async throws -> String {
public func getMobbinQueryToken() async throws -> String {
guard let URL = URL(string: "https://mobbin.com/") else { throw MobbinError.cannotFindToken }
var request = URLRequest(url: URL)
request.httpMethod = "GET"
Expand Down
2 changes: 1 addition & 1 deletion Sources/MobbinAPI/Model/Version.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import Foundation

struct Version {
public struct Version {
let id: String
let createdAt: Date
let publishedAt: Date
Expand Down
12 changes: 12 additions & 0 deletions Tests/MobbinAPITests/MobbinAPITests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,18 @@ final class MobbinAPITests: XCTestCase {
XCTAssertEqual(flows.count, 30)
}

func testGetiOSScreensByVersion() async throws {
let api = MobbinAPI(email: "[email protected]", token: Token(accessToken: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJhdXRoZW50aWNhdGVkIiwiZXhwIjoxNjgyOTU1Nzk5LCJzdWIiOiJkMmI0MTU5MC01M2E0LTRjNGQtOWQ5NC0wNmY1ZDcxODA3YzMiLCJlbWFpbCI6InpodWhhb3l1MDkwOUBpY2xvdWQuY29tIiwicGhvbmUiOiIiLCJhcHBfbWV0YWRhdGEiOnsicHJvdmlkZXIiOiJlbWFpbCIsInByb3ZpZGVycyI6WyJlbWFpbCJdfSwidXNlcl9tZXRhZGF0YSI6eyJhdmF0YXJfdXJsIjoiaHR0cHM6Ly91amFzbnRrZnBoeXdpenNkYWFwaS5zdXBhYmFzZS5jby9zdG9yYWdlL3YxL29iamVjdC9wdWJsaWMvdXNlci91c2VyX2F2YXRhcnMvYTcyZTgwNjQtZjdlYi00YjBhLTg0MWMtMzlhM2ExMGRmY2E0LmpwZWciLCJmdWxsX25hbWUiOiJVVFN6aHkifSwicm9sZSI6ImF1dGhlbnRpY2F0ZWQiLCJhYWwiOiJhYWwxIiwiYW1yIjpbeyJtZXRob2QiOiJvdHAiLCJ0aW1lc3RhbXAiOjE2ODI4NjkzOTl9XSwic2Vzc2lvbl9pZCI6Ijc3MmM5YmQxLTY2NWEtNGVmMS1hNjkxLWZkYWNhNDQyMGI5NCJ9.ffaXhHJtn45KUHSs3uI8LaRik1MSVUdIIjRsZAyVil0", refreshToken: ""))

let apps = try await api.queryNextPage(nil)

let version = try await api.versions(of: apps[1])[1]

let flows = try await api.getiOSFlows(by: version)

XCTAssertEqual(flows.count, 39)
}

func testQueryCollections() async throws {
let api = MobbinAPI(email: "[email protected]", token: Token(accessToken: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJhdXRoZW50aWNhdGVkIiwiZXhwIjoxNjgyNzc3MTQ0LCJzdWIiOiJkMmI0MTU5MC01M2E0LTRjNGQtOWQ5NC0wNmY1ZDcxODA3YzMiLCJlbWFpbCI6InpodWhhb3l1MDkwOUBpY2xvdWQuY29tIiwicGhvbmUiOiIiLCJhcHBfbWV0YWRhdGEiOnsicHJvdmlkZXIiOiJlbWFpbCIsInByb3ZpZGVycyI6WyJlbWFpbCJdfSwidXNlcl9tZXRhZGF0YSI6eyJhdmF0YXJfdXJsIjoiaHR0cHM6Ly91amFzbnRrZnBoeXdpenNkYWFwaS5zdXBhYmFzZS5jby9zdG9yYWdlL3YxL29iamVjdC9wdWJsaWMvdXNlci91c2VyX2F2YXRhcnMvYTcyZTgwNjQtZjdlYi00YjBhLTg0MWMtMzlhM2ExMGRmY2E0LmpwZWciLCJmdWxsX25hbWUiOiJVVFN6aHkifSwicm9sZSI6ImF1dGhlbnRpY2F0ZWQiLCJhYWwiOiJhYWwxIiwiYW1yIjpbeyJtZXRob2QiOiJvdHAiLCJ0aW1lc3RhbXAiOjE2ODI1MjE1OTR9XSwic2Vzc2lvbl9pZCI6ImNjMzI3ZDMzLWVkODAtNDM1Mi05NTRlLTI5OWZiNzQ1YmM5ZiJ9.s4eXeIaY9OBKT_-TxAPeWtnivxdRO1yM9K7gT68jAac", refreshToken: ""))

Expand Down

0 comments on commit a9cbec7

Please sign in to comment.