To download a Billboard chart, we use the BillboardManager constructor.
Let's fetch the current Hot 100 chart and for a particular date.
Dont forget to set Allow Arbitrary Loads under App Transport Security Settings in your info.plist to YES
import BillboardSwiftLibrary
let manager = BillboardManager()
manager.getChart(chartType: ChartType.hot100) { (entries, error) in
if error != nil{
print(error!.localizedDescription)
return
}
print(entries!) //Array of ChartEntry
}
//FOR A PARTICULAR DATE (always remember date is in the form YYYY-MM-DD)
manager.getChart(chartType: ChartType.hot100, date: "2018-11-18") { (entries, error) in
if error != nil{
print(error!.localizedDescription)
return
}
print(entries!) //Array of ChartEntry
}
//FOR A PARTICULAR DATE (with individual date components)
manager.getChart(chartType: ChartType.hot100, day: 18, month: 11, year: 2018) { (entries, error) in
if error != nil{
print(error!.localizedDescription)
return
}
print(entries!) //Array of ChartEntry
}
To run the example project, clone the repo, and run pod install
from the Example directory first.
- iOS 9.0+ / OSX 10.10+
- Swift 4.0+
To install, simply add the following line to your Podfile:
pod 'BillboardSwiftLibrary'
Add BillboardSwiftLibrary
to your Package.swift
import PackageDescription
let package = Package(
dependencies: [
package(url: "https://github.com/FitzAfful/BillboardSwiftLibrary.git", "0.1.2")
])
A chart entry (typically a single track) is of type ChartEntry
. A ChartEntry
instance has the following attributes:
title
– The title of the track.artist
– The name of the artist, as formatted on Billboard.com.peakPos
– The track's peak position on the chart at any point in time, including future dates, as an int (orNone
if the chart does not include this information).lastPos
– The track's position on the previous week's chart, as an int (orNone
if the chart does not include this information). This value is 0 if the track was not on the previous week's chart.weeks
– The number of weeks the track has been or was on the chart, including future dates (up until the present time).rank
– The track's current position on the chart.isNew
– Whether the track is new to the chart.
Pull requests are welcome!
Think you found a bug? Create an issue here.
Based on Billboard.py by Allen Guo
Fitzafful, fitzafful@gmail.com
BillboardSwiftLibrary is available under the MIT license. See the LICENSE file for more info.