redd 0.6.2 → 0.6.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +5 -10
  3. data/.rspec +1 -1
  4. data/README.md +2 -0
  5. data/Rakefile +0 -4
  6. data/lib/redd/client/unauthenticated.rb +2 -0
  7. data/lib/redd/client/unauthenticated/captcha.rb +1 -1
  8. data/lib/redd/client/unauthenticated/listing.rb +1 -2
  9. data/lib/redd/client/unauthenticated/subreddits.rb +2 -3
  10. data/lib/redd/client/unauthenticated/users.rb +66 -0
  11. data/lib/redd/version.rb +1 -1
  12. data/redd.gemspec +1 -3
  13. data/spec/README.md +18 -0
  14. data/spec/redd/base_spec.rb +36 -0
  15. data/spec/redd/client/authenticated/account_spec.rb +5 -0
  16. data/spec/redd/client/authenticated/apps_spec.rb +2 -0
  17. data/spec/redd/client/authenticated/flair_spec.rb +26 -0
  18. data/spec/redd/client/authenticated/gold_spec.rb +2 -0
  19. data/spec/redd/client/authenticated/links_comments_spec.rb +231 -0
  20. data/spec/redd/client/authenticated/live_spec.rb +2 -0
  21. data/spec/redd/client/unauthenticated/account_spec.rb +15 -0
  22. data/spec/redd/client/unauthenticated/captcha_spec.rb +23 -0
  23. data/spec/redd/client/unauthenticated/links_comments_spec.rb +28 -0
  24. data/spec/redd/client/unauthenticated/listing_spec.rb +23 -0
  25. data/spec/redd/client/unauthenticated/live_spec.rb +2 -0
  26. data/spec/redd/client/unauthenticated/moderation_spec.rb +14 -0
  27. data/spec/redd/client/unauthenticated/subreddits_spec.rb +35 -0
  28. data/spec/redd/client/unauthenticated/users_spec.rb +34 -0
  29. data/spec/redd/client/unauthenticated/wiki_spec.rb +18 -0
  30. data/spec/redd/oauth2_access_spec.rb +83 -0
  31. data/spec/redd/thing_spec.rb +22 -0
  32. data/spec/spec_helper.rb +16 -0
  33. metadata +41 -32
  34. data/spec/redd/client/unauthenticated_spec.rb +0 -15
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f1c9095dc0fc6208e07728e40a724e40a0c0a24d
4
- data.tar.gz: 7a752d0341708cbd837e1ae23e486aaa6c29f468
3
+ metadata.gz: 0369bfc4c491d26f3330c1644d9f5724d9ad583a
4
+ data.tar.gz: 3b3507c642e26bc6b7817965c1fcdfb1f4fde177
5
5
  SHA512:
6
- metadata.gz: 56bc149cb63a27a6bd6531f85a4ad56491dd888270cc70963d82cfd748445641e9d404bbea4cc0100dd673800d14fec1b5edcd5311e456ddf77854a271436574
7
- data.tar.gz: 490cc65032031f6d0ed56b69eeef554773865b5503a47bae20ffea12bd8314b083ffbb43b537e8650a749b241e6f6b58721cb38968dc9b01c6cd3f07dbccbbd3
6
+ metadata.gz: 5bcc787430010a207c9375df1d7a3be3f9689e3bd116cadb7aa4123141776271b3db74ede823c484e502128cfc75fdd53a428dc7286c8815f73e579b40673844
7
+ data.tar.gz: 117dbdf5f5e4fc0fa5d93055a3bde0136d7bbc6e29dcc2aa1d972bb9c496911671e03eb8eab1833137f18346b48c1d73cd07741dc4375ac20a8b3d00c86a8b03
data/.gitignore CHANGED
@@ -9,15 +9,6 @@
9
9
  /test/version_tmp/
10
10
  /tmp/
11
11
 
12
- ## Working on Codio!
13
- # Seriously, it's free and it's awesome.
14
- .codio
15
-
16
- ## Specific to RubyMotion:
17
- .dat*
18
- .repl_history
19
- build/
20
-
21
12
  ## Documentation cache and generated files:
22
13
  /.yardoc/
23
14
  /_yardoc/
@@ -35,4 +26,8 @@ Gemfile.lock
35
26
  .ruby-gemset
36
27
 
37
28
  # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
38
- .rvmrc
29
+ .rvmrc
30
+
31
+ # Ignore VCR cassettes. It helps for testing quickly, but we want to test
32
+ # against the latest API.
33
+ /spec/cassettes
data/.rspec CHANGED
@@ -1,4 +1,4 @@
1
1
  --color
2
- --warnings
3
2
  --format documentation
3
+ --no-profile
4
4
  --require spec_helper
data/README.md CHANGED
@@ -221,6 +221,8 @@ Extending any ruby library, including redd is incredibly easy. Let's try this ou
221
221
  ## Contributing
222
222
  [Fork the repository](https://github.com/avidw/redd/fork), [create a pull request](https://github.com/avidw/redd/compare) and [go nuts](https://i.imgur.com/lz7hOlC.jpg).
223
223
 
224
+ *You don't have to run the tests, Travis CI will automatically do that with my testing subreddit and account when you submit a pull request.*
225
+
224
226
  ## Supported Rubies
225
227
  This gem aims to work on the following rubies:
226
228
 
data/Rakefile CHANGED
@@ -1,10 +1,6 @@
1
1
  require "bundler/gem_tasks"
2
2
  require "rspec/core/rake_task"
3
- require "rubocop/rake_task"
4
- require "yard"
5
3
 
6
4
  RSpec::Core::RakeTask.new
7
- RuboCop::RakeTask.new
8
- YARD::Rake::YardocTask.new
9
5
 
10
6
  task default: :spec
@@ -16,6 +16,7 @@ module Redd
16
16
  require "redd/client/unauthenticated/moderation"
17
17
  require "redd/client/unauthenticated/subreddits"
18
18
  require "redd/client/unauthenticated/utilities"
19
+ require "redd/client/unauthenticated/users"
19
20
  require "redd/client/unauthenticated/wiki"
20
21
 
21
22
  include Redd::Client::Unauthenticated::Account
@@ -26,6 +27,7 @@ module Redd
26
27
  include Redd::Client::Unauthenticated::Moderation
27
28
  include Redd::Client::Unauthenticated::Subreddits
28
29
  include Redd::Client::Unauthenticated::Utilities
30
+ include Redd::Client::Unauthenticated::Users
29
31
  include Redd::Client::Unauthenticated::Wiki
30
32
 
31
33
  # @!attribute [r] api_endpoint
@@ -12,7 +12,7 @@ module Redd
12
12
  # Create a new captcha identifier.
13
13
  # @return [String] The identifier.
14
14
  def new_captcha
15
- response = get "/api/new_captcha", api_type: "json"
15
+ response = post "/api/new_captcha", api_type: "json"
16
16
  response[:json][:data][:iden]
17
17
  end
18
18
 
@@ -13,7 +13,6 @@ module Redd
13
13
 
14
14
  # @!method get_hot
15
15
  # @!method get_new
16
- # @!method get_random
17
16
  # @!method get_top
18
17
  # @!method get_controversial
19
18
  # @!method get_comments
@@ -23,7 +22,7 @@ module Redd
23
22
  # @param params [Hash] A list of params to send with the request.
24
23
  #
25
24
  # @see #get_listing
26
- %w(hot new random top controversial comments).each do |sort|
25
+ %w(hot new top controversial comments).each do |sort|
27
26
  define_method :"get_#{sort}" do |subreddit = nil, params = {}|
28
27
  get_listing(sort, subreddit, params)
29
28
  end
@@ -11,8 +11,7 @@ module Redd
11
11
  end
12
12
 
13
13
  # Get a list of subreddits sorted by the given parameter.
14
- # @param where [:subscriber, :contributor, :moderator, :popular, :new]
15
- # The type of subreddits to look for.
14
+ # @param where [:popular, :new] The type of subreddits to look for.
16
15
  # @param params [Hash] A hash of parameters to send with the request.
17
16
  # @option params [String] :after Return results after the given
18
17
  # fullname.
@@ -41,7 +40,7 @@ module Redd
41
40
  # return.
42
41
  # @return [Redd::Object::Listing] A listing of subreddits.
43
42
  def search_subreddits(query, params = {})
44
- params << {q: query}
43
+ params[:q] = query
45
44
  object_from_response :get, "/subreddits/search.json", params
46
45
  end
47
46
  end
@@ -0,0 +1,66 @@
1
+ module Redd
2
+ module Client
3
+ class Unauthenticated
4
+ # Methods to interact with other redditors
5
+ module Users
6
+ # Return a User object from the username of a redditor.
7
+ # @param username [String] The username.
8
+ # @return [Redd::Object::User]
9
+ def user(username)
10
+ object_from_response :get, "/user/#{username}/about.json"
11
+ end
12
+
13
+ # @!method get_user_overview
14
+ # @!method get_user_submitted
15
+ # @!method get_user_comments
16
+ # @!method get_user_liked
17
+ # @!method get_user_disliked
18
+ # @!method get_user_hidden
19
+ # @!method get_user_saved
20
+ # @!method get_user_gilded
21
+ #
22
+ # Get the appropriate listing.
23
+ # @param user [Redd::Object::User] The user to query.
24
+ # @param params [Hash] A list of params to send with the request.
25
+ #
26
+ # @see #get_user_listing
27
+ %w(
28
+ overview submitted comments liked disliked hidden saved gilded
29
+ ).each do |sort|
30
+ define_method :"get_user_#{sort}" do |user, params = {}|
31
+ get_user_listing(user, sort, params)
32
+ end
33
+ end
34
+
35
+ private
36
+
37
+ # Get comments and submissions related to a user.
38
+ #
39
+ # @param user [Redd::Object::User, String] The user to query.
40
+ # @param type [:overview, :submitted, :comments, :liked, :disliked,
41
+ # :hidden, :saved, :gilded] The type of listing to return.
42
+ # @param params [Hash] A list of params to send with the request.
43
+ # @option params [String] :after Return results after the given
44
+ # fullname.
45
+ # @option params [String] :before Return results before the given
46
+ # fullname.
47
+ # @option params [Integer] :count (0) The number of items already seen
48
+ # in the listing.
49
+ # @option params [1..100] :limit (25) The maximum number of things to
50
+ # return.
51
+ # @option params [:hot, :new, :top, :controversial] :sort The order to
52
+ # sort the results by.
53
+ # @option params [:hour, :day, :week, :month, :year, :all] :t The
54
+ # time period to consider when sorting.
55
+ # @return [Redd::Object::Listing] A listing of submissions or comments.
56
+ def get_user_listing(user, type, params = {})
57
+ name = extract_attribute(user, :name)
58
+ path = "/user/#{name}/#{type}.json"
59
+ params[:show] ||= :given
60
+
61
+ object_from_response :get, path, params
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
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.6.2"
4
+ VERSION = "0.6.3"
5
5
  end
data/redd.gemspec CHANGED
@@ -18,10 +18,8 @@ Gem::Specification.new do |s|
18
18
  s.test_files = s.files.grep(/^(test|spec|features)\//)
19
19
  s.require_paths = ["lib"]
20
20
 
21
- s.add_development_dependency "bundler", "~> 1.6"
22
- s.add_development_dependency "rubocop"
21
+ s.add_development_dependency "bundler"
23
22
  s.add_development_dependency "rake"
24
- s.add_development_dependency "yard"
25
23
  s.add_development_dependency "rspec"
26
24
  s.add_development_dependency "vcr"
27
25
  s.add_development_dependency "webmock"
data/spec/README.md ADDED
@@ -0,0 +1,18 @@
1
+ ## Setting up the testing environment on reddit
2
+
3
+ # Create a subreddit for testing.
4
+ $ export REDDIT_SUBREDDIT=redd_testing
5
+
6
+ # Create an account for testing. You can use your reddit account.
7
+ $ export REDDIT_USERNAME=redd-testing
8
+ $ export REDDIT_PASSWORD=????????
9
+
10
+ # Create an example post on the subreddit
11
+ $ export REDDIT_LINKID=t3_2gngbm
12
+
13
+ # Create a page on the wiki with the following name
14
+ # Remember to make the wiki set to "mod editing"
15
+ $ export REDDIT_WIKIPAGE=redd_wiki_test
16
+
17
+ # Grab a sandwich or something. The tests are rate-limited.
18
+ $ rspec
@@ -0,0 +1,36 @@
1
+ describe Redd::Base do
2
+ before do
3
+ stub_const "ReddObject", Class.new(Redd::Base)
4
+ ReddObject.attr_reader :string
5
+ ReddObject.attr_reader :condition
6
+ ReddObject.attr_reader :nonexistent
7
+ end
8
+
9
+ let(:base) do
10
+ client = Redd::Client::Unauthenticated.new
11
+ object = {
12
+ kind: "test_object",
13
+ data: {
14
+ string: "test", condition: true,
15
+ nonexistent: nil, undocumented: :accessible
16
+ }
17
+ }
18
+ ReddObject.new(client, object)
19
+ end
20
+
21
+ it "defines an attribute method" do
22
+ expect(base.string).to eq("test")
23
+ expect(base.condition).to eq(true)
24
+ expect(base.nonexistent).to eq(nil)
25
+ end
26
+
27
+ it "defines a predicate method" do
28
+ expect(base.string?).to eq(true)
29
+ expect(base.condition?).to eq(true)
30
+ expect(base.nonexistent?).to eq(false)
31
+ end
32
+
33
+ it "returns undocumented attributes via #attributes" do
34
+ expect(base.attributes[:undocumented]).to eq(:accessible)
35
+ end
36
+ end
@@ -0,0 +1,5 @@
1
+ describe Redd::Client::Authenticated::Account do
2
+ describe "#me" do
3
+ it "returns the current user"
4
+ end
5
+ end
@@ -0,0 +1,2 @@
1
+ describe Redd::Client::Authenticated::Apps do
2
+ end
@@ -0,0 +1,26 @@
1
+ describe Redd::Client::Authenticated::Flair do
2
+ describe "#get_flair_list" do
3
+ it "returns an array"
4
+
5
+ context "when the limit is set to 5" do
6
+ it "only returns 5 results"
7
+ end
8
+ end
9
+
10
+ describe "#get_flair" do
11
+ before do
12
+ # set a random flair
13
+ end
14
+
15
+ it "returns the correct flair of the user"
16
+
17
+ after do
18
+ # unset the flair? "if it's random each time, there's no point
19
+ end
20
+ end
21
+
22
+ describe "#set_flair" do
23
+ it "sets the flair of a user correctly"
24
+ it "sets the flair of a link correctly"
25
+ end
26
+ end
@@ -0,0 +1,2 @@
1
+ describe Redd::Client::Authenticated::Gold do
2
+ end
@@ -0,0 +1,231 @@
1
+ describe Redd::Client::Authenticated::LinksComments do
2
+ describe "#submit" do
3
+ before do
4
+ # create the posts
5
+ end
6
+
7
+ it "submits a text post correctly"
8
+ it "submits a link post correctly"
9
+
10
+ after do
11
+ # delete the posts?
12
+ end
13
+ end
14
+
15
+ describe "#add_comment" do
16
+ context "when commenting on a link" do
17
+ it "posts the comment correctly"
18
+ end
19
+
20
+ context "when replying to a comment" do
21
+ it "posts the reply correctly"
22
+ end
23
+
24
+ context "when replying to a message" do
25
+ it "replies to the message correctly"
26
+ end
27
+
28
+ after do
29
+ # delete the reply and the comment?
30
+ # we can't do anything for messages
31
+ end
32
+ end
33
+
34
+ describe "#delete" do
35
+ context "when deleting a comment" do
36
+ before do
37
+ # create a comment
38
+ end
39
+
40
+ it "deletes a comment successfully"
41
+ end
42
+
43
+ context "when deleting a link" do
44
+ before do
45
+ # create a link
46
+ end
47
+
48
+ it "deletes a link successfully"
49
+ end
50
+ end
51
+
52
+ describe "#edit" do
53
+ context "when editing a comment" do
54
+ before do
55
+ # create a comment
56
+ end
57
+
58
+ it "edits a comment successfully"
59
+
60
+ after do
61
+ # delete the comment
62
+ end
63
+ end
64
+
65
+ context "when editing a link" do
66
+ before do
67
+ # create a link
68
+ end
69
+
70
+ it "edits a link successfully"
71
+
72
+ after do
73
+ # delete the link
74
+ end
75
+ end
76
+ end
77
+
78
+ describe "#hide" do
79
+ before do
80
+ # create a link
81
+ end
82
+
83
+ it "hides a link successfully"
84
+
85
+ after do
86
+ # delete the link
87
+ end
88
+ end
89
+
90
+ describe "#unhide" do
91
+ before do
92
+ # create a link
93
+ end
94
+
95
+ it "unhides a link successfully"
96
+
97
+ after do
98
+ # delete the link
99
+ end
100
+ end
101
+
102
+ describe "#mark_as_nsfw" do
103
+ before do
104
+ # create a link
105
+ end
106
+
107
+ it "marks a link as NSFW successfully"
108
+
109
+ after do
110
+ # delete the link
111
+ end
112
+ end
113
+
114
+ describe "#unmark_as_nsfw" do
115
+ before do
116
+ # create a link
117
+ end
118
+
119
+ it "removes the NSFW mark from a link successfully"
120
+
121
+ after do
122
+ # delete the link
123
+ end
124
+ end
125
+
126
+ # Nobody's going to give my testing suite gold, are they?
127
+ describe "#save" do
128
+ before do
129
+ # create a link
130
+ end
131
+
132
+ it "saves the link successfully"
133
+
134
+ after do
135
+ # delete the link
136
+ end
137
+ end
138
+
139
+ describe "#unsave" do
140
+ before do
141
+ # create a link
142
+ end
143
+
144
+ it "unsaves the link successfully"
145
+
146
+ after do
147
+ # delete the link
148
+ end
149
+ end
150
+
151
+ describe "#upvote" do
152
+ context "when upvoting a comment" do
153
+ before do
154
+ # create a comment
155
+ end
156
+
157
+ # We can't always count on the score increasing
158
+ it "adds the comment to the user's liked list"
159
+
160
+ after do
161
+ # delete the comment
162
+ end
163
+ end
164
+
165
+ context "when upvoting a link" do
166
+ before do
167
+ # create a link
168
+ end
169
+
170
+ it "adds the link to the user's liked list"
171
+
172
+ after do
173
+ # delete the link
174
+ end
175
+ end
176
+ end
177
+
178
+ describe "#downvote" do
179
+ context "when downvoting a comment" do
180
+ before do
181
+ # create a comment
182
+ end
183
+
184
+ # We can't always count on the score increasing
185
+ it "adds the comment to the user's disliked list"
186
+
187
+ after do
188
+ # delete the comment
189
+ end
190
+ end
191
+
192
+ context "when downvoting a link" do
193
+ before do
194
+ # create a link
195
+ end
196
+
197
+ it "adds the link to the user's disliked list"
198
+
199
+ after do
200
+ # delete the link
201
+ end
202
+ end
203
+ end
204
+
205
+ describe "#unvote" do
206
+ context "when unvoting a comment" do
207
+ before do
208
+ # create a comment and like it
209
+ end
210
+
211
+ # We can't always count on the score increasing
212
+ it "removes the comment from the user's liked list"
213
+
214
+ after do
215
+ # delete the comment
216
+ end
217
+ end
218
+
219
+ context "when unvoting a link" do
220
+ before do
221
+ # create a link
222
+ end
223
+
224
+ it "removes the link from the user's liked list"
225
+
226
+ after do
227
+ # delete the link
228
+ end
229
+ end
230
+ end
231
+ end
@@ -0,0 +1,2 @@
1
+ describe Redd::Client::Authenticated::Live do
2
+ end
@@ -0,0 +1,15 @@
1
+ describe Redd::Client::Unauthenticated::Account do
2
+ describe "#login" do
3
+ let(:logged_in_client) do
4
+ unauthenticated_client.login(test_username, test_password)
5
+ end
6
+
7
+ it "returns an Authenticated client" do
8
+ expect(logged_in_client).to be_a(Redd::Client::Authenticated)
9
+ end
10
+
11
+ it "can be used to make requests" do
12
+ expect(logged_in_client.me[:name]).to match(/#{test_username}/i)
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,23 @@
1
+ require "uri"
2
+
3
+ describe Redd::Client::Unauthenticated::Captcha do
4
+ describe "#needs_captcha?" do
5
+ it "returns a boolean" do
6
+ expect(unauthenticated_client.needs_captcha?).to be(true).or be(false)
7
+ end
8
+ end
9
+
10
+ describe "#new_captcha" do
11
+ it "returns a string" do
12
+ expect(unauthenticated_client.new_captcha).to be_a(String)
13
+ end
14
+ end
15
+
16
+ describe "#captcha_url" do
17
+ it "returns a valid url" do
18
+ new_captcha = unauthenticated_client.new_captcha
19
+ captcha_url = unauthenticated_client.captcha_url(new_captcha)
20
+ expect(captcha_url).to match(URI::ABS_URI)
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,28 @@
1
+ describe Redd::Client::Unauthenticated::LinksComments do
2
+ describe "#get_info" do
3
+ let(:response) { unauthenticated_client.get_info(id: test_link_id) }
4
+
5
+ it "returns a listing" do
6
+ expect(response).to be_a(Redd::Object::Listing)
7
+ end
8
+
9
+ it "returns the correct objects" do
10
+ link = response.things.first
11
+ expect(link).to be_a(Redd::Object::Submission)
12
+ expect(link.fullname).to eq(test_link_id)
13
+ end
14
+ end
15
+
16
+ describe "#submission_comments" do
17
+ it "returns a listing of comments and morecomments only"
18
+ end
19
+
20
+ describe "#get_replies" do
21
+ it "returns a listing of comments and morecomments only"
22
+ end
23
+
24
+ describe "expand_morecomments" do
25
+ it "returns a listing of comments only"
26
+ it "returns the same number of comments as it indicated"
27
+ end
28
+ end
@@ -0,0 +1,23 @@
1
+ describe Redd::Client::Unauthenticated::Listing do
2
+ describe "#by_id" do
3
+ let(:response) { unauthenticated_client.by_id(test_link_id) }
4
+
5
+ it "returns a listing" do
6
+ expect(response).to be_a(Redd::Object::Listing)
7
+ end
8
+
9
+ it "returns the correct object" do
10
+ link = response.things.first
11
+ expect(link).to be_a(Redd::Object::Submission)
12
+ expect(link.fullname).to eq(test_link_id)
13
+ end
14
+ end
15
+
16
+ describe "#get_hot, #get_new, #get_op, #get_controversial" do
17
+ it "returns a listing of submissions only"
18
+ end
19
+
20
+ describe "#get_comments" do
21
+ it "returns a listing of comments only"
22
+ end
23
+ end
@@ -0,0 +1,2 @@
1
+ describe Redd::Client::Unauthenticated::Live do
2
+ end
@@ -0,0 +1,14 @@
1
+ require "uri"
2
+
3
+ describe Redd::Client::Unauthenticated::Moderation do
4
+ describe "#stylesheet_url" do
5
+ it "returns a valid url" do
6
+ url = unauthenticated_client.stylesheet_url(test_subreddit)
7
+ expect(url).to match(URI::ABS_URI)
8
+ end
9
+ end
10
+
11
+ describe "#stylesheet" do
12
+ it "returns valid CSS" # Yeah, nope.
13
+ end
14
+ end
@@ -0,0 +1,35 @@
1
+ describe Redd::Client::Unauthenticated::Subreddits do
2
+ describe "#subreddit" do
3
+ let(:subreddit) { unauthenticated_client.subreddit(test_subreddit) }
4
+
5
+ it "returns a subreddit object" do
6
+ expect(subreddit).to be_a(Redd::Object::Subreddit)
7
+ end
8
+
9
+ it "returns the correct subreddit" do
10
+ expect(subreddit.display_name).to eq(test_subreddit)
11
+ end
12
+ end
13
+
14
+ describe "#get_subreddits" do
15
+ let(:subreddits) { unauthenticated_client.get_subreddits }
16
+
17
+ it "returns a listing" do
18
+ expect(subreddits).to be_a(Redd::Object::Listing)
19
+ end
20
+
21
+ it "returns a listing of subreddits"
22
+ end
23
+
24
+ describe "#search_subreddits" do
25
+ let(:search) { unauthenticated_client.search_subreddits(test_subreddit) }
26
+
27
+ it "returns a listing" do
28
+ expect(search).to be_a(Redd::Object::Listing)
29
+ end
30
+
31
+ it "returns a listing of subreddits"
32
+
33
+ it "includes the subreddit searched for"
34
+ end
35
+ end
@@ -0,0 +1,34 @@
1
+ describe Redd::Client::Unauthenticated::Users do
2
+ describe "#user" do
3
+ let(:user) { unauthenticated_client.user(test_username) }
4
+
5
+ it "returns a user" do
6
+ expect(user).to be_a(Redd::Object::User)
7
+ end
8
+
9
+ it "returns the user requested" do
10
+ expect(user.name).to match(/#{test_username}/i)
11
+ end
12
+ end
13
+
14
+ describe "#get_user_overview" do
15
+ it "returns a listing"
16
+ it "contains content only created by the user"
17
+ end
18
+
19
+ describe "#get_user_submitted" do
20
+ it "returns a listing"
21
+ it "contains only submissions"
22
+ it "contains submissions only created by the user"
23
+ end
24
+
25
+ describe "#get_user_comments" do
26
+ it "returns a listing"
27
+ it "contains only comments"
28
+ it "contains comments only created by the user"
29
+ end
30
+
31
+ describe "#get_user_liked, #get_user_disliked, #get_user_hidden, #get_user_saved, #get_user_gilded" do
32
+ it "returns a listing"
33
+ end
34
+ end
@@ -0,0 +1,18 @@
1
+ describe Redd::Client::Unauthenticated::Wiki do
2
+ describe "#get_wikipages" do
3
+ let(:pages) { unauthenticated_client.get_wikipages(test_subreddit) }
4
+
5
+ it "returns an array of pages in the wiki" do
6
+ expect(pages).to be_an(Array)
7
+ expect(pages).to include(test_wikipage)
8
+ end
9
+ end
10
+
11
+ describe "#wikipage" do
12
+ let(:page) { unauthenticated_client.wikipage(test_wikipage, test_subreddit) }
13
+
14
+ it "returns a wikipage" do
15
+ expect(page).to be_a(Redd::Object::WikiPage)
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,83 @@
1
+ require "json"
2
+
3
+ describe Redd::OAuth2Access do
4
+
5
+ # TODO: Use the password grant with a future OAuth2Stript Client for more
6
+ # for more accurate responses.
7
+ let(:access) do
8
+ Redd::OAuth2Access.new(
9
+ access_token: "TEST_ACCESS_TOKEN",
10
+ refresh_token: "TEST_REFRESH_TOKEN",
11
+ scope: "identity,TEST_SCOPE",
12
+ expires_in: 3600
13
+ )
14
+ end
15
+
16
+ it "has an accessible access token" do
17
+ expect(access.access_token).to be_a(String)
18
+ end
19
+
20
+ it "has an accessible duration" do
21
+ expect(access.duration).to eq(:temporary).or eq(:permanent)
22
+ end
23
+
24
+ it "has an array of scopes" do
25
+ expect(access.scope).to be_an(Array)
26
+ end
27
+
28
+ it "shows the correct time of expiry" do
29
+ expect(access.expires_at).to be_within(60).of(Time.now + 3600)
30
+ end
31
+
32
+ describe "#refresh" do
33
+ let(:refreshed_access) { access.dup }
34
+ let(:new_access_token) { "NEW_ACCESS_TOKEN" }
35
+ let(:new_expires_in) { 1600 }
36
+
37
+ before do
38
+ response = {access_token: new_access_token, expires_in: new_expires_in}
39
+ refreshed_access.refresh(response)
40
+ end
41
+
42
+ it "sets the new access token" do
43
+ expect(refreshed_access.access_token).to eq(new_access_token)
44
+ end
45
+
46
+ it "sets the new expiry time" do
47
+ expect(refreshed_access.expires_at).to be_within(60).of(Time.now + new_expires_in)
48
+ end
49
+ end
50
+
51
+ describe "#expired?" do
52
+ context "when the access token isn't expired" do
53
+ it "returns false"
54
+ end
55
+
56
+ context "when the access token is expired" do
57
+ it "returns true"
58
+ end
59
+ end
60
+
61
+ describe "#to_json" do
62
+ let(:json_str) { access.to_json }
63
+
64
+ it "transcribes to valid json" do
65
+ expect(JSON.parse(json_str)).to be_a(Hash)
66
+ end
67
+ end
68
+
69
+ describe "#from_json" do
70
+ let(:object) do
71
+ json = access.to_json
72
+ Redd::OAuth2Access.from_json(json)
73
+ end
74
+
75
+ it "creates a proper object from a JSON string" do
76
+ expect(object.access_token).to eq(access.access_token)
77
+ expect(object.refresh_token).to eq(access.refresh_token)
78
+ expect(object.scope).to eq(access.scope)
79
+ expect(object.duration).to eq(access.duration)
80
+ expect(object.expires_at).to be_within(60).of(access.expires_at)
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,22 @@
1
+ describe Redd::Thing do
2
+ before do
3
+ stub_const "ReddThing", Class.new(Redd::Thing)
4
+ ReddThing.attr_reader :string
5
+ ReddThing.attr_reader :condition
6
+ ReddThing.attr_reader :nonexistent
7
+ end
8
+
9
+ let(:thing) do
10
+ client = Redd::Client::Unauthenticated.new
11
+ object = {kind: "tx", data: {id: "abc123"}}
12
+ ReddThing.new(client, object)
13
+ end
14
+
15
+ it "has a kind" do
16
+ expect(thing.kind).to be_a(String)
17
+ end
18
+
19
+ it "has an id" do
20
+ expect(thing.id).to be_a(String)
21
+ end
22
+ end
data/spec/spec_helper.rb CHANGED
@@ -4,10 +4,26 @@ require "vcr"
4
4
 
5
5
  require "redd"
6
6
 
7
+ def test_username; ENV["REDDIT_USERNAME"]; end
8
+ def test_password; ENV["REDDIT_PASSWORD"]; end
9
+ def test_subreddit; ENV["REDDIT_SUBREDDIT"]; end
10
+
11
+ def test_link_id; ENV["REDDIT_LINKID"] || "t3_2gngbm"; end
12
+ def test_wikipage; ENV["REDDIT_WIKIPAGE"] || "redd_wiki_test"; end
13
+
14
+ def unauthenticated_client
15
+ $unauthenticated_client ||= Redd::Client::Unauthenticated.new
16
+ end
17
+
18
+ def authenticated_client
19
+ $authenticated_client ||= Redd::Client::Authenticated.new_from_credentials(test_username, test_password)
20
+ end
21
+
7
22
  VCR.configure do |config|
8
23
  config.cassette_library_dir = "spec/cassettes"
9
24
  config.default_cassette_options = {record: :new_episodes}
10
25
  config.hook_into :webmock
26
+ config.filter_sensitive_data("<PASSWORD>") { test_password }
11
27
  end
12
28
 
13
29
  RSpec.configure do |config|
metadata CHANGED
@@ -1,31 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redd
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.2
4
+ version: 0.6.3
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-15 00:00:00.000000000 Z
11
+ date: 2014-09-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ~>
18
- - !ruby/object:Gem::Version
19
- version: '1.6'
20
- type: :development
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ~>
25
- - !ruby/object:Gem::Version
26
- version: '1.6'
27
- - !ruby/object:Gem::Dependency
28
- name: rubocop
29
15
  requirement: !ruby/object:Gem::Requirement
30
16
  requirements:
31
17
  - - '>='
@@ -52,20 +38,6 @@ dependencies:
52
38
  - - '>='
53
39
  - !ruby/object:Gem::Version
54
40
  version: '0'
55
- - !ruby/object:Gem::Dependency
56
- name: yard
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - '>='
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - '>='
67
- - !ruby/object:Gem::Version
68
- version: '0'
69
41
  - !ruby/object:Gem::Dependency
70
42
  name: rspec
71
43
  requirement: !ruby/object:Gem::Requirement
@@ -207,6 +179,7 @@ files:
207
179
  - lib/redd/client/unauthenticated/live.rb
208
180
  - lib/redd/client/unauthenticated/moderation.rb
209
181
  - lib/redd/client/unauthenticated/subreddits.rb
182
+ - lib/redd/client/unauthenticated/users.rb
210
183
  - lib/redd/client/unauthenticated/utilities.rb
211
184
  - lib/redd/client/unauthenticated/wiki.rb
212
185
  - lib/redd/error.rb
@@ -234,8 +207,26 @@ files:
234
207
  - lib/redd/thing/voteable.rb
235
208
  - lib/redd/version.rb
236
209
  - redd.gemspec
237
- - spec/redd/client/unauthenticated_spec.rb
210
+ - spec/README.md
211
+ - spec/redd/base_spec.rb
212
+ - spec/redd/client/authenticated/account_spec.rb
213
+ - spec/redd/client/authenticated/apps_spec.rb
214
+ - spec/redd/client/authenticated/flair_spec.rb
215
+ - spec/redd/client/authenticated/gold_spec.rb
216
+ - spec/redd/client/authenticated/links_comments_spec.rb
217
+ - spec/redd/client/authenticated/live_spec.rb
218
+ - spec/redd/client/unauthenticated/account_spec.rb
219
+ - spec/redd/client/unauthenticated/captcha_spec.rb
220
+ - spec/redd/client/unauthenticated/links_comments_spec.rb
221
+ - spec/redd/client/unauthenticated/listing_spec.rb
222
+ - spec/redd/client/unauthenticated/live_spec.rb
223
+ - spec/redd/client/unauthenticated/moderation_spec.rb
224
+ - spec/redd/client/unauthenticated/subreddits_spec.rb
225
+ - spec/redd/client/unauthenticated/users_spec.rb
226
+ - spec/redd/client/unauthenticated/wiki_spec.rb
227
+ - spec/redd/oauth2_access_spec.rb
238
228
  - spec/redd/rate_limit_spec.rb
229
+ - spec/redd/thing_spec.rb
239
230
  - spec/redd_spec.rb
240
231
  - spec/spec_helper.rb
241
232
  homepage: ''
@@ -263,8 +254,26 @@ signing_key:
263
254
  specification_version: 4
264
255
  summary: A Reddit API Wrapper for Ruby.
265
256
  test_files:
266
- - spec/redd/client/unauthenticated_spec.rb
257
+ - spec/README.md
258
+ - spec/redd/base_spec.rb
259
+ - spec/redd/client/authenticated/account_spec.rb
260
+ - spec/redd/client/authenticated/apps_spec.rb
261
+ - spec/redd/client/authenticated/flair_spec.rb
262
+ - spec/redd/client/authenticated/gold_spec.rb
263
+ - spec/redd/client/authenticated/links_comments_spec.rb
264
+ - spec/redd/client/authenticated/live_spec.rb
265
+ - spec/redd/client/unauthenticated/account_spec.rb
266
+ - spec/redd/client/unauthenticated/captcha_spec.rb
267
+ - spec/redd/client/unauthenticated/links_comments_spec.rb
268
+ - spec/redd/client/unauthenticated/listing_spec.rb
269
+ - spec/redd/client/unauthenticated/live_spec.rb
270
+ - spec/redd/client/unauthenticated/moderation_spec.rb
271
+ - spec/redd/client/unauthenticated/subreddits_spec.rb
272
+ - spec/redd/client/unauthenticated/users_spec.rb
273
+ - spec/redd/client/unauthenticated/wiki_spec.rb
274
+ - spec/redd/oauth2_access_spec.rb
267
275
  - spec/redd/rate_limit_spec.rb
276
+ - spec/redd/thing_spec.rb
268
277
  - spec/redd_spec.rb
269
278
  - spec/spec_helper.rb
270
279
  has_rdoc:
@@ -1,15 +0,0 @@
1
- describe Redd::Client::Unauthenticated, :vcr do
2
- let(:client) { Redd::Client::Unauthenticated.new }
3
-
4
- it "has configurable options" do
5
- newclient = Redd::Client::Unauthenticated.new(
6
- rate_limit: "SPEC_RATELIMIT",
7
- user_agent: "SPEC_USERAGENT",
8
- api_endpoint: "SPEC_ENDPOINT.COM"
9
- )
10
-
11
- expect(newclient.rate_limit).to eq("SPEC_RATELIMIT")
12
- expect(newclient.user_agent).to eq("SPEC_USERAGENT")
13
- expect(newclient.api_endpoint).to eq("SPEC_ENDPOINT.COM")
14
- end
15
- end