Skip to content
This repository has been archived by the owner on Jun 30, 2023. It is now read-only.

Commit

Permalink
Merge pull request #130 from mironal/add-all-property
Browse files Browse the repository at this point in the history
Add .all static properties to Expansions and Fields
  • Loading branch information
mironal committed Jul 15, 2022
2 parents 89308a3 + 26a98ef commit 586cdfd
Show file tree
Hide file tree
Showing 4 changed files with 201 additions and 8 deletions.
29 changes: 29 additions & 0 deletions Sources/TwitterAPIKit/APIv2/ExpansionsV2.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,17 @@ public enum TwitterTweetExpansionsV2: TwitterExpansionsParameterV2, Hashable {
case .other(let string): return string
}
}

public static let all: Set<Self> = [
.attachmentsPollIDs,
.attachmentsMediaKeys,
.authorID,
.entitiesMentionsUsername,
.geoPlaceID,
.inReplyToUserID,
.referencedTweetsID,
.referencedTweetsIDAuthorID,
]
}

public enum TwitterUserExpansionsV2: TwitterExpansionsParameterV2, Hashable {
Expand All @@ -47,6 +58,10 @@ public enum TwitterUserExpansionsV2: TwitterExpansionsParameterV2, Hashable {
case .other(let string): return string
}
}

public static let all: Set<Self> = [
.pinnedTweetID
]
}

public enum TwitterListExpansionsV2: TwitterExpansionsParameterV2, Hashable {
Expand All @@ -59,6 +74,10 @@ public enum TwitterListExpansionsV2: TwitterExpansionsParameterV2, Hashable {
case .other(let string): return string
}
}

public static let all: Set<Self> = [
.ownerID
]
}

public enum TwitterSpaceExpansionsV2: TwitterExpansionsParameterV2, Hashable {
Expand All @@ -67,6 +86,7 @@ public enum TwitterSpaceExpansionsV2: TwitterExpansionsParameterV2, Hashable {
case speakerIDs
case creatorID
case hostIDs
case topicIDs
case other(String)

public var stringValue: String {
Expand All @@ -75,7 +95,16 @@ public enum TwitterSpaceExpansionsV2: TwitterExpansionsParameterV2, Hashable {
case .speakerIDs: return "speaker_ids"
case .creatorID: return "creator_id"
case .hostIDs: return "host_ids"
case .topicIDs: return "topic_ids"
case .other(let string): return string
}
}

public static let all: Set<Self> = [
.invitedUserIDs,
.speakerIDs,
.creatorID,
.topicIDs,
.hostIDs,
]
}
118 changes: 118 additions & 0 deletions Sources/TwitterAPIKit/APIv2/FieldsV2.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,29 @@ public enum TwitterTweetFieldsV2: TwitterAPIv2RequestParameter, Hashable {
return other
}
}

public static let all: Set<Self> = [
.attachments,
.authorID,
.contextAnnotations,
.conversationID,
.createdAt,
.entities,
.geo,
.id,
.inReplyToUserID,
.lang,
.nonPublicMetrics,
.publicMetrics,
.organicMetrics,
.promotedMetrics,
.possiblySensitive,
.referencedTweets,
.replySettings,
.source,
.text,
.withheld,
]
}

extension Set where Element == TwitterTweetFieldsV2 {
Expand Down Expand Up @@ -134,6 +157,23 @@ public enum TwitterUserFieldsV2: TwitterAPIv2RequestParameter, Hashable {
return other
}
}

public static let all: Set<Self> = [
.createdAt,
.description,
.entities,
.id,
.location,
.name,
.pinnedTweetID,
.profileImageUrl,
.protected,
.publicMetrics,
.url,
.username,
.verified,
.withheld,
]
}

extension Set where Element == TwitterUserFieldsV2 {
Expand Down Expand Up @@ -177,6 +217,17 @@ public enum TwitterPlaceFieldsV2: TwitterAPIv2RequestParameter, Hashable {
return other
}
}

public static let all: Set<Self> = [
.containedWithin,
.country,
.countryCode,
.fullName,
.geo,
.id,
.name,
.placeType,
]
}

extension Set where Element == TwitterPlaceFieldsV2 {
Expand Down Expand Up @@ -210,6 +261,14 @@ public enum TwitterPollFieldsV2: TwitterAPIv2RequestParameter, Hashable {
return other
}
}

public static let all: Set<Self> = [
.durationMinutes,
.endDatetime,
.id,
.options,
.votingStatus,
]
}

extension Set where Element == TwitterPollFieldsV2 {
Expand All @@ -232,6 +291,7 @@ public enum TwitterMediaFieldsV2: TwitterAPIv2RequestParameter, Hashable {
case organicMetrics
case promotedMetrics
case altText
case variants
case other(String)

public var stringValue: String {
Expand All @@ -248,9 +308,26 @@ public enum TwitterMediaFieldsV2: TwitterAPIv2RequestParameter, Hashable {
case .organicMetrics: return "organic_metrics"
case .promotedMetrics: return "promoted_metrics"
case .altText: return "alt_text"
case .variants: return "variants"
case .other(let string): return string
}
}

public static let all: Set<Self> = [
.durationMs,
.height,
.mediaKey,
.previewImageUrl,
.type,
.url,
.width,
.publicMetrics,
.nonPublicMetrics,
.organicMetrics,
.promotedMetrics,
.altText,
.variants,
]
}

extension Set where Element == TwitterMediaFieldsV2 {
Expand Down Expand Up @@ -285,6 +362,17 @@ public enum TwitterListFieldsV2: TwitterAPIv2RequestParameter, Hashable {
case .other(let string): return string
}
}

public static let all: Set<Self> = [
.createdAt,
.followerCount,
.memberCount,
.private,
.description,
.id,
.name,
.ownerID,
]
}

extension Set where Element == TwitterListFieldsV2 {
Expand All @@ -296,6 +384,8 @@ extension Set where Element == TwitterListFieldsV2 {
/// space.fields
public enum TwitterSpaceFieldsV2: TwitterAPIv2RequestParameter, Hashable {

case id
case state
case hostIDs
case createdAt
case creatorID
Expand All @@ -315,6 +405,8 @@ public enum TwitterSpaceFieldsV2: TwitterAPIv2RequestParameter, Hashable {

public var stringValue: String {
switch self {
case .id: return "id"
case .state: return "state"
case .hostIDs: return "host_ids"
case .createdAt: return "created_at"
case .creatorID: return "creator_id"
Expand All @@ -333,6 +425,26 @@ public enum TwitterSpaceFieldsV2: TwitterAPIv2RequestParameter, Hashable {
case .other(let string): return string
}
}

public static let all: Set<Self> = [
.id,
.state,
.hostIDs,
.createdAt,
.creatorID,
.lang,
.invitedUserIDs,
.participantCount,
.speakerIDs,
.startedAt,
.endedAt,
.subscriberCount,
.topicIDs,
.title,
.updatedAt,
.scheduledStart,
.isTicketed,
]
}

extension Set where Element == TwitterSpaceFieldsV2 {
Expand All @@ -357,6 +469,12 @@ public enum TwitterTopicFieldsV2: TwitterAPIv2RequestParameter, Hashable {
case .other(let string): return string
}
}

public static let all: Set<Self> = [
.id,
.name,
.description,
]
}

extension Set where Element == TwitterTopicFieldsV2 {
Expand Down
19 changes: 18 additions & 1 deletion Tests/TwitterAPIKitTests/APIv2/ExpansionsV2Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ class ExpansionsV2Tests: XCTestCase {
)
}

func testTwitterTweetExpansionsV2All() throws {
XCTAssertEqual(TwitterTweetExpansionsV2.all.count, 8)
}

func testTwitterUserExpansionsV2() throws {

let allCases: [TwitterUserExpansionsV2] = [
Expand All @@ -44,6 +48,10 @@ class ExpansionsV2Tests: XCTestCase {
)
}

func testTwitterUserExpansionsV2All() throws {
XCTAssertEqual(TwitterUserExpansionsV2.all.count, 1)
}

func testTwitterListExpansionsV2() throws {
let allCases: [TwitterListExpansionsV2] = [
.ownerID,
Expand All @@ -57,20 +65,29 @@ class ExpansionsV2Tests: XCTestCase {
)
}

func testTwitterListExpansionsV2All() throws {
XCTAssertEqual(TwitterListExpansionsV2.all.count, 1)
}

func testTwitterSpaceExpansionsV2() throws {
let allCases: [TwitterSpaceExpansionsV2] = [
.invitedUserIDs,
.speakerIDs,
.creatorID,
.hostIDs,
.topicIDs,
.other("~~~"),
]

// curl https://api.twitter.com/2/openapi.json | jq '.components.parameters.SpaceExpansionsParameter.schema.items.enum | sort | join(",")'
XCTAssertEqual(
allCases.commaSeparatedString,
"creator_id,host_ids,invited_user_ids,speaker_ids,~~~"
"creator_id,host_ids,invited_user_ids,speaker_ids,topic_ids,~~~"
)
}

func testTwitterSpaceExpansionsV2All() throws {
XCTAssertEqual(TwitterSpaceExpansionsV2.all.count, 5)
}

}

0 comments on commit 586cdfd

Please sign in to comment.