Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Combine support and updated model properties to camel case (#4) #40

Closed
wants to merge 12 commits into from
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ public enum CommentSortType: String, Codable, CustomStringConvertible, CaseItera
case top = "Top"
case new = "New"
case old = "Old"
case controversial = "Controversial"

public var description: String {
return rawValue
Expand Down
159 changes: 159 additions & 0 deletions Sources/Lemmy-Swift-Client/Lemmy API/Enums/LemmyErrorType.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
import Foundation

public enum LemmyErrorType: String, Codable, CustomStringConvertible, CaseIterable {
case report_reason_required
case report_too_long
case not_a_moderator
case not_an_admin
case cant_block_yourself
case cant_block_admin
case couldnt_update_user
case passwords_do_not_match
case email_not_verified
case email_required
case couldnt_update_comment
case couldnt_update_private_message
case cannot_leave_admin
case no_lines_in_html
case site_metadata_page_is_not_doctype_html
case pictrs_response_error
case pictrs_purge_response_error
case pictrs_caching_disabled
case image_url_missing_path_segments
case image_url_missing_last_path_segment
case pictrs_api_key_not_provided
case no_content_type_header
case not_an_image_type
case not_a_mod_or_admin
case no_admins
case not_top_admin
case not_top_mod
case not_logged_in
case site_ban
case deleted
case banned_from_community
case couldnt_find_community
case couldnt_find_person
case person_is_blocked
case community_is_blocked
case instance_is_blocked
case downvotes_are_disabled
case instance_is_private
case invalid_password
case site_description_length_overflow
case honeypot_failed
case registration_application_is_pending
case cant_enable_private_instance_and_federation_together
case locked
case couldnt_create_comment
case max_comment_depth_reached
case no_comment_edit_allowed
case only_admins_can_create_communities
case community_already_exists
case language_not_allowed
case only_mods_can_post_in_community
case couldnt_update_post
case no_post_edit_allowed
case couldnt_find_post
case edit_private_message_not_allowed
case site_already_exists
case application_question_required
case invalid_default_post_listing_type
case registration_closed
case registration_application_answer_required
case email_already_exists
case federation_forbidden_by_strict_allow_list
case person_is_banned_from_community
case object_is_not_public
case invalid_community
case cannot_create_post_or_comment_in_deleted_or_removed_community
case cannot_receive_page
case new_post_cannot_be_locked
case only_local_admin_can_remove_community
case only_local_admin_can_restore_community
case no_id_given
case incorrect_login
case invalid_query
case object_not_local
case post_is_locked
case person_is_banned_from_site
case invalid_vote_value
case page_does_not_specify_creator
case page_does_not_specify_group
case no_community_found_in_cc
case no_email_setup
case email_smtp_server_needs_a_port
case missing_an_email
case rate_limit_error
case invalid_name
case invalid_display_name
case invalid_matrix_id
case invalid_post_title
case invalid_body_field
case bio_length_overflow
case missing_totp_token
case missing_totp_secret
case incorrect_totp_token
case couldnt_parse_totp_secret
case couldnt_generate_totp
case totp_already_enabled
case couldnt_like_comment
case couldnt_save_comment
case couldnt_create_report
case couldnt_resolve_report
case community_moderator_already_exists
case community_user_already_banned
case community_block_already_exists
case community_follower_already_exists
case couldnt_update_community_hidden_status
case person_block_already_exists
case user_already_exists
case token_not_found
case couldnt_like_post
case couldnt_save_post
case couldnt_mark_post_as_read
case couldnt_update_community
case couldnt_update_replies
case couldnt_update_person_mentions
case post_title_too_long
case couldnt_create_post
case couldnt_create_private_message
case couldnt_update_private
case system_err_login
case couldnt_set_all_registrations_accepted
case couldnt_set_all_email_verified
case banned
case couldnt_get_comments
case couldnt_get_posts
case invalid_url
case email_send_failed
case slurs
case couldnt_find_object
case registration_denied
case federation_disabled
case domain_blocked
case domain_not_in_allow_list
case federation_disabled_by_strict_allow_list
case site_name_required
case site_name_length_overflow
case permissive_regex
case invalid_regex
case captcha_incorrect
case password_reset_limit_reached
case couldnt_create_audio_captcha
case invalid_url_scheme
case couldnt_send_webmention
case contradicting_filters
case instance_block_already_exists
case auth_cookie_insecure
case too_many_items
case community_has_no_followers
case ban_expiration_in_past
case invalid_unix_time
case invalid_bot_action
case unknown

public var description: String {
return rawValue
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ public enum ListingType: String, Codable, CustomStringConvertible, CaseIterable
case all = "All"
case local = "Local"
case subscribed = "Subscribed"
case moderatorView = "ModeratorView"

public var description: String {
return rawValue
Expand Down
11 changes: 11 additions & 0 deletions Sources/Lemmy-Swift-Client/Lemmy API/Enums/PostListingMode.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import Foundation

public enum PostListingMode: String, Codable, CustomStringConvertible, CaseIterable {
case list = "List"
case card = "Card"
case smallCard = "SmallCard"

public var description: String {
return rawValue
}
}
2 changes: 2 additions & 0 deletions Sources/Lemmy-Swift-Client/Lemmy API/Enums/SortType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public enum SortType: String, Codable, CustomStringConvertible, CaseIterable {
case topThreeMonths = "TopThreeMonths"
case topSixMonths = "TopSixMonths"
case topNineMonths = "TopNineMonths"
case controversial = "Controversial"
case scaled = "Scaled"

public var description: String {
return rawValue
Expand Down
11 changes: 4 additions & 7 deletions Sources/Lemmy-Swift-Client/Lemmy API/Requests/AddAdmin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,15 @@ public struct AddAdminRequest: APIRequest {
public static let httpMethod: HTTPMethod = .post
public static let path: String = "/admin/add"

public let person_id: PersonId
public let personId: PersonId
public let added: Bool
public let auth: String

public init(
person_id: PersonId,
added: Bool,
auth: String
personId: PersonId,
added: Bool
) {
self.person_id = person_id
self.personId = personId
self.added = added
self.auth = auth
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,18 @@ public struct AddModToCommunityRequest: APIRequest {
public static let httpMethod: HTTPMethod = .post
public static let path: String = "/community/mod"

public let community_id: CommunityId
public let person_id: PersonId
public let communityId: CommunityId
public let personId: PersonId
public let added: Bool
public let auth: String

public init(
community_id: CommunityId,
person_id: PersonId,
added: Bool,
auth: String
communityId: CommunityId,
personId: PersonId,
added: Bool
) {
self.community_id = community_id
self.person_id = person_id
self.communityId = communityId
self.personId = personId
self.added = added
self.auth = auth
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,42 +6,39 @@ public struct BanFromCommunityRequest: APIRequest {
public static let httpMethod: HTTPMethod = .post
public static let path: String = "/community/ban_user"

public let community_id: CommunityId
public let person_id: PersonId
public let communityId: CommunityId
public let personId: PersonId
public let ban: Bool
public let remove_data: Bool?
public let removeData: Bool?
public let reason: String?
public let expires: Int?
public let auth: String

public init(
community_id: CommunityId,
person_id: PersonId,
communityId: CommunityId,
personId: PersonId,
ban: Bool,
remove_data: Bool? = nil,
removeData: Bool? = nil,
reason: String? = nil,
expires: Int? = nil,
auth: String
expires: Int? = nil
) {
self.community_id = community_id
self.person_id = person_id
self.communityId = communityId
self.personId = personId
self.ban = ban
self.remove_data = remove_data
self.removeData = removeData
self.reason = reason
self.expires = expires
self.auth = auth
}
}

public struct BanFromCommunityResponse: APIResponse {
public let person_view: PersonView
public let personView: PersonView
public let banned: Bool

public init(
person_view: PersonView,
personView: PersonView,
banned: Bool
) {
self.person_view = person_view
self.personView = personView
self.banned = banned
}
}
23 changes: 10 additions & 13 deletions Sources/Lemmy-Swift-Client/Lemmy API/Requests/BanPerson.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,39 +6,36 @@ public struct BanPersonRequest: APIRequest {
public static let httpMethod: HTTPMethod = .post
public static let path: String = "/user/ban"

public let person_id: PersonId
public let personId: PersonId
public let ban: Bool
public let remove_data: Bool?
public let removeData: Bool?
public let reason: String?
public let expires: Int?
public let auth: String

public init(
person_id: PersonId,
personId: PersonId,
ban: Bool,
remove_data: Bool? = nil,
removeData: Bool? = nil,
reason: String? = nil,
expires: Int? = nil,
auth: String
expires: Int? = nil
) {
self.person_id = person_id
self.personId = personId
self.ban = ban
self.remove_data = remove_data
self.removeData = removeData
self.reason = reason
self.expires = expires
self.auth = auth
}
}

public struct BanPersonResponse: APIResponse {
public let person_view: PersonView
public let personView: PersonView
public let banned: Bool

public init(
person_view: PersonView,
personView: PersonView,
banned: Bool
) {
self.person_view = person_view
self.personView = personView
self.banned = banned
}
}
17 changes: 7 additions & 10 deletions Sources/Lemmy-Swift-Client/Lemmy API/Requests/BlockCommunity.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,27 @@ public struct BlockCommunityRequest: APIRequest {
public static let httpMethod: HTTPMethod = .post
public static let path: String = "/community/block"

public let community_id: CommunityId
public let communityId: CommunityId
public let block: Bool
public let auth: String

public init(
community_id: CommunityId,
block: Bool,
auth: String
communityId: CommunityId,
block: Bool
) {
self.community_id = community_id
self.communityId = communityId
self.block = block
self.auth = auth
}
}

public struct BlockCommunityResponse: APIResponse {
public let community_view: CommunityView
public let communityView: CommunityView
public let blocked: Bool

public init(
community_view: CommunityView,
communityView: CommunityView,
blocked: Bool
) {
self.community_view = community_view
self.communityView = communityView
self.blocked = blocked
}
}
Loading
Loading