Thanks for your interest in contributing to Twift! This library is still young, so may not cover all your needs or work the way you expected—whether you have ideas for improving it, or want to add new methods and types, contributions and discussion are actively welcomed!
Below are some things to bear in mind when contributing to the library.
Thorough documentation is an important part of making this library useful. All new methods and types should be documented with:
- A title or summary
- A detailed description (optional)
- Parameters (where applicable)
- Return types (where applicable)
Please refer to Apple’s developer documentation article detailing how to write symbol documentation in source files.
Where possible, documentation for object properties, methods, and method parameters should copy Twitter’s API documentation.
Proper testing has not yet been developed for Twift; I’d advise testing your contributions locally by linking the library to a test app.
Twift’s API methods follow a common implementation:
- Accept parameters specific to the API endpoint
- Call the internal
call()method with the desired route, HTTP method, body data (where applicable), and query parameters - Throw any errors encountered
- Return a decoded
TwitterAPIresponse with data, includes, and/or metadata
The easiest way to figure out how to write a new method is to reference methods already in the library. Some examples:
- A paginated request with data, includes, and metadata (
GET /2/tweets/:id/liked_by):getLikingUsers(for tweetId) - A data-only request (
POST /2/users/:user_id/likes):likeTweet(_ tweetId)
Symbols should follow Twitter’s API names as closely as possible, favouring camelCase instead of snake_case for member names.
Method names should follow a rule of {action}{Object}, for example postTweet() or getLists(). When in doubt about what the right action is, prefer to use the HTTP method for the API endpoint.
The library is organised into two types of files:
- Class extensions (
Twift+Example.swift) - Type extensions (
Types+Example.swift)
Create type extension files to globally define types for new objects (e.g. Tweets or Spaces). Create class extensions to extend the Twift class and implement methods related to specific objects.
You should prefer let over var for struct properties unless the struct is intentionally mutable (for example, when the struct will be used to post data to the Twitter API).
Always prefer writing methods as async where possible.
Always mark objects, methods, and members as public if they are intended to be used by library consumers. Prefer fileprivate access control for internal implementation details, or internal where implementation details are shared throughout the library.