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

Commit 63533d7

Browse files
committed
Merge branch 'main' into linux-support
2 parents 6e18211 + 7bbdd82 commit 63533d7

27 files changed

+905
-23
lines changed

.github/FUNDING.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# These are supported funding model platforms
2+
3+
github: [mironal] # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
4+
patreon: # Replace with a single Patreon username
5+
open_collective: # Replace with a single Open Collective username
6+
ko_fi: # Replace with a single Ko-fi username
7+
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
8+
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
9+
liberapay: # Replace with a single Liberapay username
10+
issuehunt: # Replace with a single IssueHunt username
11+
otechie: # Replace with a single Otechie username
12+
lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry
13+
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']

.github/workflows/swift.yml

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,31 +12,26 @@ jobs:
1212
runs-on: ${{ matrix.os }}
1313
strategy:
1414
matrix:
15-
os: [ubuntu-latest, macos-latest]
15+
os: [ubuntu-latest, macos-12]
1616
steps:
1717
- uses: actions/checkout@v2
1818
- uses: actions/cache@v2
1919
id: "cache-spm"
2020
with:
2121
path: BuildTools/.build
2222
key: ${{ runner.os }}-spm-${{ hashFiles('**/BuildTools/Package.resolved') }}
23-
restore-keys: |
24-
${{ runner.os }}-spm-
2523
- uses: fwal/setup-swift@v1
2624
with:
27-
swift-version: "5.6"
25+
swift-version: "5.7"
2826
- name: Install Sourcery
2927
run: brew update && brew install sourcery
3028
- name: Check Flat API
3129
run: ./flat-api.sh -c
32-
- name: Build tools & Lint
30+
- name: Build tools
3331
if: steps.cache-spm.outputs.cache-hit != 'true'
34-
run: swift run -c release --package-path BuildTools swift-format lint -p --strict --recursive ./Sources ./Tests ./scripts
32+
run: ./build_tools.sh
3533
- name: Lint
36-
if: steps.cache-spm.outputs.cache-hit == 'true'
37-
run: |
38-
swift run -c release --skip-build --package-path BuildTools swift-format --version
39-
swift run -c release --skip-build --package-path BuildTools swift-format lint -p --strict --recursive ./Sources ./Tests ./scripts
34+
run: ./lint.sh
4035
- name: Build
4136
run: swift build
4237

BuildTools/Package.resolved

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

BuildTools/Package.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
// swift-tools-version:5.1
1+
// swift-tools-version:5.5
22
import PackageDescription
33

44
let package = Package(
55
name: "BuildTools",
66
platforms: [.macOS(.v10_11)],
77
dependencies: [
8-
.package(url: "https://github.com/apple/swift-format", from: "0.50600.1"),
8+
.package(url: "https://github.com/apple/swift-format", from: "0.50700.0"),
99
],
1010
targets: [.target(name: "BuildTools", path: "")]
1111
)

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,12 @@ And the following sample project includes a sample authentication.
9090

9191
[Please see "HowToDecodeResponse.md"](./HowToDecodeResponse.md)
9292

93+
## Linux support (experimental)
94+
95+
TwitterAPIKit can be used on Linux, but cannot be merged into the main branch because it cannot run tests.
96+
97+
If you want to use it on Linux, use [THIS BRANCH](https://github.com/mironal/TwitterAPIKit/pull/121).
98+
9399
## Example
94100

95101
### Projects
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import Foundation
2+
3+
open class DirectMessageAPIv2: TwitterAPIBase {
4+
/// https://developer.twitter.com/en/docs/twitter-api/direct-messages/lookup/api-reference/get-dm_events
5+
public func getDmEvents(
6+
_ request: GetDmEventsRequestV2
7+
) -> TwitterAPISessionJSONTask {
8+
return session.send(request)
9+
}
10+
11+
/// https://developer.twitter.com/en/docs/twitter-api/direct-messages/lookup/api-reference/get-dm_conversations-with-participant_id-dm_events
12+
public func getDmEventsWithParticipantId(
13+
_ request: GetDmConversationsWithParticipantIdDmEventsRequestV2
14+
) -> TwitterAPISessionJSONTask {
15+
return session.send(request)
16+
}
17+
18+
/// https://developer.twitter.com/en/docs/twitter-api/direct-messages/lookup/api-reference/get-dm_conversations-dm_conversation_id-dm_events
19+
public func getDmEventsByConversationsId(
20+
_ request: GetDmConversationsIdDmEventsRequestV2
21+
) -> TwitterAPISessionJSONTask {
22+
return session.send(request)
23+
}
24+
25+
/// https://developer.twitter.com/en/docs/twitter-api/direct-messages/manage/api-reference/post-dm_conversations-dm_conversation_id-messages
26+
public func postDmConversationById(
27+
_ request: PostDmConversationByIdRequestV2
28+
) -> TwitterAPISessionJSONTask {
29+
return session.send(request)
30+
}
31+
32+
/// https://developer.twitter.com/en/docs/twitter-api/direct-messages/manage/api-reference/post-dm_conversations-with-participant_id-messages
33+
public func postDmConversationWithUser(
34+
_ request: PostDmConversationWithUserRequestV2
35+
) -> TwitterAPISessionJSONTask {
36+
return session.send(request)
37+
}
38+
39+
/// https://developer.twitter.com/en/docs/twitter-api/direct-messages/manage/api-reference/post-dm_conversations
40+
public func postDmConversation(
41+
_ request: PostDmConversationRequestV2
42+
) -> TwitterAPISessionJSONTask {
43+
return session.send(request)
44+
}
45+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import Foundation
2+
3+
/// Returns DM Events for a DM Conversation
4+
/// Required OAuth 2.0 scopes: dm.read, tweet.read, users.read
5+
open class GetDmConversationsIdDmEventsRequestV2: TwitterAPIRequest {
6+
7+
/// The DM Conversation ID.
8+
public let id: String
9+
/// The maximum number of results.
10+
public let maxResults: Int?
11+
/// This parameter is used to get a specified 'page' of results.
12+
public let paginationToken: String?
13+
/// The set of event_types to include in the results.
14+
public let eventTypes: Set<TwitterDirectMessageEventTypeV2>?
15+
/// A comma separated list of DmEvent fields to display.
16+
public let dmEventFields: Set<TwitterDmEventFieldsV2>?
17+
/// A comma separated list of fields to expand.
18+
public let expansions: Set<TwitterDmEventExpansionsV2>?
19+
/// A comma separated list of Media fields to display.
20+
public let mediaFields: Set<TwitterMediaFieldsV2>?
21+
/// A comma separated list of User fields to display.
22+
public let userFields: Set<TwitterUserFieldsV2>?
23+
/// A comma separated list of Tweet fields to display.
24+
public let tweetFields: Set<TwitterTweetFieldsV2>?
25+
26+
public var method: HTTPMethod {
27+
return .get
28+
}
29+
30+
public var path: String {
31+
return "/2/dm_conversations/\(id)/dm_events"
32+
}
33+
34+
open var parameters: [String: Any] {
35+
var p = [String: Any]()
36+
maxResults.map { p["max_results"] = $0 }
37+
paginationToken.map { p["pagination_token"] = $0 }
38+
eventTypes?.bind(param: &p)
39+
dmEventFields?.bind(param: &p)
40+
expansions?.bind(param: &p)
41+
mediaFields?.bind(param: &p)
42+
userFields?.bind(param: &p)
43+
tweetFields?.bind(param: &p)
44+
return p
45+
}
46+
47+
public init(
48+
id: String,
49+
maxResults: Int? = .none,
50+
paginationToken: String? = .none,
51+
eventTypes: Set<TwitterDirectMessageEventTypeV2>? = .none,
52+
dmEventFields: Set<TwitterDmEventFieldsV2>? = .none,
53+
expansions: Set<TwitterDmEventExpansionsV2>? = .none,
54+
mediaFields: Set<TwitterMediaFieldsV2>? = .none,
55+
userFields: Set<TwitterUserFieldsV2>? = .none,
56+
tweetFields: Set<TwitterTweetFieldsV2>? = .none
57+
) {
58+
self.id = id
59+
self.maxResults = maxResults
60+
self.paginationToken = paginationToken
61+
self.eventTypes = eventTypes
62+
self.dmEventFields = dmEventFields
63+
self.expansions = expansions
64+
self.mediaFields = mediaFields
65+
self.userFields = userFields
66+
self.tweetFields = tweetFields
67+
}
68+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import Foundation
2+
3+
/// Returns DM Events for a DM Conversation
4+
/// Required OAuth 2.0 scopes: dm.read, tweet.read, users.read
5+
open class GetDmConversationsWithParticipantIdDmEventsRequestV2: TwitterAPIRequest {
6+
7+
/// The ID of the participant user for the One to One DM conversation.
8+
public let participantID: String
9+
/// The maximum number of results.
10+
public let maxResults: Int?
11+
/// This parameter is used to get a specified 'page' of results.
12+
public let paginationToken: String?
13+
/// The set of event_types to include in the results.
14+
public let eventTypes: Set<TwitterDirectMessageEventTypeV2>?
15+
/// A comma separated list of DmEvent fields to display.
16+
public let dmEventFields: Set<TwitterDmEventFieldsV2>?
17+
/// A comma separated list of fields to expand.
18+
public let expansions: Set<TwitterDmEventExpansionsV2>?
19+
/// A comma separated list of Media fields to display.
20+
public let mediaFields: Set<TwitterMediaFieldsV2>?
21+
/// A comma separated list of User fields to display.
22+
public let userFields: Set<TwitterUserFieldsV2>?
23+
/// A comma separated list of Tweet fields to display.
24+
public let tweetFields: Set<TwitterTweetFieldsV2>?
25+
26+
public var method: HTTPMethod {
27+
return .get
28+
}
29+
30+
public var path: String {
31+
return "/2/dm_conversations/with/\(participantID)/dm_events"
32+
}
33+
34+
open var parameters: [String: Any] {
35+
var p = [String: Any]()
36+
maxResults.map { p["max_results"] = $0 }
37+
paginationToken.map { p["pagination_token"] = $0 }
38+
eventTypes?.bind(param: &p)
39+
dmEventFields?.bind(param: &p)
40+
expansions?.bind(param: &p)
41+
mediaFields?.bind(param: &p)
42+
userFields?.bind(param: &p)
43+
tweetFields?.bind(param: &p)
44+
return p
45+
}
46+
47+
public init(
48+
participantID: String,
49+
maxResults: Int? = .none,
50+
paginationToken: String? = .none,
51+
eventTypes: Set<TwitterDirectMessageEventTypeV2>? = .none,
52+
dmEventFields: Set<TwitterDmEventFieldsV2>? = .none,
53+
expansions: Set<TwitterDmEventExpansionsV2>? = .none,
54+
mediaFields: Set<TwitterMediaFieldsV2>? = .none,
55+
userFields: Set<TwitterUserFieldsV2>? = .none,
56+
tweetFields: Set<TwitterTweetFieldsV2>? = .none
57+
) {
58+
self.participantID = participantID
59+
self.maxResults = maxResults
60+
self.paginationToken = paginationToken
61+
self.eventTypes = eventTypes
62+
self.dmEventFields = dmEventFields
63+
self.expansions = expansions
64+
self.mediaFields = mediaFields
65+
self.userFields = userFields
66+
self.tweetFields = tweetFields
67+
}
68+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import Foundation
2+
3+
/// Returns recent DM Events across DM conversations
4+
/// Required OAuth 2.0 scopes: dm.read, tweet.read, users.read
5+
open class GetDmEventsRequestV2: TwitterAPIRequest {
6+
7+
/// The maximum number of results.
8+
public let maxResults: Int?
9+
/// This parameter is used to get a specified 'page' of results.
10+
public let paginationToken: String?
11+
/// The set of event_types to include in the results.
12+
public let eventTypes: Set<TwitterDirectMessageEventTypeV2>?
13+
/// A comma separated list of DmEvent fields to display.
14+
public let dmEventFields: Set<TwitterDmEventFieldsV2>?
15+
/// A comma separated list of fields to expand.
16+
public let expansions: Set<TwitterDmEventExpansionsV2>?
17+
/// A comma separated list of Media fields to display.
18+
public let mediaFields: Set<TwitterMediaFieldsV2>?
19+
/// A comma separated list of User fields to display.
20+
public let userFields: Set<TwitterUserFieldsV2>?
21+
/// A comma separated list of Tweet fields to display.
22+
public let tweetFields: Set<TwitterTweetFieldsV2>?
23+
24+
public var method: HTTPMethod {
25+
return .get
26+
}
27+
28+
public var path: String {
29+
return "/2/dm_events"
30+
}
31+
32+
open var parameters: [String: Any] {
33+
var p = [String: Any]()
34+
maxResults.map { p["max_results"] = $0 }
35+
paginationToken.map { p["pagination_token"] = $0 }
36+
eventTypes?.bind(param: &p)
37+
dmEventFields?.bind(param: &p)
38+
expansions?.bind(param: &p)
39+
mediaFields?.bind(param: &p)
40+
userFields?.bind(param: &p)
41+
tweetFields?.bind(param: &p)
42+
return p
43+
}
44+
45+
public init(
46+
maxResults: Int? = .none,
47+
paginationToken: String? = .none,
48+
eventTypes: Set<TwitterDirectMessageEventTypeV2>? = .none,
49+
dmEventFields: Set<TwitterDmEventFieldsV2>? = .none,
50+
expansions: Set<TwitterDmEventExpansionsV2>? = .none,
51+
mediaFields: Set<TwitterMediaFieldsV2>? = .none,
52+
userFields: Set<TwitterUserFieldsV2>? = .none,
53+
tweetFields: Set<TwitterTweetFieldsV2>? = .none
54+
) {
55+
self.maxResults = maxResults
56+
self.paginationToken = paginationToken
57+
self.eventTypes = eventTypes
58+
self.dmEventFields = dmEventFields
59+
self.expansions = expansions
60+
self.mediaFields = mediaFields
61+
self.userFields = userFields
62+
self.tweetFields = tweetFields
63+
}
64+
}

0 commit comments

Comments
 (0)