Skip to content

Commit a021574

Browse files
committed
Add more detailed instructions for contributing
1 parent 69f09fc commit a021574

1 file changed

Lines changed: 53 additions & 19 deletions

File tree

README.md

Lines changed: 53 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,115 @@
11
# X
22

3-
A Ruby interface to the X API.
3+
#### A Ruby interface to the X API.
44

55
## Installation
66

7-
Install the gem and add to the application's Gemfile by executing:
7+
Install the gem and add to the application's Gemfile:
88

9-
$ bundle add x
9+
bundle add x
1010

11-
If bundler is not being used to manage dependencies, install the gem by executing:
11+
Or, if Bundler is not being used to manage dependencies:
1212

13-
$ gem install x
13+
gem install x
1414

1515
## Usage
1616

17+
First, obtain X credentails from https://developer.x.com.
18+
1719
```ruby
18-
x_oauth_credentials = {
20+
x_credentials = {
1921
api_key: "INSERT YOUR X API KEY HERE",
2022
api_key_secret: "INSERT YOUR X API KEY SECRET HERE",
2123
access_token: "INSERT YOUR X ACCESS TOKEN HERE",
2224
access_token_secret: "INSERT YOUR X ACCESS TOKEN SECRET HERE",
2325
}
2426

25-
# Initialize X API client with OAuth credentials
26-
x_client = X::Client.new(**x_oauth_credentials)
27+
# Initialize an X API client with your OAuth credentials
28+
x_client = X::Client.new(**x_credentials)
2729

28-
# Request yourself
30+
# Get data about yourself
2931
x_client.get("users/me")
3032
# {"data"=>{"id"=>"7505382", "name"=>"Erik Berlin", "username"=>"sferik"}}
3133

3234
# Post a tweet
3335
tweet = x_client.post("tweets", '{"text":"Hello, World! (from @gem)"}')
3436
# {"data"=>{"edit_history_tweet_ids"=>["1234567890123456789"], "id"=>"1234567890123456789", "text"=>"Hello, World! (from @gem)"}}
3537

36-
# Delete a tweet
38+
# Delete the tweet you just posted
3739
x_client.delete("tweets/#{tweet["data"]["id"]}")
3840
# {"data"=>{"deleted"=>true}}
3941

4042
# Initialize an API v1.1 client
41-
v1_client = X::Client.new(base_url: "https://api.twitter.com/1.1/", **x_oauth_credentials)
43+
v1_client = X::Client.new(base_url: "https://api.twitter.com/1.1/", **x_credentials)
4244

4345
# Request your account settings
4446
v1_client.get("account/settings.json")
4547

4648
# Initialize an X Ads API client
47-
ads_client = X::Client.new(base_url: "https://ads-api.twitter.com/12/", **x_oauth_credentials)
49+
ads_client = X::Client.new(base_url: "https://ads-api.twitter.com/12/", **x_credentials)
4850

4951
# Request your ad accounts
5052
ads_client.get("accounts")
5153
```
5254

5355
## History and Philosophy
5456

55-
This library is a rewrite of the [Twitter Ruby library](https://github.com/sferik/twitter). Over 16 years, that library ballooned to over 3,000 lines of code (plus 7,500 lines of tests). At the time of writing, this library is about 300 lines of code (plus 200 test lines) and I’d like to keep it that way. That doesn’t mean new features won’t be added over time, but the benefits of potential new features must be weighed against the benefits of simplicity:
57+
This library is a rewrite of the [Twitter Ruby library](https://github.com/sferik/twitter). Over 16 years of development, that library ballooned to over 3,000 lines of code (plus 7,500 lines of tests). At the time of writing, this library is about 300 lines of code (plus 200 test lines) and I’d like to keep it that way. That doesn’t mean new features won’t be added over time, but the benefits of more code must be weighted against the benefits of less:
5658

5759
* Less code is easier to maintain.
5860
* Less code means fewer bugs.
5961
* Less code runs faster.
6062

61-
In the immortal words of [Ezra Zygmuntowicz](https://github.com/ezmobius) and his [Merb](https://github.com/merb) project (may they both rest in peace): “No code is faster than no code.” The fastest code is the code that is never executed because it doesn’t exist. That principle should apply not just to this library itself but to third-party dependencies. At present, this library has one dependency ([oauth](https://rubygems.org/gems/oauth)) and I’d like to keep it that way. If anything, it should have fewer.
63+
In the immortal words of [Ezra Zygmuntowicz](https://github.com/ezmobius) and his [Merb](https://github.com/merb) project (may they both rest in peace):
64+
65+
> No code is faster than no code.
6266
63-
The tests for the previous version of this library ran in about 2 seconds. That sounds pretty fast until you see that tests for this library run in 2 hundredths of a second. This means you can automatically run the tests any time you write a file and receive immediate feedback. For such of workflows, 2 seconds feels painfully slow. At the same time, we aim to maintain 100% C0 code coverage.
67+
The fastest code is the code that is never executed because it doesn’t exist. That principle should apply not just to this library itself but to third-party dependencies. At present, this library has one runtime dependency ([oauth](https://rubygems.org/gems/oauth)) and I’d like to keep it that way. If anything, it should have fewer dependencies.
6468

65-
This code is not littered with comments that are intended to generate documentation. Rather, this code is intended to be simple enough to serve as its own documentation. If you want to understand how something works, don’t read the documentation—it might be wrong—just read the code. The code is always right.
69+
Tests for the previous version of this library ran in about 2 seconds. That sounds pretty fast until you see that tests for this library run in 2 hundredths of a second. This means you can automatically run the tests any time you write a file and receive immediate feedback. For such of workflows, 2 seconds feels painfully slow.
6670

67-
This project conforms to [Standard Ruby](https://github.com/standardrb/standard). Patches that don’t maintain that standard will not be accepted.
71+
This code is not littered with comments that are intended to generate documentation. Rather, this code is intended to be simple enough to serve as its own documentation. If you want to understand how something works, don’t read the documentation—it might be wrong—read the code. The code is always right.
6872

6973
## Development
7074

71-
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
75+
1. Checkout and repo:
76+
77+
git checkout git@github.com:sferik/x.git
78+
79+
2. Enter the repo’s directory:
80+
81+
cd x
82+
83+
3. Install dependencies via Bundler:
84+
85+
bin/setup
86+
87+
4. Run the default Rake task to ensure all tests pass:
88+
89+
bundle exec rake
7290

73-
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
91+
5. Create a new branch for your feature or bug fix:
92+
93+
git checkout -b my-new-branch
7494

7595
## Contributing
7696

7797
Bug reports and pull requests are welcome on GitHub at https://github.com/sferik/x.
7898

99+
Pull requests will only be accepted if they meet all the following criteria:
100+
101+
1. Code must conform to [Standard Ruby](https://github.com/standardrb/standard). This can be verified with:
102+
103+
bundle exec rake standard
104+
105+
2. For any new code paths, tests must be added to maintain 100% C0 code coverage. This can be verified with:
106+
107+
bundle exec rake test
108+
109+
3. For any new classes or methods, RBS type signatures must be added (to sig/x.rbs). This can be verified with:
110+
111+
bundle exec rake steep
112+
79113
## License
80114

81115
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).

0 commit comments

Comments
 (0)