-
-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
List of sponsors is now dynamic. Fetched from server.
Closes #571
- Loading branch information
Showing
9 changed files
with
70 additions
and
27 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import Foundation | ||
|
||
struct Sponsor: Decodable { | ||
var name: String | ||
var link: String? | ||
} |
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
File renamed without changes.
File renamed without changes.
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,24 @@ | ||
import Foundation | ||
|
||
class OctoPodPrintUtils { | ||
|
||
static func getSponsors(timeoutInterval: TimeInterval?, callback: @escaping (Array<Sponsor>?, Error?, HTTPURLResponse) -> Void) { | ||
let url = URL(string: "http://octopodprint.com/v1/octopod/sponsors")! | ||
let urlRequest = URLRequest(url: url, timeoutInterval: timeoutInterval ?? 5.0) | ||
URLSession.shared.dataTask(with: urlRequest) { (data: Data?, response: URLResponse?, error: Error?) in | ||
if let response = response as? HTTPURLResponse, let data = data { | ||
if response.statusCode == 200 { | ||
do { | ||
let sponsors = try JSONDecoder().decode(Array<Sponsor>.self, from: data) | ||
callback(sponsors, error, response) | ||
} catch let error { | ||
callback(nil, error, response) | ||
} | ||
} else { | ||
callback(nil, error, response) | ||
} | ||
} | ||
}.resume() | ||
|
||
} | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.