-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Load guardians from backend
- Loading branch information
Showing
11 changed files
with
138 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
Multisig/Data/Services/Safe Claiming Service /GuardiansRequest.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// | ||
// GuardiansRequest.swift | ||
// Multisig | ||
// | ||
// Created by Mouaz on 8/11/22. | ||
// Copyright © 2022 Gnosis Ltd. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
struct GuardiansRequest: JSONRequest { | ||
var httpMethod: String { "GET" } | ||
|
||
var urlPath: String { | ||
"/api/v1/guardians/" | ||
} | ||
|
||
typealias ResponseType = [Guardian] | ||
} | ||
|
||
struct Guardian: Decodable { | ||
let name: String? | ||
let reason: String? | ||
let contribution: String? | ||
let address: AddressString | ||
let ens: String? | ||
let imageUrl: String? | ||
let startDate: String? | ||
var imageURL: URL? { | ||
imageUrl == nil ? nil : URL(string: imageUrl!) | ||
} | ||
} | ||
|
||
extension SafeClaimingService { | ||
func asyncGuardians(completion: @escaping (Result<GuardiansRequest.ResponseType, Error>) -> Void) -> URLSessionTask? { | ||
asyncExecute(request: GuardiansRequest(), completion: completion) | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
Multisig/Data/Services/Safe Claiming Service /SafeClaimingService.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// | ||
// SafeClaimingService.swift | ||
// Multisig | ||
// | ||
// Created by Mouaz on 8/11/22. | ||
// Copyright © 2022 Gnosis Ltd. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
class SafeClaimingService { | ||
var url: URL | ||
private let httpClient: JSONHTTPClient | ||
|
||
var jsonDecoder: JSONDecoder { | ||
httpClient.jsonDecoder | ||
} | ||
|
||
init(logger: Logger) { | ||
self.url = URL(string: "https://claim-mobile-api.herokuapp.com")! | ||
httpClient = JSONHTTPClient(url: url, logger: logger) | ||
httpClient.jsonDecoder.dateDecodingStrategy = .millisecondsSince1970 | ||
} | ||
|
||
@discardableResult | ||
func execute<T: JSONRequest>(request: T) throws -> T.ResponseType { | ||
try httpClient.execute(request: request) | ||
} | ||
|
||
func asyncExecute<T: JSONRequest>(request: T, completion: @escaping (Result<T.ResponseType, Error>) -> Void) -> URLSessionTask? { | ||
httpClient.asyncExecute(request: request, completion: completion) | ||
} | ||
} |
Oops, something went wrong.