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

MOB-1950 - Updated some API hosts #483

Merged
merged 2 commits into from
Apr 5, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -303,10 +303,3 @@ extension PublicProfileView {
}

}

func loadImageFrom(url: URL) async -> UIImage? {
let urlRequest = URLRequest(url: url)
guard let (imageData, _) = try? await URLSession.shared.data(for: urlRequest) else { return nil }

return UIImage(data: imageData)
}
Original file line number Diff line number Diff line change
Expand Up @@ -609,26 +609,23 @@ extension Endpoint {
static let expirationPeriodMin: TimeInterval = 5
static func getPublicProfile(for domain: DomainItem,
fields: Set<GetDomainProfileField>) -> Endpoint {
// https://profile.ud-staging.com/api/public/aaron.x
return getPublicProfile(for: domain.name, fields: fields)
}

static func getPublicProfile(for domainName: DomainName,
fields: Set<GetDomainProfileField>) -> Endpoint {
// https://profile.ud-staging.com/api/public/aaron.x
let fieldsQuery = fields.map({ $0.rawValue }).joined(separator: ",")
return Endpoint(
host: NetworkConfig.baseProfileHost,
host: NetworkConfig.baseAPIHost,
path: "/profile/public/\(domainName)",
queryItems: fields.isEmpty ? [] : [URLQueryItem(name: "fields", value: fieldsQuery)],
body: ""
)
}

static func getBadgesInfo(for domainName: DomainName) -> Endpoint {
//https://profile.unstoppabledomains.com/api/public/aaronquirk.x/badges
return Endpoint(
host: NetworkConfig.baseProfileHost,
host: NetworkConfig.baseAPIHost,
path: "/profile/public/\(domainName)/badges",
queryItems: [],
body: ""
Expand All @@ -645,9 +642,8 @@ extension Endpoint {
}

static func getBadgeDetailedInfo(for badge: BadgesInfo.BadgeInfo) -> Endpoint {
// https://profile.unstoppabledomains.com/api/badges/opensea-tothemoonalisa
return Endpoint(
host: NetworkConfig.baseProfileHost,
host: NetworkConfig.baseAPIHost,
path: "/profile/badges/\(badge.code)",
queryItems: [],
body: ""
Expand All @@ -662,7 +658,7 @@ extension Endpoint {
.init(name: "reverse-resolution-required", value: String(shouldBeSetAsRR))]

return Endpoint(
host: NetworkConfig.baseProfileHost,
host: NetworkConfig.baseAPIHost,
path: "/profile/search",
queryItems: queryItems,
body: ""
Expand All @@ -671,10 +667,9 @@ extension Endpoint {

static let yearInSecs: TimeInterval = 60 * 60 * 24 * 356
static func getGeneratedMessageToRetrieve(for domain: DomainItem) -> Endpoint {
// https://profile.ud-staging.com/api/user/aaron.x/signature?expiry=1765522015090
let expiry = Int( (Date().timeIntervalSince1970 + yearInSecs) * 1000)
return Endpoint(
host: NetworkConfig.baseProfileHost,
host: NetworkConfig.baseAPIHost,
path: "/profile/user/\(domain.name)/signature",
queryItems: [URLQueryItem(name: "expiry", value: String(expiry)),
URLQueryItem(name: "device", value: String(true))], /// This flag will allow signature to be used in all profile API endpoints for this domain
Expand All @@ -694,7 +689,6 @@ extension Endpoint {
expires: UInt64,
signature: String,
fields: Set<GetDomainProfileField>) throws -> Endpoint {
// https://profile.ud-staging.com/api/user/aaron.x
let expiresString = "\(expires)"
let headers = [
SignatureComponentHeaders.CodingKeys.domain.rawValue: domain.name,
Expand All @@ -703,7 +697,7 @@ extension Endpoint {
]
let fieldsQuery = fields.map({ $0.rawValue }).joined(separator: ",")
return Endpoint(
host: NetworkConfig.baseProfileHost,
host: NetworkConfig.baseAPIHost,
path: "/profile/user/\(domain.name)",
queryItems: [URLQueryItem(name: "fields", value: fieldsQuery)],
body: "",
Expand All @@ -712,10 +706,9 @@ extension Endpoint {
}

static func getGeneratedMessageToUpdate(for domain: DomainItem, body: String) -> Endpoint {
// https://profile.ud-staging.com/api/user/aaron.x/signature?expiry=1765522015090
let expiry = Int( (Date().timeIntervalSince1970 + 60_000_000) * 1000)
return Endpoint(
host: NetworkConfig.baseProfileHost,
host: NetworkConfig.baseAPIHost,
path: "/profile/user/\(domain.name)/signature",
queryItems: [URLQueryItem(name: "expiry", value: String(expiry))],
body: body
Expand All @@ -726,15 +719,14 @@ extension Endpoint {
with message: GeneratedMessage,
signature: String,
body: String) throws -> Endpoint {
// https://profile.ud-staging.com/api/user/aaron.x
let expires = "\(message.headers.expires)"
let headers = [
SignatureComponentHeaders.CodingKeys.domain.rawValue: domain.name,
SignatureComponentHeaders.CodingKeys.expires.rawValue: expires,
SignatureComponentHeaders.CodingKeys.signature.rawValue: signature
]
return Endpoint(
host: NetworkConfig.baseProfileHost,
host: NetworkConfig.baseAPIHost,
path: "/profile/user/\(domain.name)",
queryItems: [],
body: body,
Expand All @@ -746,15 +738,14 @@ extension Endpoint {
expires: UInt64,
signature: String,
body: String = "") throws -> Endpoint {
// https://profile.ud-staging.com/api/user/aaron.x
let expiresString = "\(expires)"
let headers = [
SignatureComponentHeaders.CodingKeys.domain.rawValue: domain.name,
SignatureComponentHeaders.CodingKeys.expires.rawValue: expiresString,
SignatureComponentHeaders.CodingKeys.signature.rawValue: signature
]
return Endpoint(
host: NetworkConfig.baseProfileHost,
host: NetworkConfig.baseAPIHost,
path: "/profile/user/\(domain.name)/notifications/preferences",
queryItems: [],
body: body,
Expand All @@ -764,9 +755,8 @@ extension Endpoint {

static func getFollowingStatus(for followerDomain: DomainName,
followingDomain: DomainName) -> Endpoint {
//https://api.unstoppabledomains.com/profile/followers/lisa.x/follow-status/oleg.x
return Endpoint(
host: NetworkConfig.baseProfileHost,
host: NetworkConfig.baseAPIHost,
path: "/profile/followers/\(followingDomain)/follow-status/\(followerDomain)",
queryItems: [],
body: ""
Expand All @@ -777,14 +767,13 @@ extension Endpoint {
relationshipType: DomainProfileFollowerRelationshipType,
count: Int,
cursor: Int?) -> Endpoint {
//https://api.unstoppabledomains.com/profile/followers/oleg.x?relationship_type=followers&cursor=4266&take=50
var queryItems: [URLQueryItem] = [.init(name: "relationship_type", value: relationshipType.rawValue),
.init(name: "take", value: "\(count)")]
if let cursor {
queryItems.append(.init(name: "cursor", value: "\(cursor)"))
}
return Endpoint(
host: NetworkConfig.baseProfileHost,
host: NetworkConfig.baseAPIHost,
path: "/profile/followers/\(domain)",
queryItems: queryItems,
body: ""
Expand All @@ -797,15 +786,14 @@ extension Endpoint {
expires: UInt64,
signature: String,
body: String) -> Endpoint {
// https://profile.ud-staging.com/api/user/aaron.x
let expiresString = "\(expires)"
let headers = [
SignatureComponentHeaders.CodingKeys.domain.rawValue: domain,
SignatureComponentHeaders.CodingKeys.expires.rawValue: expiresString,
SignatureComponentHeaders.CodingKeys.signature.rawValue: signature
]
return Endpoint(
host: NetworkConfig.baseProfileHost,
host: NetworkConfig.baseAPIHost,
path: "/profile/followers/\(domainNameToFollow)",
queryItems: [],
body: body,
Expand All @@ -815,29 +803,26 @@ extension Endpoint {


static func joinBadgeCommunity(body: String) -> Endpoint {
//https://messaging.ud-staging.com/api/push/group/join
return Endpoint(
host: NetworkConfig.baseMessagingHost,
path: "/api/push/group/join",
host: NetworkConfig.baseAPIHost,
path: "/messaging/push/group/join",
queryItems: [],
body: body
)
}

static func leaveBadgeCommunity(body: String) -> Endpoint {
//https://messaging.ud-staging.com/api/push/group/leave
return Endpoint(
host: NetworkConfig.baseMessagingHost,
path: "/api/push/group/leave",
host: NetworkConfig.baseAPIHost,
path: "/messaging/push/group/leave",
queryItems: [],
body: body
)
}

static func getSpamStatus(for address: HexAddress) -> Endpoint {
//https://api.unstoppabledomains.com/messaging/xmtp/spam/0x9B4Ed628640A73154895e369AE39a93732535924
return Endpoint(
host: NetworkConfig.baseProfileHost,
host: NetworkConfig.baseAPIHost,
path: "/messaging/xmtp/spam/\(address)",
queryItems: [],
body: ""
Expand All @@ -847,7 +832,6 @@ extension Endpoint {
static func uploadRemoteAttachment(for domain: DomainItem,
with timedSignature: PersistedTimedSignature,
body: String) throws -> Endpoint {
// https://profile.ud-staging.com/api/user/aaron.x/attachment
let expires = "\(timedSignature.expires)"
let signature = timedSignature.sign
let headers = [
Expand All @@ -856,7 +840,7 @@ extension Endpoint {
SignatureComponentHeaders.CodingKeys.signature.rawValue: signature
]
return Endpoint(
host: NetworkConfig.baseProfileHost,
host: NetworkConfig.baseAPIHost,
path: "/profile/user/\(domain.name)/attachment",
queryItems: [],
body: body,
Expand All @@ -866,19 +850,17 @@ extension Endpoint {

static func getProfileConnectionSuggestions(for domain: DomainName,
filterFollowings: Bool) -> Endpoint {
//https://api.unstoppabledomains.com/profile/public/oleg.x/connections
return Endpoint(
host: NetworkConfig.baseProfileHost,
host: NetworkConfig.baseAPIHost,
path: "/profile/public/\(domain)/connections",
queryItems: [.init(name: "recommendationsOnly", value: String(filterFollowings))],
body: ""
)
}

static func getProfileFollowersRanking(count: Int) -> Endpoint {
//https://api.unstoppabledomains.com/profile/followers/rankings?count=20
return Endpoint(
host: NetworkConfig.baseProfileHost,
host: NetworkConfig.baseAPIHost,
path: "/profile/followers/rankings",
queryItems: [.init(name: "count", value: String(count))],
body: ""
Expand All @@ -889,11 +871,10 @@ extension Endpoint {
// MARK: - Open methods
extension Endpoint {
static func getCryptoPortfolio(for wallet: String) -> Endpoint {
//https://api.ud-staging.com/profile/user/0xcd0dadab45baf9a06ce1279d1342ecc3f44845af/wallets
let queryItems: [URLQueryItem] = [.init(name: "walletFields", value: "native,token"),
.init(name: "forceRefresh", value: String(Int(Date().timeIntervalSince1970)))]
return Endpoint(
host: NetworkConfig.baseProfileHost,
host: NetworkConfig.baseAPIHost,
path: "/profile/user/\(wallet)/wallets",
queryItems: queryItems,
body: "",
Expand All @@ -905,7 +886,6 @@ extension Endpoint {
cursor: String?,
chain: String?,
forceRefresh: Bool) -> Endpoint {
//https://api.ud-staging.com/profile/user/0xcd0dadab45baf9a06ce1279d1342ecc3f44845af/transactions
var queryItems: [URLQueryItem] = []
if let cursor {
queryItems.append(URLQueryItem(name: "cursor", value: cursor))
Expand All @@ -918,7 +898,7 @@ extension Endpoint {
headers = headers.appending(dict2: ["refreshCache" : String(Date().timeIntervalSince1970)])
}
return Endpoint(
host: NetworkConfig.baseProfileHost,
host: NetworkConfig.baseAPIHost,
path: "/profile/user/\(wallet)/transactions",
queryItems: queryItems,
body: "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ final class NFTsAPIRequestBuilder {
}

private func baseURL() -> String {
"https://" + NetworkConfig.baseProfileHost + "/profile/user"
"https://" + NetworkConfig.baseAPIHost + "/profile/user"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,31 +59,19 @@ struct NetworkConfig {
}

static var baseResolveUrl: String {
if User.instance.getSettings().isTestnetUsed {
return "https://resolve.ud-staging.com"
} else {
return "https://resolve.unstoppabledomains.com"
}
baseAPIUrl + "/resolve"
}

static var baseProfileHost: String {
static var baseAPIHost: String {
if User.instance.getSettings().isTestnetUsed {
return "api.ud-staging.com"
} else {
return "api.unstoppabledomains.com"
}
}

static var baseProfileUrl: String {
"https://\(baseProfileHost)"
}

static var baseMessagingHost: String {
if User.instance.getSettings().isTestnetUsed {
return "messaging.ud-staging.com"
} else {
return "messaging.unstoppabledomains.com"
}
static var baseAPIUrl: String {
"https://\(baseAPIHost)"
}

private static let StagingAccessApiKey = "mob-01-stg-8792ed66-f0d6-463d-b08b-7f5667980676"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ struct XMTPPushNotificationsHelper {
private extension XMTPPushNotificationsHelper {
static func makeRequestFor(topics: [String], accepted: Bool?, blocked: Bool?, by client: Client) async throws {
do {
let url = URL(string: "https://\(NetworkConfig.baseMessagingHost)/api/xmtp/topics/register")!
let subReq = try await buildSubscribeRequestFor(topics: topics,
let url = URL(string: "https://\(NetworkConfig.baseAPIHost)/messaging/xmtp/topics/register")!
let subReq = try await buildSubscribeRequestFor(topics: topics,
accepted: accepted,
blocked: blocked,
by: client)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ extension NetworkService: DomainProfileNetworkServiceProtocol {
}

public func fetchBadgesInfo(for domainName: DomainName) async throws -> BadgesInfo {
// https://profile.unstoppabledomains.com/api/public/aaronquirk.x/badges
guard let url = Endpoint.getBadgesInfo(for: domainName).url else {
throw NetworkLayerError.creatingURLFailed
}
Expand All @@ -69,7 +68,6 @@ extension NetworkService: DomainProfileNetworkServiceProtocol {
}

public func fetchBadgeDetailedInfo(for badge: BadgesInfo.BadgeInfo) async throws -> BadgeDetailedInfo {
// https://profile.unstoppabledomains.com/api/badges/opensea-tothemoonalisa
guard let url = Endpoint.getBadgeDetailedInfo(for: badge).url else {
throw NetworkLayerError.creatingURLFailed
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,11 @@ struct NetworkService {
}

extraHeaders.forEach { urlRequest.addValue($0.value, forHTTPHeaderField: $0.key)}
urlRequest.addValue(Version.getCurrentAppVersionString() ?? "version n/a", forHTTPHeaderField: Self.appVersionHeaderKey)

let version = Version.getCurrentAppVersionString() ?? "version n/a"
urlRequest.addValue(version, forHTTPHeaderField: Self.appVersionHeaderKey)
let userAgent = "UnstoppableDomainsMobile<IOS>/<\(version)>"
urlRequest.setValue(userAgent, forHTTPHeaderField: "User-Agent")

Debugger.printInfo(topic: .Network, "--- REQUEST TO ENDPOINT")
Debugger.printInfo(topic: .Network, "METHOD: \(method) | URL: \(url.absoluteString)")
Debugger.printInfo(topic: .Network, "BODY: \(body)")
Expand Down Expand Up @@ -466,7 +469,7 @@ extension NetworkService {
/// This function will return UD/ENS/Null name and corresponding PFP if available OR throw 404
func fetchGlobalReverseResolution(for identifier: HexAddress) async throws -> GlobalRR? {
do {
guard let url = URL(string: "\(NetworkConfig.baseProfileUrl)/profile/resolve/\(identifier)") else { return nil } // User's input contains not allowed characters
guard let url = URL(string: "\(NetworkConfig.baseAPIUrl)/profile/resolve/\(identifier)") else { return nil } // User's input contains not allowed characters

let data = try await NetworkService().fetchData(for: url,
method: .get)
Expand Down