Created
February 27, 2018 02:03
-
-
Save amadeu01/947677acb082c53bc3357ed2f8be4ae3 to your computer and use it in GitHub Desktop.
Swift initial implementation of correios API
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
import Foundation | |
let arguments = CommandLine.arguments | |
let getPrazo = "/calculador/CalcPrecoPrazo.asmx/CalcPrazo?nCdServico=string&sCepOrigem=string&sCepDestino=string" | |
if arguments.count != 2 { | |
print("Correios CLI ") | |
var urlComponents = URLComponents(string: "ws.correios.com.br/calculador/CalcPrecoPrazo.asmx/CalcPrazo")! | |
urlComponents.queryItems = [ | |
URLQueryItem(name: "nCdServico", value: "1"), | |
URLQueryItem(name: "sCepOrigem", value: "1"), | |
URLQueryItem(name: "sCepDestino", value: "2") | |
] | |
urlComponents.scheme = "http" | |
var request = URLRequest(url: urlComponents.url!) | |
request.httpMethod = "GET" | |
URLSession.shared.dataTask(with: request) { (data, response, error) in | |
if let response = response { | |
print(response) | |
} | |
if let data = data { | |
let xmlDocument = try? XMLDocument(data: data, options: []) | |
print(xmlDocument) | |
} | |
if let error = error { | |
print(error) | |
} | |
}.resume() | |
} else { | |
dump(arguments) | |
} | |
RunLoop.main.run(until: Date(timeIntervalSinceNow: 15)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment