redd 0.6.3 → 0.6.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +4 -2
- data/lib/redd.rb +1 -0
- data/lib/redd/client/authenticated.rb +2 -0
- data/lib/redd/client/oauth2_script.rb +24 -0
- data/lib/redd/client/oauth2_script/authorization.rb +21 -0
- data/lib/redd/client/unauthenticated/listing.rb +1 -0
- data/lib/redd/client/unauthenticated/users.rb +1 -0
- data/lib/redd/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7d9b725f4c257d4b0ce3119e81c7395253399290
|
4
|
+
data.tar.gz: d6078a42f2bca04fae6497d8cfa935085e581cc8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 08ed7d7fb94496d5307df3cd54d1eca7bf2211773353c51ecddce04234f6fb898e63016feb4c85e10ead5d75bf86eda72d720a3350bc79fb599a78ff027167c6
|
7
|
+
data.tar.gz: 29015295ac9d449230f2c4785e450c66dd1bbe7cd86aea3dc29763be51cc61385151d4eb60383817c5fb0ce72b26aa396b3a6d72fde253834a6a2def8a3c6b1b
|
data/README.md
CHANGED
@@ -48,7 +48,7 @@ Ruby and redd make creating reddit bots accessible and fun. To demonstrate, let'
|
|
48
48
|
```
|
49
49
|
|
50
50
|
3. **Scouting**
|
51
|
-
Redd has a really cool method similar to praw's `helpers.comment_stream` that "streams" comments to you while avoiding duplicates. You won't have to take care of rate-limiting either
|
51
|
+
Redd has a really cool method similar to praw's `helpers.comment_stream` that "streams" comments to you while avoiding duplicates. **You won't have to take care of rate-limiting either**; Redd `sleep`s after requests to avoid ratelimit errors. If you want to write a less blocking rate limiting class, take a look at [`lib/redd/rate_limit.rb`](https://github.com/avidw/redd/blob/master/lib/redd/rate_limit.rb#L2-L23)
|
52
52
|
|
53
53
|
```ruby
|
54
54
|
r.comment_stream "test" do |comment|
|
@@ -75,7 +75,9 @@ Ruby and redd make creating reddit bots accessible and fun. To demonstrate, let'
|
|
75
75
|
```
|
76
76
|
|
77
77
|
## OAuth2
|
78
|
-
Redd also provides a wrapper to connect to reddit via OAuth2. The
|
78
|
+
Redd also provides a wrapper to connect to reddit via OAuth2 for both the `authorization_code` and `password` grants with the `Redd::Client::OAuth2` and `Redd::Client::OAuth2Script` clients. The clients' methods are similar to the authenticated client, given that you have the required scopes. Refer to [reddit's api](https://www.reddit.com/dev/api/oauth) for the various scopes. Getting OAuth2 running is easy and can even be used to integrate reddit's features into a [**Rails**](https://github.com/rails/rails) application. Another plus is that logging in via OAuth2 lets you make twice as many requests without hitting a rate limit (1/second). Let's try logging into reddit with [**sinatra**](http://www.sinatrarb.com/).
|
79
|
+
|
80
|
+
*If you're using the `OAuth2Script` client, you don't have to do all this work. For the `password` grant, you can just jump straight to `request_access` without having to get a code, which is pretty sweet.*
|
79
81
|
|
80
82
|
The first thing you need to do is to create an OAuth2 application in reddit [**here**](https://ssl.reddit.com/prefs/apps). For more information, refer to [**"Getting Started"**](https://github.com/reddit/reddit/wiki/OAuth2#getting-started) on reddit's wiki.
|
81
83
|
|
data/lib/redd.rb
CHANGED
@@ -0,0 +1,24 @@
|
|
1
|
+
require "redd/client/oauth2"
|
2
|
+
|
3
|
+
module Redd
|
4
|
+
module Client
|
5
|
+
class OAuth2Script < Redd::Client::OAuth2
|
6
|
+
require "redd/client/oauth2_script/authorization"
|
7
|
+
|
8
|
+
include Redd::Client::OAuth2Script::Authorization
|
9
|
+
|
10
|
+
attr_reader :username
|
11
|
+
|
12
|
+
def initialize(client_id, secret, username, password, options = {})
|
13
|
+
@client_id = client_id
|
14
|
+
@secret = secret
|
15
|
+
@username = username
|
16
|
+
@password = password
|
17
|
+
|
18
|
+
@rate_limit = options[:rate_limit] || Redd::RateLimit.new(1)
|
19
|
+
@api_endpoint = options[:api_endpoint] || "https://oauth.reddit.com/"
|
20
|
+
@auth_endpoint = options[:auth_endpoint] || "https://ssl.reddit.com/"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require "redd/oauth2_access"
|
2
|
+
|
3
|
+
module Redd
|
4
|
+
module Client
|
5
|
+
class OAuth2Script
|
6
|
+
# Methods for obtaining an access token
|
7
|
+
module Authorization
|
8
|
+
def request_access(set_access = true)
|
9
|
+
response = auth_connection.post "/api/v1/access_token",
|
10
|
+
grant_type: "password",
|
11
|
+
username: @username,
|
12
|
+
password: @password
|
13
|
+
|
14
|
+
access = Redd::OAuth2Access.new(response.body)
|
15
|
+
@access = access if set_access
|
16
|
+
access
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -20,6 +20,7 @@ module Redd
|
|
20
20
|
# Get the appropriate listing.
|
21
21
|
# @param subreddit [Redd::Object::Subreddit] The subreddit to query.
|
22
22
|
# @param params [Hash] A list of params to send with the request.
|
23
|
+
# @return [Redd::Object::Listing]
|
23
24
|
#
|
24
25
|
# @see #get_listing
|
25
26
|
%w(hot new top controversial comments).each do |sort|
|
data/lib/redd/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: redd
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Avinash Dwarapu
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-09-
|
11
|
+
date: 2014-09-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -171,6 +171,8 @@ files:
|
|
171
171
|
- lib/redd/client/oauth2.rb
|
172
172
|
- lib/redd/client/oauth2/authorization.rb
|
173
173
|
- lib/redd/client/oauth2/identity.rb
|
174
|
+
- lib/redd/client/oauth2_script.rb
|
175
|
+
- lib/redd/client/oauth2_script/authorization.rb
|
174
176
|
- lib/redd/client/unauthenticated.rb
|
175
177
|
- lib/redd/client/unauthenticated/account.rb
|
176
178
|
- lib/redd/client/unauthenticated/captcha.rb
|