README.md in redd-0.1.3 vs README.md in redd-0.1.4
- old
+ new
@@ -9,19 +9,18 @@
---
<p align="center">
<a href="#getting-started">Getting Started</a> |
<a href="#extending-redd">Extending Redd</a> |
- <a href="#conventions">Conventions</a> |
<a href="#supported-rubies">Supported Rubies</a> |
<a href="#copyright">Copyright</a>
</p>
---
## Getting Started
-Ruby and redd make creating reddit bots accessible and fun. To demonstrate, let's create a simple bot in three steps that responds to "Hello?" with "World!". *Note: this is just a tutorial; although you're welcome to take it on a test drive on a testing subreddit, don't actually host this bot.*
+Ruby and redd make creating reddit bots accessible and fun. To demonstrate, let's create a simple bot in four steps that responds to "Hello?" with "World!". *Note: this is just a tutorial; although you're welcome to take it on a test drive on a testing subreddit, don't actually host this bot.*
1. **Installing**
You can either install the gem directly by running `gem install redd` or by placing the gem into your `Gemfile` and running `bundle install`.
```ruby
source "https://rubygems.org"
@@ -52,10 +51,29 @@
comment.reply "World!"
end
end
```
+4. **Just in Case**
+ It's also a good idea to escape some common errors from reddit in case they happen:
+ ```ruby
+ begin
+ r.comment_stream "test" do |comment|
+ if comment.body =~ /^Hello\?$/i
+ comment.reply "World!"
+ end
+ end
+ rescue Redd::Error::RateLimited => e
+ time_left = e.time
+ sleep(time_left)
+ rescue Redd::Error => e
+ status = e.message.status
+ # 5-something errors are usually errors on reddit's end.
+ raise e unless status.to_s.start_with? "5"
+ end
+ ```
+
## Extending Redd
Extending any ruby library, including redd is incredibly easy. Let's try this out by adding a gilding extension. Reddit provides an api to be able to gild posts and comments, given that you have "creddits".
1. Let's start by creating a module for the methods to live in.
```ruby
@@ -99,32 +117,15 @@
Redd::Object::Submission.include(Gildable)
Redd::Object::Comment.include(Gildable)
```
-## Conventions
-### Method Names
-- A method that returns a Redd::Object directly is called that in lowercase. For example, a method that returns a single `Redd::Object::Subreddit` is called `subreddit`
-- Any method that return a listing is in the format `get_[thing]s`. For example, a method that returns a listing of subreddits is named `get_subreddits`.
-- An **internal** method that edits an existing object is **usually** named `edit_[thing]`. Some exeptions to this rule are `vote` that edit a user's vote.
-- Any method that returns something specific to the user must have "my" in the middle. For example, a method that returns a users subscribed subreddits is named `get_my_subscriptions`.
-
-### Methods
-- Most methods that use an http request should usually follow this convention. I haven't had time to check the methods to see if they follow this, but this should be the case
- ```ruby
- def subreddit(thing, options = {})
- fullname = extract_fullname(thing)
-
- meth = :get
- path = "/r/ruby/about.json"
- params = options << {additional: "options"}
-
- object_from_response(meth, path, params)
- end
- ```
-
## Supported Rubies
TODO: Travis CI
## Copyright
Copyright (c) [Avinash Dwarapu](http://github.com/avidw) under the MIT License. See LICENSE.md for more details.
Some code has been used from [RedditKit.rb](http://github.com/samsymons/RedditKit.rb). See RedditKit.LICENSE.md for more details.
+
+---
+
+Redd not your cup of tea? Check out [RedditKit.rb](http://github.com/samsymons/RedditKit.rb)!