Skip to content

Commit

Permalink
update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
Santiago Medina Rolong committed Dec 16, 2024
1 parent c8654ca commit e81b368
Showing 1 changed file with 68 additions and 52 deletions.
120 changes: 68 additions & 52 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,85 +1,110 @@

# xurl - A curl-like CLI Tool for the X API
`xurl` is a command-line tool that simplifies making authenticated requests to the X (formerly Twitter) API. It handles OAuth 2.0 authentication automatically and provides a curl-like interface for API interactions.

A command-line tool for interacting with the X (formerly Twitter) API, supporting both OAuth 1.0a and OAuth 2.0 authentication.

## Features
- OAuth 2.0 authentication with PKCE
- Token persistence for multiple users
- Automatic token refresh
- Support for all HTTP methods
- JSON request/response handling
- Custom header support

- OAuth 2.0 PKCE flow authentication
- OAuth 1.0a authentication
- Multiple OAuth 2.0 account support
- Persistent token storage
- HTTP request customization (headers, methods, body)

## Installation
```bash
curl -fsSL https://raw.githubusercontent.com/santiagomed/xurl/main/install.sh | sudo bash
```

## Configuration
Before using xurl, you need to set up the following environment variables:

Create a `.env` file with your X API credentials:

```env
CLIENT_ID=your_client_id
CLIENT_SECRET=your_client_secret
```

Optional environment variables:
- `REDIRECT_URI` (default: http://localhost:8080/callback)
- `AUTH_URL` (default: https://x.com/i/oauth2/authorize)

This comment has been minimized.

Copy link
@Junejuan060188

Junejuan060188 Jan 19, 2025

Image

twurl -H ads-api.twitter.com "/9/accounts/18ce54d4x5t/cards?include_legacy_cards=true"
{
"request": {
"params": {
"account_id": "18ce54d4x5t",
"include_legacy_cards": true
}
},
"next_cursor": null,
"data": [
{
"name": "previously-created-card",
"components": [
{
"type": "MEDIA",
"media_key": "13_1387900674604560386"
},
{
"type": "DETAILS",
"title": "Twitter",
"destination": {
"type": "WEBSITE",
"url": "https://www.twitter.com"
}
}
],
"created_at": "2021-04-29T22:46:45Z",
"card_uri": "card://1387901195730055172",
"updated_at": "2021-04-29T22:46:45Z",
"deleted": false
}
]
}

- `TOKEN_URL` (default: https://api.x.com/2/oauth2/token)
- `API_BASE_URL` (default: https://api.x.com)

## Usage

### Authentication

OAuth 2.0 authentication:
```bash
export CLIENT_ID="your_client_id"
export CLIENT_SECRET="your_client_secret"
xurl auth oauth2
```

Optional environment variables (to override defaults):
OAuth 1.0a authentication:
```bash
export REDIRECT_URI="<your_redirect_uri>"
export AUTH_URL="<your_auth_url>"
export TOKEN_URL="<your_token_url>"
xurl auth oauth1 --consumer-key KEY --consumer-secret SECRET --access-token TOKEN --token-secret SECRET
```

## Usage
Basic usage:
View authentication status:
```bash
xurl '/2/users/me'
xurl auth status
```

To cache authentication for a specific user, use the `-u` option:
Clear authentication:
```bash
xurl -u santiagomedr '/2/users/me'
xurl auth clear --all # Clear all tokens
xurl auth clear --oauth1 # Clear OAuth 1.0a tokens
xurl auth clear --oauth2-username USERNAME # Clear specific OAuth 2.0 token
```

### Making Requests

POST request with data:
Basic GET request:
```bash
xurl -X POST -d '{"text":"Hello, World!"}' '/2/tweets'
xurl /2/users/me
```

Adding custom headers:
Custom HTTP method:
```bash
xurl -H "Content-Type: application/json" '/2/users/me'
xurl -X POST /2/tweets -d '{"text":"Hello world!"}'
```

## Authentication Flow
The tool implements OAuth 2.0 with PKCE for secure authentication. When you make your first request:
1. A browser window opens for X authentication
2. After authorizing, you'll be redirected back to the local callback server
3. The token is automatically saved for future use
Add headers:
```bash
xurl -H "Content-Type: application/json" /2/tweets
```

Specify authentication type:
```bash
xurl --auth oauth2 /2/users/me
xurl --auth oauth1 /2/tweets
```

## Code Structure
- `src/auth/`: OAuth implementation and token management
- `src/api/`: API client and request handling
- `src/cli/`: Command-line interface and argument parsing
- `src/config/`: Configuration management
- `src/errors/`: Error handling
Use specific OAuth 2.0 account:
```bash
xurl --username johndoe /2/users/me
```

## Token Storage

Tokens are stored securely in `~/.xurl` in your home directory.

## Error Handling
- OAuth authentication errors
- Network and HTTP errors
- API response errors
- Configuration errors
## Development

The project uses the following structure:
- `src/main.rs`: Entry point and command handling
- `src/auth/`: Authentication implementation
- `src/api/`: API client implementation
- `src/cli/`: Command-line interface definitions
- `src/config/`: Configuration management
- `src/error/`: Error types and handling

## Testing
To run tests:

Run the test suite:
```bash
cargo test
```


## Contributing
Contributions are welcome!

Expand All @@ -89,14 +114,5 @@ Contributions are welcome!
4. Push to the branch
5. Create a new Pull Request

## Dependencies
Key dependencies include:
- `oauth2`: OAuth 2.0 authentication
- `reqwest`: HTTP client
- `tokio`: Async runtime
- `axum`: Web server for OAuth callback
- `clap`: Command line argument parsing
- `serde`: Serialization/deserialization

## License
This project is open-sourced under the MIT License - see the LICENSE file for details.
This project is open-sourced under the MIT License - see the LICENSE file for details.

0 comments on commit e81b368

Please sign in to comment.