redd 0.2.0 → 0.3.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cabe1bab129d4622fc26a19bea40fcbf27a676f4
4
- data.tar.gz: 00a8d3c241c58c0ed449a1002e5e4ae3fb936093
3
+ metadata.gz: ea1e887784c57e6c3bef623557618c0b2cf85b6f
4
+ data.tar.gz: a0c3e6e653857d9f10d5915d433866b166d436da
5
5
  SHA512:
6
- metadata.gz: 1275d0cba8f74d11d17b0bdb2644cfb4fcfa982fcc8597e665c505bcfc2252f990a6ecdbdc26d4f4671aef012353997428fac1845319b0ecc703bf673e364354
7
- data.tar.gz: 5f21e8de382d108263b1fda22fd833e5862d0d214c9e54ab64f0b153a560185685326688571304120aeeb2e0484ca8627ce3d8505d219789dc0de6c7943827a5
6
+ metadata.gz: 7cd3dc27fe73b93382f5a2cb651d391fc6dd6fc43e2257871419c77703d1b070c7fd7e561e29724f54c7736d7340860866ee0b05b0c10f39f666cb32a7ed2f3e
7
+ data.tar.gz: 9ae7e3b594a3f4db301623737e63f9771a71f3c9663ccd2a9ccbc9e1965f95a2dcf0c5c5d989432ac7614284b08d74f4ea74cb96068db39a0d28f45161be4915
@@ -99,6 +99,8 @@ module Redd
99
99
  vote(thing, 0)
100
100
  end
101
101
 
102
+ alias_method :clear_vote, :unvote
103
+
102
104
  private
103
105
 
104
106
  def vote(thing, direction)
@@ -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
- # @return [Hash] The headers that are sent with every request.
66
- def headers
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
- @access_token = response.body[:access_token] if set_token
26
- response.body
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
@@ -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
@@ -3,6 +3,10 @@ require "redd/thing"
3
3
  module Redd
4
4
  module Object
5
5
  class PrivateMessage < Redd::Thing
6
+ require "redd/thing/inboxable"
7
+
8
+ include Redd::Thing::Inboxable
9
+
6
10
  attr_reader :created_utc
7
11
  attr_reader :body
8
12
  attr_reader :body_html
@@ -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
 
@@ -3,6 +3,10 @@ require "redd/thing"
3
3
  module Redd
4
4
  module Object
5
5
  class User < Redd::Thing
6
+ require "redd/thing/messageable"
7
+
8
+ include Redd::Thing::Messageable
9
+
6
10
  attr_reader :created_utc
7
11
  attr_reader :name
8
12
  attr_reader :is_friend
@@ -0,0 +1,15 @@
1
+ require "redd/thing"
2
+
3
+ module Redd
4
+ class Thing
5
+ module Editable
6
+ def delete
7
+ client.delete(self)
8
+ end
9
+
10
+ def edit(text)
11
+ client.edit(self, text)
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ require "redd/thing"
2
+
3
+ module Redd
4
+ class Thing
5
+ module Hideable
6
+ def hide
7
+ client.hide(self)
8
+ end
9
+
10
+ def unhide
11
+ client.unhide(self)
12
+ end
13
+ end
14
+ end
15
+ end
@@ -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,11 @@
1
+ require "redd/thing"
2
+
3
+ module Redd
4
+ class Thing
5
+ module Reportable
6
+ def report
7
+ client.report(self)
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,15 @@
1
+ require "redd/thing"
2
+
3
+ module Redd
4
+ class Thing
5
+ module Saveable
6
+ def save(category = nil)
7
+ client.save(self, category)
8
+ end
9
+
10
+ def unsave
11
+ client.unsave(self)
12
+ end
13
+ end
14
+ end
15
+ 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
@@ -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.2.0"
4
+ VERSION = "0.3.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.2.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-09 00:00:00.000000000 Z
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