Skip to content

Commit

Permalink
CustomStringConvertible fix for HTTP GET requests (#4)
Browse files Browse the repository at this point in the history
* add missing init

* Fixing formatting

* CustomStringConvertible

* Fixing formatting

---------

Co-authored-by: Charlie Fish <[email protected]>
  • Loading branch information
mdhiggins and fishcharlie authored Jun 13, 2023
1 parent 0790791 commit d5ddbf9
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import Foundation

public enum CommentSortType: String, Codable {
public enum CommentSortType: String, Codable, CustomStringConvertible {
/// Comments sorted by a decaying rank.
case hot = "Hot"
/// Comments sorted by new.
Expand All @@ -16,4 +16,8 @@ public enum CommentSortType: String, Codable {
case old = "Old"
/// Comments sorted by top score.
case top = "Top"

public var description: String {
return self.rawValue
}
}
6 changes: 5 additions & 1 deletion Sources/Lemmy-Swift-Client/Lemmy API/Enums/ListingType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@

import Foundation

public enum ListingType: String, Codable {
public enum ListingType: String, Codable, CustomStringConvertible {
case all = "All"
case community = "Community"
case local = "Local"
case subscribed = "Subscribed"

public var description: String {
return self.rawValue
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import Foundation

public enum ModlogActionType: String, Codable {
public enum ModlogActionType: String, Codable, CustomStringConvertible {
case adminPurgeComment = "AdminPurgeComment"
case adminPurgeCommunity = "AdminPurgeCommunity"
case adminPurgePerson = "AdminPurgePerson"
Expand All @@ -24,4 +24,8 @@ public enum ModlogActionType: String, Codable {
case modRemoveComunity = "ModRemoveCommunity"
case modRemovePost = "ModRemovePost"
case modTransferCommunity = "ModTransferCommunity"

public var description: String {
return self.rawValue
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@

import Foundation

public enum PostFeatureType: String, Codable {
public enum PostFeatureType: String, Codable, CustomStringConvertible {
case community = "Community"
case local = "Local"

public var description: String {
return self.rawValue
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@

import Foundation

public enum RegistrationMode: String, Codable {
public enum RegistrationMode: String, Codable, CustomStringConvertible {
case closed = "closed"
case open = "open"
case requireApplication = "requireapplication"

public var description: String {
return self.rawValue
}
}
6 changes: 5 additions & 1 deletion Sources/Lemmy-Swift-Client/Lemmy API/Enums/SearchType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,15 @@

import Foundation

public enum SearchType: String, Codable {
public enum SearchType: String, Codable, CustomStringConvertible {
case all = "All"
case comments = "Comments"
case communities = "Communities"
case posts = "Posts"
case url = "Url"
case users = "Users"

public var description: String {
return self.rawValue
}
}
6 changes: 5 additions & 1 deletion Sources/Lemmy-Swift-Client/Lemmy API/Enums/SortType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import Foundation

/// Different post sort types used in lemmy.
public enum SortType: String, Codable {
public enum SortType: String, Codable, CustomStringConvertible {
/// Posts sorted by hot, but bumped by new comments up to 2 days.
case active = "Active"
/// Posts sorted by a decaying rank.
Expand All @@ -31,4 +31,8 @@ public enum SortType: String, Codable {
case topWeek = "TopWeek"
/// The top posts for this last year.
case topYear = "TopYear"

public var description: String {
return self.rawValue
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@

import Foundation

public enum SubscribedType: String, Codable {
public enum SubscribedType: String, Codable, CustomStringConvertible {
case notSubscribed = "NotSubscribed"
case pending = "Pending"
case subscribed = "Subscribed"

public var description: String {
return self.rawValue
}
}
4 changes: 2 additions & 2 deletions Sources/Lemmy-Swift-Client/Lemmy_Swift_Client.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ public class LemmyAPI {
if T.httpMethod == .get {
let mirror = Mirror(reflecting: apiRequest)
request.url = request.url?.appending(queryItems: mirror.children.compactMap { (label, value) in
guard let label, let valueString = value as? String else { return nil }
guard let label, let valueString = value as? CustomStringConvertible else { return nil }

return URLQueryItem(name: label, value: valueString)
return URLQueryItem(name: label, value: String(describing: valueString))
})
} else {
request.httpBody = try encoder.encode(apiRequest)
Expand Down

0 comments on commit d5ddbf9

Please sign in to comment.