redd 0.5.0 → 0.6.0

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: 0d5b672f674cc48bf220c0a76b7074de9c509e13
4
- data.tar.gz: 3fb2b44e36f0ed4f38c3633a4134c4cf85b0e48b
3
+ metadata.gz: b44594ffd55f136e44b2ec3ee48fa04b2d69c611
4
+ data.tar.gz: ed0efe9a7f3cf79b22aae8a3a8942cf1b6fc8699
5
5
  SHA512:
6
- metadata.gz: 884382cf0fa1c690f9743e30992fc58b09bc7310660057034505b8c66ccea813c8442dde09e610ca610a6a21122c62cde61fdb5f33abfcc81a15efc2fa63d366
7
- data.tar.gz: a7db6250cbdf1a3e3b5613af36245d5fcb44eb824d340cfa025b920caea59d3d99d2cfdc30052762ac2c594a955eb710e9baecd5116a2a5a8e5cff91ebc63820
6
+ metadata.gz: b7903c63b7044e3f4abb504d9c9ec93f1360622e744c4e88ec282d9bdf4438a448ed8b2c4810ee7861a45b32b2a6eef3f81e74b51e17885aac0c1f977bf97381
7
+ data.tar.gz: 5f4142ff913b834502cbb0fe5d114c19a69c2cba1e7de735383baac3923040c4bc9e51302b5f183ef91532d7681d740968e346e9f51f846a30324ecb6f05a7cd
@@ -43,6 +43,34 @@ module Redd
43
43
  object_from_response(:get, path, params)
44
44
  end
45
45
 
46
+ # Get users related to the subreddit.
47
+ #
48
+ # @param where [:banned, :wikibanned, :contributors, :wikicontributors,
49
+ # :moderators] The order of users to return.
50
+ # @param subreddit [Redd::Object::Subreddit, String] The subreddit.
51
+ # The order of subreddits to return.
52
+ # @param params [Hash] A list of params to send with the request.
53
+ # @option params [String] :after Return results after the given
54
+ # fullname.
55
+ # @option params [String] :before Return results before the given
56
+ # fullname.
57
+ # @option params [Integer] :count (0) The number of items already seen
58
+ # in the listing.
59
+ # @option params [1..100] :limit (25) The maximum number of things to
60
+ # return.
61
+ # @return [Redd::Object::Listing] A listing of users.
62
+ # @note On reddit's end, this is actually a UserList, which is slightly
63
+ # different to a real listing, since it only provides names and ids.
64
+ def get_special_users(where, subreddit, params = {})
65
+ name = extract_attribute(subreddit, :display_name)
66
+ response = get "/r/#{name}/about/#{where}.json", params
67
+
68
+ things = response[:data][:children].map! do |user|
69
+ object_from_body(kind: "t2", data: user)
70
+ end
71
+ Redd::Object::Listing.new(data: {children: things})
72
+ end
73
+
46
74
  private
47
75
 
48
76
  # Subscribe or unsubscribe to a subreddit.
@@ -38,8 +38,10 @@ module Redd
38
38
  # @param code [String] The code that was sent in the GET request.
39
39
  # @param set_access [Boolean] Whether to automatically use this token
40
40
  # for all future requests with this client.
41
- # @return [Redd::OAuth2Access] A package of the necessary information
42
- # to access the user's information.
41
+ # @return [Redd::OAuth2Access, nil] A package of the necessary
42
+ # information to access the user's information or nil if there was
43
+ # an error.
44
+ # @todo Custom Errors for OAuth2
43
45
  def request_access(code, set_access = true)
44
46
  response = auth_connection.post "/api/v1/access_token",
45
47
  grant_type: "authorization_code",
@@ -76,6 +78,30 @@ module Redd
76
78
  new_access
77
79
  end
78
80
  end
81
+
82
+ # Dispose of an access or refresh token when you're done with it.
83
+ #
84
+ # @param access [Redd::OAuth2Access, String] The token to revoke.
85
+ # @param remove_refresh_token [Boolean] Whether you intend to revoke a
86
+ # refresh token.
87
+ def revoke_access(access, remove_refresh_token = nil)
88
+ token =
89
+ if remove_refresh_token
90
+ extract_attribute(access, :refresh_token)
91
+ else
92
+ extract_attribute(access, :access_token)
93
+ end
94
+
95
+ params = {token: token}
96
+
97
+ if remove_refresh_token
98
+ params[:token_type_hint] = true
99
+ elsif remove_refresh_token == false
100
+ params[:token_type_hint] = false
101
+ end
102
+
103
+ auth_connection.post "/api/v1/revoke_token", params
104
+ end
79
105
  end
80
106
  end
81
107
  end
data/lib/redd/error.rb CHANGED
@@ -19,6 +19,20 @@ module Redd
19
19
  case status
20
20
  when 200
21
21
  case body
22
+ when /ACCESS_DENIED/i
23
+ Redd::Error::OAuth2AccessDenied
24
+ when /UNSUPPORTED_RESPONSE_TYPE/i
25
+ Redd::Error::InvalidResponseType
26
+ when /UNSUPPORTED_GRANT_TYPE/i
27
+ Redd::Error::InvalidGrantType
28
+ when /INVALID_SCOPE/i
29
+ Redd::Error::InvalidScope
30
+ when /INVALID_REQUEST/i
31
+ Redd::Error::InvalidRequest
32
+ when /NO_TEXT/i
33
+ Redd::Error::NoTokenGiven
34
+ when /INVALID_GRANT/i
35
+ Redd::Error::ExpiredCode
22
36
  when /WRONG_PASSWORD/i
23
37
  Redd::Error::InvalidCredentials
24
38
  when /BAD_CAPTCHA/i
@@ -36,6 +50,8 @@ module Redd
36
50
  end
37
51
  when 400
38
52
  Redd::Error::BadRequest
53
+ when 401
54
+ Redd::Error::InvalidOAuth2Credentials
39
55
  when 403
40
56
  case body
41
57
  when /USER_REQUIRED/i
@@ -66,16 +82,38 @@ module Redd
66
82
  body[:json][:errors].first
67
83
  elsif body.key?(:jquery)
68
84
  body[:jquery]
85
+ elsif body.key?(:error)
86
+ body[:error]
87
+ elsif body.key?(:code) && body[:code] == "NO_TEXT"
88
+ "NO_TEXT"
69
89
  end
70
90
  end
71
91
  end
72
92
 
93
+ class NoTokenGiven < Error; end
94
+
95
+ class ExpiredCode < Error; end
96
+
97
+ class InvalidGrantType < Error; end
98
+
99
+ class InvalidOAuth2Credentials < Error; end
100
+
101
+ class OAuth2AccessDenied < Error; end
102
+
103
+ class InvalidResponseType < Error; end
104
+
105
+ class InvalidScope < Error; end
106
+
107
+ class InvalidRequest < Error; end
108
+
73
109
  class AuthenticationRequired < Error; end
74
110
 
75
111
  class InvalidCaptcha < Error; end
76
112
 
77
113
  class BadGateway < Error; end
78
114
 
115
+ class BadRequest < Error; end
116
+
79
117
  class InvalidMultiredditName < Error; end
80
118
 
81
119
  class Conflict < Error; end
@@ -19,7 +19,7 @@ module Redd
19
19
  attr_reader :before
20
20
 
21
21
  def initialize(listing)
22
- @kind = listing[:kind]
22
+ @kind = "Listing"
23
23
  @things = listing[:data][:children]
24
24
  @after = listing[:data][:after]
25
25
  @before = listing[:data][:before]
data/lib/redd/version.rb CHANGED
@@ -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.5.0"
4
+ VERSION = "0.6.0"
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.5.0
4
+ version: 0.6.0
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-08-17 00:00:00.000000000 Z
11
+ date: 2014-08-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler