Skip to content

Commit

Permalink
Merge pull request #4 from superturboryan/develop
Browse files Browse the repository at this point in the history
1.0.1
  • Loading branch information
superturboryan authored Nov 12, 2023
2 parents 9c38e2f + fe2e7da commit 56aa29c
Show file tree
Hide file tree
Showing 13 changed files with 125 additions and 104 deletions.
8 changes: 7 additions & 1 deletion Sources/SoundCloud/DAO/DAO.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
/// Describes a data access object used for persisting an item of generic `Codable` type `DataType`
/// - Parameters:
/// - codingKey: key used to encode + decode persisted object
public protocol DAO: AnyObject {
public protocol DAO<DataType>: AnyObject {
associatedtype DataType: Codable

var codingKey: String { get }
Expand All @@ -17,3 +17,9 @@ public protocol DAO: AnyObject {
func save(_ value: DataType) throws
func delete() throws
}

public enum DAOError: Error {
case noData
case decoding
case encoding
}
12 changes: 0 additions & 12 deletions Sources/SoundCloud/DAO/DAOError.swift

This file was deleted.

3 changes: 1 addition & 2 deletions Sources/SoundCloud/DAO/KeychainDAO.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,13 @@ import Foundation
import KeychainSwift

public final class KeychainDAO<T: Codable>: DAO {
public typealias DataType = T

private let encoder = JSONEncoder()
private let decoder = JSONDecoder()
private let persistence = KeychainSwift()

public var codingKey: String
init(_ codingKey: String) {
public init(_ codingKey: String) {
self.codingKey = codingKey
}

Expand Down
6 changes: 2 additions & 4 deletions Sources/SoundCloud/DAO/UserDefaultsDAO.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@
import Foundation
/// Data access object used for persisting a `Codable` object to device's `UserDefaults`.
///
/// - Note: **Unexpected behaviour across app launches:**
/// `UserDefaults` may not be properly synchronized after terminating app with Xcode.
/// **Terminate app via device** for expected synchronization behaviour.
/// - Warning: **Unexpected behaviour across app launches:** `UserDefaults` may not be properly synchronized
/// after terminating app with Xcode. **Terminate app via device** for expected read-write behaviour.
public final class UserDefaultsDAO<T: Codable>: DAO {
public typealias DataType = T

private let encoder = JSONEncoder()
private let decoder = JSONDecoder()
Expand Down
4 changes: 2 additions & 2 deletions Sources/SoundCloud/Extension/ASWebAuthenticationSession.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public extension ASWebAuthenticationSession {
/// - context: Delegate object that specifies how to present web page. Defaults to UIApplication.shared.keyWindow
/// - ephemeralSession: 🍪❓
/// - Returns: Authorization code from callback URL
@MainActor static func getAuthCode(
static func getAuthCode(
from url: String,
with redirectURI: String,
context: ASWebAuthenticationPresentationContextProviding = ApplicationWindowContextProvider(),
Expand Down Expand Up @@ -60,7 +60,7 @@ public extension ASWebAuthenticationSession {
/// - with: URI for OAuth web page to use to redirect back to your app. Should take the form "<your app scheme>://<path>"
/// - ephemeralSession: 🍪❓
/// - Returns: Authorization code from callback URL
@MainActor static func getAuthCode(
static func getAuthCode(
from url: String,
with redirectURI: String,
ephemeralSession: Bool = false
Expand Down
5 changes: 5 additions & 0 deletions Sources/SoundCloud/Models/Page.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
public struct Page<ItemType: Decodable>: Decodable {
public var items: [ItemType]
public var nextPage: String?

public init(items: [ItemType], nextPage: String? = nil) {
self.items = items
self.nextPage = nextPage
}
}

extension Page {
Expand Down
2 changes: 0 additions & 2 deletions Sources/SoundCloud/Models/Playlist.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
// Created by Ryan Forsyth on 2023-10-03.
//

import Foundation

public struct Playlist: Decodable, Identifiable, Equatable {
public let id: Int
public let genre: String
Expand Down
2 changes: 0 additions & 2 deletions Sources/SoundCloud/Models/StatusCode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
// Created by Ryan Forsyth on 2023-09-07.
//

import Foundation

public extension SoundCloud {
enum StatusCode: Int {
case success = 200
Expand Down
10 changes: 2 additions & 8 deletions Sources/SoundCloud/Models/Test Models.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
// Created by Ryan Forsyth on 2023-10-03.
//

import Foundation
import SwiftUI

public func testUser(_ id: Int = Int.random(in: 0..<1000)) -> User {
User(
avatarUrl: "https://i1.sndcdn.com/avatars-0DxRBnyCNCI3zL1X-oeoRyw-large.jpg",
Expand Down Expand Up @@ -98,11 +95,6 @@ public func testTrack() -> Track {
)
}

public func testTrackBinding() -> Binding<Track> {
var track = testTrack()
return Binding(get: { track }, set: { newTrack in track = newTrack })
}

public var testDefaultLoadedPlaylists: [Int : Playlist] {
var loadedPlaylists = [Int : Playlist]()
let user = testUser()
Expand All @@ -118,3 +110,5 @@ public let testNextProSubscription = User.Subscription(product: User.Subscriptio

@MainActor
public var testSC = SoundCloud(SoundCloud.Config(apiURL: "", clientId: "", clientSecret: "", redirectURI: ""))

public let testStreamInfo = StreamInfo(httpMp3128Url: "", hlsMp3128Url: "")
16 changes: 8 additions & 8 deletions Sources/SoundCloud/Models/TokenResponse.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@

import Foundation

internal struct TokenResponse: Codable {
let accessToken: String
let expiresIn: Int
let refreshToken: String
let scope: String
let tokenType: String
var expiryDate: Date? = nil // Set when persisting object
public struct TokenResponse: Codable {
internal let accessToken: String
internal let expiresIn: Int
internal let refreshToken: String
internal let scope: String
internal let tokenType: String

internal var expiryDate: Date? = nil // Set when persisting object
}

internal extension TokenResponse {
Expand Down
3 changes: 0 additions & 3 deletions Sources/SoundCloud/Request.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
//
// Created by Ryan Forsyth on 2023-08-12.
//
// https://developers.soundcloud.com/docs/api/explorer/open-api#/

import Foundation

extension SoundCloud {

Expand Down
Loading

0 comments on commit 56aa29c

Please sign in to comment.