redd 0.6.3 → 0.6.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0369bfc4c491d26f3330c1644d9f5724d9ad583a
4
- data.tar.gz: 3b3507c642e26bc6b7817965c1fcdfb1f4fde177
3
+ metadata.gz: 7d9b725f4c257d4b0ce3119e81c7395253399290
4
+ data.tar.gz: d6078a42f2bca04fae6497d8cfa935085e581cc8
5
5
  SHA512:
6
- metadata.gz: 5bcc787430010a207c9375df1d7a3be3f9689e3bd116cadb7aa4123141776271b3db74ede823c484e502128cfc75fdd53a428dc7286c8815f73e579b40673844
7
- data.tar.gz: 117dbdf5f5e4fc0fa5d93055a3bde0136d7bbc6e29dcc2aa1d972bb9c496911671e03eb8eab1833137f18346b48c1d73cd07741dc4375ac20a8b3d00c86a8b03
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; Redd `sleep`s after requests to avoid ratelimit errors. If you want to write a rate limiting class yourself, take a look at [`lib/redd/rate_limit.rb`](https://github.com/avidw/redd/blob/master/lib/redd/rate_limit.rb#L2-L23)
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 client's 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 it running is really simple 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/).
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
 
@@ -1,3 +1,4 @@
1
1
  require "redd/client/unauthenticated"
2
2
  require "redd/client/authenticated"
3
3
  require "redd/client/oauth2"
4
+ require "redd/client/oauth2_script"
@@ -1,3 +1,5 @@
1
+ require "redd/client/unauthenticated"
2
+
1
3
  module Redd
2
4
  module Client
3
5
  # The class that handles requests when authenticated using a username and
@@ -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|
@@ -22,6 +22,7 @@ module Redd
22
22
  # Get the appropriate listing.
23
23
  # @param user [Redd::Object::User] The user to query.
24
24
  # @param params [Hash] A list of params to send with the request.
25
+ # @return [Redd::Object::Listing]
25
26
  #
26
27
  # @see #get_user_listing
27
28
  %w(
@@ -1,5 +1,5 @@
1
1
  # The main Redd module.
2
2
  module Redd
3
3
  # The semantic version number for Redd.
4
- VERSION = "0.6.3"
4
+ VERSION = "0.6.4"
5
5
  end
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.3
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-17 00:00:00.000000000 Z
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