redd 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/redd/client/authenticated/links_comments.rb +2 -0
- data/lib/redd/client/oauth2.rb +8 -10
- data/lib/redd/client/oauth2/authorization.rb +15 -2
- data/lib/redd/object/comment.rb +12 -4
- data/lib/redd/object/private_message.rb +4 -0
- data/lib/redd/object/submission.rb +13 -0
- data/lib/redd/object/subreddit.rb +4 -0
- data/lib/redd/object/user.rb +4 -0
- data/lib/redd/thing/editable.rb +15 -0
- data/lib/redd/thing/hideable.rb +15 -0
- data/lib/redd/thing/inboxable.rb +19 -0
- data/lib/redd/thing/messageable.rb +18 -0
- data/lib/redd/thing/moderatable.rb +31 -0
- data/lib/redd/thing/reportable.rb +11 -0
- data/lib/redd/thing/saveable.rb +15 -0
- data/lib/redd/thing/voteable.rb +22 -0
- data/lib/redd/version.rb +1 -1
- metadata +10 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ea1e887784c57e6c3bef623557618c0b2cf85b6f
|
4
|
+
data.tar.gz: a0c3e6e653857d9f10d5915d433866b166d436da
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7cd3dc27fe73b93382f5a2cb651d391fc6dd6fc43e2257871419c77703d1b070c7fd7e561e29724f54c7736d7340860866ee0b05b0c10f39f666cb32a7ed2f3e
|
7
|
+
data.tar.gz: 9ae7e3b594a3f4db301623737e63f9771a71f3c9663ccd2a9ccbc9e1965f95a2dcf0c5c5d989432ac7614284b08d74f4ea74cb96068db39a0d28f45161be4915
|
data/lib/redd/client/oauth2.rb
CHANGED
@@ -10,10 +10,6 @@ module Redd
|
|
10
10
|
include Redd::Client::OAuth2::Authorization
|
11
11
|
include Redd::Client::OAuth2::Identity
|
12
12
|
|
13
|
-
# @!attribute [r] api_endpoint
|
14
|
-
# @return [String] The site to make oauth requests with.
|
15
|
-
attr_accessor :api_endpoint
|
16
|
-
|
17
13
|
# @!attribute [r] auth_endpoint
|
18
14
|
# @return [String] The site to connect to authenticate with.
|
19
15
|
attr_accessor :auth_endpoint
|
@@ -30,6 +26,10 @@ module Redd
|
|
30
26
|
# @return [String] The access token used to make requests.
|
31
27
|
attr_accessor :access_token
|
32
28
|
|
29
|
+
# @!attribute [rw] refresh_token
|
30
|
+
# @return [String] The token used to refresh the access token.
|
31
|
+
attr_accessor :refresh_token
|
32
|
+
|
33
33
|
def initialize(client_id, secret, redirect_uri, options = {})
|
34
34
|
@client_id = client_id
|
35
35
|
@secret = secret
|
@@ -50,21 +50,19 @@ module Redd
|
|
50
50
|
faraday.adapter Faraday.default_adapter
|
51
51
|
|
52
52
|
faraday.headers["Authorization"] = "bearer #{access_token}"
|
53
|
+
faraday.headers["User-Agent"] = "Redd/Ruby, v#{Redd::VERSION}"
|
53
54
|
end
|
54
55
|
end
|
55
56
|
|
56
57
|
def auth_connection
|
57
58
|
@auth_connection ||= Faraday.new(url: auth_endpoint) do |faraday|
|
58
59
|
faraday.use Faraday::Request::UrlEncoded
|
60
|
+
faraday.use Redd::Response::RaiseError
|
59
61
|
faraday.use Redd::Response::ParseJson
|
60
|
-
faraday.basic_auth(@client_id, @secret)
|
61
62
|
faraday.adapter Faraday.default_adapter
|
62
|
-
end
|
63
|
-
end
|
64
63
|
|
65
|
-
|
66
|
-
|
67
|
-
@headers ||= {}
|
64
|
+
faraday.basic_auth(@client_id, @secret)
|
65
|
+
end
|
68
66
|
end
|
69
67
|
end
|
70
68
|
end
|
@@ -22,8 +22,21 @@ module Redd
|
|
22
22
|
grant_type: "authorization_code", code: code,
|
23
23
|
redirect_uri: @redirect_uri
|
24
24
|
|
25
|
-
|
26
|
-
|
25
|
+
body = response.body
|
26
|
+
@access_token = body[:access_token] if set_token
|
27
|
+
@refresh_token = body[:refresh_token] if body[:refresh_token]
|
28
|
+
body
|
29
|
+
end
|
30
|
+
|
31
|
+
def refresh_access_token(
|
32
|
+
refresh_token = @refresh_token, set_token = true
|
33
|
+
)
|
34
|
+
response = auth_connection.post "/api/v1/access_token",
|
35
|
+
grant_type: "refresh_token", refresh_token: refresh_token
|
36
|
+
|
37
|
+
body = response.body
|
38
|
+
@access_token = body[:access_token] if set_token
|
39
|
+
body
|
27
40
|
end
|
28
41
|
end
|
29
42
|
end
|
data/lib/redd/object/comment.rb
CHANGED
@@ -4,6 +4,18 @@ module Redd
|
|
4
4
|
module Object
|
5
5
|
# A comment made on links.
|
6
6
|
class Comment < Redd::Thing
|
7
|
+
require "redd/thing/editable"
|
8
|
+
require "redd/thing/inboxable"
|
9
|
+
require "redd/thing/moderatable"
|
10
|
+
require "redd/thing/reportable"
|
11
|
+
require "redd/thing/voteable"
|
12
|
+
|
13
|
+
include Redd::Thing::Editable
|
14
|
+
include Redd::Thing::Inboxable
|
15
|
+
include Redd::Thing::Moderatable
|
16
|
+
include Redd::Thing::Reportable
|
17
|
+
include Redd::Thing::Voteable
|
18
|
+
|
7
19
|
attr_reader :created_utc
|
8
20
|
attr_reader :author
|
9
21
|
|
@@ -51,10 +63,6 @@ module Redd
|
|
51
63
|
def gilded?
|
52
64
|
gilded > 0
|
53
65
|
end
|
54
|
-
|
55
|
-
def reply(text)
|
56
|
-
client.reply(self, text)
|
57
|
-
end
|
58
66
|
end
|
59
67
|
end
|
60
68
|
end
|
@@ -4,6 +4,19 @@ module Redd
|
|
4
4
|
module Object
|
5
5
|
# A submission made in a subreddit.
|
6
6
|
class Submission < Redd::Thing
|
7
|
+
require "redd/thing/editable"
|
8
|
+
require "redd/thing/hideable"
|
9
|
+
require "redd/thing/moderatable"
|
10
|
+
require "redd/thing/reportable"
|
11
|
+
require "redd/thing/saveable"
|
12
|
+
require "redd/thing/voteable"
|
13
|
+
|
14
|
+
include Redd::Thing::Editable
|
15
|
+
include Redd::Thing::Hideable
|
16
|
+
include Redd::Thing::Moderatable
|
17
|
+
include Redd::Thing::Saveable
|
18
|
+
include Redd::Thing::Voteable
|
19
|
+
|
7
20
|
attr_reader :created_utc
|
8
21
|
attr_reader :author
|
9
22
|
|
@@ -5,6 +5,10 @@ module Redd
|
|
5
5
|
# A comment made on links.
|
6
6
|
# @note This model can sure benefit from some lazy-loading...
|
7
7
|
class Subreddit < Redd::Thing
|
8
|
+
require "redd/thing/messageable"
|
9
|
+
|
10
|
+
include Redd::Thing::Messageable
|
11
|
+
|
8
12
|
attr_reader :display_name
|
9
13
|
attr_reader :title
|
10
14
|
|
data/lib/redd/object/user.rb
CHANGED
@@ -0,0 +1,19 @@
|
|
1
|
+
require "redd/thing"
|
2
|
+
|
3
|
+
module Redd
|
4
|
+
class Thing
|
5
|
+
module Inboxable
|
6
|
+
def mark_as_read
|
7
|
+
client.mark_as_read(self)
|
8
|
+
end
|
9
|
+
|
10
|
+
def mark_as_unread
|
11
|
+
client.mark_as_unread(self)
|
12
|
+
end
|
13
|
+
|
14
|
+
def reply(text)
|
15
|
+
client.add_comment(self, text)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require "redd/thing"
|
2
|
+
|
3
|
+
module Redd
|
4
|
+
class Thing
|
5
|
+
module Messageable
|
6
|
+
def send_message(subject, text, captcha = nil, identifier = nil)
|
7
|
+
to = case self
|
8
|
+
when Redd::Object::Subreddit
|
9
|
+
"/r/" + display_name
|
10
|
+
when Redd::Object::User
|
11
|
+
name
|
12
|
+
end
|
13
|
+
|
14
|
+
client.send_message(to, subject, text, captcha, identifier)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require "redd/thing"
|
2
|
+
|
3
|
+
module Redd
|
4
|
+
class Thing
|
5
|
+
module Moderatable
|
6
|
+
def approve
|
7
|
+
client.approve(self)
|
8
|
+
end
|
9
|
+
|
10
|
+
def remove
|
11
|
+
client.remove(self)
|
12
|
+
end
|
13
|
+
|
14
|
+
def distinguish(how = :yes)
|
15
|
+
client.distinguish(self, how)
|
16
|
+
end
|
17
|
+
|
18
|
+
def undistinguish
|
19
|
+
client.undistinguish(self)
|
20
|
+
end
|
21
|
+
|
22
|
+
def ignore_reports
|
23
|
+
client.ignore_reports(self)
|
24
|
+
end
|
25
|
+
|
26
|
+
def unignore_reports
|
27
|
+
client.unignore_reports(self)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require "redd/thing"
|
2
|
+
|
3
|
+
module Redd
|
4
|
+
class Thing
|
5
|
+
module Voteable
|
6
|
+
def upvote
|
7
|
+
client.upvote(self)
|
8
|
+
end
|
9
|
+
|
10
|
+
def downvote
|
11
|
+
client.upvote(self)
|
12
|
+
end
|
13
|
+
|
14
|
+
def unvote
|
15
|
+
client.upvote(self)
|
16
|
+
end
|
17
|
+
|
18
|
+
alias_method :clear_vote, :unvote
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
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.
|
4
|
+
version: 0.3.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-
|
11
|
+
date: 2014-08-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -210,6 +210,14 @@ files:
|
|
210
210
|
- lib/redd/response/parse_json.rb
|
211
211
|
- lib/redd/response/raise_error.rb
|
212
212
|
- lib/redd/thing.rb
|
213
|
+
- lib/redd/thing/editable.rb
|
214
|
+
- lib/redd/thing/hideable.rb
|
215
|
+
- lib/redd/thing/inboxable.rb
|
216
|
+
- lib/redd/thing/messageable.rb
|
217
|
+
- lib/redd/thing/moderatable.rb
|
218
|
+
- lib/redd/thing/reportable.rb
|
219
|
+
- lib/redd/thing/saveable.rb
|
220
|
+
- lib/redd/thing/voteable.rb
|
213
221
|
- lib/redd/version.rb
|
214
222
|
- redd.gemspec
|
215
223
|
- spec/redd/client/unauthenticated_spec.rb
|