Note: This code is deprecated as the KPCC API has been decomissioned and is no longer accessible. We will leave this repo in place for future reference.
This is a native Swift tool for accessing the KPCC API.
It was designed to be used with iOS, macOS, watchOS, and tvOS targets. With some work it should also be usable for server-side Swift projects, such as Vapor.
This project is licensed under the MIT license.
To integrate this framework into your Xcode project, clone (or otherwise download) it onto your development machine and drag the included KPCCAPIClient.xcodeproj file into your project's file navigator in Xcode.
Once you have done so, drag the appropriate framework file from the Products group into the Embedded Binaries section of the targets you wish to build it with. Then make sure to import KPCCAPIClient at the top of any file(s) you wish to use it in.
Currently, the KPCC API only supports GET requests, used to retrieve information about the associated resource.
These calls are exposed in this API Client as static methods under the associated model struct (ie, Program
or Episode
), each beginning with the word get
- so, for example, you can type "Program.get" and hit escape to display Xcode's autocompletion popover with methods for retrieving Programs.
A number of examples showing common usage are provided below.
The model layer exposed by this framework largely mirrors the KPCC server API in order to lessen confusion and make it easier to work with.
For instances of Program, Episode, Article, etc. we highly recommend referring to the server API documentation for further details. The properties for the model layer have been designed to adhere as closely as possible to that provided by the server API.
Option-clicking any method name will provide 'Quick Help' inline documentation for that method. The same applies to instance properties for model objects such as Program, Episode, etc.
You can modify the level of verbosity by setting a debug level to one of the following levels: disabled
, basic
, or verbose
.
We recommend setting the debug level to disabled
(the default) for production code.
KPCCAPIClient.shared.debugLevel = .basic
Retrieve Program objects to get information about KPCC programs.
Example: The following method returns an array of both 'On Air' and 'Online Only' type Programs.
Program.get { (programs, error) in
if let programs = programs {
print(programs)
}
}
Example: The following method returns an array of 'Online Only' type Programs.
Program.get(programsWithStatuses: [.onlineOnly]) { (programs, error) in
if let programs = programs {
print(programs)
}
}
Example: The following method returns a Program associated with the 'airtalk' slug.
Program.get(withProgramSlug: "airtalk") { (program, error) in
if let program = program {
print(program)
}
}
Retrieve Episode objects for individual on-demand episodes of KPCC programs.
Example: The following method returns an array AirTalk Episodes.
Episode.get(withProgramSlug: "airtalk") { (episodes, error) in
if let episodes = episodes {
print(episodes)
}
}
Example: The following method returns an array of up to AirTalk Episodes (the first page of results).
Episode.get(withProgramSlug: "airtalk", limit: 8, page: 1) { (episodes, error) in
if let episodes = episodes {
print(episodes)
}
}
Example: The following method an Episode with the ID '123456'.
Episode.get(withID: 123456) { (episode, error) in
if let episode = episode {
print(episode)
}
}
Retrieve ProgramSchedule objects to get information about what programs are or will be played during within a given span of time.
Example: The following method returns a ProgramSchedule starting at Monday of the current week and ending 1 week later.
ProgramSchedule.get { (programSchedule, error) in
if let programSchedule = programSchedule {
print(programSchedule)
}
}
Example: The following method returns a ProgramSchedule starting at the current date and ending in 1 day.
ProgramSchedule.get(withStartDate: Date(), length: 86400) { (programSchedule, error) in
if let programSchedule = programSchedule {
print(programSchedule)
}
}
Retrieve Article objects for news articles, blog posts, etc.
Example: The following method returns an array of 'Blog' or 'News' type Articles.
Article.get(withTypes: [.blogs, .news]) { (articles, error) in
if let articles = articles {
print(articles)
}
}
Example: The following method returns an array of up to 10 'News' type Articles with the search query 'Steve Jobs' and matching the tag of 'iphone'.
Article.get(withTypes: [.news], date: nil, startDate: nil, endDate: nil, query: "Steve Jobs", categories: nil, tags: ["iphone"], limit: 20, page: nil) { (articles, error) in
if let articles = articles {
print(articles)
}
}
Example: The following method returns an Article with a specified ID of 'asdf1234'.
Article.get(withID: "asdf1234") { (article, error) in
if let article = article {
print(article)
}
}
Retrieve Event objects for live, in-person KPCC events.
Example: The following method returns an array of 'Community Engagement' or 'Town Hall' type Events.
Event.get(withTypes: [.communityEnagement, .townHall]) { (events, error) in
if let events = events {
print(events)
}
}
Example: The following method returns an array of up to 10 Cultural type Events, with a start date starting now and an end date 30 days in the future.
Event.get(withTypes: [.cultural], startDate: Date(), endDate: Date().addingTimeInterval(86400 * 30), limit: 10) { (events, error) in
if let events = events {
print(events)
}
}
Retrieve List objects for curated lists of Article, Program, or Episode objects.
Example: The following method returns an array of Lists, including those with the supplied context of 'ios'.
List.get(withContext: "ios") { (lists, error) in
if let lists = lists {
print(lists)
}
}
Example: The following method returns a List with the supplied ID of '123456'.
List.get(withID: 123456) { (lists, error) in
if let lists = lists {
print(lists)
}
}
Retrieve Member object.
Example: The following method returns a Member associated with the supplied pledge token 'asdf1234'.
Member.get(withPledgeToken: "asdf1234") { (member, error) in
if let member = member {
print(member)
}
}
Retrieve settings (returned as a Dictionary).
Example: The following method returns settings not associated with any context.
Settings.get(withContext: nil) { (settings, error) in
if let settings = settings {
print(settings)
}
}