Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // ApiService.swift
- // academylogsapps
- //
- // Created by Alfa Centaury on 04/05/21.
- //
- import UIKit
- class ApiService {
- private let apiKey = ""
- func getListApps(completion: @escaping ([RecordsApps]) -> Void) {
- let urlApps = URLComponents(string: "https://api.airtable.com/v0/appl5upXW9B14V2S2/App")!
- var request = URLRequest(url: urlApps.url!)
- request.addValue("Bearer " + apiKey, forHTTPHeaderField: "Authorization")
- let task = URLSession.shared.dataTask(with: request) { data, response, error in
- if error != nil {
- print("Failed : Some think wrong!")
- } else if let data = data, let response = response as? HTTPURLResponse, response.statusCode == 200 {
- let decoder = JSONDecoder()
- decoder.dateDecodingStrategy = .iso8601
- do {
- let listApps = try decoder.decode(Apps.self, from: data).records
- completion(listApps)
- } catch {
- print("Invalid Response \(error)")
- }
- }
- }
- task.resume()
- }
- func getListExplorer(completion: @escaping ([RecordsExplorer]) -> Void) {
- let urlExplorer = URLComponents(string: "https://api.airtable.com/v0/appl5upXW9B14V2S2/Explorer")!
- var request = URLRequest(url: urlExplorer.url!)
- request.addValue("Bearer " + apiKey, forHTTPHeaderField: "Authorization")
- let task = URLSession.shared.dataTask(with: request) { data, response, error in
- if error != nil {
- print("Failed : Some think wrong!")
- } else if let data = data, let response = response as? HTTPURLResponse, response.statusCode == 200 {
- let decoder = JSONDecoder()
- decoder.dateDecodingStrategy = .iso8601
- do {
- let listExplorer = try decoder.decode(Explorer.self, from: data).records
- completion(listExplorer)
- } catch {
- print("Invalid Response \(error)")
- }
- }
- }
- task.resume()
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement