Files
GitHawk/Playgrounds/Github API.playground/Contents.swift
James Sherlock c28c088629 Initial repository spring clean (#415)
* Move SwipeCellKit & SlackTextViewController to Local Pods directory

* Move playgrounds to own folder

* Create podspec for MMMarkdown and move to Local Pods
2017-09-24 18:35:05 -04:00

40 lines
1.3 KiB
Swift

//: Playground - noun: a place where people can play
import UIKit
import PlaygroundSupport
PlaygroundPage.current.needsIndefiniteExecution = true
func curl(request: NSURLRequest) {
print(request)
let task = URLSession.shared.dataTask(with: request as URLRequest, completionHandler: { (data, response, err) in
print(response)
if let data = data {
let json = try! JSONSerialization.jsonObject(with: data, options: [])
print(json)
} else {
print(err ?? "error failure")
}
})
task.resume()
}
let basic = "Basic " + "USERNAME:PASSWORD".data(using: .ascii)!.base64EncodedString()
let request = NSMutableURLRequest(url: URL(string: "https://api.github.com/authorizations")!)
request.httpMethod = "POST"
request.setValue(basic, forHTTPHeaderField: "Authorization")
request.setValue("123456", forHTTPHeaderField: "X-GitHub-OTP")
request.addValue("application/json", forHTTPHeaderField: "Content-Type")
request.addValue("application/json", forHTTPHeaderField: "Accept")
let json: [String: Any] = [
"scopes": ["repo"],
"note": "gitter app development",
"client_id": "CLIENT_ID",
"client_secret": "CLIENT_SECRET",
]
request.httpBody = try! JSONSerialization.data(withJSONObject: json, options: [])
curl(request: request)