Created
May 20, 2019 02:20
-
-
Save Alexs2424/d583552f8664c0d82d6932fe1df918e0 to your computer and use it in GitHub Desktop.
Swift Version of the Lights Code to get it to work.
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
if let hexBackgroundColor = colorsToUse.background.toHex() { | |
print("BACKGROUND: \(hexBackgroundColor)") | |
let backgroundRed = self.getRed(forColor: colorsToUse.background) | |
let backgroundGreen = self.getGreen(forColor: colorsToUse.background) | |
let backgroundBlue = self.getBlue(forColor: colorsToUse.background) | |
print("RED: \(backgroundRed)") | |
if let red = backgroundRed, let blue = backgroundBlue, let green = backgroundGreen { | |
let redBackgroundStr = self.stringForRGBValue(value: red) | |
print("RED STR: \(redBackgroundStr)") | |
let greenBackgroundStr = self.stringForRGBValue(value: green) | |
let blueBackgroundStr = self.stringForRGBValue(value: blue) | |
let url = URL(string: "feeds/albumColor/data") | |
let parameters = ["value": "\(redBackgroundStr)-\(greenBackgroundStr)-\(blueBackgroundStr)"] | |
var request = URLRequest(url: url!) | |
request.httpMethod = "POST" | |
request.addValue("application/json", forHTTPHeaderField: "Content-Type") | |
guard let httpBody = try? JSONSerialization.data(withJSONObject: parameters, options: []) else { return } | |
request.httpBody = httpBody | |
let session = URLSession.shared | |
session.dataTask(with: request) { (data, response, error) in | |
if let response = response { | |
print(response) | |
} | |
if let data = data { | |
do { | |
let json = try JSONSerialization.jsonObject(with: data, options: []) | |
print(json) | |
} catch { | |
print(error) | |
} | |
} | |
}.resume() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment