-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e39e981
commit 04a0577
Showing
6 changed files
with
165 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import Foundation | ||
|
||
#if canImport(FoundationNetworking) | ||
import FoundationNetworking | ||
#endif | ||
|
||
extension Helix { | ||
public func addBlockedTerm(inChannel broadcasterID: String, text: String) async throws | ||
-> BlockedTerm | ||
{ | ||
let queryItems = self.makeQueryItems( | ||
("broadcaster_id", broadcasterID), ("moderator_id", self.authenticatedUserId)) | ||
|
||
let (rawResponse, result): (_, HelixData<BlockedTerm>?) = try await self.request( | ||
.post("moderation/blocked_terms"), with: queryItems, jsonBody: ["text": text]) | ||
|
||
guard let term = result?.data.first else { | ||
throw HelixError.invalidResponse(rawResponse: rawResponse) | ||
} | ||
|
||
return term | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import Foundation | ||
|
||
#if canImport(FoundationNetworking) | ||
import FoundationNetworking | ||
#endif | ||
|
||
extension Helix { | ||
public func getBlockedTerms( | ||
inChannel broadcasterID: String, limit: Int? = nil, after cursor: String? = nil | ||
) async throws -> (terms: [BlockedTerm], cursor: String?) { | ||
let queryItems = self.makeQueryItems( | ||
("broadcaster_id", broadcasterID), ("moderator_id", self.authenticatedUserId), | ||
("first", limit.map(String.init)), ("after", cursor)) | ||
|
||
let (rawResponse, result): (_, HelixData<BlockedTerm>?) = try await self.request( | ||
.get("moderation/blocked_terms"), with: queryItems) | ||
|
||
guard let result else { throw HelixError.invalidResponse(rawResponse: rawResponse) } | ||
|
||
return (result.data, result.pagination?.cursor) | ||
} | ||
} | ||
|
||
public struct BlockedTerm: Decodable { | ||
let broadcasterID: String | ||
let moderatorID: String | ||
|
||
let id: String | ||
let text: String | ||
|
||
let createdAt: Date | ||
let updatedAt: Date | ||
|
||
let expiresAt: Date? | ||
|
||
enum CodingKeys: String, CodingKey { | ||
case broadcasterID = "broadcaster_id" | ||
case moderatorID = "moderator_id" | ||
|
||
case id, text | ||
|
||
case createdAt = "created_at" | ||
case updatedAt = "updated_at" | ||
|
||
case expiresAt = "expires_at" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import Foundation | ||
|
||
#if canImport(FoundationNetworking) | ||
import FoundationNetworking | ||
#endif | ||
|
||
extension Helix { | ||
public func removeBlockedTerm(inChannel broadcasterID: String, termId: String) | ||
async throws | ||
{ | ||
let queryItems = self.makeQueryItems( | ||
("broadcaster_id", broadcasterID), ("moderator_id", self.authenticatedUserId), | ||
("id", termId)) | ||
|
||
(_, _) = | ||
try await self.request(.delete("moderation/blocked_terms"), with: queryItems) | ||
as (_, HelixData<BlockedTerm>?) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
Tests/TwitchTests/API/MockResources/Endpoints/Moderation/getBlockedTerms.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"data": [ | ||
{ | ||
"broadcaster_id": "5678", | ||
"moderator_id": "1234", | ||
"id": "520e4d4e-0cda-49c7-821e-e5ef4f88c2f2", | ||
"text": "A phrase I'm not fond of", | ||
"created_at": "2021-09-29T19:45:37Z", | ||
"updated_at": "2021-09-29T19:45:37Z", | ||
"expires_at": null | ||
} | ||
], | ||
"pagination": { | ||
"cursor": "eyJiIjpudWxsLCJhIjp7IkN1cnNvciI6I" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters